Alex
Alex

Reputation: 5668

(C++ Builder) DWARF debug info in separate file?

Is there a way to instruct C++ Builder's linker to output DWARF debug information (64-bit C++ apps) in standalone file rather than inject it directly into executable? I.e. the option similar to "Place debug information in separate TDS file" (which does not work for DWARF debug format).

If there is no such option - is there a way to strip info from already compiled executable?

Upvotes: 2

Views: 1240

Answers (2)

Rajendra
Rajendra

Reputation: 1770

To place debug info in separate file follow below steps

// Build    
$ clang -O2 -g -o hello.full hello.c

// Package hello.stripped is run as "hello" in production environment
$ strip -o hello.stripped hello.full

// Extract debug info to separate file
$ objcopy --only-keep-debug hello.full hello.debug

// Create a section which contains a reference to debug file 
$ objcopy --strip-debug --add-gnu-debuglink=hello.debug hello.full hello

// Debug - GDB automatically reads hello.debug
$ gdb hello
. . .
Reading symbols from ./hello...
Reading symbols from /homes/syrajendra/hello.debug...done.
(gdb)

// Core from hello.stripped
$ gdb --core core-file --exec hello

Upvotes: 3

Electron
Electron

Reputation: 1480

Assuming you are on a platform with GNU Binutils you can use objcopy to extract the DWARF information to a separate file as a post-compilation step. If you like you can then use strip to remove the debugging information from the executable binary.

Upvotes: 1

Related Questions