Skip to content

Commit

Permalink
linuxManualConfig: install GDB scripts
Browse files Browse the repository at this point in the history
These are required to debug kernel modules.  Since we're now able to
do that, there's another reason besides BTF to enable DEBUG_INFO, so
I've done that for pre-BTF kernel modules as well here.

For GDB to get configured correctly, vmlinux-gdb.py has to be two
directories up from scripts/gdb, and vmlinux has to be next to
vmlinux-gdb.py.  The least invasive way to satisfy these constraints
is to make vmlinux a symlink, which GDB will resolve before looking
for vmlinux-gdb.py.

Tested both ways of getting the scripts into GDB that I know of:

gdb /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/vmlinux \
    -iex 'add-auto-load-safe-path /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/lib/modules/6.1.19/build/vmlinux-gdb.py' \
    -ex 'lx-version' \
    -ex 'q'
gdb /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/vmlinux \
    -ex 'source /nix/store/7n77ijlxkxr6d613h02lr707kvjx6j1k-linux-6.1.19-dev/lib/modules/6.1.19/build/vmlinux-gdb.py' \
    -ex 'lx-version' \
    -ex 'q'

Also tested that the strip changes don't result in meaningful output
size changes (there's some small variation due to BTF data not always
coming out the same size, which is unrelated), and built every kernel
I can on x86_64 to make sure I'm not relying on build system behaviour
specific to newer kernels.
  • Loading branch information
alyssais committed Mar 20, 2023
1 parent 41f788b commit d57568f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 3 additions & 4 deletions pkgs/os-specific/linux/kernel/common-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ let

debug = {
# Necessary for BTF
DEBUG_INFO = mkMerge [
(whenOlder "5.2" (if (features.debug or false) then yes else no))
(whenBetween "5.2" "5.18" yes)
];
DEBUG_INFO = yes;
DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT = whenAtLeast "5.18" yes;
# Reduced debug info conflict with BTF and have been enabled in
# aarch64 defconfig since 5.13
Expand All @@ -62,6 +59,8 @@ let
SUNRPC_DEBUG = yes;
# Provide access to tunables like sched_migration_cost_ns
SCHED_DEBUG = yes;

GDB_SCRIPTS = yes;
};

power-management = {
Expand Down
18 changes: 13 additions & 5 deletions pkgs/os-specific/linux/kernel/manual-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ let
];

postInstall = optionalString isModular ''
cp vmlinux $dev/
if [ -z "''${dontStrip-}" ]; then
installFlagsArray+=("INSTALL_MOD_STRIP=1")
fi
Expand All @@ -297,12 +296,16 @@ let
# from a `try-run` call from the Makefile
rm -f $dev/lib/modules/${modDirVersion}/build/.[0-9]*.d
# Keep some extra files on some arches (powerpc, aarch64)
for f in arch/powerpc/lib/crtsavres.o arch/arm64/kernel/ftrace-mod.o; do
if [ -f "$buildRoot/$f" ]; then
cp $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f
# Keep some extra files
for f in arch/powerpc/lib/crtsavres.o arch/arm64/kernel/ftrace-mod.o \
scripts/gdb/linux vmlinux vmlinux-gdb.py
do
if [ -e "$buildRoot/$f" ]; then
mkdir -p "$(dirname "$dev/lib/modules/${modDirVersion}/build/$f")"
cp -HR $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f
fi
done
ln -s $dev/lib/modules/${modDirVersion}/build/vmlinux $dev
# !!! No documentation on how much of the source tree must be kept
# If/when kernel builds fail due to missing files, you can add
Expand Down Expand Up @@ -345,6 +348,11 @@ let
sed -i Makefile -e 's|= ${buildPackages.kmod}/bin/depmod|= depmod|'
'';

preFixup = ''
# Don't strip $dev/lib/modules/*/vmlinux
stripDebugList="$(cd $dev && echo lib/modules/*/build/*/)"
'';

requiredSystemFeatures = [ "big-parallel" ];

meta = {
Expand Down

0 comments on commit d57568f

Please sign in to comment.