2013-05-08 2 views
4

일부 gdb 명령을 실행하는 간단한 텍스트 기반 사용자 인터페이스를 개발하려고합니다. 코드의 특정 영역에서 점을 설정하고 중단/추적하고 디버그 명령을 실행할 수 있기를 원합니다.GDB에서 함수 코드보기/인쇄

사용자가 디버깅해야하는 기능을 입력하고 싶습니다. 그런 다음이 함수 이름을 사용하여 함수의 소스 코드를 인쇄 한 다음 사용자에게 중단 점/추적 점을 설정할 코드 행을 선택하도록 요청합니다. 현재, 디스어셈블 명령을 사용하여 사용자의 메모리 주소를 출력 할 수 있지만 대신 실제 소스 코드를 인쇄하고 싶습니다.

gdb에서이 작업을 수행 할 수 있습니까? 현재

는 :

Dump of assembler code for function test_function: 
    0x03800f70 <test_function+0>: push %ebp 
    0x03800f71 <test_function+1>: mov %esp,%ebp 
    0x03800f73 <test_function+3>: sub $0x48,%esp 

내가 원하는 것은 :

void main() 
{ 
    printf("Hello World\n"); 
} 

감사합니다!

편집 : "목록 파일 이름을

(gdb) list directory/directory_etc/sourcefile.c:941 
936  in directory/directory_etc/sourcefile.c 

그래서 행동은 당신이 설명하는 것과 유사하지만, : 내가 지정 linenum 인 시도 후

(gdb) list myFunction 
941  directory/directory_etc/sourcefile.c: No such file or directory. 
     in directory/directory_etc/sourcefile.c 

: 나는이납니다 linenum 인을 "아직 작동하지 않습니다

고마워요!

+0

현재 함수 : http://stackoverflow.com/questions/12824251/gdb-list-source-of-current-function-without-typing-its-name –

답변

6

사용 : 당신은 아마 다음과 같은 경우에 충돌 것, 비 장난감 프로젝트의

(gdb) help list 
List specified function or line. 
With no argument, lists ten more lines after or around previous listing. 
"list -" lists the ten lines before a previous ten-line listing. 
One argument specifies a line, and ten lines are listed around that line. 
Two arguments with comma between specify starting and ending lines to list. 
Lines can be specified in these ways: 
    LINENUM, to list around that line in current file, 
    FILE:LINENUM, to list around that line in that file, 
    FUNCTION, to list around beginning of that function, 
    FILE:FUNCTION, to distinguish among like-named static functions. 
    *ADDRESS, to list around the line containing that address. 
With two args if one is empty it stands for ten lines away from the other arg. 

:

(gdb) list FUNCTION 

세부 사항에 대한 list 명령의 온라인 도움말을 참조하십시오

$ gdb /bin/true 
<...> 
(gdb) start 
<...> 
(gdb) list printf 
file: "/usr/include/bits/stdio2.h", line number: 104 
file: "printf.c", line number: 29 

코드베이스에있는 함수의 다중 정의를 나열합니다. 위의 경우 printf() 경우 오버로드되지 않은 순수 C 함수에는 두 가지 정의가 있습니다. 하나는 stdio2.h에 정의되어 있습니다. 를 들어

(gdb) list printf.c:29 
24 
25 /* Write formatted output to stdout from the format string FORMAT. */ 
26 /* VARARGS1 */ 
27 int 
28 __printf (const char *format, ...) 
29 { 
30 va_list arg; 
31 int done; 
32 
33 va_start (arg, format); 

: 당신은 다음 목록 할 일 지정 list FILE:LINENUM 양식을 사용할 수 없습니다 "sourcefile.c : 그런 파일이나 디렉토리"당신이보고있는 오류를, 당신은 어디 있는지하는 GDB 말할 필요 소스 코드. GDB Manual: Source Path을 참조하십시오. 분명히 당신은 실제로 당신이 당신의 기계에리스트하고 싶은 기능을위한 소스 코드를 가지고있을 필요가있을 것이다.

+0

감사합니다.이 명령을 간단한 파일에서 실행할 때 HelloWorld.exe) 문제가 없습니다. 그러나, 큰 라이브 시스템을 디버깅하는 데 gdb를 사용하려고합니다. 내가보기를 원하는 함수는 .elf 파일로 컴파일되는 많은 c 파일 중 하나입니다. 그리고 거기에서 실행할 때 : (gdb) list디렉토리/directory_etc/code.c의 941 – user2342775

+0

@ user2342775 , gdb의 list 명령이 함수 이름에 대한 몇 가지 정의를 보여주는 경우에 대한 답을 수정했습니다. 이게 너가 본거야? – scottt

+0

원래의 질문을 편집하여 읽기 쉽도록했습니다. 감사합니다. – user2342775