달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

http://suite.tistory.com 2011.10

static 한 실행파일만 gdb로 디버깅해보다가 
dynamic 실행시 디버깅 방법 구글링좀하고 정리해둠~~
(데몬형태로 so 파일을 활용한 프로그램이  있을경우 디버깅  방법)

그냥 단순 예제로 tail 일경우 실제로는 디버깅할 프로세스명 사용!!!

ex)  특정 로그를 볼때 자주쓰는 tail -f 파일명.log 해두고

$]tail -f   Server.log

먼저 프로세스 번호 찾고
$) ps -ef |grep tail
18588 18560  0 17:20 pts/3    00:00:00 tail -f Server.log
19983 17905  0 18:44 pts/1    00:00:00 grep tail

gdb 실행후 실행프로세 디버깅 시작(attach)
$)gdb  tail
$)attach 18588
또는 한방에 $) gdb tail 18588

아래와같이 참조된 so 가 나오고
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gdb tail 18588
GNU gdb Red Hat Linux (6.3.0.0-1.159.el4rh)
Copyright 2004 Free Software Foundation, Inc.
to program: /usr/bin/tail, process 18588
Reading symbols from /lib/tls/i686/nosegneg/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/tls/i686/nosegneg/libm.so.6
Reading symbols from /lib/tls/i686/nosegneg/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/tls/i686/nosegneg/librt.so.1

...............
Loaded symbols for /lib/tls/i686/nosegneg/libpthread.so.0
0x009af7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 (gdb) b write
Breakpoint 1 at 0xb9c6b0

(gdb) continue

중지하고 다시 설정 할려면

(gdb) ctrl + c 하고 
source.cpp 에 77라인 브레이크 포인트 걸때 
(gdb)  b source.cpp:77
(gdb) continue
다음 n , s , p 등.. 디버깅 수행

뭐 이렇게하면 tail은 단순예이고 실제 개발한 so 파일이나  유지보수를 위해 실행하면서 소스 분석시 활용 가능함


 

 

:
Posted by mastar