Passion/Programming

cscope 사용하기 + Emacs + FreeBSD

sunshout 2007. 3. 12. 00:25
- FreeBSD에서 cscope 설치하기
$ pkg_add -r cscope (패키지로 설치하면 emacs 사용시 필요한 것들을 만들지 못한다)
$ cd /usr/ports/devel/cscope
$ make

(cscope-indexer, xcscope.el 을 적당한 장소로 옮겨야 한다)
$ cd /usr/ports/devel/cscope/work/cscope-15.6/contrib/xcscope/
$ cp cscope-indexer /usr/local/bin
$ cp xcscope.el /usr/local/share/emacs/site-lisp/


- emacs 용 설정 하기
좀전에 copy 한 xcscope.el 파일을 보면 자신의 .emacs 파일에 무엇을 추가해야 하는지 나온다.

.emacs 파일 (Language : text)
;; Cscope setting
(require 'xcscope)

- emacs 에서 사용하기
이제 cscope 설치를 마쳤으니 emacs에서 cscope를 사용하면 된다.
먼저 할일은 emacs에서 cscope database를 생성하는 것이다.
M-x cscope-index-file <RET> 를 입력하고, 원하는 디렉토리 (ex. /usr/src/sys) 를 입력한다.
이후 원하는 파일을 열고 cscope를 사용하면 된다.

키 입력 설명
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.


- cscope 파일 만들기 (cscope 를 중심으로 사용하기)
$ rm -f cscope.files cscope.out
$ find . \( -name '*.c' -o -name '*.cc' -o -name '*.h' -o -name '*.s' \) -print >cscope.files
$ cscope -i cscope.files
찾는 방법을 줄일 수 있음
find ./ -name *.[chS] -print > cscope.files

- python 소스코드 분석용

find . \( -name '*.py' \) -print > cscope.files


검색을 통해 나온 리스트를 따라 가는 것은 SPACE (not Enter ^^;)