gdb searching for source directories

谁都会走 提交于 2020-01-09 06:28:29

问题


how do i mention to gdb in unix to search for source files inside a single directory recursively for example if there are some different buiding blocks in one module. a is parent directory for b, c, d where b,c,d are child directories. and source files are distributed in b,c,b. i just have to mention to gdb that all the source files are located in a(parent directory). which gdb will use as a reference and search for source files recursively while debugging a program.


回答1:


Or you can do something like this, for debugging program prog with source in directory srcdir:

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

I think it's a more direct answer to your question. Also useful if your executable doesn't contain the compilation directories and/or you don't have version 6.6+ of gdb.




回答2:


What you need for this is the command set substitute-path.

    (gdb) set substitute-path /usr/src/include /mnt/include

Only available in recent versions (6.6+) of gdb, though.




回答3:


(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.  



回答4:


For me directory command worked well.

I just entered top level directory where target system binaries, libraries and sources are (target sysroot). And the GDB recursively found all what was necessary.

Check it out, here's screenshot:

(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) 


来源:https://stackoverflow.com/questions/1103161/gdb-searching-for-source-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!