Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Linux source code analysis tool     - PostgreSQL Source Customization: Online global read only (Database)

- vector C ++ sequence containers (Programming)

- Attic-- delete duplicate data backup program (Linux)

- Installation Elementary OS Freya to do some settings (Linux)

- Two programs HAProxy + Heartbeat (note, the secondary server vip, normal HAProxy boot method) (Server)

- To create and manage virtual machines on Ubuntu Redhat (Linux)

- How to defragment the hard disk in Linux (Linux)

- Use Docker containers (Linux)

- About Linux operating system security (Linux)

- To install file manager Nautilus 3.12.2 under ubuntu (Linux)

- Select helps secure the system network management tools (Linux)

- Github Getting Started Basic Course (Linux)

- C # how to generate a folder or file automatically rename (Programming)

- xCAT line installation on CentOS 6.X (Linux)

- PostgreSQL 9.3.5 database installation under Ubuntu Server 14.04 (Database)

- How do you access Dropbox Linux command line (Linux)

- count (*) function in MySQL optimization of InnoDB storage engine (Database)

- Ubuntu 14.04 / 13.10 users how to install Ubuntu Touch core applications (Linux)

- How to install and configure in Ubuntu 14.10 'Weather Information Indicator' (Linux)

- Ubuntu derivative version of the user and how to install SmartGit / HG 6.0.0 (Linux)

  Linux source code analysis tool
  Add Date : 2018-11-21      

See the source code is a programmer must be going through, but also can enhance the ability of a shortcut. Personal: To fully grasp a software only way to read the source code.

In Windows there sourceinsight the source reading software (although I have not used, but the online evaluation also good), because I was Linuxer, do not like to use Windows, so naturally select tools under Linux read the source code.

Now I'll walk in the Linux source code reading tools.

vim + ctags + cscope

Source Read Three Musketeers: vim with ctags and cscope, enough to fly freely inside the source code, functions and variables between the free jump.


sudo apt-get install vim ctags cscope


vim used to skip, and a lot of information online, we can say it is not an article, the future I might write a vim use experience. Suggest a concise Vim leveling Raiders, watching almost be used.


ctags is very simple to use, vim has built-in support for ctags.

First, the implementation of ctags -R root directory in the source code, the source code for a recursive build tags, in the root directory Tags will generate a file stored tag various functions and variables to facilitate the jump:

The cursor on a function or variable, Ctrl +] to jump to its definition of the
Ctrl + t to return to the position before you jump
For simple code, ctags enough, but for more complex the code is, ctags seemed a bit powerless, so the next swordsman on debut.


vim also built-in support for the cscope.

First, in the root directory of the source code execute cscope -Rbq, will generate cscope.out file (index database)

-R: When generating the index file, the search subtree code
-b: only generates an index file, do not enter the cscope interface
-q: generating cscope.in.out and cscope.po.out files, speed up the indexing speed cscope
Then execute vim: cs add cscope.out, add the database.

Then you can use: cs find x var lookup. (X representing query options, var represents a function or variable name you want to find)

cscope supports eight query

s: Find C language symbols, namely to find occurrences of function names, macros, enumeration values, etc.
g: lookup functions, macros, enumeration and other defined location, similar to the functionality provided by ctags
d: Find functions calling this function
c: Find functions calling this function
t: Find specified string
e: Find egrep pattern, egrep equivalent function, but look much faster
f: Locate and open the file, similar to the find function vim
i: Find files containing this file
For example, we want to find the call do_cscope in vim 7.0 source code () function is a function, we can enter: ": cs find c do_cscope", after the carriage return and found no match is found, the function may not function calls do_cscope () . We then enter ": cs find s do_cscope", find the location of the C symbol appears now vim lists all the positions this symbol appears.

Cs find every time enter to find the data is a bit of trouble, there is no more convenient way to do that. Of course, vim magic in its customizability. Cscope provide a configuration, it can be placed in your .vimrc.

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
"Cscope setting
"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
if it has ( "cscope")
set csprg = / usr / bin / cscope
set csto = 1
set cst
set nocsverb
"Add any database in current directory
if filereadable ( "cscope.out")
cs add cscope.out
set csverb
nmap < C - @> s: cs find s < C-R> = expand ( "< cword>") < CR> < CR>
nmap < C - @> g: cs find g < C-R> = expand ( "< cword>") < CR> < CR>
nmap < C - @> c: cs find c < C-R> = expand ( "< cword>") < CR> < CR>
nmap < C - @> t: cs find t < C-R> = expand ( "< cword>") < CR> < CR>
nmap < C - @> e: cs find e < C-R> = expand ( "< cword>") < CR> < CR>
nmap < C - @> f: cs find f < C-R> = expand ( "< cfile>") < CR> < CR>
nmap < C - @> i: cs find i ^ < C-R> = expand ( "< cfile>") < CR> $ < CR>
nmap < C - @> d: cs find d < C-R> = expand ( "< cword>") < CR> < CR>
The above configuration is used as the Ctrl + @: cs find shortcuts, that is to find a function name, just put the cursor on the function name, press Ctrl + @ + s can be, simply could not be more convenient . And you can change your configuration, mapping to feel comfortable on the shortcut.

