简体   繁体   中英

searching for source directories in GDB

How do I tell GDB in *nix to search for source files inside a single directory recursively? For example:

  • if there are some different building blocks in one module.
  • a is parent directory for b, c, d where b,c,d are child directories.
  • source files are distributed in b,c,b.

I would need to specify to GDB that all the source files are located in 'a'(parent directory) which GDB should use as a reference and search for source files recursively while debugging a program.

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.

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.

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

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM