문제

누구든지 공유 라이브러리에서 런타임 디버깅을 수행하는 방법을 알려줄 수 있습니까?

공유 라이브러리에서 함수를 런타임으로 바꾸어야하지만 다른 프로그램에 의해 호출되어야합니다. 공유 라이브러리와 함께 DBX와 같은 일을하려면 어떻게해야합니까?

AIX에서 DBX를 사용하고 있습니다. GDB가 내가하려는 일에 대해 DBX보다 더 나은가?.

도움이 되었습니까?

해결책

실행 파일로 GDB에 전화하면됩니다 (귀하의 경우 또는 타사 인 경우에는 중요하지 않습니다). 다음은 내가 디버깅하는 예입니다 ls (공유)에서 중단 점을 명령하고 설정 C 도서관. 이 예제는 지연된 (보류) 브레이크 포인트를 지원하는 GDB 6.8을 사용하여 다음을 쉽게 만듭니다.

gdb /bin/ls
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(no debugging symbols found)
(gdb) b write
Function "write" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (write) pending.
(gdb) r
Starting program: /bin/ls
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
(no debugging symbols found)
(no debugging symbols found)
[New Thread 0x7f98d2d23780 (LWP 7029)]
[Switching to Thread 0x7f98d2d23780 (LWP 7029)]

Breakpoint 1, 0x00007f98d2264bb0 in write () from /lib/libc.so.6
(gdb)

보시다시피 GDB는 실행 파일에서 사용하는 모든 스레드를 자동으로 관리합니다. 당신은 거기에서 스레드를 위해 특별한 일을 할 필요가 없습니다. 중단 점은 모든 스레드에서 작동합니다.

또는 디버거를 이미 실행중인 애플리케이션에 첨부하려면 꼬리 -f /tmp /ttt 여기에서 예를 들어) :

ps ux | grep tail
lothar    8496  0.0  0.0   9352   804 pts/3    S+   12:38   0:00 tail -f /tmp/ttt
lothar    8510  0.0  0.0   5164   840 pts/4    S+   12:39   0:00 grep tail

gdb
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(no debugging symbols found)
(gdb) attach 8496
Attaching to program: /usr/bin/tail, process 8496
Reading symbols from /lib/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/librt.so.1
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x7f24853f56e0 (LWP 8496)]
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/ld-linux-x86-64.so.2...
(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
(no debugging symbols found)
0x00007f2484d2bb50 in nanosleep () from /lib/libc.so.6
(gdb) b write
Breakpoint 1 at 0x7f2484d57bb0
(gdb) c
Continuing.
[Switching to Thread 0x7f24853f56e0 (LWP 8496)]

Breakpoint 1, 0x00007f2484d57bb0 in write () from /lib/libc.so.6
(gdb)

다른 팁

일반적으로 공유 라이브러리를 디버깅하는 절차는 실행 파일을 디버깅하는 것과 거의 동일합니다. 주된 차이점은 공유 라이브러리가 메모리에로드 될 때까지 중단 점을 설정할 수 없다는 것입니다. 디버거를 기본 실행 가능에 부착합니다.

귀하가 소유하지 않은 응용 프로그램을 디버깅하는 경우 플러그인 아키텍처에서 모듈을 사용하는 경우에도 동일한 방법을 사용합니다. 공유 라이브러리에 사용할 수있는 정보를 디버깅 할 수 있는지 확인하십시오. Windows에서 .pdb 파일을 생성합니다. GCC를 사용하면 디버깅 정보가 제공되도록 특수 컴파일러 플래그 (-g?)를 지정한다고 생각합니다. 디버거를 타사 응용 프로그램에 연결합니다.

Lothar의 답변에 대한 또 다른 예 :

동적 라이브러리에서 테스트를 실행하고 있습니다 test.so (컴파일 test.c) Linux에서 사용합니다 python 및 Python의 장치 테스트 라이브러리 unittest ~라고 불리는 tests/test_pwmbasic.py. (이름 지정 체계는 약간 모노톤입니다. 지금은 알고 있습니다)

~/my/test/path/
    tests/
        __init__.py
        test_pwmbasic.py
    test.c
    test.so

들어있는 것이 무엇인지 디버그하고 싶습니다 test.so 자극에서 test_pwmbasic.py. 그래서 이것이 내가 작동하는 방법입니다 ...

$ cd ~/my/test/path
$ gdb $(which python)
   ... gdb blah ...
(gdb) b test.c:179
(gdb) run
>>> from tests.test_pwmbasic import *
>>> import unittest
>>> unittest.main()
   ... unittest blah ...
Breakpoint 1, pwmTest_setDutyCycles (dutyCycles=0x7ffff7ece910) at ./test.c:179
(gdb) print pwm_errorCode
$1 = PWM_ERROR_NONE

그리고 지금 나는 GDB와 결혼하고 싶다

노트: test.c 또한 포함됩니다 ../pwm.c, 그래서 나는 또한 해당 라이브러리 내에서 중단 점을

(gdb) b pwm.c:123

나는 그것을 사용하는 모의 앱을 만들어 공유 라이브러리를 테스트하는 것을 기억합니다. 많은 작업을 수행하려는 경우, 타사 앱에서 라이브러리를 사용하는 방법에 대한 정보를 수집 한 다음 Mock 앱이 해당 정보를 재생하도록하는 두 번째 Mock Shared Library를 만들 수 있습니다.

물론, 잘 배치 된 printf 및 fprintf 호출의 힘을 의심하지 마십시오.

AIX에서 DBX를 사용해야 한 지 오랜 시간이 지났 으며이 문제에 직면했습니다. GDB를 설치하는 것은 옵션이 아닙니다.

dbx  /path/to/your/program
(dbx) run [args to your program]
(dbx) set $ignoreonbptrap           # I kept hitting a trace/bpt trap
(dbx) set $deferevents              # allows setting bp in not loaded shared library
(dbx) set $repeat                   # useful, repeat commands with <enter> tjust like gdb
(dbx) stop in MySharedLibraryFunc   # defers breakpoint
(dbx) cont

라이브러리를 정적으로 컴파일하고 연결하여 디버깅을 시도 할 수 있습니다.
버그가 공유 된대로 컴파일 된 경우에만 나타나면 단서를 줄 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top