我正在阅读一些关于gdb的资料,但我在让gdb (我运行的是7.11.1)从库中调试函数时遇到了问题。
用于了解调试器的示例代码非常简单:
#include <stdio.h>
#include <string.h>
int main() {
char str_a[20];
strcpy(str_a, "Hello, world!\n");
printf(str_a);
}我编译它时启用了调试符号,启动了GDB,并设置了一些断点:
(gdb) list
1 #include <stdio.h>
2 #include <string.h>
3
4 int main() {
5 char str_a[20];
6
7 strcpy(str_a, "Hello, world!\n");
8 printf(str_a);
9 }
(gdb) break 7
Breakpoint 1 at 0x4005ad: file char_array2.c, line 7.
(gdb) break strcpy
Function "strcpy" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (strcpy) pending.
(gdb) break 8
Breakpoint 3 at 0x4005cf: file char_array2.c, line 8.
(gdb) run
Starting program: /home/david/hacking_the_art_of_exploitation/Chapter_2/char_array2
Breakpoint 1, main () at char_array2.c:7
7 strcpy(str_a, "Hello, world!\n");
(gdb) continue
Continuing.
Breakpoint 3, main () at char_array2.c:8
8 printf(str_a);
(gdb) continue
Continuing.
Hello, world!
[Inferior 1 (process 7061) exited normally]如您所见,调试器永远不会深入到strcpy函数。
我尝试将set stop-on-solib-events 1添加到我的.gdbinit中。这会导致不同但仍然不受欢迎的结果:
(gdb) run
Starting program: /home/david/hacking_the_art_of_exploitation/Chapter_2/char_array2
Stopped due to shared library event (no libraries added or removed)我有点不知所措。提前感谢您的帮助。
发布于 2017-11-25 18:28:59
我相信您需要libc-dbg包和libc源码包来调试libc函数。在Ubuntu上,你可以通过
sudo apt-get install libc6-dbg
mkdir ~/libc ; cd ~/libc
apt-get source libc6https://stackoverflow.com/questions/47482211
复制相似问题