From 3cc33a8fe8f36d91f2c9a1aca1f1043b7f998c04 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sat, 14 Apr 2018 23:36:18 +0100 Subject: [PATCH] readme: find module load address with pr_debug Post mortem stack to line with GDB. --- README.adoc | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/README.adoc b/README.adoc index 9eaf32d..1d4c71e 100644 --- a/README.adoc +++ b/README.adoc @@ -819,6 +819,20 @@ Ctrl-C add-symbol-file ../kernel_module-1.0/fops.ko 0xfffffffa00000000 .... +Alternatively, if the module panics before you can read `/proc/modules`, there is a <> which shows the load address: + +.... +echo 8 > /proc/sys/kernel/printk +echo 'file kernel/module.c +p' > /sys/kernel/debug/dynamic_debug/control +/myinsmod.out /hello.ko +.... + +And then search for a line of type: + +.... +[ 84.877482] 0xfffffffa00000000 .text +.... + === GDB step debug early boot TODO: why can't we break at early startup stuff such as: @@ -1923,12 +1937,14 @@ Kernel Offset: disabled ---[ end Kernel panic - not syncing: hello panic .... -First notice how our panic message `hello panic` is visible at: +Notice how our panic message `hello panic` is visible at: .... Kernel panic - not syncing: hello panic .... +===== Kernel module stack trace to source line + The log shows which module each symbol belongs to if any, e.g.: .... @@ -1957,6 +1973,21 @@ Line 7 of "/linux-kernel-module-cheat/out/x86_64/buildroot/build/kernel_module-1 as explained at: https://stackoverflow.com/questions/8545931/using-gdb-to-convert-addresses-to-lines/27576029#27576029 +The exact same thing can be done post mortem with: + +.... +./out/x86_64/buildroot/host/usr/bin/x86_64-buildroot-linux-uclibc-gdb \ + -batch \ + -ex 'info line *(myinit+0x1d)' \ + ./out/x86_64/buildroot/build/kernel_module-1.0/panic.ko \ +; +.... + +Related: + +* https://stackoverflow.com/questions/6151538/addr2line-on-kernel-module +* https://stackoverflow.com/questions/13468286/how-to-read-understand-analyze-and-debug-a-linux-kernel-panic + ===== BUG_ON Basically just calls `panic("BUG!")` for most archs. @@ -2061,13 +2092,7 @@ Error occurred in Python command: Cannot access memory at address 0xbf00010c so we need to either: * <> -* <> - -===== addr2line kernel module - -https://stackoverflow.com/questions/6151538/addr2line-on-kernel-module - -TODO +* <> post-mortem method [[dump_stack]] ==== dump_stack kernel module