http://wiki.freescale.net/display/MADCPOIMX/Integrating+CSCOPE+with+vim+or+gvim
What is CSCOPE?
CSCOPE is an open source application that allows you navigate across software projects code base.
This is very useful if, for example, you need to read or search something within a large software project like the Linux kernel or U-boot code tree.
This is the official website for CSCOPE: http://cscope.sourceforge.net/
What do I need?
- Make sure the application cscope is installed and available in your PATH.
- For any given project you need a CSCOPE database file. You must find a way to generate such files. You can use this python script (bsp_cscope_gen.py ) to generate the CSCOPE database for any Linux Kernel source tree or U-boot source tree.
- Although you can use cscope command to traverse the source tree and all of the relevant symbols, the real benefit starts if you integrate CSCOPE with your text editor.
- This tutorial is focused on CSCOPE and vim integration. If you usegvim, you'll get CSCOPE integration too.
Steps to integrate CSCOPE and VIM.
- Add the following file to your HOME directory: cscope_maps.vim
- Edit your "HOME/.vimrc" file so it sources the newly added cscope_maps.vim file.
- Here is the content of my "HOME/.vimrc" file (pay attention to the last line):
set tabstop=4 set shiftwidth=4 set expandtab set wrap! color murphy syntax on source ~/cscope_maps.vim
You are ready to go !
How to use it?
- Assume you compiled our Linux BSP using LTIB: .../ltib/rpm/BUILD/linux.
- Let's assume that after doing the first kernel compilation you used bsp_cscope_gen.py and created the CSCOPE database files under ".../ltib/rpm/BUILD/linux".
- On the linux prompt you just have to do this:
$cd .../ltib/rpm/BUILD/linux
$gvim &
- An empty gvim text editor window will open and you can start using cscope commands inside gvim (or vim).
- EXAMPLE: If you compile Linux for MX53, and you know there's a function named "mx53_clocks_init" and you want to go directly to the file where that function was implemented then on vim you execute:
:cs find g mx53_clocks_init
VIM cscope command reference (Quick List)
find : Query cscope. All cscope query options are available except option #5 ("Change this grep pattern").
USAGE
:cs find {querytype} {name}
Unknown macro: {querytype}
corresponds to the actual cscope search mode:
- "Ctrl t" (return to previus file in the stack)
- s: Find this C symbol "Ctrl \"+s
- g: Find this definition "Ctrl \" + g
- d: Find functions called by this function
- c: Find functions calling this function
- t: Find this text string
- e: Find this egrep pattern
- f: Find this file
- i: Find files #including this file
EXAMPLE
:cs find c mx53_clocks_init