In Jonesforth, a dictionary entry is laid out as follows:

<--- DICTIONARY ENTRY (HEADER) -----------------------> +------------------------+--------+---------- - - - - +----------- - - - - | LINK POINTER | LENGTH/| NAME | DEFINITION | | FLAGS | | +--- (4 bytes) ----------+- byte -+- n bytes - - - - +----------- - - - -

We can take a peek at one of these entries using GDB. (See this question for details on using GDB with Jonesforth.)

Let's display the first 16 bytes of the dictionary entry for SWAP as characters:

>>> x/16cb &name_SWAP 0x105cc: -68 '\274' 5 '\005' 1 '\001' 0 '\000' 4 '\004' 83 'S' 87 'W' 65 'A' 0x105d4: 80 'P' 0 '\000' 0 '\000' 0 '\000' 43 '+' 0 '\000' 1 '\001' 0 '\000'

You can kind of see what's going on here.

The first four bytes are the pointer to the previous word in the dictionary:

-68 '\274' 5 '\005' 1 '\001' 0 '\000'

Then comes the length of the name:

4 '\004'

Then we see the characters of the word name, "SWAP":

83 'S' 87 'W' 65 'A' 80 'P'

And finally some padding to align on a 32-bit boundary:

0 '\000' 0 '\000' 0 '\000'

It would be nice if there was a way to format the word entry in a nicer manner.

If we do the following:

>>> x/1xw &name_SWAP 0x105cc: 0x000105bc

we note that name_SWAP is at 0x105cc .

Let's use GDB's printf to display the word entry:

>>> printf "link: %#010x name length: %i name: %s

", *(0x105cc), (char)*(0x105cc+4), (0x105cc+5) link: 0x000105bc name length: 4 name: SWAP

OK, that's not bad! We see the link, the name length, and name, all nicely displayed and labeled.

The downside here is that I have to use the explicit address in the call to printf :

printf "link: %#010x name length: %i name: %s

", *(0x105cc), (char)*(0x105cc+4), (0x105cc+5)

Ideally, I'd just be able to say something like:

show_forth_word name_SWAP

and it'd display the above.

What's the best way to go about this? Is this doable with a GDB user-defined command? Or is it something more appropriate for the GDB Python interface?