Difference between revisions of "Editor Tips"

From eLinux.org
Jump to: navigation, search
(reword section on kernel man pages)
Line 57: Line 57:
  
 
== Using kernel man pages with VIM ==
 
== Using kernel man pages with VIM ==
You can create man pages for kernel functions by typing "make mandocs", and install them using
+
You can create man pages for kernel functions using the kernel build system:
"sudo make installmandocs".
+
$ 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).
 
As of kernel version 4.4, "make mandocs" will take a long time to complete (about 45 minutes on my machine).
  
Line 73: Line 75:
 
  $ man 9 abs
 
  $ man 9 abs
  
To see the kernel man page for a symbol under the cursor in vim, use Shift-K
+
To see the kernel man page for a symbol under the cursor in vim, use '''Shift-K'''

Revision as of 13:21, 4 December 2015

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.

Using cscope and ctags with VIM

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.

install pre-requisites

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

building the ctags database

To build the ctags database, do:

$ make ARCH=arm tags

This creates the file 'tags' in the root of the kernel source tree.

navigating symbols in vim

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

For example:

$ 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:

ctrl-]

then select one of the references. Use ctrl-T to return to where you jumped from.

other commands

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>

For example:

$ man printk
$ man 9 abs

To see the kernel man page for a symbol under the cursor in vim, use Shift-K