Here are some tips for using editors with the Linux kernel.
These are not really specific to embedded, but some of the tips below incorporate cross-platform issues into the tips.
You can do symbol navigation with scope and ctags in VIM. This is handy to explore the kernel and to get information about function calls and structures when coding.
First, install cscope and exuberant-ctags onto your workstation.
sudo apt-get install cscope exuberant-ctags
These are the packages that handle building and indexing the cscope and ctags database, respectively.
building the cscope database
To build the cscope database for a particular architecture, do:
$ make ARCH=arm cscope
(of course, supply the appropriate architecture for your project on the kernel command line)
This creates the following files in the root of the kernel source tree:
- cscope.files - this is the list of files that were indexed by cscope
- cscope.out - this is the cscope database
- cscope.out.in and cscope.out.po - these are a reverse index, to speed up lookups in the database
To build the ctags database, do:
$ make ARCH=arm tags
This creates the file 'tags' in the root of the kernel source tree.
To use cscope symbols in vim, do the following:
To open the editor and position the cursor to where a particular tag is located, do:
$ vi -t tag
$ vi -t start_kernel
This will open init/main.c and position the cursor on the 'start_kernel' function.
From inside the editor, to navigate to the symbol that is under the cursor:
then select one of the references. Use ctrl-T to return to where you jumped from.
You can use colon commands to perform specific operations:
- :ta tag - to find a tag
- :cs find g name - find the definition for 'name'
- :cs find d func - find functions called by 'func'
- :cs find c func - find functions that call 'func'
- :cs help - show cscope help in VIM
See http://cscope.sourceforge.net/cscope_vim_tutorial.html for more information.
Using kernel man pages with VIM
You can create man pages for kernel functions using the kernel build system:
$ make mandocs $ sudo make installmandocs
The first command builds the kernel man pages, and the second installs them (usually into /usr/local/share/man/man9) As of kernel version 4.4, "make mandocs" will take a long time to complete (about 45 minutes on my machine).
Once the kernel man pages are installed, you can access them from the command line with:
$ man <symbol>
If the symbol is found in other places than the kernel (such as in libc or in some other man pages), you can add the man section number for the kernel, which is '9'.
$ man 9 <symbol>
$ man printk $ man 9 abs
To see the kernel man page for a symbol under the cursor in vim, use Shift-K