Debugging

Don't strip symbols
As a first step, you may want to keep symbols in elf files by the  FEATURE.

That way, all functions in the code will keep their name and e.g. can then show names in a backtrace instead of function addresses only.

Install debugging information and sources for selected packages
To install debugging information you can use the  feature. Furthermore, to install the source code you can activate the  feature which in turn requires the. These features are integrated so they provide you with an environment where can find both the debugging information and the sources and lets you fully use its interactive debugging features.

If  is in your default FEATURES,   won't do anything!

Then you can activate those new "environments" for packages you need the sources and/or debug info:

Now, if you debug program with gdb it will find the sources and debugging infos.

{{CodeBox|title=Example gdb session for debugging {{Package|dev-util/radare2}}|1= % gdb --args r2 /bin/ls Reading symbols from r2...Reading symbols from /usr/lib64/debug//usr/bin/radare2.debug...done. done. = gdb>> break main Breakpoint 1 at 0x2e70: file radare2.c, line 372. = gdb>> run Starting program: /usr/bin/r2 /bin/ls

Breakpoint 1, main (argc=2, argv=0x7fffffffdd98, envp=0x7fffffffddb0) at radare2.c:372 372   int main(int argc, char **argv, char **envp) { = gdb>> ...etc }}

Valgrind
You often need to have gcc debug information in order to run valgrind on any binary at all.

It is possible that valgrind refuses to launch with an error containing the following. valgrind: A must-be-redirected function valgrind: whose name matches the pattern:      strlen valgrind: in an object with soname matching:   ld-linux-x86-64.so.2

In this case, you need to :

Create a copy of the glibc ebuild in a custom repository, then edit the file, line 226 :

and add -fno-builtin-strlen at the end of the line.

Also, activate the nostrip feature:

You can remove or comment out the FEATURES line after glibc is merged.