Run the below script from the top level project directory.

Setup Script

find  -type f -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' -o -iname '*.cc' -o -iname '*.hh'  -type f  > ~/cscope.files
cscope -q -R -b -i ~/cscope.files -f ~/cscope.out
export CSCOPE_DB=~/cscope.out
ctags -R .

The path of the cscope database file can be customized according to your environment.

Working with Multiple directory
You can specify multiple directory to find command above. See below:

$find misc/xxxx/abc/ net/wireless/xyz/ ../../../kernel/topic/include/ -type f -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' -o -iname '*.cc' -o -iname '*.hh'  -type f  > ~/cscope.files

Error tag not found
By default ctrl-] doesn’t look into the cscope database rather it looks into the ctag database. So to search in cscope database add the following in your .vimrc file:

set cscopetag

After opening a vim session do the below:

:cs add $CSCOPE_DB

Alternatively you may add it in your ~/.vimrc file as below:

:cs add $CSCOPE_DB
:set cscopetag

Remember in this configuration the CSCOPE_DB will always point to ~/cscope.out. So if you were to start working with a different code base at a later point of time, you have to regenerate your cscope.out file as described above. You can place the cscope.out file anywhere you like but you have to keep in mind the CSCOPE_DB should be pointing to that location. For example if you decide to place it under /home/xyz/abc instead of ~/ then in your environment the CSCOPE_DB should be set as:

export CSCOPE_DB=/home/xyz/abc/cscope.out

For re-generating the cscope.out you can to do:

$find  -type f -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' -o -iname '*.cc' -o -iname '*.hh'  -type f  > /home//xyz/abc/cscope.files
$cscope -q -R -b -i /home/xyz/abc/cscope.files -f /home//xyz/abc/cscope.out

Exit Cscope
Hit CTRL-D to exit Cscope.

Leave a Reply