Find the path of the source code for the executable being currently debugged in GDB

Viewed 17970

I can set a breakpoint in main and debug the code with the correct source code, but I don't know where GDB is taking the source code from.

The source code is not present in CWD (current working directory).

How do I find from which location GDB is taking the code?

5 Answers

You can use the GDB command:

info source

Sample output:

Current source file is a.c
Compilation directory is /home/user/test
Located in /home/user/test/a.c
Contains 17 lines.
Source language is c.
Compiled with DWARF 2 debugging format.
Includes preprocessor macro info.

This information is kept in the binary in the DWARF2 format. So, in order to see the DWARF2 information, you can use the dwarfdump utility. Needed information is kept in the DW_AT_comp_dir field.

The binary is probably compiled with "-g" - i.e. debugging.

Use the GDB "show directories" command to see the source search path.

Related