[LLVMdev] how to dump DSA graph in gdb?

John Criswell criswell at cs.uiuc.edu
Wed Apr 23 08:59:40 PDT 2008

Dear Tianwei,

You can use the -analyze option to the opt tool to tell the DSA passes 
to store their results in files.  When you use the -analyze option, the 
DSA passes will create a separate file for each function (and possible 
one file to hold the globals graph).  For this reason, I recommend 
running opt in a special empty directory because DSA will generate *a 
lot* of files.

Second, to look at these files, you run them through the dot command 
from the GraphViz package to convert them into a graphic format.  For 
example, I use:

dot -Tpng file.dot > file.png

... to convert the file into a PNG graphic which I can then examine 
using my graphics program of choice.

Also, you're aware that the -datastructure pass is just the local 
analysis pass, correct?  The inter-procedural part is in the Bottom Up, 
Complete Bottom Up, and Top Down passes.

-- John T.

Tianwei wrote:
> Hi, all:
>    Recently I am debugging the DSA and want to learn how it work, and now I am checking the local datastructure analysis.
> I use the following command to print the graph:
> (gdb) p g.dump()
> digraph DataStructures {
>     label="Function addG";
>     Node0xe1f3a0 [shape=record,shape=Mrecord,label="{ i32: MRE\n|{<g0>}}"];
>     Node0xe1f4d0 [shape=record,shape=Mrecord,label="{ i32*: SMR\n|{<g0>|<g1>}}"];
>     Node0xe1f4d0:g0 -> Node0xe1f3a0;
>     Node0xe20900 [shape=record,shape=Mrecord,label="{ i32: GR\n @global\n|{<g0>}}"];
>     Node0xe16530[  label =" %x_addr"];
>     Node0xe16530 -> Node0xe1f4d0[arrowtail=tee,color=gray63];
>     Node0xe162f0[  label =" %x"];
>     Node0xe162f0 -> Node0xe1f3a0[arrowtail=tee,color=gray63];
>     Node0xe16950[  label =" %tmp4"];
>     Node0xe16950 -> Node0xe1f3a0[arrowtail=tee,color=gray63];
>     Node0xe16730[  label =" %tmp"];
>     Node0xe16730 -> Node0xe1f3a0[arrowtail=tee,color=gray63];
> }
> then I had to copy these lines out into a .dot file and use dot to convert it into a ps file.
> I note that it also provide a lot print and dump functions in Printer.cpp, such as
> void DSGraph::writeGraphToFile(std::ostream &O,
>                                const std::string &GraphName) const {
> but i don't know how to use it, also there are other functions:
> // print - Print out the analysis results...
> void LocalDataStructures::print(std::ostream &O, const Module *M) const {
>   if (DontPrintAnything) return;
>   printCollection(*this, O, M, "ds.");
> }
> ..........
> how these functions can be used in gdb? furthermore, are there any options which i can type in command line for DSA?, such as:
> opt -load=xxxxxx  -print_the_local_analysis_result  list.bc -o list-opt.bc
> also any suggestions for how to debug DSA efficiently?
> Thanks.
> Tianwei

More information about the llvm-dev mailing list