Friday, January 3, 2014

Practical Cscope

I have used GUI based code indexers and browsers for quite a while but the amount of data they throw for a function or symbol( or variable) search is huge and it takes quite some time to scroll down the complete list to find the right one using a mouse(my wrist was complaining a lot :)). It has been quite a long period that I missed to key in the information I've gathered while using cscope.

There comes the Cscope for my rescue and I found some posts on internet but none of them are kind of one stop solution. I thought of sharing the information I've gathered after toiling my hands to make cscope work for my projects, so let's not waste any more time and jump in and start browsing your code using cscope.

I don't want to reiterate the information that is already shared over the internet on how to start with Cscope, so go through the following link straight away.

http://cscope.sourceforge.net/cscope_vim_tutorial.html

1)As mentioned in the point 11 if you are working on a large project and would like to browse the code from any folder in the project then instead of providing the '.' as the path to search and generate list of files, provide the absolute path.

2)Generate the DB by using -R or -b option. Set the CSCOPE_DB variable in the rc file of the shell you are working with. Following is the syntax with the commonly used shells.
Bash:
>export CSCOPE_DB=<path to cscope.out>

Csh:
>setenv CSCOPE_DB <path to cscope.out>

3)Launch  vim and check the DB loaded by running ":cs show" and it should show the cscope.out file you've create if you are in the same directory where the DB is otherwise absolute file path will be shown.

4) After you've added some code to your project then to reflect the newly added symbols and functions in the cscope DB from the shell run the following command.
>cscope -b

If you are in the vim editor and would like to see the changes run the following in vim itself.
:!cscope -b
:cscope reset

Overcoming Common Errors:

1)E259: no matches found for cscope query c of ...

  This error is usually thrown when you don't have a correct nmap present in the file ~/.vim/plugin/cscope_maps.vim. If you've extra spaces around the '=' in the following you may get this error.

Example:
nmap <C-\>s :cs find s <C-R> = expand("<cword>")<CR><CR>

  Other common problem I faced was when the file names in the cscope.files are not absolute so generate the file list accordingly to avoid this error.



I will appreciate your input if anything is missing or wrongly mentioned here.

No comments: