debuginfod

Software bugs are unavoidable, and developers usually use tools such as gdb and systemtap to load debuginfo and locate issues.

What is debuginfo? Source code is human readable but not machine readable, while binary files are machine readable but not human readable. When a program encounters a problem, humans cannot quickly locate the problem through binary instructions, so it is necessary to associate the binary instructions with the source code. When a bug occurs in the running instructions, it can be quickly located in the source code. Debuginfo plays this role and serves as a bridge between binary instructions and source code. Debug information is generally variable name, variable type, function name, function parameters, function address range, the correspondence between line numbers and addresses, etc. These contents are written into the compiled file in a specific format. The most commonly used format now is DWARF (Debugging With Attributed Record Formats). For an introduction to DWAERF (dwarfstd.org), see dwarfstd.org/doc/Debugging%20using%20DWARF-..

What is debuginfod? debuginfod is an http file server for transferring debug information resources.

debuginfod periodically scans the contents in specified paths, such as deb and rpm files, extract debug info and executable files based onBuild-id from them, and use sqlite to save this info.

When using a client to access the debug information of the knownBuild-id , debuginfod returns the corresponding resources, such as debuginfo , executable and source file . The Build-id of the file can be obtained by readelf . Here is an example for obtaining the Build-id of dde-dock=5.5.66–1 .

readelf -n /u sr/bin/dde-dock | grep Build.ID Build ID: 3f958ed5f3924da2e3ba2e07a9e065ecbba59437

How to build debuginfod? debuginfod supports scanning deb, rpm and ELF/DWARF files. The following are some parameters for a simple build. For more parameters, please refer to the debuginfod man manual.

-U path/to/debs/ # Scanned paths of deb files. -R path/to/rpms/ # Scanned paths of rpm files. -I REGEX --include=REGEX -X REGEX --exclude=REGEX # Regular rules for excluding and including files during scanning. -p port # Port to start. -L # Handle symlink or not. If the directory contains soft links, it should be used.

On deepin, use the following command to quickly start a debuginfod server. The default port is 8002.

sudo apt install debuginfod debuginfod -U path/to/debs/

Use systemd to manage debuginfod services by writing a service file.

[Unit] Description=Debuginfod Service Documentation=man: debuginfod(8) After=network.target nginx.service ​[Service] EnvironmentFile=/etc/sysconfig/debuginfod ExecStart=/usr/bin/debuginfod --port=${PORT} --database=${DATABASE_FILE} -U ${REPO_PATH}​ [Install] wantedBy=multi-user.target

4.How to use debuginfod services?

Configure the DEBUGINFOD_URLS environment variable to point to the upstream debuginfod server, for example, using the debuginfod server provided by deepin on deepin. If you need to use the debuginfod server for a long time, configure it in the .bashrc file.

ex port DEBUGINFOD_URLS=https://debuginfod.deepin.com

Then use a client that supports debuginfod to get debug information, such as debuginfod-find ,gdb ,systemtap ,perf , etc.

deepin 20 loads debug info from debuginfod via gdb client:

# Install gdb v20 gdb=10.1-1.7 sudo apt install gdb​ # Configure the upstream debuginfod server. Here take the debuginfod of deepin as an example. export DEBUGINFOD_URLS=https://debuginfod.deepin.com​ # Start debugging gdb /usr/bin/dde-dock Reading symbols from /usr/bin/dde-dock... # When the following appears, it downloads and loads debug information from the debuginfod server. Downloading separate debug info for /usr/bin/dde-dock... Reading symbols from /home/tsic/.cache/debuginfod_client/3f958ed5f3924da2e3ba2e07a9e065ecbba59437/debuginfo... ....... Starting program: /usr/bin/dde-dock ....... Downloading separate debug info for /lib/x86_64-linux-gnu/libdtkwidget.so.5... ....... Downloading separate debug info for /lib/x86_64-linux-gnu/libsystemd.so.0...

Note:

debuginfod has limited support for obtaining source code from deb packages. The service isn’t working! I can’t download the source code while debugging a package! Here is the support for debuginfod by clients (2022.08) from debuginfod.

image.png