[ CnUnix ] in KIDS 글 쓴 이(By): swhan (Nameless1) 날 짜 (Date): 2004년 12월 27일 월요일 오후 04시 18분 38초 제 목(Title): Re: 기초적인 gdb 질문 뭐가 문제죠? 아래꺼 그대로 해보시고 안되면 -O0옵션을 줘보세요 ---- test.c --- #include <stdio.h> _a() { char TMPBUF[1024]; printf(__FUNCTION__"called \n");fflush(stdout); memset(TMPBUF, 0,sizeof(TMPBUF)); sprintf(TMPBUF, "HAHA I'm _a()"); printf(__FUNCTION__"TMPBUF=\"%s\" \n");fflush(stdout); printf(__FUNCTION__"return \n");fflush(stdout); } a() { printf(__FUNCTION__"before _a()\n");fflush(stdout); _a(); printf(__FUNCTION__"after _a()\n");fflush(stdout); } main() { a(); } --- end ---- $ gcc296 -g test.c Script started on Mon 27 Dec 2004 04:27:25 PM KST [swhan@cnode2 /tmp/test]$ gdb a.out [생략] (gdb) b _a Breakpoint 1 at 0x80484c5: file test.c, line 6. (gdb) run Starting program: /tmp/test/a.out abefore _a() Breakpoint 1, _a () at test.c:6 6 printf(__FUNCTION__"called \n");fflush(stdout); (gdb) bt #0 _a () at test.c:6 #1 0x08048588 in a () at test.c:15 #2 0x080485b7 in main () at test.c:21 #3 0x42015574 in __libc_start_main () from /lib/tls/libc.so.6 (gdb) p TMPBUF $1 = '\0' <repeats 72 times>, [garbages] ... (gdb) n _acalled 7 memset(TMPBUF, 0,sizeof(TMPBUF)); (gdb) n 8 sprintf(TMPBUF, "HAHA I'm _a()"); (gdb) p TMPBUF $2 = '\0' <repeats 1023 times> (gdb) n 9 printf(__FUNCTION__"TMPBUF=\"%s\" \n");fflush(stdout); (gdb) p TMPBUF $3 = "HAHA I'm _a()", '\0' <repeats 1010 times> (gdb) n _aTMPBUF="HAHA I'm _a()" 10 printf(__FUNCTION__"return \n");fflush(stdout); (gdb) n _areturn 11 } (gdb) n a () at test.c:16 16 printf(__FUNCTION__"after _a()\n");fflush(stdout); (gdb) n aafter _a() 17 } (gdb) bt #0 a () at test.c:17 #1 0x080485b7 in main () at test.c:21 #2 0x42015574 in __libc_start_main () from /lib/tls/libc.so.6 (gdb) c Continuing. Program exited normally. (gdb) quit [swhan@cnode2 /tmp/test]$ exit Script done on Mon 27 Dec 2004 04:28:13 PM KST |