Programmable debugger
Project description
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.
Fedora >= 32
$ sudo dnf install drgn
RHEL/CentOS >= 8
Enable EPEL. Then:
$ sudo dnf install drgn
Arch Linux
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
The GitHub issue tracker is the preferred method to report issues.
There is also a Linux Kernel Debuggers Matrix room.
License
Copyright (c) Meta Platforms, Inc. and affiliates.
drgn is licensed under the LGPLv2.1 or later.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file drgn-0.0.29.tar.gz
.
File metadata
- Download URL: drgn-0.0.29.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acbd5b7504a04cde4f61ed1a7e9906ef9d43f623013ad8312a2cd9b74406b7c9 |
|
MD5 | 8f670c4dc5c8fa3abdbfb5cfd79e407e |
|
BLAKE2b-256 | bbe343bcab41a3b819993a6b0f1e0e584892cbc7861f6870e5686c8877e3d46c |
File details
Details for the file drgn-0.0.29-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.8 MB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c7dfea2872ca9a56af6f411ad275d529c2b21b74ada6964125feeef38de2cd3 |
|
MD5 | 91d23b7b22114ea604457124f37512a3 |
|
BLAKE2b-256 | 8e3c4056f5034cc474bcf51230c97cbba6d11b1af9fe446ca565f9941b1b9384 |
File details
Details for the file drgn-0.0.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d22073306d56c31934654e372458bf0ccd485454ca4afbc94c28adb9c4c1a339 |
|
MD5 | b1b2866d223e42abc9df1965b5ab2287 |
|
BLAKE2b-256 | ab4704c789a0871239857ae0827982c94fbd880ff0e208316e27f3efedf1638c |
File details
Details for the file drgn-0.0.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec17315e5fa4fdd0145fa92955dcef6e306dfcd283c8c7e2edb6f36f20da3289 |
|
MD5 | c54f010289b62204894d44232ab39542 |
|
BLAKE2b-256 | 6c4bac01edc13040b0ad34ef58c4cbc4991aaa0231ec4bbdbed655d5a7b9babd |
File details
Details for the file drgn-0.0.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0579653edf836959bf7b1e3153e5e0aee7be3741a0d2576bf44de0734905ebbd |
|
MD5 | bb8f555ccc67a7989e1ad3c009022669 |
|
BLAKE2b-256 | f43d1a7ea6264dadb15eeebe096e3469c80e10f1119184a99b703b656a51f352 |
File details
Details for the file drgn-0.0.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b949350d973f6889b670fb07ce3dc7acdfb4822c78ebd70847a705647ede82 |
|
MD5 | 311d7147404e69008d302af23d0b71c8 |
|
BLAKE2b-256 | 14dacbab780d8e3a5a766d1ce926eb66bc961ab787d101706aa627129093a434 |
File details
Details for the file drgn-0.0.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ce6e1e92eadfa6bbf730f0430279695b6ca0aa8342e97216ef3922e8709960d |
|
MD5 | 94feb3b2b8175a414089330e0ad90239 |
|
BLAKE2b-256 | b47ed320c55f073bfc63d9191276fba8aea35ef875f6829c272299b04563b1e2 |
File details
Details for the file drgn-0.0.29-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ba1fac0c037e8bd22a7b31710b672396821e8a9068d8ac78e5215fddd098f42 |
|
MD5 | 833159f4c7959bb13306b855a3243c99 |
|
BLAKE2b-256 | 59b743d971f47f04349aaf8fb86124e4edd1bad22019fbda3bdd43e1cf3e0023 |
File details
Details for the file drgn-0.0.29-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf95b94c2fca75f2674fe4b7eddb57d1f57f79093f3c693b08993656768dea68 |
|
MD5 | 8b393b1ad622b8e59d5d7b297fa3604c |
|
BLAKE2b-256 | d1fdf2d4fa49c56270b982e53b7f9d34a1cb215fee1f106ab1686914a69d5c34 |
File details
Details for the file drgn-0.0.29-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drgn-0.0.29-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bee7d9d4bdbd69484affec66763a83f4ab1ec766bc04b531d348c98ef4b6a34 |
|
MD5 | 9b3d5b86522a9ea1fddf1ca0eb2db306 |
|
BLAKE2b-256 | 2a815d62998e38a06d4c5f8f1579b36033cffc83d63630d48975767ead5530e2 |