In line with the principle of non-repetition-create the wheel, I would simply write the basic usage of cscope, in fact, basically enough to use, advanced usage refer to the article vi / vim use Advanced: programmer's tool - cscope.


Above we talked about with vim to view the source code, but the face of hundreds of thousands of code, you want to look at the relationship between the various structures is not able to do the vim. This time we need to help the doxygen.

Doxygen is the de facto standard tool for generating documentation from annotated C ++ sources, but it also supports other popular programming languages ​​such as C, Objective-C, C #, PHP, Java, Python, IDL (Corba, Microsoft, and UNO / OpenOffice flavors ), Fortran, VHDL, Tcl, and to some extent D.

doxygen is a tool to generate documentation from the source code, though this cargo is mainly used for C ++, but it also has support for other languages.

Direct Quguan network installation, can be installed in accordance with its guidance.

Here's how to use the doxygen.

First, the implementation of the source code root directory doxygen -g, and then in the root directory will pop up a file named Doxyfile of this document is to generate documentation doxygen configuration files.

So, the focus here, how to configure this file, the default configuration is to generate data for each member of the structure according to the code, and then generate html and latex two folders, which are pages and latex document.

To be honest, the default generated document and no eggs available, in addition to let you more easily see the composition of the members of each structure. Our concern is the relationship between the various structures, this is for C terms. For C ++ and java, the concern is the relationship between classes. Therefore, the default configuration is certainly want to modify. As for how to change, see the official documents.

Of course, if the recommendations given in this article is to look at the only documents that have what meaning does this article. We all know that to see the document can solve the problem, but the time cost is too high, and is in English. The purpose of writing this article is to share their own experiences learning to give, so that we avoid detours, if you can not solve the problem, only to see the documents.

Then I look at my own configuration file used with you to explain.

First, Doxygen configuration which can be described as long and boring, you will not have the desire to read it. So I give a few key configuration items, you can modify it to search time

This is the option for a variety of languages ​​to optimize the output. The default is NO, because it is not clear what language you are using (words look suffix does not know yet ...)

This is the type of document generation option, the default generated html and latex, supports a total of six types of documents, each type of configuration is generating a lot of details need to be configured according to

The option of generating an image. doxygen use this tool to dot drawing, so we have to execute sudo apt-get install graphviz installed dot. After setting the graphics options, doxygen will generate relationships among structure, function calls will be generated for class relations (I have not tried, because only the tried C).

HAVE_DOT (must be set to YES, the latter option are dependent on this)
DOT_NUM_THREADS (using dot drawing the number of threads, the more the faster, I usually set up with the same auditor cpu)

Into a structure diagram is generated by doxygen.


The final step in the implementation of doxygen source root directory, it will automatically find a Doxygen configuration, according to the configuration document generation.


The last tool, the famous gdb. Code execution flow analysis is the best way to run it, and then step by step execution. It is the best tool to observe the course of gdb (for C / C ++).

I do not intend to use gdb-create the wheel, the direct reference GDB debugger, this well written, easy to understand.


That is all I used when reading source Linux tools, The Three Musketeers vim + ctags + cscope, two tricks doxygen gdb, enough to ride the source of rivers and lakes.
- To remove those IP is prohibited Fail2ban on CentOS 6/7 (Server)
- C ++ class implementation date operator overloading (Programming)
- Linux user opens a number of adjustment processes (Linux)
- Computer security perimeter recommendations (Linux)
- Debian (Wheezy) Install Java environment / replace OpenJDK as the SUN JDK (Linux)
- Binary search -Java achieve (Programming)
- Android memory optimization of the optimal load Bitmap (Linux)
- Linux installation Jetty deployment under RedHat5 8 (Linux)
- Three kinds of implementation model of the Linux thread history (Programming)
- Linux file compression and archiving (Linux)
- How to use GRUB2 files directly from the hard disk to run ISO (Linux)
- C language header file defines a global variable (Programming)
- Debian 8 (amd64) installation deployment Memcached management tools MemAdmin (Server)
- To achieve a two-way static NAT stateless available modules on Linux (Linux)
- To install Internet security firewall Raiders (Linux)
- GitHub multiplayer co-development configuration (Linux)
- Android Studio simple setup (Linux)
- installation process of Matlab 2012a under Ubuntu 14.04 (Linux)
- Practical Handbook: 130+ improve the efficiency of commonly used commands Vim (Linux)
- Design and implementation of environment sniffer running under Linux (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.