Skip to content

Some useful gdb commands for debugging Scryer Prolog

Mark Thom edited this page Mar 13, 2024 · 4 revisions

These work in the present Rust release (1.76) with stable-gnu set to the default in rustup. I have them in my .gdbinit to load them automatically upon starting rust-gdb. They’ll of course break as the underlying Rust APIs shift with new Rust releases, but that is the reason for posting them here.

define print-rust-string
  printf "%s\n", $arg0.vec.buf.ptr.pointer.pointer
end

define cell-tag
  print $arg0.get_tag()
end

define cell-value
  print $arg0.get_value()
end

define index-cell
  print *($arg0.buf.ptr.pointer.pointer + $arg1)
end

define print-scryer-atom
  set $atom_table = scryer_prolog::atom_table::global_atom_table::GLOBAL_ATOM_TABLE
  set $inner_tbl  = $atom_table.value.value.value.value.data.value.ptr.pointer.data.inner.active_value.p.value
  set $block_base = $inner_tbl.block.base
  # 16 bytes is the size of &str on 64-bit machines, which are fat pointers
  set $STRINGS_len = sizeof(scryer_prolog::atom_table::STRINGS) / 16
  set $atom_idx = $arg0.index >> 3

  if $atom_idx < $STRINGS_len
    printf "%s\n", scryer_prolog::atom_table::STRINGS[$atom_idx]
  else
    printf "%s\n", $block_base + ($atom_idx - $STRINGS_len) * 8 + 8
  end
end
Clone this wiki locally