-
Notifications
You must be signed in to change notification settings - Fork 3
Diagramming C types using j2
Jason Nyberg edited this page May 11, 2018
·
5 revisions
The j2 system can read and comprehend Dwarf information; As a debugging feature, it can also dump items you select in the form of the "dot" language, which allows the type information hierarchy to be displayed in graphical form. The "stack" function, which displays items on the interpreter's top layer of stack, also dumps these items out to /tmp/VMRES_STACK.dot.
To diagram an item, all that's needed is to reference it by name (if it's not already on the stack), and then invoke the stack function with, "stack!" (which references the function "stack" by name, and then evaluates it via the "!" operator.)
A complete sample session demonstrating this:
jnyberg@jnyberg-debian8:~/j2$ make
cd build && cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jnyberg/j2/build
make -C build
make[1]: Entering directory '/home/jnyberg/j2/build'
make[2]: Entering directory '/home/jnyberg/j2/build'
make[3]: Entering directory '/home/jnyberg/j2/build'
make[3]: Leaving directory '/home/jnyberg/j2/build'
[ 83%] Built target reflect
make[3]: Entering directory '/home/jnyberg/j2/build'
make[3]: Leaving directory '/home/jnyberg/j2/build'
[100%] Built target jj
make[2]: Leaving directory '/home/jnyberg/j2/build'
make[1]: Leaving directory '/home/jnyberg/j2/build'
MALLOC_CHECK=1 ./jj
reflection module path is: /home/jnyberg/j2/build/libreflect.so
opening dwarf2edict input file /home/jnyberg/j2/build/libreflect.so
initializing dwarf reader
reading cu list
finalizing dwarf reader
/home/jnyberg/j2/build/libreflect.so
"/home/jnyberg/j2/cll.c"
IMM 0xe15
"/home/jnyberg/j2/compile.c"
IMM 0x827d
"/home/jnyberg/j2/extensions.c"
IMM 0xa3a4
"/home/jnyberg/j2/listree.c"
IMM 0x1761
"/home/jnyberg/j2/reflect.c"
IMM 0x42e7
"/home/jnyberg/j2/trace.c"
IMM 0xb
"/home/jnyberg/j2/util.c"
IMM 0x28
"/home/jnyberg/j2/vm.c"
IMM 0x8bd9
traversing module type units
resolving type_unit alias references
traversing module compute units
linking symbolic names
closing shared library
cleaning up and linking types to pointers
traversing module
j2> loadlib([test/build/libtestlib.so]) @testlib
conflict for "char": DW_TAG_typedef (00000144) "(null)" vs. (installed) DW_TAG_base_type (000001e5) "char"
conflict for "int": DW_TAG_typedef (00000135) "(null)" vs. (installed) DW_TAG_base_type (000001c6) "int"
conflict for "unsigned int": DW_TAG_typedef (0000013a) "(null)" vs. (installed) DW_TAG_base_type (000001d7) "unsigned int"
conflict for "sizetype": DW_TAG_typedef (0000013f) "(null)" vs. (installed) DW_TAG_base_type (000001de) "sizetype"
conflict for "int": DW_TAG_typedef (00000193) "(null)" vs. (installed) DW_TAG_base_type (000001c6) "int"
j2> testlib.teststruct stack!
VMRES_STACK
<null>
TYPE_INFO 0000012a|typedef|base 000000b4|symbolic|info
"die base"
TYPE_INFO 000000b4|structure_type|bytesize 28|symbolic|info
"a"
TYPE_INFO 000000c0|member|base 000001e5|member loc 0x0|info
"die base"
TYPE_INFO 000001e5|base_type|bytesize 1|encoding 6|symbolic|info
"die meta"
TYPE_INFO 000002db|pointer_type|base 000001e5|bytesize 8|symbolic|info
"die base"
"die symb"
(char)*
"ffi type"
Flagged as FFI
"die symb"
char
"ffi type"
Flagged as FFI
"b"
TYPE_INFO 000000ca|member|base 000001c6|member loc 0x4|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
"die meta"
TYPE_INFO 00000283|pointer_type|base 000001c6|bytesize 8|symbolic|info
"die base"
"die symb"
(int)*
"ffi type"
Flagged as FFI
(subtree omitted...)
"die symb"
int
"ffi type"
Flagged as FFI
"c"
TYPE_INFO 000000d4|member|base 00000015|member loc 0x8|info
"die base"
TYPE_INFO 00000015|typedef|base 000001c6|symbolic|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
(subtree omitted...)
"die symb"
testint
"d"
TYPE_INFO 000000de|member|base 000001c6|bytesize 4|bitsize 1|bitoffset 31|member loc 0xc|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
(subtree omitted...)
"die list"
TYPE_INFO 000000c0|member|base 000001e5|member loc 0x0|info
(subtree omitted...)
TYPE_INFO 000000ca|member|base 000001c6|member loc 0x4|info
(subtree omitted...)
TYPE_INFO 000000d4|member|base 00000015|member loc 0x8|info
(subtree omitted...)
TYPE_INFO 000000de|member|base 000001c6|bytesize 4|bitsize 1|bitoffset 31|member loc 0xc|info
(subtree omitted...)
TYPE_INFO 000000eb|member|base 000001d7|bytesize 4|bitsize 2|bitoffset 29|member loc 0xc|info
"die base"
TYPE_INFO 000001d7|base_type|bytesize 4|encoding 7|symbolic|info
"die symb"
unsigned int
"ffi type"
Flagged as FFI
TYPE_INFO 000000f8|member|base 000001c6|bytesize 4|bitsize 4|bitoffset 25|member loc 0xc|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
(subtree omitted...)
TYPE_INFO 00000105|member|base 000001d7|bytesize 4|bitsize 8|bitoffset 17|member loc 0xc|info
"die base"
TYPE_INFO 000001d7|base_type|bytesize 4|encoding 7|symbolic|info
(subtree omitted...)
TYPE_INFO 00000112|member|base 000001c6|bytesize 4|bitsize 16|bitoffset 1|member loc 0xc|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
(subtree omitted...)
TYPE_INFO 0000011f|member|base 000000a9|member loc 0x10|info
"die base"
TYPE_INFO 000000a9|typedef|base 0000007e|symbolic|info
"die base"
TYPE_INFO 0000007e|structure_type|bytesize 12|symbolic|info
"a"
TYPE_INFO 0000008a|member|base 000001e5|member loc 0x0|info
"die base"
TYPE_INFO 000001e5|base_type|bytesize 1|encoding 6|symbolic|info
(subtree omitted...)
"b"
TYPE_INFO 00000094|member|base 000001c6|member loc 0x4|info
"die base"
TYPE_INFO 000001c6|base_type|bytesize 4|encoding 5|symbolic|info
(subtree omitted...)
"c"
TYPE_INFO 0000009e|member|base 000001d7|member loc 0x8|info
"die base"
TYPE_INFO 000001d7|base_type|bytesize 4|encoding 7|symbolic|info
(subtree omitted...)
"die list"
TYPE_INFO 0000008a|member|base 000001e5|member loc 0x0|info
(subtree omitted...)
TYPE_INFO 00000094|member|base 000001c6|member loc 0x4|info
(subtree omitted...)
TYPE_INFO 0000009e|member|base 000001d7|member loc 0x8|info
(subtree omitted...)
"die symb"
struct basicstruct
"ffi type"
Flagged as FFI
"die symb"
basicstruct
"die symb"
struct teststruct
"e"
TYPE_INFO 000000eb|member|base 000001d7|bytesize 4|bitsize 2|bitoffset 29|member loc 0xc|info
(subtree omitted...)
"f"
TYPE_INFO 000000f8|member|base 000001c6|bytesize 4|bitsize 4|bitoffset 25|member loc 0xc|info
(subtree omitted...)
"ffi type"
Flagged as FFI
"g"
TYPE_INFO 00000105|member|base 000001d7|bytesize 4|bitsize 8|bitoffset 17|member loc 0xc|info
(subtree omitted...)
"h"
TYPE_INFO 00000112|member|base 000001c6|bytesize 4|bitsize 16|bitoffset 1|member loc 0xc|info
(subtree omitted...)
"i"
TYPE_INFO 0000011f|member|base 000000a9|member loc 0x10|info
(subtree omitted...)
"die meta"
TYPE_INFO 000003fb|pointer_type|base 0000012a|bytesize 8|symbolic|info
"die base"
"die symb"
(teststruct)*
"ffi type"
Flagged as FFI
(subtree omitted...)
"die symb"
teststruct
j2> <<< Control-D to exit the interpreter >>>
<null>
jnyberg@jnyberg-debian8:~/j2$ xdot /tmp/VMRES_STACK.dot
...which results in: