How to use debug version of libc
I think that the version of libc with debug symbols is in /usr/lib/debug/lib. I tried setting my LD_LIBRARY_PATH variable to have this at the front of the path but that did not seem to make a difference.
These are not the droids you are looking for.
The libraries in /usr/lib/debug
are not real libraries. Rather, they contain only debug info, but do not contain .text
nor .data
sections of the real libc.so.6
. You can read about the separate debuginfo files here.
The files in /usr/lib/debug
come from libc6-dbg
package, and GDB will load them automatically, so long as they match your installed libc6
version. If your libc6
and libc6-dbg
do not match, you should get a warning from GDB.
You can observe the files GDB is attempting to read by setting set verbose on
. Here is what you should see when libc6
and libc6-dbg
do match:
(gdb) set verbose on
(gdb) run
thread_db_load_search returning 0
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done.
thread_db_load_search returning 0
done.
thread_db_load_search returning 0
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from system-supplied DSO at 0x7ffff7ffb000...done.
WARNING: no debugging symbols found in system-supplied DSO at 0x7ffff7ffb000.
thread_db_load_search returning 0
Reading in symbols for dl-debug.c...done.
Reading in symbols for rtld.c...done.
Reading symbols from /lib/librt.so.1...Reading symbols from /usr/lib/debug/lib/librt-2.11.1.so...done.
thread_db_load_search returning 0
... etc ...
Update:
For instance I see
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done
That implies that your GDB is not searching /usr/lib/debug
. One way that could happen is if you set debug-file-directory
in your .gdbinit
incorrectly.
Here is the default setting:
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
Is there a debug version of libc.a on Linux like libcmtd.lib on Windows?
I've found libc.a and libc.so on my Manjaro OS, didn't find libcd.a.
You will never find such library on any UNIX system, because UNIX systems package debug info directly into the object files.
That is, depending on how your libc.a
is built, it will or will not contain all the debug info in itself.
Some distributions ship libc.a
with debug info, while others do not. If your distribution doesn't, you'll have to build libc.a yourself (default build procedure does build it with debug info enabled).
However, a much simpler solution might be to link with libc.so
instead -- most distributions allow you to install libc6-dbg
or similar package, which magically provides debug info for libc.so.6
.
How to link against debug versions of libc and libstdc++ in GCC?
On many Linux installations the debug libraries do not contain real code; they only contain the debug info. The two are separated so that you can choose not to install them if you don't need them and you are short of disk space, but the debug libraries are no good on their own.
GDB is normally preconfigured to find the debug libraries when you need them.
Of course, your system maybe different. You don't say what it is.
How do I tell gcc (or ld) to link against debug versions of the standard c and c++ libraries
Assuming Linux,
- Static libraries: add a
-L/usr/lib/debug
to your linker command line.gcc
/ld
will look there before default system directories. Useldd
command to verify that correct library versions were linked against (shared libraries only). - Shared libraries: set
LD_LIBRARY_PATH=usr/lib/debug
, and your application will pick up libraries from there even without step 1, as long as there is a version of a library, which is very likely if you are installing with distribution's package manager.
It's a good idea to do both, though, as some libraries may be only in static form.
Related Topics
Sed In-Place Flag That Works Both on MAC (Bsd) and Linux
How to Prevent a Background Process from Being Stopped After Closing Ssh Client in Linux
What Does Set -E Mean in a Bash Script
How to Pass Command Output as Multiple Arguments to Another Command
How to Change Permissions For a Folder and Its Subfolders/Files
How to Recursively Find All Files in Current and Subfolders Based on Wildcard Matching
What Does "&" At the End of a Linux Command Mean
How to Merge Two Files Using Awk
What Does $@ Mean in a Shell Script
Bash Script Prints "Command Not Found" on Empty Lines
What Happens to an Open File Handle on Linux If the Pointed File Gets Moved or Deleted
Confused About Stdin, Stdout and Stderr
How to Add a Default Include Path For Gcc in Linux
Convert Dos Line Endings to Linux Line Endings in Vim
How to Kill a Process Running on Particular Port in Linux