< Debugging

Debugging/Getting traces

This article aims to help in creating a debugging Arch package and using it to provide trace and debug information for reporting software bugs to developers.

Usually, executable files are stripped of human readable context to make them smaller. Not only that, enhanced debugging information is usually not added to the executable in the first place, which drastically reduces the quality of the trace. So, before getting traces with debug information, one has to rebuild the package without stripping and with debugging information.

Use the complete stack trace to inform developers of a bug you have discovered before. This will be highly appreciated by them and will help to improve your favorite program.

Package names

The first thing to do is to obtain the names of the packages which require rebuilding.

When looking at debug messages, such as by using gdb on a core dump:

[...]
Backtrace was generated from '/usr/bin/epiphany'

(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread -1241265952 (LWP 12630)]
(no debugging symbols found)
0xb7f25410 in __kernel_vsyscall ()
#0  0xb7f25410 in __kernel_vsyscall ()
#1  0xb741b45b in ?? () from /lib/libpthread.so.0
[...]

?? shows where debugging info is missing, as well as the name of library or executable which called the function. Similarly, when (no debugging symbols found) appears, you should look for the stated file names. For example, with pacman:

$ pacman -Qo /lib/libthread_db.so.1
/lib/libthread_db.so.1 is owned by ''glibc'' 2.5-8

The package is called in version 2.5-8. Repeat this step for every package that needs debugging.

To retrieve debug information, proceed with the #Debuginfod, #Install debug packages or #Rebuild packages section.

Debuginfod

For packages in the official repositories that support it , debug information can be retrieved directly over HTTP with debuginfod.

If one wants to retrieve the debug symbols for , along with some source files, one can utilize debuginfod-find:

Debuggers like gdb can download them automatically.

You can do for example:

# coredumpctl gdb

And then inside gdb

(gdb) bt full

and you will have the debug symbols of the last crashed application in your system.

Install debug packages

Note: Debug packages are not archived by Arch Linux on Arch Linux Archive.

A few mirrors currently distribute debug packages in accessible repositories. These are sponsored mirrors controlled by Arch Linux and are given access to the debug repositories.

To install a package you can install it directly from the repository. For example:

# pacman -U https://geo.mirror.pkgbuild.com/core-debug/os/x86_64/zstd-debug-1.5.2-2-x86_64.pkg.tar.zst

Another option is to add the repositories to your pacman configuration.

Place a mirror with debug packages as the first one in the mirrorlist file:

Rebuild packages

If debug information is not exposed through debuginfod (for example, when the package originates from the AUR), then it can be rebuilt from source. See ABS for packages in the official repositories, or AUR#Acquire build files for packages in the AUR.

To set the required #Compilation options, you can modify the makepkg configuration if you will only use makepkg for debug purposes. In other cases, you should modify package's file only for each package you would like to rebuild.

Compilation options

As of pacman 4.1, has debug compilation flags in and . To use them, enable the makepkg option, and disable strip.

These settings will force compilation with debug symbols and will disable their stripping from executables.

To apply this setting to a single package, modify the :

Alternatively you can put the debug information in a separate package by enabling both and strip, debug symbols will then be stripped from the main package and placed, together with source files to aid in stepping through the debugger, in a separate pkgbase-debug package. This is advantageous if the package contains very large binaries (e.g. over a GB with debug symbols included) as it might cause freezing and other strange, unwanted behavior occurring.

glibc

Certain packages such as glibc are stripped regardless. Check the for sections such as:

And remove them where appropriate.

Clang

Packages using Clang as the compiler will not build with the option due to the debug flag not being handled (e.g. ).

Add the following at the top of the function to only remove the flag for the affected package:

Building and installing the package

Build the package from source using while in the 's directory. This could take some time:

$ makepkg

Then install the built package:

# pacman -U glibc-2.26-1-x86_64.pkg.tar.gz

Getting the trace

The actual backtrace (or stack trace) can now be obtained via e.g. gdb, the GNU Debugger. Run it either via:

# gdb /path/to/file

or:

# gdb
(gdb) exec /path/to/file

The path is optional, if already set in the variable.

Then, within , type followed by any arguments you wish the program to start with, e.g.:

(gdb) run --no-daemon --verbose

to start execution of the file. Do whatever necessary to evoke the bug. For the actual log, type the lines:

(gdb) set logging file trace.log
(gdb) set logging enabled on

and then:

(gdb) thread apply all bt full

to output the trace to into the directory was started in. To exit, enter:

(gdb) set logging enabled off
(gdb) quit

You can also debug an already running application, e.g.:

# gdb --pid=$(pidof firefox)
(gdb) continue

To debug an application that has already crashed, you will want to invoke on its core dump.

gollark: Besides, the fact that governments are crazy and not ethical doesn't mean that all other behavior is somehow justified.
gollark: I have only seen small bits of the article.
gollark: Yes... regardless of actual legal requirements, it's at least more *ethical* to allow people access to the data *about them*.
gollark: I'm not sure how organization is defined, but it definitely operates within it.
gollark: Okay, back to kind of worried.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.