emacs ecb cscope 阅读源代码

来源:互联网 发布:淘宝店铺页头装修代码 编辑:程序博客网 时间:2024/06/02 07:37

声明:这篇博文全部内容均来源于网络,在这里针对自己的需要做了整理,主要是为了方便以后查找;参考资料全部在结尾给出。
步骤:
1、首先安装emacs:sudo apt-get install emacs
2、安装ecb:  sudo apt-get install ecb
     启动emacs, 执行命令: M-x ecb-activate 会调出4个窗口;ecb启动的时候会弹出一个提示窗口,如果不想看到它,可以在emacs配置文件(~/.emacs)里加这一句:
     (setq ecb-tip-of-the-day nil)
3、安装cscope: 首先到 Cscope 的主页 上去下载最新的源代码包,编译安装(注意cscope需要安装在emacs可以找到的地方,如PATH中)。要在 Emacs 里面
     使用,首先必须把 xcscope.el 拷贝到 load-path 里面包含的目录里面。并在 ~/.emacs 里面加上 (require 'xcscope) 。把 脚本cscope-indexer 拷贝到系
     统 PATH 里面去(如 /usr/bin/)。
4、默认情况下, Emacs每次调用 Cscope 时都会检查是否有文件被改动过。如果有的话,就会自动重新编译 cscope 数据库 (cscope.out)。这个功
     能相当实用。但是如果工程十分庞大,即使是判断文件更新与否也很费时,可以告诉 Emacs 别自动更新 cscope.out:
     (setq cscope-do-not-update-database t)
5、基本使用:
     这里以内核源码为例,介绍Cscope的基本用法。
     1. 首先,在源码根目录下,如~/kernerl/linux-2.6.29.3,利用cscope-indexer脚本生成文件列表和数据库,方法是执行
         cscope-indexer -r
     -r  参数表示递归检索子目录,文件列表和数据库的默认文件名分别为cscope.files和cscope.out,可以使用-i,-f参数进行修改,请参考man了解脚本参数用法。
     2. 激动人心的时刻到了。用emacs打开init/main.c,C-s搜索sched_init函数,将光标停在函数名上,按C-c s d,回车进行查找。结果居然用了35.32秒,汗!
         原 来,Cscope默认在每次进行查找时更新cscope.out。当工程十分庞大时,建议关闭该选项以提高查找速度。方法是在~/.emacs文件中加入
        (setq cscope-do-not-update-database t)
        重复上述操作,结果仍然用了9.89秒,再汗!莫非是我的古董本太慢?
     3. 百度一下,你就知道:) Cscope可以通过创建反向索引加速查找,方法是调用Cscope时,使用-q参数。真的假的,一试便知。修改cscope-indexer脚本,将
         cscope -b -i $LIST_FILE -f $DATABASE_FILE
         替换为
         cscope -q -b -i $LIST_FILE -f $DATABASE_FILE
         进入内核根目录,删除先前的文件列表和数据库,重新调用cscope-indexer。这回多生成了两个文件,cscope.in.out和cscope.po.out。重试刚才的查找,
         结果只用了0.08秒,大功告成。
 6、快捷键绑定

     默认是的快捷键都是绑定到 C-c s 的前缀上面,如果嫌麻烦的话可以自己更改 快捷键绑定。这是默认的用于查找的键绑定:
         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.
     下面是在搜索到的结果之间切换用的快捷键:
         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.

7、参考资料
         a) 在Emacs中使用cscope   http://lifegoo.pluskid.org/wiki/EmacsCscope.html
         b)  配置emacs 阅读C代码   http://hi.baidu.com/liuhengloveyou/blog/item/e5cf03c7a25239dbd1006013.html
         c)  Cscope在emacs中的配置与使用  http://www.cnblogs.com/jtf-china/articles/2077922.html

 

原创粉丝点击