2009-07-09 10 views
17

단일 디렉토리에있는 소스 파일을 재귀 적으로 검색하기 위해 유닉스에서 gdb를 언급하는 방법 예 : 하나의 모듈에 다른 buiding 블록이있는 경우. a는 b, c, d의 상위 디렉토리입니다. 여기서 b, c, d는 하위 디렉토리입니다. 이고 원본 파일은 b, c, b로 배포됩니다. gdb에 모든 소스 파일이 (상위 디렉토리)에 있다는 것을 언급하면됩니다. gdb는 프로그램을 디버깅하는 동안 참조로 사용하고 소스 파일을 재귀 적으로 검색합니다.gdb 소스 디렉토리 검색

답변

16

아니면 디렉토리 srcdir에 소스 프로그램 prog 디버깅을 위해이 같은 작업을 수행 할 수 있습니다

gdb `find srcdir -type d -printf '-d %p '` prog 

나는 그것이 당신의 질문에 직접적인 대답 생각합니다. 실행 파일에 컴파일 디렉토리가 없거나 gdb 버전 6.6 이상이없는 경우에도 유용합니다.

5
(gdb) help files 
Specifying and examining files. 

List of commands: 

add-shared-symbol-files -- Load the symbols from shared objects in the dynamic linkers link map 
add-symbol-file -- Load symbols from FILE 
add-symbol-file-from-memory -- Load the symbols out of memory from a dynamically loaded object file 
cd -- Set working directory to DIR for debugger and program being debugged 
core-file -- Use FILE as core dump for examining memory and registers 
directory -- Add directory DIR to beginning of search path for source files 
edit -- Edit specified file or function 
exec-file -- Use FILE as program for getting contents of pure memory 
file -- Use FILE as program to be debugged 
forward-search -- Search for regular expression (see regex(3)) from last line listed 
generate-core-file -- Save a core file with the current state of the debugged process 

(gdb) help directory 

Add directory DIR to beginning of search path for source files. 
Forget cached info on source file locations and line positions. 
DIR can also be $cwd for the current working directory, or $cdir for the 
directory in which the source file was compiled into object code. 
With no argument, reset the search path to $cdir:$cwd, the default. 
21

set substitute-path입니다.

(gdb) set substitute-path /usr/src/include /mnt/include 

gdb의 최근 버전 (6.6 이상)에서만 사용 가능합니다.

+0

"set directories"는 최신 버전에서도 사용할 수 있습니다. – ernesto

+0

또한'set substitute-path/home/me/project c : \\ Users \\ me \\ project'와 같은 Windows에서도 작동합니다. –

+0

다른 컴퓨터에 코어 파일을로드하면 소스 경로가 다를 수 있습니다. '$ gdb program corefile' 또는'$ gdb -c corefile program'의 경우에는 대체 할 수 없습니다. 이 경우'$ gdb program'을 실행하고'(gdb) set substitute-path/home/me/project/my/new/path'를 대체하고 corefile'(gdb) core-file corefile'을 적재해야합니다. –