how to dump DSA graph in gdb?

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|{}}"];
Node0xe1f4d0 [shape=record,shape=Mrecord,label="{ i32*: SMR\n|{|}}"];
Node0xe1f4d0:g0 → Node0xe1f3a0;
Node0xe20900 [shape=record,shape=Mrecord,label="{ i32: GR\n @global\n|{}}"];
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

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:

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.

John, thanks so much, but i tried the -analyze option, It didn’t produce any .dot file in my working directory:
opt -analyze -load=/home/stw/llvm/install/lib/libLLVMDataStructure.so list.bc -o list-opt.bc

also the -analyze option in “-help” result shows that:
-analyze - Only perform analysis, no optimization

did I misunderstand what your said, or my building problem?

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.

Ok, I read Chris’s thesis, and only knew the basic framework, so i want to debug the code to
learn that in more depth.

Tianwei wrote:

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.

John, thanks so much, but i tried the -analyze option, It didn't produce any .dot file in my working directory:
opt -analyze -load=/home/stw/llvm/install/lib/libLLVMDataStructure.so list.bc -o list-opt.bc
  

Sorry; I wasn't clear. The -analyze option is an option to opt to tell it to print analysis results instead of doing transformations. You still need to specify the analysis passes that you want run.

For example, to see the local DSA results, do the following:

opt -load <path to libLLVMDataStructure.so> -analyze -datastructure list.bc

To get the Top-Down results, you would do:

opt -load <path to libLLVMDataStructure.so> -analyze -tddatastructure list.bc

also the -analyze option in "-help" result shows that:
  -analyze - Only perform analysis, no optimization

did I misunderstand what your said, or my building problem?

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.
Ok, I read Chris's thesis, and only knew the basic framework, so i want to debug the code to
learn that in more depth.
  

You can also get information on DSA from the PLDI 2007 paper (http://llvm.org/pubs/2007-06-10-PLDI-DSA.html).

-- John T.

Tianwei wrote:

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.

John, thanks so much, but i tried the -analyze option, It didn’t produce any .dot file in my working directory:
opt -analyze -load=/home/stw/llvm/install/lib/libLLVMDataStructure.so list.bc -o list-opt.bc

Sorry; I wasn’t clear. The -analyze option is an option to opt to tell
it to print analysis results instead of doing transformations. You still
need to specify the analysis passes that you want run.

For example, to see the local DSA results, do the following:

opt -load -analyze -datastructure list.bc

To get the Top-Down results, you would do:

opt -load -analyze -tddatastructure
list.bc

thanks so much, it works:-). but in my version, i use the following pass flag:
-ds-aa - Data Structure Graph Based Alias Analysis
-ds-opt - DSA-based simple optimizations
-dsa-bu - Bottom-up Data Structure Analysis
-dsa-local - Local Data Structure Analysis
-dsa-stdlib - Standard Library Local Data Structure Analysis
-dsa-td - Top-down Data Structure Analysis

Tianwei