관심있는 것들 정리

cscope 사용법 정리 본문

utility 사용법/그 외

cscope 사용법 정리

내공강화 2014. 7. 28. 23:58

Cscope 사용법

web site: http://cscope.sourceforge.net

  • database file 만들기

다음과 같은 스크립트를 만들어 db 파일인 cscope.out 파일 생성시 사용

mkcscope.sh

#!/bin/bash
files=$(find . -name '*.cpp' -o -name '*.c' -o -name '*.cc' -o -name '*.h' -o -name '*.s' -o -name ‘*.S’)
cscope -i $$files
  • cscope 사용

shell에서 cscope를 입력하면 다음과 같이 symbol lookup 화면이 나타남

Cscope version 15.8a                                   Press the ? key for help







Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Find assignments to this symbol:

여기서 원하는 symbol을 입력후 RETURN 키를 누르면 원하는 파일을 찾아준다.

C symbol: printf

  File    Function Line
0 test.c  main     6 printf("hello world\n");
1 test2.c main     5 printf("hello world!\n");




Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:
Find assignments to this symbol:

화살표 위/아래 버튼 또는 ^P/^N 버튼으로 커서를 위 아래로 이동하며 ENTER를 누르거나 제일 왼쪽에 나타난 숫자를 입력하면 바로 해당 파일로 이동한다.

위 화면에서 ^B을 누르면 다시 symbol을 찾는 위치로 이동해 새로운 symbol을 찾을 수가 있다.

  • vim에서 cscope 설정

.vimrc에 다음과 같은 설정을 해 주어야 vim과 연동이 가능하다.

(설정은 MacOSX 10.9를 기준으로 작성하였음)

set cscopeprg=/usr/local/bin/cscope
set csto=0
set cst
set nocsverb
cs add ./cscope.out
set csverb

cscope.out이 포함된 디렉토리 추가시 cs add 와 함께 디렉토리를 추가해주면 된다. 위 예는 vim을 실행할 때 위치하는 현재 디렉토리의 cscope.out 파일을 DB 파일로 사용한다는 설정이다.

vim에서 cscope를 사용할 때는 command mode에서 다음과 같이 명령을 입력한다.

:cs find {querytype} {name}

querytype은 다음과 같다.

0 or s: Find this C symbol
1 or g: Find this definition
2 or d: Find functions called by this function
3 or c: Find functions calling this function
4 or t: Find this text string
6 or e: Find this egrep pattern
7 or f: Find this file
8 or i: Find files #including this file

상세한 내용은 vim 내부 문서인 vimdoc에서 찾아 볼 수 있는데 vim 실행 후 command mode에서 다음과 같이 입력하면 상세 내용을 참고할 수 있다.

:help cscope-find

출력 화면

  cscope-find cs-find E567
find  : Query cscope.  All cscope query options are available
except option #5 ("Change this grep pattern").

USAGE   :cs find {querytype} {name}

{querytype} corresponds to the actual cscope line
interface numbers as well as default nvi commands:

0 or s: Find this C symbol
1 or g: Find this definition
2 or d: Find functions called by this function
3 or c: Find functions calling this function
4 or t: Find this text string
6 or e: Find this egrep pattern
7 or f: Find this file
8 or i: Find files #including this file

For all types, except 4 and 6, leading white space for {name} is
if_cscop.txt [Help][-][RO]                                    115,11-39      23%
  • emacs에서 cscope 사용하기

emacs용 cscope 활용은 다음 링크를 참조하도록 한다.

http://sunshout.tistory.com/92

반응형