Http://blog.chinaunix.net/u3/119403/showart_2347423.html
Install
1. Install graphviz
The generation of call graphs depends on graphviz. Therefore, you must first install
Graphviz. You can download the source code package for compilation and installation.
I am a little lazy here: tbag @:~ $ Sudo apt-Get install
Graphviz
2. simple installation of codeviz
Download the codevize source package: http://www.csn.ul.ie /~ Mel/projects/codeviz/codeviz-1.0.11.tar.gz
Decompress: tbag @:~ /Down $
Tar xvf codeviz-1.0.11.tar.gz
Tbag @:~ /Down $ CD codeviz-1.0.11/
Codeviz
A patch version of the GCC compiler is used, and different codeviz versions use
The GCC version is also different. You can download the source code package of codeviz and view it.
Makefile to determine the GCC version to be used
The codeviz-1.0.11 uses a GCC-3.4.6. Actually install codeviz
The installation script automatically downloads the corresponding gcc
And patch, but here we are step-by-step installation, it is better to be clear,
Install GCC before installing codeviz.
3. Install gcc
Download gcc-3.4.6.tar.gz to CD
Compilers under the codeviz-1.0.11 directory.
: Ftp://ftp.mirrorservice.org/site...
CC/releases/gcc-3.4
.. 6/gcc-3.4.6.tar.gz
Codeviz installation script
Compilers/install_gcc-3.4.6.sh automatically detects under the compilers directory
Whether the GCC source code package exists. If not, it is automatically downloaded and typed
Patch, which has been downloaded before.
Directory, and the rest is decompressed and installed. The install_gcc-3.4.6.sh will decompress GCC
Patch, and
It is installed in the specified directory. If no directory is specified, $ home/GCC-graph is used by default/
Local/GCC-graph (in this case
Root permission ).
Tbag @:~ /Down/codeviz-1.0.11 $ cd
Compilers/
Tbag @:~ /Down/codeviz-1.0.11/compilers $
Ls
Gcc-3.4.6.tar.gz gcc-graph gcc-patches install_gcc-3.4.6.sh
Tbag @:~ /Down/codeviz-1.0.11/compilers $
/Install_gcc-3.4.6.sh
Then you can have a cup of coffee .....
Install
Codeviz
Tbag @:~ /Down/codeviz-1.0.11 $
./Configure
Tbag @:~ /Down/codeviz-1.0.11 $ make
# Make
(This is not required because the script does not check whether the gcc-3.4.6 has been made, before
So you only need to install codeviz. The goal of compilation is
Gcc-3.4.6, codeviz not required
Translation. For more information, see makefile.
File)
Tbag @:~ /Down/codeviz-1.0.11 $ make install-codeviz
(You have installed
GCC, the so-called installation of codeviz is just to make install-codeviz
Script genfull and gengraph
Copy to the/usr/local/bin directory. Codeviz requires support from the Perl library. I
By default
Perl, so there is no problem. If problems occur during installation, View
Configure and makefile determine which libraries need to be installed)
So far, codeviz has been installed. Let's take a look at its usage.
4. Use
Graphviz
Supports generating call diagrams of different styles, but some additional support tools or libraries need to be installed. Program ,
Interested friends can go to http://www.graphviz.org
Find the relevant information. Here we will focus on codeviz's
The specific image style control is not described in detail.
Codeviz uses two scripts to generate a call diagram. One is
Genfull. This script can generate a complete project call.
Therefore, calling graphs can be very complex. cdepn is used by default.
File to create a call diagram; the other is
Gengraph. This script can generate a small call graph for a given set of functions and generate a corresponding
Postscript
File. These two scripts are copied to/usr/local/bin during installation.
Directory, so you can directly use
You do not need to specify a path.
5. Compile
The patch
Gcc/g ++ generates. cdepn for each compiled C/C ++ File
File, which contains the function call
Use and declare information.
Demo:
1) tbag @:~ /Test/JPEG $
Http://www.cnblogs.com/gcc-graph/bin/gcc *. C-o tbag
2) tbag @:~ /Test/JPEG $
Genfull
3) tbag @:~ /Test/JPEG $ gengraph-D 2-output-type "PNG"-F
Pai_decompress2bmp
Step 1: Use the just-installed gcc-3.4.6 to compile all. c files under the current directory, GCC/g ++ for each compiled
C/C ++ file generation. cdepn file.
Step 2: Use this script to generate a full. Graph file in the current directory. This script can generate a complete project call.
Use graph information files,
Therefore, calling the graph information file may be very complex. By default, the cdepn file is used to create the calling graph information file;
Step 3: This script can generate a small call graph for a given group of functions, '-d
2 'the parameter only shows the call relationship between two layers.'-output-type "PNG" 'specifies that the output format is PNG,'-F
Pai_decompress2bmp 'specifies the function from which to generate the call relationship diagram.
Http://blog.csdn.net/Solstice/archive/2005/09/22/486788.aspx
Codeviz is an analysis of C/C ++ written by Mel Gorman, author of understanding the Linux Virtual Memory Manager (at Amazon ).Source codeOpen Source Tool for function call relationships (similar open source software includes Egypt and NCC ). The basic principle is to patch GCC so that it can dump the call graph of the function during each source file during compilation, and then collect and sort out the call relationship using the Perl script, transfer the image to graphviz to draw the image.
Codeviz was originally a small tool used by the author to analyze the source code of Linux virtual memory. Now it basically supports C ++, the latest version 1.0.9 can be compiled and used smoothly in Windows + cygwin :). Note: 1) download the source code gcc-3.4.1.tar.gz for GCC 3.4.1 to the codeviz-1.0.9/compilers, 2) install the patch program (which belongs to the utils class), 3) download from the http://www.graphviz.org and install graphviz 2.6.
I used codeviz to analyze the first sample program in embedded real-time operating system uC/OS-II (second edition), as follows:
1. Find a way for GCC to compile the source code of uC/OS 2.52 and the sample program. Each C source file generates the. C. cdepn file. You only need to compile (parameter-C) and do not need to connect.
2. Call genfull to generate full. graph. This file records the location of all functions in the source code and the call relationship between them.
3. Use gengraph to generate the call relationships of functions I care about.
First, analyze main ():
1. gengraph -- output-type GIF-F Main Analyze the Call Graph of main (), and the figure is as follows. The essentials are not displayed:
2. gengraph -- output-type GIF-F Main-s osinit Do not care about the internal implementation details (parameter-S) of osinit () for the moment, so that it is displayed as a node. The figure below is a bit messy, but it is much better:
3. gengraph -- output-type GIF-F Main-s osinit-I "oscpusavesr; oscpurestoresr" Basically, each function hasCode, Ignore (parameter-I ). The figure is as follows, which is clear:
4. gengraph -- output-type GIF-F Main-s "osinit; ossemcreate"-I "oscpusavesr; oscpurestoresr"-K The internal details of ossemcreate () do not seem to be concerned, but keep the intermediate file sub. Graph (parameter-k), as shown in the following figure,
5. Dot-TGIF-O main.gif sub. Graph Modify sub. Graph to make the graph conform to the function call sequence. The final figure is shown below. You don't need to read the code when you do this :)
Next, analyze the call relationship of ostimedly:
Gengraph -- output-type GIF-r-F ostimedly
Check which functions call ostimedly (), parameter-R, task (), and taskstart () are user-written functions:
Finally, let's see which functions are directly called by task:
Gengraph -- output-type GIF-D 1-F task
Only the first-layer call starting from the task (parameter-D 1 ):
When analyzing the source code, print these images at hand and take notes on them, which is very convenient.