Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the name and/or path of the debug symbol file which is linked to a binary executable?

How to know the name and/or path of the debug symbol file which is linked to a binary executable?

Suppose you did like this:

objcopy --only-keep-debug foo foo.dbg
objcopy --strip-debug foo
objcopy --add-gnu-debuglink=foo.dbg foo

Now foo.dbg has debug symbols, foo only has the link to foo.dbg that gdb can use. Since gdb can know the symbol file from foo, how can we know same without actually running gdb?

I have observed that even if I rename the executable from foo to xyz still gdb loads symbols from foo.dbg so it is not like binaryname.extension, and extension is optional anyway.

like image 662
Sumit Avatar asked Mar 12 '17 16:03

Sumit


People also ask

How can I tell if a program was compiled with debug symbols?

To check if there's debug info inside the kernel object, you can add the following at the end of the objdump command: | grep debug . If this string is found, you know the kernel object contains debug information. If not, then it's a "clean" kernel object.

How do I see loaded symbols in Visual Studio?

In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).

What are debugging symbols in GDB?

A debugging symbol table is information included in the binary file that maps the compiled instructions to the corresponding line, function, and/or variable in the original source code. This is not something you would want to do with your final builds of any code, as it makes the final executable larger and slower.

What is the file command in GDB?

A command file for GDB is a file of lines that are GDB commands. Comments (lines starting with # ) may also be included. An empty line in a command file does nothing; it does not mean to repeat the last command, as it would from the terminal. When you start GDB, it automatically executes commands from its init files.


1 Answers

how can we know same without actually running gdb?

Either of these commands will tell you:

readelf -x.gnu_debuglink foo
objdump -sj.gnu_debuglink foo

The objcopy --add-gnu-debuglink simply adds .gnu_debuglink section containing the given path, and a checksum of the debug file.

More info here.

like image 144
Employed Russian Avatar answered Nov 15 '22 19:11

Employed Russian