我正在学习使用 /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
您应该在您的
.gdbinit
中设置以下内容:
set auto-load safe-path /
然后source或重启机器使其生效。
您可以允许内核脚本目录加载,如下所示:
sudo gdb -iex "add-auto-load-safe-path $PWD/scripts/gdb" \
vmlinux /proc/kcore
-iex 标志用于传递在 gdb 开始加载图像并查找脚本之前运行的命令。