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.