【notes】【cscope】安装及配置使用等

0.env

ubuntu1804

1.下载、安装

1.下载

官网URL:
http://cscope.sourceforge.net/
下载URL参考:
https://sourceforge.net/projects/cscope/files/
下载文件名参考如下:
cscope-15.9.tar.gz

2.安装

前言:
可以通过sudo apt-get install cscope 安装。
没必要像我这样安装,我是因为版本问题才这么搞的。
使用apt安装后,如下安装步骤就不需要看了,可以直接看配置步骤了。

1, 解压源码得到如下文件夹:

$ tree cscope-15.9/
cscope-15.9/
├── acinclude.m4
├── aclocal.m4
├── AUTHORS
├── ChangeLog
├── compile
├── config.guess
├── config.h.in
├── config.sub
├── configure
├── configure.in
├── contrib
│   ├── cctree.txt
│   ├── cctree.vim
│   ├── Makefile.am
│   ├── Makefile.in
│   ├── ocs
│   ├── README
│   ├── webcscope
│   │   ├── cgi-lib.pl
│   │   ├── cscope
│   │   ├── hilite.c
│   │   ├── icons
│   │   │   ├── back.gif
...资源图片...
│   │   │   └── world2.gif
│   │   ├── INSTALL
│   │   ├── LICENSE
│   │   └── TODO
│   └── xcscope
│       ├── cscope-indexer
│       └── xcscope.el
├── COPYING
├── depcomp
├── doc                                                                                                                                                                               
│   ├── cscope.1
│   ├── Makefile.am
│   ├── Makefile.in
│   └── xcscope.1
├── INSTALL
├── INSTALL.gnu
├── install-sh
├── Makefile.am
├── Makefile.in
├── missing
├── mkinstalldirs
├── NEWS
├── packages
│   ├── cscope.spec
│   ├── MSDOS
│   │   ├── djmake.bat
│   │   ├── README
│   │   └── ylwrap.pat
│   └── uw7
│       ├── cscope_pkg.sh
│       ├── pkginfo
│       └── Prototype
├── README
├── src
│   ├── alloc.c
....各类源文件...
│   └── vpopen.c
├── TODO
└── ylwrap
  1. 编译命令参考如下:
# 1.生成Makefile
cd xxxxx/cscope-15.9/
./configure
# ret : 得到Makefile文件
# 2. 编译 
make
# 3. intall到系统
sudo make install

2.配置

1. 自动导入依赖文件

cscope依赖cscope.out的数据库,每次vim需要手动导入这个文件,
修改vim启动文件~/.vimrc,追加如下信息:

# 1.vim ~/.vimrc
if has("cscope")
    if filereadable("cscope.out")
        cs add cscope.out
    endif
endif

2.修改键盘映射

vim命令行模式输入命令执行各类命令,可以添加键盘映射,快捷执行,不必每次输入命令。
如下,vim命令,cs find g xxxxx可以查找该函数调用与被调用的文件名及其信息。修改键盘映射为ctrl+\ g 快捷组合键。

# 1. vim ~/.vimrc
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
# 修改cs find g xxx 为快捷键ctrl+\ g 。 映射其他命令也类似这里的操作,不再赘述。

3.使用autoload_cscope.vim插件,实现任意子目录下跳转

1.去官网下载autoload_cscope.vim插件,URL:https://www.vim.org/scripts/script.php?script_id=157
2.修改~/.vimrc , 可以将上述脚本程序直接追加到当前.vimrc中,如果有其他自定义配置,不建议覆盖当前.vimrc。修改环境文件前注意备份操作,养成好习惯。
PS:命令参考如下:
cp ~/.vimrc ~/.vimrc-bak
cat autoload_cscope.vim >> ~/.vimrc

3.使用

1.init database cscope.out

在当前文件夹下建立database及相关文件

# cmd 执行如下文件会多出三个文件
cscope -Rbq 
# R 循环遍历,包括子文件夹。其他参数参考如下:
/*
-b            Build the cross-reference only.
-C            Ignore letter case when searching.
-c            Use only ASCII characters in the cross-ref file (don't compress).
-d            Do not update the cross-reference.
-e            Suppress the <Ctrl>-e command prompt between files.
-F symfile    Read symbol reference lines from symfile.
-f reffile    Use reffile as cross-ref file name instead of cscope.out.
-h            This help screen.
-I incdir     Look in incdir for any #include files.
-i namefile   Browse through files listed in namefile, instead of cscope.files
-k            Kernel Mode - don't use /usr/include for #include files.
-L            Do a single search with line-oriented output.
-l            Line-oriented interface.
-num pattern  Go to input field num (counting from 0) and find pattern.
-P path       Prepend path to relative file names in pre-built cross-ref file.
-p n          Display the last n file path components.
-q            Build an inverted index for quick symbol searching.
-R            Recurse directories for files.
-s dir        Look in dir for additional source  files.
-T            Use only the first eight characters to match against C symbols.
-U            Check file time stamps.
-u            Unconditionally build the cross-reference file.
-v            Be more verbose in line mode.
-V            Print the version number.
*/

2.组合快捷键

1.上述修改了:cs find g xxxxx 命令的快捷键位ctrl+\ g ,光标选中某个函数funcname(),同时按下ctrl和\键,然后按g键即可查找cscope.out初始化文件夹下所有与此函数相关的文件及相关信息,如下log:

# cmd 
vi xxx/yyyy/main.c
# cmd : 光标指向一个函数 , 快捷键 ctr+\ 然后g跳转
# log : 选中了这个文件中get_phy_address()函数,然后执行快捷键操作,显示出多处定义
/*
Cscope tag: get_phy_address
   #   line  filename / context / line
   1   1661  drivers/net/ipq6018/ipq6018_edma.c <<get_phy_address>>
             void get_phy_address(int offset)
   2   1704  drivers/net/ipq807x/ipq807x_edma.c <<get_phy_address>>
             void get_phy_address(int offset)
Type number and <Enter> (empty cancels):
*/

更新进度

20210629 - INIT
20210706 - A 添加小结"使用autoload_cscope.vim插件,实现任意子目录下跳转"

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

过得精彩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值