文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>kgdb 2.4 setup

kgdb 2.4 setup

时间:2009-06-16  来源:oxjob

  Almost three years ago, I set up kgdb but did not leave any notes. Yesterday I redid this and write down this notes.
  We can use two physical machines or virtual machines to do the kernel source code trace. I choose the former since I happen to have two at hand. We call the machine running the test kernel as target machine, the other machine running gdb to inspect as development machine.

Step one:
  Connect the two machines using a null-modem serial cable. To test the connections, boot up the two machines into a host linux, say suse 11. Open terminals on the two machines, and run the following commands to set the serial baudrate
  stty ispeed 115200 ospeed 115200 -F /dev/ttyS0
  If more than one serial port presented, just try another port if the next fails until succeed.
  On one machine run:
  echo "hello world" > /dev/ttyS0
  On the other machine run:
  cat /dev/ttyS0
  If the serial connection is ok, 'hello world' will displayed on the latter machine terminal screen.

Step two:
  Download the linux-2.6.15.5.tar.bz2 source code from http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.5.tar.bz2. And download linux-2.6.15.5-kgdb-2.4.tar.bz2 from http://kgdb.linsyssoft.com/downloads/kgdb-2/linux-2.6.15.5-kgdb-2.4.tar.bz2
  Copy the two packages to target machine, say, /usr/local/src, and compile the kernel
  #cd /usr/local/src/
  #tar xvf linux-2.6.15.5.tar.bz2
  #cd linux-2.6.15.5
  #make mrproper
  #tar xvf ../linux-2.6.15.5-kgdb-2.4.tar.bz2
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/core-lite.patch
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/8250.patch
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/i386-lite.patch
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/cfi_annotations.patch
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/sysrq_bugfix.patch
  #####Here I did not patch the module.patch, since the doc says it need recompile gdb with patches.
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/core.patch
  #patch -p1 < linux-2.6.15.5-kgdb-2.4/i386.patch
  #make menuconfig
 
  #####Make the following choice
  Loadable module support --->                       ### Since we don't plan to debug module so far
    [ ] Enable loadable module support
  Kernel hacking --->
    [*] KGDB: kernel debugging with remote gdb
    [*]   KGDB: Console messages through gdb
    [*] Simple selection of KGDB serial port
    (115200) Debug serial port baud rate
    (0) Serial port number for KGDB
  #####
  In order to get more debug information during stepping through kernel code, we can get rid of the optimization switch using vim etc editors or sed command like this
  sed -i 's/-O2 -fomit-frame-pointer/-g -ggdb/' Makefile &&
  sed -i 's/-O[2s]/-O/' Makefile
 
  change
  HOSTCFLAGS      = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 
  HOSTCXXFLAGS   = -O2

  CFLAGS         += -Os

  to
  HOSTCFLAGS      = -Wall -Wstrict-prototypes -g -ggdb

  HOSTCXXFLAGS   = -O

  CFLAGS         += -O
  #####
 
  #make bzImage
  #cp -v arch/i386/boot/bzImage /boot/kernel-kgdb
  #cp -v System.map /boot/System.map-kgdb
  ##### Edit /boot/grub/menu.lst and add the following
  # The entry for kgdb
  title kernel 2.6.15.5 kgdb
  root (hd0,0)  ## Based on your partitions configuration, in this case, /dev/hda1 is where /boot resides  
  kernel /boot/kernel-kgdb ro root=/dev/hda1 kgdbwait

Step three:
  Copy the linux-2.6.15.5 to development machine to the same directory, that is /usr/local/src. Reboot the target machine and choose the kernel 2.6.15.5 kgdb entry when grub menu is present. If the grub menu does not display, just comments out the hiddenmenu in /boot/grub/menu.lst
  On development machine, we can step through the kernel now.
  #cd /usr/local/src/linux-2.6.15.5
  #gdb ./vmlinux
 
  (gdb) target remote /dev/ttyS0
  #### We can see the following  
 
  Remote debugging using /dev/ttyS0
  breakpoint () at kgdb.c:1876
  1876            atomic_set(&kgdb_setting_breakpoint, 0);
  warning: shared library handler failed to enable breakpoint

During step through kernel code, sometimes warnings like following may appear,
 (gdb)n
    i387.h No such file or directory.
 Use the following to add the directory for gdb to lookup
 (gdb)directory include/asm-i386/
相关阅读 更多 +
排行榜 更多 +
神龙崛起之战

神龙崛起之战

冒险解谜 下载
合金击车

合金击车

冒险解谜 下载
隐藏旅途2逃脱冒险

隐藏旅途2逃脱冒险

冒险解谜 下载