Montag, 17. Dezember 2007

Kernel source code browsing

Hey,
a quick guide for browsing source code with Vi editor.
At first we need: source code (e.g. kernel-source), the vim editor, ctags (tool for generating tag files) and cscope (tool for browsing C code). This packages are all included in the OpenSUSE 10.3.

Next you need to index all files which should be browse able later, do it with 'find | grep "\.c$\|\.h$" > cscope.files' (of course in the top of your source code directory).

After this you have to build the cscope database, with "cscope -b" (for recursive build, start it in the top directory of your source code).
Afterwards build the tag database with "ctags -L cscope.files" (this is needed for code completion).

Next is to tell vim about it: do this with adding the support (key-bindings) in your vimrc. Download this vim_rc and append it to your vimrc (mostly $HOME/.vimrc). After this, the ctag/cscope key support should be enabled (of course a vi restart is needed).

Ctrl-']' brings you the definition, Ctrl-t brings you back.

The key binding is: (all with CTRL-'\'-'key'):
's' (symbol) find all references to the token under cursor
'g' (global) find global definition(s) of the token under cursor
'c' (calls) find all calls to the function name under cursor
't' (text) find all instances of the text under cursor
'e' (egrep) egrep search for the word under cursor
'f' (file) open the filename under cursor
'i' (includes) find files that include the filename under cursor
'd' (called) find functions that function under cursor calls

So hope this helps.

Keine Kommentare: