From: Ondrej Mosnacek <[email protected]>

kernel.spec: include the GDB plugin in kernel-debuginfo

Provide the GDB plugin files in the debuginfo package so that consumers
can use it when dubugging the kernel via GDB [1]. While it spossible to
do it without this plugin to some extent, it becomes essential when you
want to debug also code inside modules. And it provides many more
convenience commands on top of that.

Place the plugin files beside vmlinux so that gdb can auto-load it
(after some path setup). Example gdb command line using manually
extracted debuginfo RPM contents:

    gdb --directory <extracted_dir>/usr/src/debug/*/linux-<kver> \
        --cd <extracted_dir>/usr/lib/debug/lib/modules/<kver> \
        -iex 'add-auto-load-safe-path 
<extracted_dir>/usr/lib/debug/lib/modules/<kver>' \
        -ex 'target remote <gdb_socket_or_port>' vmlinux

I occasionally use this to debug kernels built as an RPM and having the
plugin included will be very useful to me.

[1] https://docs.kernel.org/dev-tools/gdb-kernel-debugging.html

Signed-off-by: Ondrej Mosnacek <[email protected]>

diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index blahblah..blahblah 100644
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -2415,6 +2415,13 @@ BuildKernel() {
                    cp %{vmlinux_decompressor} 
$RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer/vmlinux.decompressor
            fi
     fi
+
+    # build and copy the vmlinux-gdb plugin files into kernel-debuginfo
+    %{make} %{?_smp_mflags} scripts_gdb
+    cp -a --parents scripts/gdb/{,linux/}*.py 
$RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer
+    # this should be a relative symlink (Kbuild creates an absolute one)
+    ln -s scripts/gdb/vmlinux-gdb.py 
$RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer/vmlinux-gdb.py
+    %py_byte_compile %{python3} 
$RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer/scripts/gdb
 %endif
 
     find $RPM_BUILD_ROOT/lib/modules/$KernelVer -name "*.ko" -type f >modnames

--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2929
--
_______________________________________________
kernel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to