Skip to main content

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 >= 32

    $ sudo dnf install drgn
  • RHEL/CentOS >= 8

    Enable EPEL. Then:

    $ sudo dnf install drgn
  • Arch Linux

    Install the drgn package from the AUR.

  • Debian >= 12 (Bookworm)

    $ sudo apt install python3-drgn
  • Gentoo

    $ sudo emerge dev-debug/drgn
  • openSUSE

    $ sudo zypper install python3-drgn
  • Ubuntu

    Enable the michel-slm/kernel-utils PPA. Then:

    $ sudo apt 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 6, Debian Stretch, Ubuntu Trusty, and Ubuntu Xenial (and older) ship Python versions which are too old. Python 3.6 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

    $ sudo dnf install autoconf automake check-devel elfutils-devel gcc git libkdumpfile-devel libtool make pkgconf python3 python3-devel python3-pip python3-setuptools
  • RHEL/CentOS

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

    Optionally, install libkdumpfile-devel from EPEL on RHEL/CentOS >= 8 or install libkdumpfile from source if you want support for the makedumpfile format.

    Replace dnf with yum for RHEL/CentOS < 8.

  • Debian/Ubuntu

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

    Optionally, install libkdumpfile from source if you want support for the makedumpfile format.

  • Arch Linux

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

    Optionally, install libkdumpfile from the AUR or from source if you want support for the makedumpfile format.

  • 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
  • openSUSE

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

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; run sudo drgn. To debug a running program, run sudo 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 .:

$ sudo 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.

Metadata

Release files for drgn 0.0.29

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drgn 0.0.29
File Size Uploaded
drgn-0.0.29.tar.gz 1.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for drgn 0.0.29
File
drgn-0.0.29-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
drgn-0.0.29-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details

Total release size: 43.7 MB

Release files / drgn-0.0.29.tar.gz

Download URL drgn-0.0.29.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
acbd5b7504a04cde4f61ed1a7e9906ef9d43f623013ad8312a2cd9b74406b7c9
BLAKE2b-256 checksum
How to use checksums
bbe343bcab41a3b819993a6b0f1e0e584892cbc7861f6870e5686c8877e3d46c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.8 MB
Tags CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8c7dfea2872ca9a56af6f411ad275d529c2b21b74ada6964125feeef38de2cd3
BLAKE2b-256 checksum
How to use checksums
8e3c4056f5034cc474bcf51230c97cbba6d11b1af9fe446ca565f9941b1b9384
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d22073306d56c31934654e372458bf0ccd485454ca4afbc94c28adb9c4c1a339
BLAKE2b-256 checksum
How to use checksums
ab4704c789a0871239857ae0827982c94fbd880ff0e208316e27f3efedf1638c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ec17315e5fa4fdd0145fa92955dcef6e306dfcd283c8c7e2edb6f36f20da3289
BLAKE2b-256 checksum
How to use checksums
6c4bac01edc13040b0ad34ef58c4cbc4991aaa0231ec4bbdbed655d5a7b9babd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0579653edf836959bf7b1e3153e5e0aee7be3741a0d2576bf44de0734905ebbd
BLAKE2b-256 checksum
How to use checksums
f43d1a7ea6264dadb15eeebe096e3469c80e10f1119184a99b703b656a51f352
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e4b949350d973f6889b670fb07ce3dc7acdfb4822c78ebd70847a705647ede82
BLAKE2b-256 checksum
How to use checksums
14dacbab780d8e3a5a766d1ce926eb66bc961ab787d101706aa627129093a434
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2ce6e1e92eadfa6bbf730f0430279695b6ca0aa8342e97216ef3922e8709960d
BLAKE2b-256 checksum
How to use checksums
b47ed320c55f073bfc63d9191276fba8aea35ef875f6829c272299b04563b1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1ba1fac0c037e8bd22a7b31710b672396821e8a9068d8ac78e5215fddd098f42
BLAKE2b-256 checksum
How to use checksums
59b743d971f47f04349aaf8fb86124e4edd1bad22019fbda3bdd43e1cf3e0023
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cf95b94c2fca75f2674fe4b7eddb57d1f57f79093f3c693b08993656768dea68
BLAKE2b-256 checksum
How to use checksums
d1fdf2d4fa49c56270b982e53b7f9d34a1cb215fee1f106ab1686914a69d5c34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6

Release files / drgn-0.0.29-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL drgn-0.0.29-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.7 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1bee7d9d4bdbd69484affec66763a83f4ab1ec766bc04b531d348c98ef4b6a34
BLAKE2b-256 checksum
How to use checksums
2a815d62998e38a06d4c5f8f1579b36033cffc83d63630d48975767ead5530e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.6
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page