Package: drgn
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:>>>fromdrgn.helpers.linuximportlist_for_each_entry>>>formodinlist_for_each_entry('struct module',...prog['modules'].address_of_(),...'list'):...ifmod.refcnt.counter>10:...print(mod.name)...(char [56])"snd"
(char [56])"evdev"
(char [56])"i915"Although other debuggers likeGDBhave
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 officialtools.drgn was developed atMetafor debugging the
Linux kernel (as an alternative to thecrashutility), but it can also debug userspace
programs written in C. C++ support is in progress.Documentation can be found atdrgn.readthedocs.io.InstallationPackage Managerdrgn can be installed using the package manager on some Linux distributions.Fedora >= 32$sudodnfinstalldrgnRHEL/CentOS >= 8Enable EPEL. Then:$sudodnfinstalldrgnArch LinuxInstall thedrgnpackage from
theAUR.Debian >= 12 (Bookworm)$sudoaptinstallpython3-drgnopenSUSE$sudozypperinstallpython3-drgnUbuntuEnable themichel-slm/kernel-utils PPA.
Then:$sudoaptinstallpython3-drgnpipIf your Linux distribution doesn’t package the latest release of drgn, you can
install it withpip.First,install pip.
Then, run:$sudopip3installdrgnThis 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 listedbelowand 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 SourceTo get the development version of drgn, you will need to build it from source.
First, install dependencies:Fedora$sudodnfinstallautoconfautomakeelfutils-develgccgitlibkdumpfile-devellibtoolmakepkgconfpython3python3-develpython3-pippython3-setuptoolsRHEL/CentOS$sudodnfinstallautoconfautomakeelfutils-develgccgitlibtoolmakepkgconfpython3python3-develpython3-pippython3-setuptoolsOptionally, installlibkdumpfile-develfrom EPEL on RHEL/CentOS >= 8 or
installlibkdumpfilefrom
source if you want support for the makedumpfile format.Replacednfwithyumfor RHEL/CentOS < 8.Debian/Ubuntu$sudoapt-getinstallautoconfautomakegccgitliblzma-devlibelf-devlibdw-devlibtoolmakepkgconfpython3python3-devpython3-pippython3-setuptoolszlib1g-devOptionally, install libkdumpfile from source if you want support for the
makedumpfile format.Arch Linux$sudopacman-S--neededautoconfautomakegccgitlibelflibtoolmakepkgconfpythonpython-pippython-setuptoolsOptionally, installlibkdumpfilefrom the AUR or from
source if you want support for the makedumpfile format.openSUSE$sudozypperinstallautoconfautomakegccgitlibdw-devellibelf-devellibkdumpfile-devellibtoolmakepkgconfpython3python3-develpython3-pippython3-setuptoolsThen, run:$gitclonehttps://github.com/osandov/drgn.git$cddrgn$python3setup.pybuild$sudopython3setup.pyinstallSee theinstallation documentationfor more options.Quick Startdrgn debugs the running kernel by default; runsudo drgn. To debug a
running program, runsudo drgn-p$PID. To debug a core dump (either a
kernel vmcore or a userspace core dump), rundrgn-c$PATH. Make sure toinstall debugging symbolsfor
whatever you are debugging.Then, you can access variables in the program withprog['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 withstack_trace()and access parameters or local
variables withtrace['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 theuser guidefor more details and features.LicenseCopyright (c) Meta Platforms, Inc. and affiliates.drgn is licensed under theLGPLv2.1or later.