Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

searching for source directories in GDB

Tags:

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.

like image 776
Vijay Avatar asked Jul 09 '09 10:07

Vijay


People also ask

How does GDB find source files?

GDB has a list of directories to search for source files; this is called the source path. Each time GDB wants a source file, it tries all the directories in the list, in the order they are present in the list, until it finds a file with the desired name.

What is source path?

The source path specifies the directories where the C and C++ source files are located. If you are debugging a user-mode process on the computer where the executable file was built, and if the source files are still in their original location, the debugger can automatically locate the source files.

How do I list breakpoints in GDB?

You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.

Which command is used to display the source code for the current file?

Use the "file" command. You must compile the program with debug information in order to see the source code while debugging.


2 Answers

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.

like image 75
soru Avatar answered Oct 16 '22 06:10

soru


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.

like image 28
Sam Brightman Avatar answered Oct 16 '22 08:10

Sam Brightman