rapido-linux / rapido

Quickly test Linux kernel changes
GNU Lesser General Public License v2.1
22 stars 22 forks source link

add support for debugging with drgn #152

Open morbidrsa opened 3 years ago

morbidrsa commented 3 years ago

Drgn (pronounced dragon) is a scriptable run time kernel debugger (drgn documentation, drgn lwn.net article) written in Python.

When debugging kernel problems on test kernels in rapido it is sometimes helpful to runtime inspect kernel data structures without the overhead of attaching gdb to the VM, creating breakpoints and so on.

Unfortunately it is a bit cumbersome to just add a local --include or --install for drgn in a cut script:

diff --git a/cut/fstests_btrfs_zoned.sh b/cut/fstests_btrfs_zoned.sh
index a4c1bb134616..ef7f86fe04b9 100755
--- a/cut/fstests_btrfs_zoned.sh
+++ b/cut/fstests_btrfs_zoned.sh
@@ -19,6 +19,10 @@ _rt_require_dracut_args "$RAPIDO_DIR/autorun/fstests_btrfs_zoned.sh" "$@"
 _rt_require_fstests
 _rt_require_btrfs_progs

+DRGN_BIN_DEPS="python3 drgn"
+PYTHON_LIBS="/usr/lib/python3.8/"
+PYTHON_LIBS64="/usr/lib64/python3.8/"
+
 # wipefs mount
 "$DRACUT" --install "tail blockdev ps rmdir resize dd vim grep find df sha256sum \
                   strace mkfs  free \
@@ -36,9 +40,14 @@ _rt_require_btrfs_progs
                   ${FSTESTS_SRC}/ltp/* ${FSTESTS_SRC}/src/* \
                   ${FSTESTS_SRC}/src/log-writes/* \
                   ${FSTESTS_SRC}/src/aio-dio-regress/*
+                  $DRGN_BIN_DEPS \
                   $BTRFS_PROGS_BINS" \
        --include "$FSTESTS_SRC" "$FSTESTS_SRC" \
+       --include "/usr/lib64/libgomp.so.1" "/usr/lib64/libgomp.so.1" \
+       --include "/usr/lib64/libexpat.so.1" "/usr/lib64/libexpat.so.1" \
        $DRACUT_RAPIDO_INCLUDES \
+       --include "$PYTHON_LIBS" "$PYTHON_LIBS" \
+       --include "$PYTHON_LIBS64" "$PYTHON_LIBS64" \
        --include "$RAPIDO_DIR/wipefs" "/usr/sbin/wipefs" \
        --include "$RAPIDO_DIR/mount" "/usr/sbin/mount" \
        --add-drivers "lzo lzo-rle dm-snapshot dm-flakey btrfs raid6_pq \

so we'd need to create a dracut module and include it if needed.

ddiss commented 3 years ago

At one stage I remember looking into whether we could get Dracut to "overlay" rapido specific modules atop the distro ones packaged in /usr/lib/dracut/modules.d. Unfortunately Dracut only seems to support all or nothing via the --local parameter. That said, one option might be to use --local and play some symlink games to include /usr/lib/dracut/modules.d subpaths.

morbidrsa commented 3 years ago

Another version would be to add all the new paths, libraries and bins to a $DRACUT_RAPIDO_DRGN_INCLUDES, might be easier for starters

ddiss commented 3 years ago

At one stage I remember looking into whether we could get Dracut to "overlay" rapido specific modules atop the distro ones packaged in /usr/lib/dracut/modules.d. Unfortunately Dracut only seems to support all or nothing via the --local parameter. That said, one option might be to use --local and play some symlink games to include /usr/lib/dracut/modules.d subpaths.

One thing I found recently while digging through Documentation/driver-api/early-userspace/buffer-format.rst is that the kernel accepts cpio archives which are chained back to back. So we could add support for rapido overlays by just appending to the Dracut archive using the kernel's usr/gen_init_cpio helper binary... Just something to keep in mind :)