Skip to main content

Python bindings for libdebuginfod

Project description

Test Cases PyPI version

pylibdebuginfod

Python bindings for libdebuginfod.

This library provides a Python interface for the functions in the libdebuginfod.so library from elfutils. The debuginfod client/server infrastructure allows automatic distribution of debugging information (ELF symbol tables, DWARF and even source code) for binaries installed on the current system.

The debuginfod server is queried using a SHA-1 hash (the build ID) which is contained in a section .note.gnu.build-id in the stripped binary file.

Prerequisites

The minimum Python version required is 3.5.

The bindings require an installation of libdebuginfod.so and the pyelftools library.

libdebuginfod.so is shipped in the major distributions in the following packages:

  • Debian (buster-backports, bullseye, sid): libdebuginfod1
  • Fedora/CentOS: elfutils-debuginfod-client
  • openSUSE Tumbleweed: elfutils
  • Ubuntu (20.10 and later): libdebuginfod1

Alternatively, you can get and compile the source code from the official elfutils Git repository.

Usage

The following examples were run under Debian Buster with the libdebuginfod1, libelf1 and libdw1 packages from buster-backports.

In order to make libdebuginfod.so aware of the servers to query, you can set the DEBUGINFOD_URLS environment variable. For example, to query the Debian server, you can run:

$ export DEBUGINFOD_URLS="https://debuginfod.debian.net"

If the DEBUGINFOD_URLS environment variable is not set, it is temporarily set to the elfutils server (https://debuginfod.elfutils.org/) which federates to all trusted servers (listed on the elfutils website).

The other environment variables listed in the manual page are also respected as they are handled by libdebuginfod.so itself.

You can extract the build ID information using the readelf tool like this:

$ readelf -n /lib/x86_64-linux-gnu/libc-2.28.so

Displaying notes found in: .note.gnu.build-id
  Owner                 Data size	Description
  GNU                  0x00000014	NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: 18b9a9a8c523e5cfe5b5d946d605d09242f09798

With the prerequisites in place, you can use the DebugInfoD class as follows:

  >>> from libdebuginfod import DebugInfoD
  >>> session = DebugInfoD()
  >>> session.begin() # optional, is also called from __init__ at the moment.
  >>> fd, path = session.find_debuginfo('18b9a9a8c523e5cfe5b5d946d605d09242f09798')
  >>> print((fd, path))
  (3, b'/home/user/.cache/debuginfod_client/18b9a9a8c523e5cfe5b5d946d605d09242f09798/debuginfo')
  >>> session.end()

In a more pythonic way, DebugInfoD can also be used as a context manager where begin() and end() are called automatically.

  >>> from libdebuginfod import DebugInfoD
  >>> with DebugInfoD() as d:
  ...     fd, path = d.find_debuginfo('18b9a9a8c523e5cfe5b5d946d605d09242f09798')
  ...     print((fd, path))
  ...
  (3, b'/home/user/.cache/debuginfod_client/18b9a9a8c523e5cfe5b5d946d605d09242f09798/debuginfo')

The scripts/debuginfod-find.py script supports three commands (debuginfo, executable and source) and accepts either a build ID or a path to a target file. If the filename matches the pattern [0-9a-f]+, please provide the path (e.g., ./e3) to avoid misinterpretation of the input as a build ID. If the command is source, you need to provide the path or build ID as the first input parameter and an absolute path to the target source file (as present in the DWARF information) as the second input parameter.

Example usage:

$ ./scripts/debuginfod-find.py debuginfo /lib/x86_64-linux-gnu/libc-2.28.so
/home/user/.cache/debuginfod_client/18b9a9a8c523e5cfe5b5d946d605d09242f09798/debuginfo

License(s)

The bindings themselves are released under the MIT license. As the script at scripts/debuginfod-find.py is a reimplementation of the debuginfod-find application from elfutils (which is licensed under the GPLv3+ license), the script is also released under the GPLv3+ license and not included in the packaged release of the bindings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylibdebuginfod-0.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylibdebuginfod-0.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pylibdebuginfod-0.3.tar.gz.

File metadata

  • Download URL: pylibdebuginfod-0.3.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for pylibdebuginfod-0.3.tar.gz
Algorithm Hash digest
SHA256 6f7227b0d40956e8441371c70888e007fd425e4041dccccc16d82e5a1faea57e
MD5 fc55411fd5535a8c57fa7cec2b1e3b47
BLAKE2b-256 c30ff280b6ba018cb74b56815398a910b4d0e03ed862155dae07877343d737f5

See more details on using hashes here.

File details

Details for the file pylibdebuginfod-0.3-py3-none-any.whl.

File metadata

  • Download URL: pylibdebuginfod-0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for pylibdebuginfod-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4680555b0900c36769ff0e876cb41560be92644c50bcef5efcdc4991c127d191
MD5 4a3086b61c217feadd436ecc8b447e4e
BLAKE2b-256 2667c303552841db3c4cb95473bce1c3837ab5c59a241911c69f12b53d580a0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page