7 Using the drgn Library With Python

Debug live kernels and vmcore crash dumps in a Python shell, and Python scripts, by importing the drgn library.

Before you can start using drgn with Python scripts, ensure that Python is correctly installed on the system. For more information, see Oracle Linux 8: Installing and Managing Python.

If the script runs on Python 3.6, also install the drgn package. For more information, see Installing drgn.

Note:

To import the drgn library in scripts that run on newer versions of Python 3, enable the ol8_addons repository, then specify the version in the package name.

For example, you could install the python3.12-drgn package to import the drgn library in a script that runs on Python 3.12:

sudo dnf config-manager --enable ol8_addons
sudo dnf install python3.12-drgn

If no matching packages are available in the ol8_addons yum repository, then that Python version might no longer be supported. For more information, see Oracle Linux: Product Life Cycle Information.

You can optionally run the drgn command with Python 3.12 as the interpreter by running the following command:

python3.12 -m drgn

Unlike the crash utility, Drgn wasn't originally designed to be a standalone kernel debugging tool. Drgn is a Python programming library that exposes debugging information for scripting and review purposes.

  1. The prog array variable contains the information about the kernel that you're debugging. For example, to return the data collected for slab_caches, run the following statements in the drgn shell:
    prog["slab_caches"]
    (struct list_head){
            .next = (struct list_head *)0xffff8b831d972260,
            .prev = (struct list_head *)0xffff8b8007c02060,
    }
  2. Standard python structures can also be used to iterate through debug information:
    slab_caches = prog["slab_caches"]
    slab_caches.next
    *(struct list_head *)0xffff8b831d972260 = {
            .next = (struct list_head *)0xffff8b831d972460,
            .prev = (struct list_head *)slab_caches+0x0 = 0xffffffff836e3da0,
    }
  3. For more information about the drgn API and script syntax, see https://drgn.readthedocs.io/. Or, run the following command in the Python shell:
    help(drgn)

The Python script loaded an array of kernel debugging information and crash data.