kk Blog —— 通用基础


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

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

Connecting Two Virtual Machines

You can set up the virtual serial ports in two virtual machines to connect to each other. This is useful, for example, if you want to use an application in one virtual machine to capture debugging information sent from the other virtual machine’s serial port.

To install a direct serial connection between two virtual machines (a server and a client), take the following steps:

Windows Host In the server virtual machine

  1. Open the virtual machine settings editor (VM > Settings).
  2. Click Add to start the Add Hardware Wizard.
  3. Select Serial Port, then click Next.
  4. Select Output to named pipe, then click Next.
  5. Use the default pipe name, or enter another pipe name of your choice. The pipe name must follow the form \.\pipe\ — that is, it must begin with \.\pipe.
  6. Select This end is the server.
  7. Select The other end is a virtual machine.
  8. By default, the device status setting is Connect at power on. You may deselect this setting if you wish. Click Advanced if you want to configure this serial port to use polled mode. This option is of interest primarily to developers who are using debugging tools that communicate over a serial connection. For more information, see Special Configuration Options for Advanced Users.
  9. Click Finish, then click OK to close the virtual machine settings editor.

In the client virtual machine

  1. Open the virtual machine settings editor (VM > Settings).
  2. Click Add to start the Add Hardware Wizard.
  3. Select Serial Port, then click Next.
  4. Select Use named pipe.
  5. Use the default name, or enter another pipe name of your choice. The pipe name must follow the form \.\pipe\ — that is, it must begin with \.\pipe. The pipe name must be the same on both server and client.
  6. Select This end is the client.
  7. Select The other end is a virtual machine.
  8. By default, the device status setting is Connect at power on. You may deselect this setting if you wish. Click Advanced if you want to configure this serial port to use polled mode. This option is of interest primarily to developers who are using debugging tools that communicate over a serial connection. For more information, see Special Configuration Options for Advanced Users.
  9. Click Finish, then click OK to close the virtual machine settings editor.

Linux Host In the server virtual machine

  1. Open the virtual machine settings editor (VM > Settings).
  2. Click Add to start the Add Hardware Wizard.
  3. Select Serial Port, then click Next.
  4. Select Output to named pipe, then click Next.
  5. In the Path field, enter /tmp/ or another Unix socket name of your choice.
  6. Select This end is the server.
  7. Select The other end is a virtual machine.
  8. By default, the device status setting is Connect at power on. You may deselect this setting if you wish. Click Advanced if you want to configure this serial port to use polled mode. This option is of interest primarily to developers who are using debugging tools that communicate over a serial connection. For more information, see Special Configuration Options for Advanced Users.
  9. Click Finish, then click OK to save your configuration and close the virtual machine settings editor.

In the client virtual machine

  1. Open the virtual machine settings editor (VM > Settings).
  2. Click Add to start the Add Hardware Wizard.
  3. Select Serial Port, then click Next.
  4. Select Output to named pipe, then click Next.
  5. In the Path field, enter /tmp/ or another Unix socket name of your choice. The pipe name must be the same on both server and client.
  6. Select This end is the client.
  7. Select The other end is a virtual machine.
  8. By default, the device status setting is Connect at power on. You may deselect this setting if you wish. Click Advanced if you want to configure this serial port to use polled mode. This option is of interest primarily to developers who are using debugging tools that communicate over a serial connection. For more information, see Special Configuration Options for Advanced Users.
  9. Click Finish, then click OK to save your configuration and close the virtual machine settings editor.