Skip to main content

Programmable debugger

Project description

PyPI CI Status Documentation Status black badge

drgn (pronounced “dragon”) is a debugger with an emphasis on programmability. drgn exposes the types and variables in a program for easy, expressive scripting in Python. For example, you can debug the Linux kernel:

>>> from drgn.helpers.linux import list_for_each_entry
>>> for mod in list_for_each_entry('struct module',
...                                prog['modules'].address_of_(),
...                                'list'):
...    if mod.refcnt.counter > 10:
...        print(mod.name)
...
(char [56])"snd"
(char [56])"evdev"
(char [56])"i915"

Although other debuggers like GDB have scripting support, drgn aims to make scripting as natural as possible so that debugging feels like coding. This makes it well-suited for introspecting the complex, inter-connected state in large programs.

Additionally, drgn is designed as a library that can be used to build debugging and introspection tools; see the official tools.

drgn was developed at Meta for debugging the Linux kernel (as an alternative to the crash utility), but it can also debug userspace programs written in C. C++ support is in progress.

Documentation can be found at drgn.readthedocs.io.

Installation

Package Manager

drgn can be installed using the package manager on some Linux distributions.

Packaging Status
  • Fedora, RHEL/CentOS Stream >= 9

    $ sudo dnf install drgn
  • RHEL/CentOS < 9

    Enable EPEL. Then:

    $ sudo dnf install drgn
  • Oracle Linux >= 8

    Enable the ol8_addons or ol9_addons repository. Then:

    $ sudo dnf config-manager --enable ol8_addons  # OR: ol9_addons
    $ sudo dnf install drgn

    drgn is also available for Python versions in application streams. For example, use dnf install python3.12-drgn to install drgn for Python 3.12. See the documentation for drgn in Oracle Linux 9 and Oracle Linux 8 for more information.

  • Debian >= 12 (Bookworm)/Ubuntu >= 24.04 (Noble Numbat)

    $ sudo apt install python3-drgn

    To get the latest version on Ubuntu, enable the michel-slm/kernel-utils PPA first.

  • Arch Linux

    $ sudo pacman -S drgn
  • Gentoo

    $ sudo emerge dev-debug/drgn
  • openSUSE

    $ sudo zypper install python3-drgn

pip

If your Linux distribution doesn’t package the latest release of drgn, you can install it with pip.

First, install pip. Then, run:

$ sudo pip3 install drgn

This will install a binary wheel by default. If you get a build error, then pip wasn’t able to use the binary wheel. Install the dependencies listed below and try again.

Note that RHEL/CentOS 7, Debian 10 (“buster”), and Ubuntu 18.04 (“Bionic Beaver”) (and older) ship Python versions which are too old. Python 3.8 or newer must be installed.

From Source

To get the development version of drgn, you will need to build it from source. First, install dependencies:

  • Fedora, RHEL/CentOS Stream >= 9

    $ sudo dnf install autoconf automake check-devel elfutils-debuginfod-client-devel elfutils-devel gcc git libkdumpfile-devel libtool make pkgconf python3 python3-devel python3-pip python3-setuptools xz-devel
  • RHEL/CentOS < 9, Oracle Linux

    $ sudo dnf install autoconf automake check-devel elfutils-devel gcc git libtool make pkgconf python3 python3-devel python3-pip python3-setuptools xz-devel

    Optionally, install libkdumpfile-devel from EPEL on RHEL/CentOS >= 8 or install libkdumpfile from source if you want support for the makedumpfile format. For Oracle Linux >= 7, libkdumpfile-devel can be installed directly from the corresponding addons repository (e.g. ol9_addons).

    Replace dnf with yum for RHEL/CentOS/Oracle Linux < 8.

    When building on RHEL/CentOS/Oracle Linux < 8, you may need to use a newer version of GCC, for example, using the devtoolset-12 developer toolset. Check your distribution’s documentation for information on installing and using these newer toolchains.

  • Debian/Ubuntu

    $ sudo apt install autoconf automake check gcc git libdebuginfod-dev libkdumpfile-dev liblzma-dev libelf-dev libdw-dev libtool make pkgconf python3 python3-dev python3-pip python3-setuptools zlib1g-dev

    On Debian <= 11 (Bullseye) and Ubuntu <= 22.04 (Jammy Jellyfish), libkdumpfile-dev is not available, so you must install libkdumpfile from source if you want support for the makedumpfile format.

  • Arch Linux

    $ sudo pacman -S --needed autoconf automake check gcc git libelf libkdumpfile libtool make pkgconf python python-pip python-setuptools xz
  • Gentoo

    $ sudo emerge --noreplace --oneshot dev-build/autoconf dev-build/automake dev-libs/check dev-libs/elfutils sys-devel/gcc dev-vcs/git dev-libs/libkdumpfile dev-build/libtool dev-build/make dev-python/pip virtual/pkgconfig dev-lang/python dev-python/setuptools app-arch/xz-utils
  • openSUSE

    $ sudo zypper install autoconf automake check-devel gcc git libdebuginfod-devel libdw-devel libelf-devel libkdumpfile-devel libtool make pkgconf python3 python3-devel python3-pip python3-setuptools xz-devel

