如何为一个有。c,。cpp和。h文件的项目使用cscope ?

时间:2023-01-17 13:10:36

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:

我正在做一个项目,需要理解llvm编译器源代码。为了浏览llvm的源代码,我尝试在源代码的根目录中使用cscope,命令如下:

cscope -R *

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?

但它不工作。由于主要有.cpp和.h文件,但也有一些.c文件。现在我不知道怎么让cscope发挥作用了?有人能帮忙吗?

5 个解决方案

#1


9  

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

您可以使用以下命令从llvm源树的根目录执行所需的任务:

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!

它将创建cscope。与cscope一起使用的out文件来浏览代码。希望它可以帮助!

#2


6  

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:

列出项目中所有c++文件的一种方便的方法是使用ack工具:一种类似grep的命令,用于源代码搜索(在某些发行版中,例如Ubuntu,该工具被称为ack-grep)。你可以这样运行:

ack -f --cpp > cscope.files

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

输出是所有.cpp、.h、.cc .hpp文件的路径

#3


2  

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.

为了覆盖我们庞大的代码库,我有一个类似于这样的脚本来构建cscope索引。我更改为/的原因是,我有到源文件的完整文件路径,这使得工作更加顺利。

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

同样,也可以查看http://cscope.sourceforge.net/cscope_vim_tutorial.html

#4


0  

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

#5


0  

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

我在。bashrc中有以下内容,这使事情变得更简单。运行cscope_build()来生成数据库和cscope以启动cscope工具。

# 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"

#1


9  

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

您可以使用以下命令从llvm源树的根目录执行所需的任务:

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!

它将创建cscope。与cscope一起使用的out文件来浏览代码。希望它可以帮助!

#2


6  

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:

列出项目中所有c++文件的一种方便的方法是使用ack工具:一种类似grep的命令,用于源代码搜索(在某些发行版中,例如Ubuntu,该工具被称为ack-grep)。你可以这样运行:

ack -f --cpp > cscope.files

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

输出是所有.cpp、.h、.cc .hpp文件的路径

#3


2  

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.

为了覆盖我们庞大的代码库,我有一个类似于这样的脚本来构建cscope索引。我更改为/的原因是,我有到源文件的完整文件路径,这使得工作更加顺利。

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

同样,也可以查看http://cscope.sourceforge.net/cscope_vim_tutorial.html

#4


0  

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

#5


0  

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

我在。bashrc中有以下内容,这使事情变得更简单。运行cscope_build()来生成数据库和cscope以启动cscope工具。

# 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"