Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux source code analysis tool     - Sleuth Kit: used to analyze a disk image and restore files open source forensics tools (Linux)

- Linux common network tools: ping host sweep (Linux)

- C ++ multithreading and critical resource instance (Programming)

- Ubuntu 14.04 LTS 64-bit installation and activation Sublime Text 3 can not solve the Chinese input method to solve the problem (Linux)

- Android design patterns - state mode (Programming)

- Python Socket Network Programming (Programming)

- Android HTTP request with Get Information (Programming)

- DDOS Attacks and Prevention (Linux)

- Docker - for the development and deployment of unified lightweight Linux containers (Linux)

- Kubernetes cluster deployment (Server)

- Linux operating system Study Notes (Linux)

- MySQL related statements (CRUD) (SQLyog software) (Database)

- Setting Linux desktop environment, achieve HiDPI display support (Linux)

- To convert into a binary search tree sorted doubly linked list (Programming)

- Vim useful plugin: EasyGrep (Linux)

- Linux virtual machine settings network, hostname ssh access (Linux)

- C # Future: Tracking null reference (Programming)

- Java Access Control (Programming)

- OpenWRT environment to build (Linux)

- LogStash log analysis display system (Linux)

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

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.

installation

sudo apt-get install vim ctags cscope
 

vim

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

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.

cscope

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
endif
set csverb
endif
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.

doxygen

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 ...)

OPTIMIZE_OUTPUT_FOR_C
OPTIMIZE_OUTPUT_JAVA
OPTIMIZE_FOR_FORTRAN
OPTIMIZE_OUTPUT_VHDL
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

GENERATE_HTML
GENERATE_LATEX
GENERATE_RTF
GENERATE_XML
GENERATE_DOCBOOK
GENERATE_MAN
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.

[Machine_class]

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

gdb

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.

postscript

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.
     
         
         
         
  More:      
 
- Using Python and OpenCV detecting image barcode (Programming)
- MySQL to NoSQL avatar (Database)
- TWiki LDAP error appears the problem is solved (Linux)
- Linux start the process (Linux)
- Linux (SUSE) mount NTFS mobile hard practice (Linux)
- The method of CentOS-7.0. The installation and configuration of Tomcat-7 (Server)
- LVM basic concepts, management (Linux)
- Mounting kit under Fedora Linux (Linux)
- How to install Visual Studio Code on Ubuntu (Linux)
- C ++ based foundation: the difference between C and C ++ (Programming)
- apt-get install openstack pkg Troubleshooting (Linux)
- shell-like program (Programming)
- CentOS7 installation GAMIT and GMT (Linux)
- Use mdadm tool to create software RAID 0 (Linux)
- Distributed File System FastDFS deployment (Server)
- General Linux interface server parameter tuning (Server)
- A step by step teach have to install multi-node cluster configuration Hadoop (Server)
- Using Linux / Unix Text processing (Linux)
- Git bulk delete remote tag (Linux)
- Function Getting the Linux shell (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.