-
Notifications
You must be signed in to change notification settings - Fork 134
How to Visualize PORTIONS of the AST
Jim Leek edited this page Jan 5, 2022
·
2 revisions
Quite often an entire AST is too large to be really useful, and you only want to visualize a certain node and it's descendants. This is especially pertinent with attempting to debug ROSE with gdb. It can be very helpful to see where you are in the AST.
Several functions are provided that allow you to do this.
(gdb) up
#7 0x00007ffff418ab5d in Unparse_ExprStmt::unparseExprStmt (this=0x1a1bf950, stmt=0x7fffda63ce30, info=...) at ../../../sourcetree/src/backend/unparser/CxxCodeGeneration/unparseCxx_statements.C:9889
(gdb) p SageInterface::printAST(stmt)
└──@0x7fffda63ce30 SgExprStatement transformation 0:0
└──@0x7fffd8488790 SgFunctionCallExp transformation 0:0
├──@0x7fffe6211910 SgMemberFunctionRefExp transformation 0:0
└──@0x7fffd7f2c370 SgExprListExp transformation 0:0
└──@0x7fffd8488720 SgFunctionCallExp transformation 0:0
├──@0x7fffe6211988 SgMemberFunctionRefExp transformation 0:0
└──@0x7fffd7f2c3d8 SgExprListExp transformation 0:0
(gdb) p SageInterface::printAST(stmt, "file.ast")
└──@0x7fffda63ce30 SgExprStatement transformation 0:0
└──@0x7fffd8488790 SgFunctionCallExp transformation 0:0
├──@0x7fffe6211910 SgMemberFunctionRefExp transformation 0:0
This function will print all the types in the AST to a file after the printing the small portion of the AST comprised by 'node' and it's descendants. It will print "Types encountered ...." and then print every single type seen in the entire AST, which is always a gigantic list. Good if you need to know about types
(gdb) up 10
#48 0x00007ffff40dce69 in Unparser::unparseFile (this=0x7fffffff8c60, file=0x7fffeb786010, info=..., unparseScope=0x0) at ../../../sourcetree/src/backend/unparser/unparser.C:945
(gdb) p SageInterface::printAST2TextFile(node,"test.txt")
SageInterface::saveToPDF(SgNode* node, std:string filename)