Create a Separate File Containing Debug Information

Create this file on Linux systems that have an objcopy that supports the ‑ ‑add-gnu-debuglink and ‑ ‑only‑keep‑debug command-line options. If objcopy ‑ ‑help mentions these options, creating this file is supported. See man objcopy for more details.

To create a separate file containing debug information:

1.  Create a .debug copy of the executable or shared library. This second file is a regular executable but will contain only debugging symbol table information, with no code or data.

2.  Create a stripped copy of the image file, and add to the stripped executable a .gnu_debuglink section that identifies the .debug file.

The technique for creating a build ID separate debug information file is different and more complex than that for creating a debug link. Consult your system documentation for how to create a separate debug information file using the build ID method.

3.  Distribute the stripped image and .debug files separately.

For example:

 

objcopy --only-keep-debug hello hello.debug

objcopy --strip-all hello

objcopy --add-gnu-debuglink=hello.debug hello

The code above uses objcopy to:

1.  Create a separate debug file for an executable hello named hello.debug, containing only debug symbols and information.

2.  Strip the debug information from the hello executable.

3.  Add a .gnu_debuglink section to the hello executable.