kgdb quick start

本文档详细介绍了如何通过KGDB(Kernel GNU Debugger)在目标机与开发机之间进行Linux内核的远程调试,包括硬件设置、软件安装、内核编译、调试会话启动及使用以太网接口进行调试的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Contents

  1. Hardware setup
  2. Software setup
  3. Compiling the kernel on the development machine
  4. Starting the debug session
  5. Using KGDB over ethernet interface
  6. Useful links and miscellaneous information

Hardware setup

Use a Null modem serial cable to connect across the Target and Development machines .

Development machine ]----------------------------------[ Target machine ]

1-Hardware pinout for the null modem serial cable 

OR
  
2-Hardware pinout for the null modem serial cable

Testing  the working of the Null-modem serial cable. 

On the Development machine : 
stty ispeed 115200 ospeed 115200 -F /dev/ttyS0
cat testfile.txt > /dev/ttyS0

On the Target machine :
stty ispeed 115200 ospeed 115200 -F /dev/ttyS0
cat /dev/ttyS0

The following settings are used for the Remote debugging session, automatically.

<root #> stty -F /dev/ttyS0
speed 115200 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

Top 

Software setup

  1. Download Linux kernel source : linux-2.6.15.5.tar.bz2
  2. Download the Kgdb patch : linux-2.6.15.5-kgdb-2.4.tar.bz2
  3. Unzip the kernel sources
        cd ${BASE_DIR}
        tar -jxvf linux-2.6.15.5.tar.bz2
  4. Unzip the kgdb patch
        tar -jxvf linux-2.6.15.5-kgdb-2.4.tar.bz2
  5. Change the directory as follows:
        cd ${BASE_DIR}/linux-2.6.15.5
  6. Apply KGDB patches
        patch -p1 < ${BASE_DIR}/linux-2.6.15.5-kgdb-2.4/core-lite.patch
        ........
        patch -p1 < ${BASE_DIR}/linux-2.6.15.5-kgdb-2.4/i386.patch

    Follow the order mentioned in "series" file while applying the patches
Top 

Compiling the kernel on the development machine

  1. In the ${BASE_DIR}/linux-2.6.15.5/Makefile, set the EXTRAVERSION = -kgdb
  2. make xconfig/oldconfig/menuconfig
        Select the options appropriate for the target machine Hardware.
        Select the options pertaining to kgdb under "Kernel hacking" as shown here
  3. make bzImage
  4. Transfer the built kernel to the Target machine from the Development machine.
    Copy the Kernel image from ${BASE_DIR}/linux-2.6.15.5/arch/i386/boot/bzImage to the target machine as /boot/vmlinuz-2.6.15.5-kgdb
    Copy the Map file from ${BASE_DIR}/linux-2.6.15.5/System.map to the target machine as /boot/System.map-2.6.15.5-kgdb
    Also create links as follows:
        ln -s /boot/vmlinuz-2.6.15.5-kgdb /boot/vmlinuz
        ln -s /boot/System.map-2.6.15.5-kgdb /boot/System.map
  5. Edit the /boot/grub/grub.conf file in the target machine to have the kgdb enabled kernel entry.
        title Linux-2.6.15.5-kgdb
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.15.5-kgdb ro root=/dev/hda1 kgdbwait kgdb8250=0,115200

Top 

Starting the debug session

  1. After booting, the target machine will wait for the host development machine to connect, by displaying the message :-
        Waiting for connection from remote gdb...
  2. cd ${BASE_DIR}/linux-2.6.15.5
  3. For starting a debug session with baud rate of 115200 on /dev/ttyS0 , run the following as "root" user:-
        <root#> gdb ./vmlinux
        GNU gdb (GDB) 7.1-ubuntu
        Copyright (C) 2010 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 "i486-linux-gnu".
        For bug reporting instructions, please see:
        <http://www.gnu.org/software/gdb/bugs/>...
        (gdb) set remotebaud 115200
        (gdb) target remote /dev/ttyS0
        Remote debugging using /dev/ttyS0
        breakpoint () at kernel/kgdb.c:1212
        1212 atomic_set(&kgdb_setting_breakpoint, 0);
        (gdb)

  4. For further commands refer http://kgdb.geeksofpune.in/tockdebug.htm
Top 

Using KGDB over ethernet interface

  1. Add the following kernel parameter to the grub entry:
        kgdboe=@10.0.0.6/,@10.0.0.3/ (that's kgdboe=@LOCAL-IP/,@REMOTE-IP/)
    # Sample grub.cfg which will by default boot the kgdb enabled kernel
        title Linux-2.6.15.5-kgdb(eth)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.15.5-kgdb ro root=/dev/hda1 kgdboe=@10.0.0.6/,@10.0.0.3/ console=ttyS0,115200

  2. For starting a debug session, type the following:
        (gdb) ./vmlinux
        (gdb) target remote udp:HOSTNAME:6443

  3. For further commands refer http://kgdb.geeksofpune.in/tockdebug.htm
Top 

Useful links and Miscellaneous information

  1. Useful Links : 
    http://kgdb.sourceforge.net/
    http://kgdb.geeksofpune.in/
    http://kgdb.geeksofpune.in/downloads/

  2. Active Developers :
          Amit Kale (amitkale@geeksofpune.in),
          Swapnil Pimpale (swapnil@geeksofpune.in)
  3. Bug Report: kgdb-bugreport@lists.sourceforge.net

Contents

  1. Hardware setup
  2. Software setup
  3. Compiling the kernel on the development machine
  4. Starting the debug session
  5. Using KGDB over ethernet interface
  6. Useful links and miscellaneous information

Hardware setup

Use a Null modem serial cable to connect across the Target and Development machines .

Development machine ]----------------------------------[ Target machine ]

