Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Linux source code analysis tool     - Oracle11g build physical standby database (Database)

- MySQL display operation control tips (Database)

- iptables allow only specific ip address to access the specified port (Linux)

- Change CentOS 7 NIC name eno16777736 to eth0 (Linux)

- Android Fragment everything you need to know (Programming)

- PostgreSQL-XL installation and deployment (Database)

- Linux command ls (Linux)

- JavaScript in null undefined summary (Linux)

- Httpclient4.4 of principle (Http execution context) (Programming)

- MySQL simple operation notes under Linux (Database)

- Windows 7 hard disk installation notes Debian (Linux)

- To install PostgreSQL 9.4 (Database)

- Linux using TCP-Wrapper Service Management (Linux)

- Btrfs file system creation and their characteristics in Linux (Linux)

- CentOS directory structure Explanation (Linux)

- Use custom backup plans for Debian backupninja (Linux)

- CentOS x86 64bit upgrade to 2.7 Python2.6 (Linux)

- Analysis of memory mapping process in Linux x86-64 mode (Linux)

- EChart simple and practical control on chart (Programming)

- The simple multi-threaded Python (Programming)

  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.
- Setting up Linux machine through a proxy firewall (Linux)
- Detailed Linux network security policies and protection measures (Linux)
- Linux boot the system does not display a progress bar setting method (Linux)
- Linux system using the command line shutdown or restart (Linux)
- RHEL7.0 environment Linux kernel upgrade (Linux)
- Linux Command Line Art (Linux)
- Learning OpenCV: (VS2010-openCV2.4.3-win7 configuration instructions) (Linux)
- Ubuntu 14.04 Nvidia graphics driver installation and settings (Linux)
- Ubuntu install ruby (Linux)
- Tecplot Installation under Linux (Linux)
- Use UDEV SCSI Rules configured ASM on Oracle Linux 5 and 6 (Database)
- How to display a dialog Bash Shell script (Programming)
- Oracle Listener can not start (TNS-12555, TNS-12560, TNS-00525) (Database)
- Java Prototype Pattern (Programming)
- JavaScript, some conclusions about the implicit conversion (Programming)
- Android Scroller call mechanism and the relationship of computeScroll (Programming)
- Ubuntu 14.04 LTS next upgrade gcc to gcc-4.9, gcc-5 version (Linux)
- MySQL composite partition (Database)
- Ubuntu dual-card system configuration method (Server)
- Linux Apache server security (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.