2019-04-04 09:27:23 +01:00
|
|
|
drgn
|
|
|
|
====
|
|
|
|
|
2020-01-23 23:14:58 +00:00
|
|
|
.. image:: https://img.shields.io/pypi/v/drgn
|
|
|
|
:target: https://pypi.org/project/drgn/
|
|
|
|
:alt: PyPI
|
|
|
|
|
2020-12-31 10:26:15 +00:00
|
|
|
.. image:: https://github.com/osandov/drgn/workflows/CI/badge.svg
|
|
|
|
:target: https://github.com/osandov/drgn/actions
|
|
|
|
:alt: CI Status
|
2019-04-11 21:16:48 +01:00
|
|
|
|
2019-04-04 09:27:23 +01:00
|
|
|
.. image:: https://readthedocs.org/projects/drgn/badge/?version=latest
|
|
|
|
:target: https://drgn.readthedocs.io/en/latest/?badge=latest
|
|
|
|
:alt: Documentation Status
|
|
|
|
|
|
|
|
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
2019-08-02 08:00:59 +01:00
|
|
|
:target: https://github.com/psf/black
|
2020-01-14 19:43:58 +00:00
|
|
|
|
2019-04-04 09:27:23 +01:00
|
|
|
.. start-introduction
|
|
|
|
|
2020-01-11 00:38:51 +00:00
|
|
|
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:
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
.. code-block:: pycon
|
|
|
|
|
|
|
|
>>> 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"
|
|
|
|
|
2020-01-11 00:38:51 +00:00
|
|
|
Although other debuggers like `GDB <https://www.gnu.org/software/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. It is also designed as a
|
2020-04-18 00:15:35 +01:00
|
|
|
library that can be used to build debugging and introspection tools; see the
|
2021-05-05 01:25:33 +01:00
|
|
|
official `tools <https://github.com/osandov/drgn/tree/main/tools>`_.
|
2020-01-11 00:38:51 +00:00
|
|
|
|
2019-04-04 09:27:23 +01:00
|
|
|
drgn was developed for debugging the Linux kernel (as an alternative to the
|
|
|
|
`crash <http://people.redhat.com/anderson/>`_ utility), but it can also debug
|
2020-04-04 00:58:30 +01:00
|
|
|
userspace programs written in C. C++ support is in progress.
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
.. end-introduction
|
|
|
|
|
|
|
|
Documentation can be found at `drgn.readthedocs.io
|
|
|
|
<https://drgn.readthedocs.io>`_.
|
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
|
2019-09-04 22:40:47 +01:00
|
|
|
.. start-install-dependencies
|
2019-04-04 09:27:23 +01:00
|
|
|
|
2019-09-04 22:40:47 +01:00
|
|
|
Install dependencies:
|
|
|
|
|
2020-07-28 07:28:23 +01:00
|
|
|
Arch Linux:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-09-04 22:40:47 +01:00
|
|
|
|
2021-03-31 07:02:09 +01:00
|
|
|
$ sudo pacman -S --needed gcc libelf make pkgconf python python-pip python-setuptools
|
2019-09-04 22:40:47 +01:00
|
|
|
|
2020-07-28 07:28:23 +01:00
|
|
|
Debian/Ubuntu:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-09-04 22:40:47 +01:00
|
|
|
|
2021-03-31 07:02:09 +01:00
|
|
|
$ sudo apt-get install gcc liblzma-dev libelf-dev libdw-dev make pkgconf python3 python3-dev python3-pip python3-setuptools zlib1g-dev
|
2019-09-04 22:40:47 +01:00
|
|
|
|
|
|
|
Note that Debian Stretch, Ubuntu Trusty, and Ubuntu Xenial (and older) ship
|
2021-03-22 06:05:45 +00:00
|
|
|
Python versions which are too old. Python 3.6 or newer must be installed
|
|
|
|
manually.
|
2019-09-04 22:40:47 +01:00
|
|
|
|
2020-07-28 07:28:23 +01:00
|
|
|
Fedora:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-09-04 22:40:47 +01:00
|
|
|
|
2021-03-31 07:02:09 +01:00
|
|
|
$ sudo dnf install elfutils-devel gcc make pkgconf python3 python3-devel python3-pip python3-setuptools
|
2019-04-04 09:27:23 +01:00
|
|
|
|
2019-08-02 08:00:59 +01:00
|
|
|
Optionally, install:
|
|
|
|
|
|
|
|
* `libkdumpfile <https://github.com/ptesarik/libkdumpfile>`_ if you want
|
|
|
|
support for kdump-compressed kernel core dumps
|
|
|
|
|
2019-09-04 22:40:47 +01:00
|
|
|
.. end-install-dependencies
|
|
|
|
|
2020-07-28 07:28:23 +01:00
|
|
|
Then, run:
|
|
|
|
|
|
|
|
.. code-block:: console
|
2019-04-04 09:27:23 +01:00
|
|
|
|
2020-01-23 23:14:58 +00:00
|
|
|
$ sudo pip3 install drgn
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
See the `installation documentation
|
2020-01-23 23:14:58 +00:00
|
|
|
<https://drgn.readthedocs.io/en/latest/installation.html>`_ for more options.
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
Quick Start
|
|
|
|
-----------
|
|
|
|
|
|
|
|
.. start-quick-start
|
|
|
|
|
2019-06-28 22:04:15 +01:00
|
|
|
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``. The program
|
|
|
|
must have debugging symbols available.
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
Then, you can access variables in the program with ``prog['name']``, access
|
|
|
|
structure members with ``.``, use various predefined helpers, and more:
|
|
|
|
|
|
|
|
.. code-block:: pycon
|
|
|
|
|
2019-06-28 22:04:15 +01:00
|
|
|
$ sudo drgn
|
2019-04-04 09:27:23 +01:00
|
|
|
>>> prog['init_task'].comm
|
|
|
|
(char [16])"swapper/0"
|
|
|
|
>>> d_path(fget(find_task(prog, 1), 0).f_path.address_of_())
|
|
|
|
b'/dev/null'
|
|
|
|
>>> max(task.stime for task in for_each_task(prog))
|
|
|
|
(u64)4192109975952
|
|
|
|
>>> sum(disk.gendisk.part0.nr_sects for disk in for_each_disk(prog))
|
|
|
|
(sector_t)999705952
|
|
|
|
|
|
|
|
.. end-quick-start
|
|
|
|
|
|
|
|
See the `user guide <https://drgn.readthedocs.io/en/latest/user_guide.html>`_
|
|
|
|
for more information.
|
|
|
|
|
|
|
|
License
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. start-license
|
|
|
|
|
2020-05-15 23:13:02 +01:00
|
|
|
Copyright (c) Facebook, Inc. and its affiliates.
|
2019-04-04 09:27:23 +01:00
|
|
|
|
|
|
|
drgn is licensed under the `GPLv3
|
|
|
|
<https://www.gnu.org/licenses/gpl-3.0.en.html>`_ or later.
|
|
|
|
|
|
|
|
.. end-license
|