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 10: Installing and Managing Python.

If the script runs on Python 3.12, also install the drgn package. For more information, see Installing 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.