KGDB和gdb通过串行电缆。无法设置断点

时间:2018-01-31 10:06:11

标签: gdb kernel kgdb

两台虚拟机(让我们称之为开发和测试)Ubuntu 17.10。 我已经在内核4.15上安装了以下设置:

CONFIG_DEBUG_INFO=y
CONFIG_HAVE_ARCH_KGDB=y                                                                                               
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y

在/ boot目录中的两台机器上,我都有这些新文件:

$ ll /boot/*4.15*
-rw-r--r-- 1 root root    213741 gen 30 21:36 /boot/config-4.15.0
-rw-r--r-- 1 root root 527443588 gen 30 21:37 /boot/initrd.img-4.15.0
-rw-r--r-- 1 root root   3956360 gen 30 21:36 /boot/System.map-4.15.0
-rw-r--r-- 1 root root   7989008 gen 30 21:36 /boot/vmlinuz-4.15.0

在测试机上,我用这种方式修改了grub.cfg:

linux   /boot/vmlinuz-4.15.0 root=UUID=2f89c974-19ab-4b5f-96cc871c8aded5b ro  quiet splash $vt_handoff kgdbwait kgdboc=ttyS0,115200

我启动测试机器,它停止输入kdb

enter image description here

我启动开发机器并运行gdb(版本8.0.1)

# gdb /usr/src/linux-4.15/vmlinux
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show 
copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/src/linux-4.15/vmlinux...done.
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
0xffffffffb9f4ae04 in ?? ()
(gdb) continue 
Continuing.

关于“测试”

# echo g > /proc/sysrq-trigger

正如预期的那样,我开发了SIGTRAP。 最后,当我开始享受设置断点时,灾难就会发生

Thread 62 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 1698]
0xffffffffb9f4ae04 in ?? ()
(gdb) break oom_kill_process
Breakpoint 1 at 0xffffffff811cc0e0: file mm/oom_kill.c, line 837.
(gdb) continue 
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0xffffffff811cc0e0

Command aborted.
(gdb) 

我做错了什么?

1 个答案:

答案 0 :(得分:0)

rodata=off nokaslr添加到内核命令行。这应该可以解决这个问题。