博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
emacs + cscope 的使用
阅读量:4030 次
发布时间:2019-05-24

本文共 3177 字,大约阅读时间需要 10 分钟。

1.首先到 


下载cscope

2.安装:

     tar -zxf cscope-xx.x.tar.gz

     cd cscope-xx.x

     ./configure

     make

     make install

    然后把contib/xcscope/目录下的cscope-indexer复制到PATH目录比如/usr/local/bin 

3.配置

    接着whereis emacs 看下emacs安装在哪里,

    把cscope-xx.x目录下的 contrib/xcscope/xcscope.el文件拷贝到/usr/share/emacs/site-lisp/目录下面.

     cp contrib/xcscope/xcscope.el /usr/share/emacs/site-lisp/

     

     在.emacs文件中添加

      (require 'cc-mode)

      (load-file "/usr/share/emacs/site-lisp/xcscope.el")

      (require 'xcscope)

4 生成索引文件

   要使用cscope的强大功能,首先需要为我们的代码生成一个cscope数据库。生成数据库很简单,在我们的项目根目录运行下面的运行

     cscope -Rbkq

   会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。其中cscope.out是基本的符号索引,后两个文件是使用"-q"选项生成的,可以加快cscope的索引速度。

   参数意义如下:

    -R: 在生成索引文件时,搜索子目录树中的代码

    -b: 只生成索引文件,不进入cscope的界面

    -k: 在生成索引文件时,不搜索/usr/include目录

    -q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度

    -i: 如果保存文件列表的文件名不是cscope.files时,需要加此选项告诉cscope到哪儿去找源文件列表。可以使用“-”,表示由标准输入获得文件列表。

    -I dir: 在-I选项指出的目录中查找头文件

    -u: 扫描所有文件,重新生成交叉索引文件

    -C: 在搜索时忽略大小写

    -P path: 在以相对路径表示的文件前加上的path,这样,你不用切换到你数据库文件所在的目录也可以使用它了

    Cscope只在第一次解析时扫描全部文件,以后再调用cscope,它只扫描那些改动过的文件,这大大提高了cscope生成索引的速度。 

    在缺省情况下,cscope在生成数据库后就会进入它自己的查询界面,我们一般不用这个界面,所以使用了“-b”选项。如果你已经进入了这个界面,按CTRL-D退出。 

    Cscope在生成数据库中,在你的项目目录中未找到的头文件,会自动到/usr/include目录中查找。如果你想阻止它这样做,使用“-k”选项。

   

Cscope缺省只解析C文件(.c和.h)、lex文件(.l)和yacc文件(.y),虽然它也可以支持C++以及Java,但它在扫描目录时会跳过

C++及Java后缀的文件。如果你希望cscope解析C++或Java文件,需要把这些文件的名字和路径保存在一个名为cscope.files的文

件。当cscope发现在当前目录中存在cscope.files时,就会为cscope.files中列出的所有文件生成索引数据库。

    find . -name "*.h" -o -name "*.c" -o -name "*.cc"  -o -name "*.cpp" -o -name "*.hpp" > cscope.files

cscope -bkq -i cscope.files

5 在代码中穿梭

  查找函数或者变量 c-c s s

  查找函数或变量的定义 c-c s g

  查找函数在哪里被调用了,c-c s c

  查找该函数调用了哪些函数 c-c s C

  查找到的函数上次出现的位置 c-c s p

  查找到的函数下次出现的位置 c-c s n

;; * Keybindings:

;;

;; All keybindings use the "C-c s" prefix, but are usable only while

;; editing a source file, or in the cscope results buffer:

;;

;;      C-c s s         Find symbol.

;;      C-c s d         Find global definition.

;;      C-c s g         Find global definition (alternate binding).

;;      C-c s G         Find global definition without prompting.

;;      C-c s c         Find functions calling a function.

;;      C-c s C         Find called functions (list functions called

;;                      from a function).

;;      C-c s t         Find text string.

;;      C-c s e         Find egrep pattern.

;;      C-c s f         Find a file.

;;      C-c s i         Find files #including a file.

;;

;; These pertain to navigation through the search results:

;;

;;      C-c s b         Display *cscope* buffer.

;;      C-c s B         Auto display *cscope* buffer toggle.

;;      C-c s n         Next symbol.

;;      C-c s N         Next file.

;;      C-c s p         Previous symbol.

;;      C-c s P         Previous file.

;;      C-c s u         Pop mark.

;;

;; These pertain to setting and unsetting the variable,

;; `cscope-initial-directory', (location searched for the cscope database

;;  directory):

;;

;;      C-c s a         Set initial directory.

;;      C-c s A         Unset initial directory.

;;

;; These pertain to cscope database maintenance:

;;

;;      C-c s L         Create list of files to index.

;;      C-c s I         Create list and index.

;;      C-c s E         Edit list of files to index.

;;      C-c s W         Locate this buffer's cscope directory

;;                      ("W" --> "where").

;;      C-c s S         Locate this buffer's cscope directory.

;;                      (alternate binding: "S" --> "show").

;;      C-c s T         Locate this buffer's cscope directory.

;;                      (alternate binding: "T" --> "tell").

;;      C-c s D         Dired this buffer's directory.

另一篇文章:

转载地址:http://fambi.baihongyu.com/

你可能感兴趣的文章
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
面试---刷牛客算法题
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>
用find命令查找最近修改过的文件
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
在android上运行native可执行程序
查看>>
Phone双模修改涉及文件列表
查看>>
android UI小知识点
查看>>
Android之TelephonyManager类的方法详解
查看>>