Backend/C

GDB

petitCoding 2011. 5. 26. 11:44






GDB란?

GDB는 프로그램 실행동안 프로그램 내부에서 진행되고 있는 상황들을 Line by Line으로 훑어볼 수 있는 툴이다.

GDB는 다음과 같은 일을 한다.

  • 프로그램을 시작할때 프로그램의 행동에 영향을 줄수 있는 것을 지정할수 있다.
  • 프로그램을 지정된 조건에서 멈추도록 만든다.
  • 프로그램이 멈추었을때 무엇이 일어났는지를 시험할수 있다.
  • 프로그램 내의 어떤것을 바꾸어서, 버그를 고칠수 있도록 테스트 할수 있다.

C나 C++로 쓰여진 프로그램을 디버깅하기 위해 GDB를 사용할수 있다.

 

다음은 간단한 gdb 사용 예이다.

 

//////////////////////////////////////////////////////////////////////////////////////

[whitelka]$ gdb a.out //gdb를 실행시킨다.
GNU gdb Red Hat Linux (6.1post-1.20040607.41rh)
Copyright 2004 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-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) b 47 //break point 설정, break 47 도 가능
Breakpoint 1 at 0x804864b: file main.c, line 47.

(gdb) run //실행 'r' 도 가능
Starting program: /home/whitelka/practices/c_sources/click_shild/dir/a.out
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xffffe000

Breakpoint 1, main () at main.c:47
47              unsigned long long  i = 0;

(gdb) s //다음행 수행
51              fp = fopen("url.txt", "r");
(gdb) //그냥 엔터를 치면 이전 명령 수행
53              while(!feof(fp)&& i<bufsize)
(gdb)
55                      fscanf(fp,"%s",&buf[i]);
(gdb)
56                      i++;
(gdb)
//////////////////////////////////////////////////////////////////////////////////////







반응형

'Backend > C' 카테고리의 다른 글

valgrind  (0) 2011.05.26
gprof  (0) 2011.05.26
memset()을 이용하여 메모리를 채워보자  (0) 2011.05.20
memcpy()를 이용한 메모리 카피!  (0) 2011.05.20
Valgrind로 메모리 누수 체크하기!!  (0) 2011.05.13