1. 프로세스 아이디 확인

$ ps -ux
USER        PID  %CPU %MEM     VSZ  RSS  TT  STAT  STARTED      TIME COMMAND
myevan  46674     0.0       0.2      39732  1784  pa- SL     10 507            84:27.05 ./game

2. gdb 실행파일 로드
$ gdb game
GNU gdb 5.2.1 (FreeBSD)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
(gdb)

3. 프로세스 연결
(gdb) attach 46674
Attaching to program: home/myevan/game, process 46674
Reading symbols from /lib/libz.so.2...done.
Loaded symbols for /lib/libz.so.2
Reading symbols from /usr/lib/libstdc++.so.4...done.
Loaded symbols for /usr/lib/libstdc++.so.4
Reading symbols from /lib/libm.so.2...done.
Loaded symbols for /lib/libm.so.2
Reading symbols from /usr/lib/libc_r.so.5...done.
Loaded symbols for /usr/lib/libc_r.so.5
Reading symbols from /lib/libc.so.5...done.
Loaded symbols for /lib/libc.so.5
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
[Switching to Process 68794, Thread 1]
0x283a32af in poll () from /lib/libc.so.5
(gdb)

4. 브레이크 포인트 설정
(gdb) b do_skillup
Breakpoint 1 at 0x8111419: file cmd_general.cpp, line 791.

5. c++ 멤버 함수 브레이크 포인트 설정
(gdb) rbreak CHARACTER::SkillLevelUp
Breakpoint 2 at 0x80c91f2: file char_skill.cpp, line 576.
void CHARACTER::SkillLevelUp(unsigned long, unsigned char);

6. 브레이크 포인트 리스트 보기
(gdb) info b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x08111419 in do_skillup(CHARACTER*, char*, int, int) at cmd_general.cpp:791
2   breakpoint     keep y   0x080c91f2 in CHARACTER::SkillLevelUp(unsigned long, unsigned char) at char_skill.cpp:576

7. 브레이크 포인트 제거
(gdb) delete 1
(gdb) info b
Num Type           Disp Enb Address    What
2   breakpoint     keep y   0x080c91f2 in CHARACTER::SkillLevelUp(unsigned long, unsigned char) at char_skill.cpp:576

8. 디버깅 시작
(gdb) c
Continuing.

9. 프롬프트 모드로
^C
Program received signal SIGINT, Interrupt.
0x283a32af in poll () from /lib/libc.so.5
(gdb)

10. 프로세스 연결 해제
(gdb) detach
Detaching from program: home/myevan/game, Process 46674, Thread 0
(gdb) quit
$

관련링크:
KLDP GDB 잘 쓰기
GDB 를 이용한 디버깅
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/05/31 17:18 2007/05/31 17:18