kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

VMware配置KGDB串口

在配置KGDB时,必须通过串口才能调试一台测试Linux, 如果通过本机是Linux的话, 就可以使用应用直接链接上VMware的linux,进行通讯.

1
2
3
4
5
6
7
8
9
1: VM->Settings->Hardware->Add
2: 选择Serial Port->next-> Output to socket -> next
3: Socket=/tmp/ttyS1, From: Server To: An Application
4: Finesh
5: 在本机Linux,运行socat TCP-LISTEN:5555,fork /tmp/ttyS1 &, 绑定本地端口5555到vmware的socket文件.
6: telnet 0:5555
aaa
bbb
7: 在target Linux上, cat /dev/ttyS1, 如果有aaa bbb,则通讯成功.

KGDB配置

Host机:一个装有Ubuntu12.04-x86-64的主机
Target机:运行在vmware上的 Ubuntu12.04-server-x86-64 的Linux.

Target机器配置

  1. 配置好VMware对外串口, 详情见:http://my.oschina.net/u/139611/blog/110052
  2. 下载源码到/usr/src/linux-source-3.2.0下, 解压.
  3. make menuconfig
  4. 进入General setup,把Local version设置一下(-kgdb)
  5. 进入Kernel hacking,选"Compile the kernel with debug info"为*
  6. 选"KGDB: kernel debugging with remote gdb"为*
  7. 选"Write protect kernel read-only data structures"为空 (否则在断下来继续执行的时候可能会报错:Cannot remove breakpoints because program is no longer writable)
  8. 进入"KGDB: … “ 选"KGDB: use KGDB over the serial console"为*,选"KGDB: internal test suite“为空,否则kgdboc会注册不了
  9. 保存,编译: make -j4 && make modules install && make install
  10. 把vmliunux和System.map拷贝到host机器上
  11. 修改/boot/grub/grub.cfg中menuentry为kgdb的项,在kernel后面添加参数: kgdboc=ttyS1,115200 kgdbwait
  12. 重启,系统进入等待状态。

Host机:

  1. 安装好GDB,配好串口等。 2.运行 socat TCP-LISTEN:5555,fork /tmp/ttyS1 & , 链接到vmware对外的串口文件
  2. gdb vmlinux
  3. 在GDB中: (gdb) target remote 0:5555 就可以进入调试状态了
  4. (gdb) c ,则target进入Linux系统

KGDB--Cannot insert breakpoint

原因:

内核编译选项CONFIG_DEBUG_RODATA,会对kernel text做write protect。 那么kgdb就不能设置断点了。

解决方法是:

编辑kernel source目录下生成的.config文件, 禁用CONFIG_DEBUG_RODATA=n (read only data)重新编译即可


http://www.mail-archive.com/kgdb-bugreport@lists.sourceforge.net/msg03464.html

Hi Folks,

I’m wondering if anyone has had issues with setting breakpoints. I’m
able to break into the kernel, access data, do a backtrace, etc, but
when I attempt to set a breakpoint, then continue, I get the following error:

Cannot insert breakpoint 1.
Error accessing memory address 0xffffffff81310931: Unknown error 4294967295.

I’m attaching a sample session, I had set remote debug to 1

Thanks!
Pat Thomson

Hi Thomson,

It seems that your problem is the CONFIG_DEBUG_RODATA option was
enabled, It is recommend to turn CONFIG_DEBUG_RODATA off when using kgdb.

From the kgdb document(DocBook/kgdb.tmpl):

If the architecture that you are using supports the kernel option
CONFIG_DEBUG_RODATA, you should consider turning it off.  This
option will prevent the use of software breakpoints because it
marks certain regions of the kernel's memory space as read-only.
If kgdb supports it for the architecture you are using, you can
use hardware breakpoints if you desire to run with the
CONFIG_DEBUG_RODATA option turned on, else you need to turn off
this option.

Thanks, Dongdong