I am trying to use gdb 8.3.1 for the kernel module on RPI-4 board.
When I use the command add-symbol-file
to add .bss
and .data
sections, it doesn’t work.
The Kernel version is 5.4 and CONFIG_DEBUG_INFO
is turned on.
I list the simple code, dmesg and kgdb info below.
If you have any idea, please give me some advice.
Module code:
JavaScript
x
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
volatile int my_var_1=5;
volatile int my_var_2;
static int __init my_test_init(void)
{
printk("&my_var_1 = %lxn", &my_var_1);
printk("my_var_1 = %lxn", my_var_1);
printk("&my_var_2 = %lxn", &my_var_2);
printk("my_var_2 = %lxn", my_var_2);
return 0;
}
static void __exit my_test_exit(void)
{
printk("my_test_exitn");
}
module_init(my_test_init);
module_exit(my_test_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("This is a test module");
dmesg output:
JavaScript
pi@raspberrypi:~$ dmesg
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd083]
[ 0.000000] Linux version 5.4.83-v8+ (ken@ken-Inspiron-5458) (gcc version 7.5.0 (Linaro GCC 7.5-2019.12)) #3 SMP PREEMPT Wed Jan 20 05:57:0
0 CST 2021
[ 0.000000] Machine model: Raspberry Pi 4 Model B Rev 1.4
[ 923.192915] &my_var_1 = ffffffc008fa0000
[ 923.192919] my_var_1 = 5
[ 923.192923] &my_var_2 = ffffffc008fa03c0
[ 923.192926] my_var_2 = 0
pi@raspberrypi:~$ sudo su
root@raspberrypi:/home/pi# cat /sys/module/my_test/sections/.bss
0xffffffc008fa03c0
root@raspberrypi:/home/pi# cat /sys/module/my_test/sections/.data
0xffffffc008fa0000
root@raspberrypi:/home/pi# [ 1095.449458] sysrq: DEBUG
Entering kdb (current=0xffffffc010ebf780, pid 0) on processor 0 due to Keyboard Entry
[0]kdb>
kgdb: bt, it recognize text:
JavaScript
(gdb) bt
#0 arch_kgdb_breakpoint () at ../arch/arm64/include/asm/kgdb.h:21
#1 kgdb_breakpoint () at ../kernel/debug/debug_core.c:1138
#2 0xffffffc0101c45e4 in sysrq_handle_dbg (key=<optimized out>) at ../kernel/debug/debug_core.c:901
#3 0xffffffc01069305c in __handle_sysrq (key=103, check_mask=true) at ../drivers/tty/sysrq.c:556
#4 0xffffffc010693184 in handle_sysrq (key=103) at ../drivers/tty/sysrq.c:588
#5 0xffffffc0106b9b64 in uart_handle_sysrq_char (port=<optimized out>, ch=<optimized out>) at ../include/linux/serial_core.h:469
#6 pl011_fifo_to_tty (uap=0xffffff81f4879080) at ../drivers/tty/serial/amba-pl011.c:355
#7 0xffffffc0106ba90c in pl011_rx_chars (uap=<optimized out>) at ../drivers/tty/serial/amba-pl011.c:1380
#8 pl011_int (irq=<optimized out>, dev_id=0xffffff81f4879080) at ../drivers/tty/serial/amba-pl011.c:1536
#9 0xffffffc0101513f0 in __handle_irq_event_percpu (desc=0xffffff81f5444400, flags=0xffffffc010003ed4) at ../kernel/irq/handle.c:149
#10 0xffffffc010151688 in handle_irq_event_percpu (desc=0xffffff81f5444400) at ../kernel/irq/handle.c:189
#11 0xffffffc01015172c in handle_irq_event (desc=0xffffff81f5444400) at ../kernel/irq/handle.c:206
#12 0xffffffc010156f98 in handle_fasteoi_irq (desc=0xffffff81f5444400) at ../kernel/irq/chip.c:725
#13 0xffffffc010150114 in generic_handle_irq_desc (desc=<optimized out>) at ../include/linux/irqdesc.h:156
#14 generic_handle_irq (irq=14) at ../kernel/irq/irqdesc.c:644
#15 0xffffffc01015096c in __handle_domain_irq (domain=0xffffff81f5c10800, hwirq=14, lookup=true, regs=0xffffffc010eb3d50)
at ../kernel/irq/irqdesc.c:681
#16 0xffffffc010081af0 in handle_domain_irq (regs=<optimized out>, hwirq=<optimized out>, domain=<optimized out>)
at ../include/linux/irqdesc.h:174
#17 gic_handle_irq (regs=0xffffffc010eb3d50) at ../drivers/irqchip/irq-gic.c:364
#18 0xffffffc010083cbc in el1_irq () at ../arch/arm64/kernel/entry.S:670
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
kgdb: print
JavaScript
(gdb) monitor lsmod
Module Size modstruct Used by
my_test 16384 0xffffffc008fa0040 0 (Live) 0xffffffc008f9e000 [ ]
(gdb) add-symbol-file ~/Study/Linux_Drv/My_Test/my_test.ko 0xffffffc008f9e000 -s .bss 0xffffffc008fa03c0 -s .data 0xffffffc008fa0000
add symbol table from file "/home/ken/Study/Linux_Drv/My_Test/my_test.ko" at
.text_addr = 0xffffffc008f9e000
.bss_addr = 0xffffffc008fa03c0
.data_addr = 0xffffffc008fa0000
(y or n) y <== gdb understand the sections above
Reading symbols from /home/ken/Study/Linux_Drv/My_Test/my_test.ko
(gdb) p my_var_1
Cannot access memory at address 0x0 <== gdb still not recognize the sections
(gdb) p my_var_2
Cannot access memory at address 0x0
(gdb) x /2x 0xffffffc008fa0000
0xffffffc008fa0000 <my_var_1>: 0x00000005 0x00000000 <== my_var_1 exist but gdb can't find out
(gdb) x /2x 0xffffffc008fa03c0
0xffffffc008fa03c0 <my_var_2>: 0x00000000 0x00000000 <== my_var_2 exist but gdb can't find out
(gdb) p jiffies <==inline symbol could be recognized
$3 = 4295166156
Advertisement
Answer
I use gdb10.1 and the problem is fixed.
JavaScript
(gdb) add-symbol-file /home/ken/Study/Linux_Drv/My_Test/my_test.ko 0xffffffc008f21000 -s
.bss 0xffffffc008f233c0 -s .data 0xffffffc008f23000
add symbol table from file "/home/ken/Study/Linux_Drv/My_Test/my_test.ko" at
.text_addr = 0xffffffc008f21000
.bss_addr = 0xffffffc008f233c0
(y or n) y
Reading symbols from /home/ken/Study/Linux_Drv/My_Test/my_test.ko
I print variables and it works fine now.
JavaScript
(gdb) p &my_var_1
$1 = (volatile int *) 0xffffffc008f23000 <my_var_1>
(gdb) p &my_var_2
$2 = (volatile int *) 0xffffffc008f233c0 <my_var_2>
(gdb) p my_var_1
$3 = 5
(gdb) p my_var_2
$4 = 0
Hope this information helps you.