Source insight is the most convenient tool for viewing code in windows. However, source insight does not have a Linux version. To facilitate code browsing and learning in Linux, we can use vim and csinsight to build the source insight in Linux.
Cscope is a tool and plug-in suitable for VIM. With cscope, you can easily learn the definition of a function and which functions are called.
Cssag Installation
You can download the source code package at http://cscope.sourceforge.net/, decompress it, and compile and install the package.
./Configure
Make
Make install
Generate a cssag Database
Before using cssag, you must generate a cssag database for the code. If the current code is in the/usr/src/Linux directory, run the following command.
CD/usr/src/Linux
Cs1_rbq
Then, three files are generated: csexample. In. Out, csexample. Out, And csexample. Po. Out.
Use Vim to open the code file and import the generated cscope file to VIM.
Vim init/Main. c
: CS Add/usr/src/Linux/csout. Out/usr/src/Linux
You can also add the following statement to the vim configuration file. vimrc.
if fileradable("cscope.out") cs add csope.outelseif $CSCOPE_DB != "" cs add $CSCOPE_DBendif
Cssag Functions
Cssag is implemented through its Sub-command "find.
CS find c | d | E | G | f | I | S | T name
- S: Find the C Code Symbol
- G: search for this definition
- D: Find the function called by this function.
- C: Find the function that calls this function.
- T: search for this string
- E: Find the current egrep mode.
- F: Find this file
- I: Find the file that contains this file
You can add the following shortcut keys in. vimrc to avoid entering a long string of commands every time.
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("<cword>")<CR><CR>nmap <C-@>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
When used, move the cursor over the object to be searched, and press <c-@> G, that is, press Ctrl + @, and then press g soon ", the object definition will be searched.