cscope:
方法是調用Cscope時,使用-q參數。真的假的,一試便知。
修改cscope-indexer腳本,将 cscope -b -i $LIST_FILE -f $DATABASE_FILE 替換為 cscope -q -b -i $LIST_FILE -f $DATABASE_FILE
建立索引:
/mnt/trunk/base/3pp/linux-st7109/linux-2.6.23# gencsfil xkernel
/mnt/trunk/base/3pp/linux-st7109/linux-2.6.23# cscope-indexer -r
/mnt/trunk# gencsfil
/mnt/trunk# cscope-indexer -r //不能使用, 生成的索引太大了!!!--->>>>在trunk竟然生成了;
/mnt/trunk# cscope -Rbq --->>>>在trunk竟然生成了;
Cscope 基本快捷健: cscope-minor-mode 模式; 隻有進入c,cpp, .h 等檔案時才能使用下面的快捷鍵以及 menu菜單;
cscope-minor-mode http://www.gnu.org/software/emacs/manual/html_node/emacs/Minor-Modes.html
預設是的快捷鍵都是綁定到 C-c s 的字首上面,如果嫌麻煩的話可以自己更改 快捷鍵綁定。這是預設的用于查找的鍵綁定:
C-c C-h 檢視所有的 cscope 相關的按鍵 輸入M+x cscope 之後Tab健,就給出各種指令可以選擇;
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.; 看看指定的檔案被哪些檔案include
C-c s a 設定索引檔案所在目錄; 一般是你代碼的根目錄
C-c s I //隻要執行 C-c s I (cscope-index-files) 就可以 生成 Cscope 的資料庫; 對目錄中的相關檔案建立清單并進行索引
下面是在搜尋到的結果之間切換用的快捷鍵:
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.
1,copy 相關配置檔案 and database file.
Cscope的源碼包裡面有個xcscope.el檔案,為(X)Emacs提供了Cscope 接口。它處于源碼包的 contrib/xcscope 目錄下。
該目錄下面還有一個名為cscope-indexer的腳本檔案,用于建立檔案清單和資料庫。
xcscope.el檔案:::: http://opensource.apple.com/source/cscope/cscope-6/cscope/contrib/xcscope/xcscope.el?txt
[email protected]:/home/tools$ find . -name xcscope.el
./devtools/trunk/elisp/xcscope.el
[email protected]:/mnt/sda3/dev_iptv/ELYMUS_work$ which cscope-indexer
/home/leosu/bin/cscope-indexer
生成 cscope 索引檔案, 方法1:detail reference: http://hi.baidu.com/bamboolsu/blog/item/e61082632cca0dfde6113a90.html
find . \( -path "*3pp" \
-o -path "*testcases*" \
-o -path "*test*" \
-o -path "*applications*" \
-o -path "*Mock*" \
-o -path "*.svn*" \
-o -path "*.pc*" \
-o -path "*.idlcpp*" \
-o -path "*.idljs*" \
-o -path "*bcm*" \
-o -path "*dist*" \
-o -path "*st40*" \
-o -path "*mocks*" \) -prune -o -regex ".*\.\(cpp\|c\|h\|s\|S\|cc\)" -print > cscope.files
生成 cscope 索引檔案, 方法2:
生成 project 檔案清單,可以用如下指令完成。例如kernel代碼,找出是以 .h, .c, .S檔案
[email protected]:/mnt/sda3/dev_iptv/ELYMUS_work$find -type f | grep -E '\.[chS]$' > cscope.files
$ find . -name "*.cpp" -o -name "*.c" -o -name "*.h" > cscope.files
生成 cscope 索引檔案, -k 專門用于生成 linux kernel 源碼的索引
[email protected]:/mnt/sda3/dev_iptv/ELYMUS_work$cscope -b -k
生成 cscope 索引檔案, 方法3:
[email protected]:/mnt/sda3/dev_iptv/ELYMUS_work$ cscope-indexer
,可以根據自己的需要 hack cscope-indexer ,比如我通常用 quilt 管理 patch,會在源代碼目錄生成/.pc/目錄, 裡面是拷貝的 c 檔案,我并不希望 cscope-indexer 去搜尋這些檔案,看了一下這個檔案,無非就多加一個規則,慮除.pc 下所有檔案
egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \
- sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e 's/^\.\///' | \
+ sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e '/\/\.pc\//d' -e 's/^\.\///'| \
生成 cscope database: this need cscope.files files
# cscope -bkq
#cscope -b -i cscope.files //根據 cscope.files 生成 database
2, 修改.emacs 檔案
#vim .emacs
;;LOAD_PATH-------
;;;(add-to-list 'load-path' "/home/tools/devtools/trunk/elisp/")
;;(load "/home/tools/devtools/trunk/elisp/xcscope+.el")
;;(require 'cscope )
(setq cscope-do-not-update-database t)
(define-key global-map [(control f3)] 'cscope-set-initial-directory)
(define-key global-map [(control f4)] 'cscope-unset-initial-directory)
(define-key global-map [(control f5)] 'cscope-find-this-symbol)
(define-key global-map [(control f6)] 'cscope-find-global-definition)
(define-key global-map [(control f7)] 'cscope-find-global-definition-no-prompting)
(define-key global-map [(control f8)] 'cscope-pop-mark)
(define-key global-map [(control f9)] 'cscope-next-symbol)
(define-key global-map [(control f10)] 'cscope-next-file)
(define-key global-map [(control f11)] 'cscope-prev-symbol)
(define-key global-map [(control f12)] 'cscope-prev-file)
(define-key global-map [(meta f9)] 'cscope-display-buffer)
(define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
(require 'xcscope "/home/tools/devtools/trunk/elisp/xcscope.el")
hack xcscope.el 檔案
xcscope.el 也比較簡單,很多配置項都寫死了,沒法修改,比如在跳出的 cscope 視窗中, 選擇要跳轉到哪一個位置, 有 2 種方式: 一個是光标移動到函數位置,按回車。另一個是用滑鼠中鍵點選。
第 2 種方式是在是太奇怪了,我想把它改到滑鼠左鍵上, 修改 xcscope.el 檔案,mouse-2 改成 mouse-1 就大功告成
(if cscope-running-in-xemacs
(define-key cscope-list-entry-keymap [button2] 'cscope-mouse-select-entry-other-window)
- (define-key cscope-list-entry-keymap [mouse-2] 'cscope-mouse-select-entry-other-window))
+ (define-key cscope-list-entry-keymap [mouse-1] 'cscope-mouse-select-entry-other-window))
3 . 運作 emacs,以下是一些常用的按鍵
C-c s C-h 檢視所有的 cscope 相關的按鍵
C-c s a 設定索引檔案所在目錄
C-c s c 查找調用該函數的地方
C-c s g 查找該符号的全局定義
C-c s f 查找該符号對應的檔案
;; 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 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 cscope database maintanance:
;;
;; 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.
4, 不用快捷鍵操作 cscope,
從之後打開emacs後,輸入M+x cscope 之後Tab健,就給出各種指令可以選擇;
Possible completions are:
cscope-bury-buffer cscope-create-list-of-files-to-index
cscope-dired-directory cscope-display-buffer
cscope-display-buffer-toggle cscope-edit-list-of-files-to-index
cscope-find-called-functions cscope-find-egrep-pattern
cscope-find-files-including-file
cscope-find-functions-calling-this-function
cscope-find-global-definition
cscope-find-global-definition-no-prompting
cscope-find-this-file cscope-find-this-symbol
cscope-find-this-text-string cscope-help
cscope-index-files cscope-mouse-select-entry-other-window
cscope-next-file cscope-next-symbol
cscope-pop-mark cscope-prev-file
cscope-prev-symbol cscope-quit
cscope-select-entry-one-window cscope-select-entry-other-window
cscope-select-entry-specified-window cscope-set-initial-directory
cscope-show-entry-other-window cscope-tell-user-about-directory
cscope-unset-initial-directory cscope:menu
Reference:
http://blog.csdn.net/intrepyd/article/details/4202312
http://lifegoo.pluskid.org/wiki/EmacsCscope.html