我正在尝试使用函数源代码调试gdb中的程序,但是我总是需要为该函数设置C文件的精确路径:
frinto@kali:~/Documents/theclang/programs/helloworld$ gdb -q char_array
Reading symbols from char_array...done.
(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 6
Breakpoint 1 at 0x11c6: file char_array.c, line 6.
(gdb) break strcpy
Breakpoint 2 at 0x1040
(gdb) break 8
Breakpoint 3 at 0x11dc: file char_array.c, line 8.
(gdb) dir ~/Documents/glibc-2.28/sysdeps/i386/i686/multiarch
Source directories searched: /home/frinto/Documents/glibc-2.28/sysdeps/i386/i686/multiarch:$cdir:$cwd
(gdb) cont
The program is not being run.
(gdb) run
Starting program: /home/frinto/Documents/theclang/programs/helloworld/char_array
Breakpoint 1, main () at char_array.c:7
7 strcpy(str_a, "Hello, world!\n");
(gdb) cont
Continuing.
Breakpoint 2, strcpy_ifunc () at ../sysdeps/i386/i686/multiarch/strcpy.c:29
29 libc_ifunc_redirected (__redirect_strcpy, strcpy, IFUNC_SELECTOR ());
(gdb) cont
Continuing.
如何告诉gdb在strcpy.c
中递归查找~/Documents/glibc-2.28
,而不必每次都设置确切路径?
frinto@kali:~/Documents/theclang/programs/helloworld$ gdb -q char_array
Reading symbols from char_array...done.
(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 6
Breakpoint 1 at 0x11c6: file char_array.c, line 6.
(gdb) break strcpy
Breakpoint 2 at 0x1040
(gdb) break 8
Breakpoint 3 at 0x11dc: file char_array.c, line 8.
(gdb) dir /home/frinto/Documents/glibc-2.28
Source directories searched: /home/frinto/Documents/glibc-2.28:$cdir:$cwd
(gdb) run
Starting program: /home/frinto/Documents/theclang/programs/helloworld/char_array
Breakpoint 1, main () at char_array.c:7
7 strcpy(str_a, "Hello, world!\n");
(gdb) cont
Continuing.
Breakpoint 2, strcpy_ifunc () at ../sysdeps/i386/i686/multiarch/strcpy.c:29
29 ../sysdeps/i386/i686/multiarch/strcpy.c: No such file or directory.
(gdb) cont
Continuing.
Breakpoint 3, main () at char_array.c:8
8 printf(str_a);
(gdb)
我尝试仅设置glibc目录,但这不起作用...
答案 0 :(得分:0)
通常以这种方式构建GLIBC:
cd glibc-2.28 && mkdir build && cd build && ../configure --prefix=/usr && make
这将导致源路径类似于../sysdeps/i386/i686/multiarch/strcpy.c
(它们相对于build
目录)。
所以您想要的是:
cd ~/Documents/glibc-2.28 && mkdir build; cd -
gdb -ex 'dir ~/Documents/glibc-2.28/build' -q char_array