How to Build Kernel Debug Info as Separate File

How to build kernel debug info as separate file?

vmlinux is a binary blob. The file you're looking for is vmlinux.bin (which is the elf intermediate).

Works like charm:

objcopy --only-keep-debug vmlinux.bin vmlinux.debug

How do you include debug info for assembly files in the Linux kernel?

if building with llvm clang, remove ifndef CONFIG_AS_IS_LLVM and endif from around the KBUILD_AFLAGS

diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug
index 9f39b0130551f..1a26df0538b5b 100644
--- a/scripts/Makefile.debug
+++ b/scripts/Makefile.debug
@@ -6,9 +6,7 @@ else
DEBUG_CFLAGS += -g
endif

-ifndef CONFIG_AS_IS_LLVM
KBUILD_AFLAGS += -Wa,-gdwarf-2
-endif

ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4

How to separate debug symbols from a C static library and later load it in GDB

Don't do this:

objcopy --only-keep-debug lib_mylib.o lib_mylib.o.debug

(It only works for shared libraries.)

Do this instead:

cp lib_mylib.o lib_mylib.o.debug

Even easier may be to keep lib_mylib.o untouched, and strip debug symbols from the executable at link time:

gcc -g driver.c -o driver -L. -l_mylib -Wl,-s

And easier still: link the binary with debug info and keep it for debugging, but use stripped executable where you need it to be stripped:

gcc -g driver.c -o driver-dbg -L. -l_mylib &&
strip -g -o driver driver-dbg

With above, you wouldn't need to add-symbol-file, just point GDB to driver-dbg and it will do everything automatically.

how to install debuginfo packages from vmlinux

The binrpm-pkg target to build kernel rpm does not generate debuginfo because it disabled generation of debuginfo packages, you can try do this, open scripts/package/mkspec in your kernel source tree, and search for a line echo "%define debug_package %{nil}", comment or remove this line, and try to build again.

The reason is that this line explicitly tell rpmbuild that skip debuginfo packages.

See the link:

https://github.com/torvalds/linux/blob/9256d5a308c95a50c6e85d682492ae1f86a70f9b/scripts/package/mkspec#L45



Related Topics



Leave a reply



Submit