cscope:如何使用cscope通过命令行搜索符号? [英] cscope: How to use cscope to search for a symbol using command line?

查看:390
本文介绍了cscope:如何使用cscope通过命令行搜索符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到的所有cscope教程都讨论了如何使用cscope的交互模式在vim和emacs等编辑器中搜索符号。但是我认为应该可以在终端中发出命令来执行

All the cscope tutorials I found online talk about how to use the interactive mode of cscope to search for symbols in editors such as vim and emacs. But I think it should be possible to issue a command in terminal to do something like

cscope -d -some_options <my symbol>

我应该能够在stdout中看到结果列表,而不必输入ncurse UI并在那里执行所有操作。我认为这是可能的,因为唯一的前端浏览器可以在其TclTK UI中执行类似的操作。但是不幸的是代码没有超出我的范围。

And I should be able to see a list of results in stdout, instead of having to enter the ncurse UI and do everything there. I think this is possible because the "only" frontend cbrowser can do things like that in its TclTK UI. But the code unfortunately is quite beyond me.

但是,我没有找到有关此功能的文档。

However, I found no documentation about this capability.

Am我在做梦还是有没有记录的方法?

Am I dreaming or is there an undocumented way of doing this?

谢谢!

更新

一些进步:如果我做一个小项目,其中包含一些具有子目录结构的文件。然后rici的答案就可以使用。具有更大的项目(成千上万个具有复杂文件夹结构的文件)。即使在项目文件夹(也是我当前的工作目录)的根目录下有一个cscope.out和cscope.files,从相同的命令和相同的符号中也看不到任何东西。我怀疑该命令存在可伸缩性问题。我还尝试了命令

Some progress: If I make a small project of a few files with sub-dir structure. Then rici's answer works out of the box. With a bigger project (thousands of files with complex folder structure). Even with a cscope.out and cscope.files present at the root of the project folder (also my current working directory), I got nothing from the same command and same symbol. I suspect that there is a scalability issue with the command. I also tried command

cat cscope.files | xargs cscope -d -L1 <symbol> -i

无济于事。

更新

非常奇怪!我尝试使用其他一些符号。原来,我正在搜索的特定符号无法使用命令行显示。但是我尝试过的所有其他符号都起作用。而且cbrowser毫无问题地找到该失败符号。无论如何,我只是运气不好。我将在命令行中针对此异常询问一个单独的问题。

Extremely bizarre! I tried to use some other symbols. Turned out that the particular symbol I was searching for cannot be shown using the command line. But all other symbols I tried worked. And cbrowser has no problem finding that "failed" symbol. Anyways, I was just in bad luck. I'll ask a separate question about this anomaly in command line.

我将rici的答案标记为正确。

I marked rici's answer as correct.

推荐答案

您可以调用 -R 版本的cscope进行递归搜索。例如:

You can call cscope with the -R version for recursive searching. For example:

cscope -d -f/path/to/cscope.out -R -L1 some_symbol

(搜索some_symbol的定义)

(searches for the definition of some_symbol)

cscope -d -f/path/to/cscope.out -R -L3 some_symbol

(显示所有调用some_symbol的位置)

(shows all locations where some_symbol is called)

如果使用cscope,则可以省略 -f 选项。 out位于当前工作目录中。

You can omit the -f option if cscope.out is located in the current working directory.

请注意,如果 -R 被省略。较旧的cscope版本不支持 -R 。例如,版本15.8a确实支持它。

Note that the above call yield zero results for an indexed symbol if -R is omitted. Very old cscope versions don't support -R. For example, version 15.8a does support it.

-L 的可能值列表为:

0: Find this C symbol
1: Find this definition
2: Find functions called by this function
3: Find functions calling this function
4: Find this text string
6: Find this egrep pattern
7: Find this file
8: Find files #including this file
9: Find places where this symbol is assigned a value

The <$ c $创建 cscope.out 文件时,也可以使用c> -R 选项,例如:

The -R option can also be used when creating the cscope.out file, e.g.:

cscope -bR

这篇关于cscope:如何使用cscope通过命令行搜索符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