Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse the objcopy's strip with only-keep-debug?

Tags:

In modern linux almost all objects are stripped and splitted in two parts (two files). First is executable itself and second is debug symbols, stripped out from original ELF. Such files are created with

objcopy --only-keep-debug original.elf binary.dbg
mv original.elf binary
objcopy --strip-debug binary

How can I merge binary and binary.dbg into ELF file with debugging info? I want to recreate unstripped, original binary. It can be not byte-to-byte equal to the original, but it must to have a debug symbols inside.

PS Yes, I know about gnu.debuglink section, but it doesn't work for some debuggers (etnus) and disassemblers (objdump can't restore symbols info)

like image 429
osgx Avatar asked Mar 24 '10 16:03

osgx


People also ask

How do I get rid of debug symbols?

To remove debugging symbols from a binary (which must be an a. out or ELF binary), run strip --strip-debug filename. Wildcards can be used to treat multiple files (use something like strip --strip-debug $LFS/tools/bin/*).

What is Objcopy?

objcopy uses the GNU BFD Library to read and write the object files. It can write the destination object file in a format different from that of the source object file. The exact behavior of objcopy is controlled by command-line options.

What is the strip command?

The strip command reduces the size of XCOFF object files. The strip command optionally removes the line number information, relocation information, the debug section, the typchk section, the comment section, file headers, and all or part of the symbol table from the XCOFF object files.


1 Answers

For ELF, the elfutils package contains a tool called eu-unstrip that does the job. In the context of your example:

eu-unstrip binary binary.dbg

binary.dbg now has both the binary and debug symbols. I'd include a reference to documentation if I could find any...

like image 91
lyngvi Avatar answered Sep 21 '22 06:09

lyngvi