Linux 如何使用 cscope?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3828157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:40:19  来源:igfitidea点击:

How to use cscope?

clinuxvimcscope

提问by narayanpatra

I am using cscope to get familiar with all the keywords used in socket programming. I went to the directory with c files. I used cscope. and then I searched for AF_INET. I got this :

我正在使用 cscope 来熟悉套接字编程中使用的所有关键字。我去了有c文件的目录。我用过cscope。然后我搜索了 AF_INET。我懂了 :

#define AF_FILE         PF_FILE
#define AF_INET         PF_INET
#define AF_AX25         PF_AX25

This was a full page. I only published part of it. Now I want to know from where this PF_INET is coming? what command I should use. I have seen a guy to double click on PF_INEt and using some command to find it. I don't know what the command is? Kindly help me in this.

这是一个完整的页面。我只发表了一部分。现在我想知道这个 PF_INET 是从哪里来的?我应该使用什么命令。我见过有人双击 PF_INEt 并使用一些命令来找到它。不知道是什么命令?请帮助我。

The second thing is when i quit the page with :q command. I come to this page :

第二件事是当我使用 :q 命令退出页面时。我来到这个页面:

Global definition: AF_INET

  File     Line
0 socket.h 119 #define AF_INET PF_INET










Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:

here the cursor is blinking at 0. If I want to search again something, how I will do? How to navigate from here. I tried to google it but unable to understand anything from the tutoials. Please help me in this regard as I am complete noob to linux operating system and c programming. Thanks in advance.

此处光标在 0 处闪烁。如果我想再次搜索某些内容,我将怎么做?如何从这里导航。我试图用谷歌搜索它,但无法理解教程中的任何内容。请在这方面帮助我,因为我对 linux 操作系统和 c 编程完全是菜鸟。提前致谢。

采纳答案by Benoit

I agree that cscope documentation is not very clear.

我同意 cscope 文档不是很清楚。

Use tab to move to the interactive part. Type your symbol name in “find this C symbol” or “Find this egrep pattern” and validate pressing RETURN.

使用 Tab 键移动到交互部分。在“查找此 C 符号”或“查找此 egrep 模式”中键入您的符号名称,然后按 RETURN 确认。

If you want to call it from vim, type :help if_cscop.txt; hoping it helps!

如果你想从 vim 调用它,输入:help if_cscop.txt; 希望有帮助!

:cscope add your_cscope_database
:cscope find s [your_symbol]

This will make a new quickfix list. use :cnand :cpto navigate, :cnfand :cpfto navigate from file to file in the results, and :colderand :cnewerto restore previous quickfix lists.

这将创建一个新的快速修复列表。使用:cn:cp浏览,:cnf:cpf从文件中的结果定位到文件,:colder:cnewer恢复以前的quickfix列表。

回答by ninjalj

To exit from cscope interactive prompt, type Ctrl-d. If you just want to rebuild cscope's database, and not invoke cscope's interactive prompt, pass it the -b option. I usually invoke cscope as cscope -bcqR.

要退出 cscope 交互式提示,请键入Ctrl-d。如果您只想重建 cscope 的数据库,而不是调用 cscope 的交互式提示,请将 -b 选项传递给它。我通常将 cscope 作为cscope -bcqR.

As for jumping around in vim using cscope, it really depends on your vim config.

至于使用 cscope 在 vi​​m 中跳转,这实际上取决于您的 vim 配置。

Most probably, jump to tag (Ctrl-]) will use cscope first, then ctags (see :help cstand :help csto). Use Ctrl-Tto go back.

最有可能的是,跳转到 tag ( Ctrl-]) 将首先使用 cscope,然后是 ctags(参见:help cst:help csto)。用于Ctrl-T返回。

There are some useful mappings for cscope that you can find by typing :help cscope-suggestionsin vim. After adding those mappings to your .vimrc, you will be able to jump to symbols using Ctrl-_ s, the calling function using Ctrl-_ c, etc...

通过:help cscope-suggestions在 vim 中键入,您可以找到一些有用的 cscope 映射。将这些映射添加到您的 .vimrc 后,您将能够使用 跳转到符号Ctrl-_ s,使用Ctrl-_ c等调用函数...

You can access vim's cscope documentation by typing :help cscope.

您可以通过键入来访问 vim 的 cscope 文档:help cscope

回答by vaishnavi athipatla

I mostly use the following. These are very basic to understand the cscope.

我主要使用以下内容。这些是理解 cscope 的基础。

  1. "cscope -R" Then you get options.
  2. Press down arrow. Then you will move to your required option. Type whatever you want at the respective option.
  3. From the search result. Use arrows(Up and down) then Press "enter key" to see the detailed file.
  4. ":q" to exit from the file.
  5. Press "Tab key" to come to the cscope options.
  6. "ctrl + d" to exit from the cscope.
  1. "cscope -R" 然后你会得到选项。
  2. 按向下箭头。然后,您将转到所需的选项。在相应的选项中输入您想要的任何内容。
  3. 从搜索结果来看。使用箭头(向上和向下)然后按“输入键”查看详细文件。
  4. ":q" 退出文件。
  5. 按“Tab 键”进入 cscope 选项。
  6. “ctrl + d”退出cscope。