在GDB中搜索源目录

在GDB中搜索源目录,gdb,debugging,Gdb,Debugging,如何让*nix中的GDB递归地搜索单个目录中的源文件? 例如: 如果一个模块中有一些不同的构建块 a是b、c、d的父目录,其中b、c、d是子目录 源文件分布在b、c、b中 我需要向GDB指定所有源文件都位于“a”(父目录)中,GDB应将其用作参考,并在调试程序时递归搜索源文件。这需要的是命令 (gdb) help files Specifying and examining files. List of commands: add-shared-symbol-files -- Load

如何让*nix中的GDB递归地搜索单个目录中的源文件? 例如:

  • 如果一个模块中有一些不同的构建块
  • a是b、c、d的父目录,其中b、c、d是子目录
  • 源文件分布在b、c、b中

我需要向GDB指定所有源文件都位于“a”(父目录)中,GDB应将其用作参考,并在调试程序时递归搜索源文件。

这需要的是命令

(gdb) help files
Specifying and examining files.

List of commands:

add-shared-symbol-files -- Load the symbols from shared objects in the dynamic linkers link map  
add-symbol-file -- Load symbols from FILE  
add-symbol-file-from-memory -- Load the symbols out of memory from a dynamically loaded object file  
cd -- Set working directory to DIR for debugger and program being debugged  
core-file -- Use FILE as core dump for examining memory and registers  
directory -- Add directory DIR to beginning of search path for source files
edit -- Edit specified file or function  
exec-file -- Use FILE as program for getting contents of pure memory  
file -- Use FILE as program to be debugged  
forward-search -- Search for regular expression (see regex(3)) from last line listed  
generate-core-file -- Save a core file with the current state of the debugged process  

(gdb) help directory  

Add directory DIR to beginning of search path for source files.  
Forget cached info on source file locations and line positions.  
DIR can also be $cwd for the current working directory, or $cdir for the  
directory in which the source file was compiled into object code.  
With no argument, reset the search path to $cdir:$cwd, the default.  

但是,仅在gdb的最新版本(6.6+)中可用。

或者您可以执行类似操作,以便在目录
srcdir
中使用源代码调试程序
prog

gdb `find srcdir -type d -printf '-d %p '` prog

我认为这是对你问题的更直接的回答。如果您的可执行文件不包含编译目录和/或您没有gdb的6.6+版本,也很有用。

For medirectory命令运行良好

我刚刚进入了顶层目录,其中包含目标系统二进制文件、库和源(目标系统根)。 GDB递归地找到了所有必要的东西

请查看,以下是屏幕截图:

(gdb) list
705 /usr/src/debug/babeltrace/1.5.1-r0/git/converter/babeltrace.c: No such file or directory.
(gdb) directory /home/egradra/SDK_AXM5612/sysroots/armv7a-vfp-neon-wrs-linux-gnueabi
Source directories searched: /home/egradra/SDK_AXM5612/sysroots/armv7a-vfp-neon-wrs-linux-gnueabi:$cdir:$cwd
(gdb) list
705             goto end;
706         }
707     }
708     ret = 0;
709 
710 end:
711     bt_ctf_iter_destroy(iter);
712 error_iter:
713     bt_iter_free_pos(begin_pos);
714     bt_iter_free_pos(end_pos);
(gdb) 

“设置目录”也可以在最新版本中使用。它也适用于Windows,如
设置替换路径/home/me/project c:\\Users\\me\\project
。如果在另一台计算机上加载核心文件,则源路径可能不同。在
$gdb program corefile
$gdb-c corefile program
的情况下,不能替换。在这种情况下,您应该运行
$gdb程序
,然后进行替换
(gdb)设置替换路径/home/me/project/my/new/path
,并加载核心文件
(gdb)核心文件
(gdb) list
705 /usr/src/debug/babeltrace/1.5.1-r0/git/converter/babeltrace.c: No such file or directory.
(gdb) directory /home/egradra/SDK_AXM5612/sysroots/armv7a-vfp-neon-wrs-linux-gnueabi
Source directories searched: /home/egradra/SDK_AXM5612/sysroots/armv7a-vfp-neon-wrs-linux-gnueabi:$cdir:$cwd
(gdb) list
705             goto end;
706         }
707     }
708     ret = 0;
709 
710 end:
711     bt_ctf_iter_destroy(iter);
712 error_iter:
713     bt_iter_free_pos(begin_pos);
714     bt_iter_free_pos(end_pos);
(gdb)