[英]How to set a source files directory recursively in gdb?
I'm trying to debug a program in gdb with a functions source code but I always need to set the EXACT path of the C file for that function: 我正在尝试使用函数源代码调试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.
How can I tell gdb to recursively look for strcpy.c
in ~/Documents/glibc-2.28
without having to set the exact path every single time? 如何告诉gdb在
~/Documents/glibc-2.28
递归查找strcpy.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 /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)
I tried just setting the glibc directory but that doesn't work... 我尝试只设置glibc目录,但这不起作用...
It is common to build GLIBC this way: 通常以这种方式构建GLIBC:
cd glibc-2.28 && mkdir build && cd build && ../configure --prefix=/usr && make
This results in source paths similar to ../sysdeps/i386/i686/multiarch/strcpy.c
(they are relative to the build
directory). 这将导致源路径类似于
../sysdeps/i386/i686/multiarch/strcpy.c
(它们相对于build
目录)。
So what you want is: 所以您想要的是:
cd ~/Documents/glibc-2.28 && mkdir build; cd -
gdb -ex 'dir ~/Documents/glibc-2.28/build' -q char_array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.