Question

I am working on a project which requires the understanding of llvm compiler source-code. To browse source code of llvm, I tried to use cscope with following command in the root directory of the source:

cscope -R *

But it doesn't work. As there are mainly .cpp and .h files but some .c files are also there. So now I don't have a clue how to make cscope work? Can someone please help?

Was it helpful?

Solution

You can use following commands to do the required task from the root directory of llvm source tree:

touch tags.lst
find | grep "\.c$" >> tags.lst
find | grep "\.cpp$" >> tags.lst
find | grep "\.h$" >> tags.lst
cscope -i tags.lst

It would create cscope.out file which is used with cscope to browse the code. Hope it helps!

OTHER TIPS

A convenient way to list all C++ files in a project is to use the ack tool: a grep-like command optimized for source code searching (In some distributions, for instance Ubuntu, the tool is called ack-grep). You can run it like this:

ack -f --cpp > cscope.files

The output are paths to all .cpp, .h, .cc .hpp files

I have following in my .bashrc which make things easier. Run cscope_build() to generate data base and cscope to start cscope tool.

# Use vim to edit files
export CSCOPE_EDITOR=`which vim`

# Generate cscope database
function cscope_build() {
  # Generate a list of all source files starting from the current directory
  # The -o means logical or
  find . -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" > cscope.files
  # -q build fast but larger database
  # -R search symbols recursively
  # -b build the database only, don't fire cscope
  # -i file that contains list of file paths to be processed
  # This will generate a few cscope.* files
  cscope -q -R -b -i cscope.files
  # Temporary files, remove them
  # rm -f cscope.files cscope.in.out cscope.po.out
  echo "The cscope database is generated"
}
# -d don't build database, use kscope_generate explicitly
alias cscope="cscope -d"

To cover our large code base I have a script that looks a bit like this to build cscope indexes. The reason I change to / is so that I have full file paths to the source files which makes things work a little smoother.

cd /
find -L /home/adrianc/code -name "*.c" -o -name "*.cc" -o -name "*.h" > /home/adrianc/code/cscope.files
cd /home/adrianc/code
/usr/local/bin/cscope -b -icscope.files -q -u

Also it may be worth checking out http://cscope.sourceforge.net/cscope_vim_tutorial.html

Just because this is still the most popular entry. The stdin thingy may have been added in the meantime or not, but it makes it kind of elegant:

find -regex '.*\.\(c\|h\|cpp\|cxx\|hh\|hpp\|hxx\)$' | cscope -i- -b -q
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top