Then, run:

$ git clone https://github.com/osandov/drgn.git
$ cd drgn
$ python3 setup.py build
$ sudo python3 setup.py install

See the installation documentation for more options.

Quick Start

drgn debugs the running kernel by default; simply run drgn. To debug a running program, run drgn -p $PID. To debug a core dump (either a kernel vmcore or a userspace core dump), run drgn -c $PATH. Make sure to install debugging symbols for whatever you are debugging.

Then, you can access variables in the program with prog["name"] and access structure members with .:

$ drgn
>>> prog["init_task"].comm
(char [16])"swapper/0"

You can use various predefined helpers:

>>> len(list(bpf_prog_for_each()))
11
>>> task = find_task(115)
>>> cmdline(task)
[b'findmnt', b'-p']

You can get stack traces with stack_trace() and access parameters or local variables with trace["name"]:

>>> trace = stack_trace(task)
>>> trace[5]
#5 at 0xffffffff8a5a32d0 (do_sys_poll+0x400/0x578) in do_poll at ./fs/select.c:961:8 (inlined)
>>> poll_list = trace[5]["list"]
>>> file = fget(task, poll_list.entries[0].fd)
>>> d_path(file.f_path.address_of_())
b'/proc/115/mountinfo'

See the user guide for more details and features.

Getting Help

License

Copyright (c) Meta Platforms, Inc. and affiliates.

drgn is licensed under the LGPLv2.1 or later.

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

drgn-0.0.33.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

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

drgn-0.0.33-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

drgn-0.0.33-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file drgn-0.0.33.tar.gz.

File metadata

  • Download URL: drgn-0.0.33.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for drgn-0.0.33.tar.gz
Algorithm Hash digest
SHA256 c713ac976e5d758aae0ba60562177b39fbfb8a6a2cfc609d8f9baa14c750fcc4
MD5 7087e2713bf7de9f454d60947f2e8ebb
BLAKE2b-256 8a793b5dcb2b04f3978d76a94a3df9922d74591ee1eb342f63093c89f549dbde

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 fb971cdc10af488bd305f7adab871ef503331d0241d28e0b85ec3b3dba198855
MD5 27df795b1e90081dd0c006cfecfb4c73
BLAKE2b-256 47f14e3ad0a12a3428eb6dd60cddd03179773140a7604ad9ae4c07bf4edb9699

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d824322556cba59b2a2a58447c26808d24d448e25f0d472d8f159b971cce25fa
MD5 d4f6ed77bb0e5eddd690d85ed95aec9d
BLAKE2b-256 0c24a44960ada0aa87d77ce6b7e0dc6ab685fa2f5344f7fece9b081ce5b97ac4

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 0db7b5545e65f7aab960cb1a1cdbf26465da0c6579b7f93fe0d64e2f44fa6518
MD5 03926cfaa514b338a8e1fe11d1188ebc
BLAKE2b-256 394fb0080a3e18a058803f7b9f9b2db72373df1ef9ceb2b37d18468dc202ae14

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 2c7e185b4d8795b7c26d96adc53e8585577082cc2fd10fcbab891d9d56dd80b5
MD5 2a6d54e7a463c28f989c97121cdebcc9
BLAKE2b-256 49bafb395f7a565b7df2a180e68bde8336dc5121d9bf0dcb1d7588f8c2fc4f10

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 695be7d6979a8e5832bcaed4a91acee306c80c79bd0fd46812e68185dccc3d8c
MD5 f8ed7fbe602040962fd4083570967606
BLAKE2b-256 6d626cca355326ca8c09c87cd2b9b7162121a83d0389f38fdf28580b0757c59d

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6da34ef303439702259c9a427bb6f6b971c3d8a7bd2511bccbe8c3c9c30d60d8
MD5 9f1f9fdfcfa784ad8c0edb581df6a29e
BLAKE2b-256 f2e035de2ce0105410dc2ad27b3d8bd1af693e25059f6739daf70d9b8db21763

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 bd29efe7eef1b60909b75aaa88d0d493c8a747f4e52467c0b262a856563a5a51
MD5 9606c0349a452a89876b961a2c7a8c96
BLAKE2b-256 19274fa36531e149e50c3674cca2916918ee53f5bab7238083c08b45020d9214

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 10fa7e53463a8e69dee589bf7e4bfc09ee0a1948739773acc3aa07ff88ceaa94
MD5 452457ea1a4c725ef62b1810590565dd
BLAKE2b-256 c2acad24a8eca1b251809dfb359f38a2f71643594b2ad423c41b71a2759eb154

See more details on using hashes here.

File details

Details for the file drgn-0.0.33-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for drgn-0.0.33-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 15d274f21e870722f1f7bdfde2afc7703d69a3dc321880e20cc5e3d94cfa0066
MD5 826ef670ef3406c244811bdb4ee6fa23
BLAKE2b-256 8f441bbbfbe5730202f61b1c8d896e170ad31e4e33cf8358dd53491e481b2d1b

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