1-Hardware pinout for the null modem serial cable 

OR
  
2-Hardware pinout for the null modem serial cable

Testing  the working of the Null-modem serial cable. 

On the Development machine : 
stty ispeed 115200 ospeed 115200 -F /dev/ttyS0
cat testfile.txt > /dev/ttyS0

On the Target machine :
stty ispeed 115200 ospeed 115200 -F /dev/ttyS0
cat /dev/ttyS0

The following settings are used for the Remote debugging session, automatically.

<root #> stty -F /dev/ttyS0
speed 115200 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

Top 

Software setup

  1. Download Linux kernel source : linux-2.6.15.5.tar.bz2
  2. Download the Kgdb patch : linux-2.6.15.5-kgdb-2.4.tar.bz2
  3. Unzip the kernel sources
        cd ${BASE_DIR}
        tar -jxvf linux-2.6.15.5.tar.bz2
  4. Unzip the kgdb patch
        tar -jxvf linux-2.6.15.5-kgdb-2.4.tar.bz2
  5. Change the directory as follows:
        cd ${BASE_DIR}/linux-2.6.15.5
  6. Apply KGDB patches
        patch -p1 < ${BASE_DIR}/linux-2.6.15.5-kgdb-2.4/core-lite.patch
        ........
        patch -p1 < ${BASE_DIR}/linux-2.6.15.5-kgdb-2.4/i386.patch

    Follow the order mentioned in "series" file while applying the patches
Top 

Compiling the kernel on the development machine

  1. In the ${BASE_DIR}/linux-2.6.15.5/Makefile, set the EXTRAVERSION = -kgdb
  2. make xconfig/oldconfig/menuconfig
        Select the options appropriate for the target machine Hardware.
        Select the options pertaining to kgdb under "Kernel hacking" as shown here
  3. make bzImage
  4. Transfer the built kernel to the Target machine from the Development machine.
    Copy the Kernel image from ${BASE_DIR}/linux-2.6.15.5/arch/i386/boot/bzImage to the target machine as /boot/vmlinuz-2.6.15.5-kgdb
    Copy the Map file from ${BASE_DIR}/linux-2.6.15.5/System.map to the target machine as /boot/System.map-2.6.15.5-kgdb
    Also create links as follows:
        ln -s /boot/vmlinuz-2.6.15.5-kgdb /boot/vmlinuz
        ln -s /boot/System.map-2.6.15.5-kgdb /boot/System.map
  5. Edit the /boot/grub/grub.conf file in the target machine to have the kgdb enabled kernel entry.
        title Linux-2.6.15.5-kgdb
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.15.5-kgdb ro root=/dev/hda1 kgdbwait kgdb8250=0,115200

Top 

Starting the debug session

  1. After booting, the target machine will wait for the host development machine to connect, by displaying the message :-
        Waiting for connection from remote gdb...
  2. cd ${BASE_DIR}/linux-2.6.15.5
  3. For starting a debug session with baud rate of 115200 on /dev/ttyS0 , run the following as "root" user:-
        <root#> gdb ./vmlinux
        GNU gdb (GDB) 7.1-ubuntu
        Copyright (C) 2010 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 "i486-linux-gnu".
        For bug reporting instructions, please see:
        <http://www.gnu.org/software/gdb/bugs/>...
        (gdb) set remotebaud 115200
        (gdb) target remote /dev/ttyS0
        Remote debugging using /dev/ttyS0
        breakpoint () at kernel/kgdb.c:1212
        1212 atomic_set(&kgdb_setting_breakpoint, 0);
        (gdb)

  4. For further commands refer http://kgdb.geeksofpune.in/tockdebug.htm
Top 

Using KGDB over ethernet interface

  1. Add the following kernel parameter to the grub entry:
        kgdboe=@10.0.0.6/,@10.0.0.3/ (that's kgdboe=@LOCAL-IP/,@REMOTE-IP/)
    # Sample grub.cfg which will by default boot the kgdb enabled kernel
        title Linux-2.6.15.5-kgdb(eth)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.15.5-kgdb ro root=/dev/hda1 kgdboe=@10.0.0.6/,@10.0.0.3/ console=ttyS0,115200

  2. For starting a debug session, type the following:
        (gdb) ./vmlinux
        (gdb) target remote udp:HOSTNAME:6443

  3. For further commands refer http://kgdb.geeksofpune.in/tockdebug.htm
Top 

Useful links and Miscellaneous information

  1. Useful Links : 
    http://kgdb.sourceforge.net/
    http://kgdb.geeksofpune.in/
    http://kgdb.geeksofpune.in/downloads/

  2. Active Developers :
          Amit Kale (amitkale@geeksofpune.in),
          Swapnil Pimpale (swapnil@geeksofpune.in)
  3. Bug Report: kgdb-bugreport@lists.sourceforge.net

Using kgdb, kdb and the kernel debugger internals  by  https://www.kernel.org/doc/htmldocs/kgdb/index.html   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值