使用/ proc / kcore调试内核

时间:2018-12-05 01:29:46

标签: linux debugging linux-kernel gdb

我正在使用/ proc / kcore学习调试内核

我构建了最新的稳定版4.19 Linux版本并将其安装在我的虚拟机上。

然后,我进入linux源代码的编译文件夹,并运行以下命令。

sudo gdb vmlinux /proc/kcore

它给了我以下错误

Core was generated by `BOOT_IMAGE=/boot/vmlinuz-4.19.6 root=UUID=c17d5f82-e020-4ded-a082-89fd7e54d893'.
#0  0x0000000000000000 in irq_stack_union ()
warning: File "/home/jamal/linux/linux-4.19.6/scripts/gdb/vmlinux-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
    add-auto-load-safe-path /home/jamal/linux/linux-4.19.6/scripts/gdb/vmlinux-gdb.py
line to your configuration file "/home/jamal/.gdbinit".
To completely disable this security protection add
    set auto-load safe-path /
line to your configuration file "/home/jamal/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
    info "(gdb)Auto-loading safe path"

所以,我添加了

$ cat /home/jamal/.gdbinit 
add-auto-load-safe-path /home/jamal/linux/linux-4.19.6/scripts/gdb/vmlinux-gdb.py

然后,当我尝试刷新kcore文件并打印'jiffies'值时,它一次又一次地打印相同的值。我在这里犯了什么错误?

Reading symbols from vmlinux...done.
[New process 1]
Core was generated by `BOOT_IMAGE=/boot/vmlinuz-4.19.6 root=UUID=c17d5f82-e020-4ded-a082-89fd7e54d893'.
#0  0x0000000000000000 in irq_stack_union ()
(gdb) print jiffies
$1 = 4294892296
(gdb) core-file /proc/kcore
[New process 1]
Core was generated by `BOOT_IMAGE=/boot/vmlinuz-4.19.6 root=UUID=c17d5f82-e020-4ded-a082-89fd7e54d893'.
#0  0x0000000000000000 in irq_stack_union ()
(gdb) print jiffies
$2 = 4294892296
(gdb) 
$3 = 4294892296
(gdb) q

1 个答案:

答案 0 :(得分:0)

您需要在.gdbinit中设置以下内容

设置自动加载安全路径/

然后获取源代码或重新启动计算机以使其生效。

-JJ