Skip to main content

Kernel (for 2.6) debugging- kgdb

Kernel (for 2.6) debugging- kgdb &

kgdb is a kernel patch that, once applied, allows for the use of the familiar gdb interface for source-level debugging of a running Linux kernel.

The kgdb patch supplies the kernel with a debugging stub. This stub uses gdb remote serial/Ethernet protocol to communicate with gdb (host machine). This patch is applied to the kernel on the machine that will run the gdb session (host machine).

The gdbmod for module debugging, gdbmod version of gdb is required to debug modules that are loaded dynamically on to the testing machine.

Configuring kgdb

Download kgdb and gdbmod patch for your kernel version from http://kgdb.linsyssoft.com/downloads.htm

Copy the patch to the kernel source directory on the development machine, and apply,

  1. Unzip the kgdb patch
    mkdir ${BASE_DIR}/patch-kgdb
    cd ${BASE_DIR}/patch-kgdb
    tar -jxvf linux-2.6.7-kgdb-2.2.tar.bz2
  2. patch -p1 < ${BASE_DIR}/patch-kgdb/core-lite.patch
  3. patch -p1 < ${BASE_DIR}/patch-kgdb/i386-lite.patch
  4. patch -p1 < ${BASE_DIR}/patch-kgdb/8250.patch
  5. patch -p1 < ${BASE_DIR}/patch-kgdb/eth.patch
  6. patch -p1 < ${BASE_DIR}/patch-kgdb/i386.patch
  7. patch -p1 < ${BASE_DIR}/patch-kgdb/core.patch

This kernel will be for target board, the patch applied here are for i386, for ARM patch download latest patch from for kernel 2.6.15.5 http://kgdb.linsyssoft.com/downloads/kgdb-2/linux-2.6.15.5-kgdb-2.4.tar.bz2

Apply the patch for arm board as

  1. patch -p1 < ${BASE_DIR}/patch-kgdb/core-lite.patch
  2. patch -p1 < ${BASE_DIR}/patch-kgdb/arm-lite.patch
  3. patch -p1 < ${BASE_DIR}/patch-kgdb/8250.patch
  4. patch -p1 < ${BASE_DIR}/patch-kgdb/eth.patch
  5. patch -p1 < ${BASE_DIR}/patch-kgdb/core.patch

The patched kernel must now be recompiled.

        $ make menuconfig

From the main menu navigate to and select kernel hacking. You should now see an option for Remote (serial) debugging with gdb. Make sure this option is selected and then exit.

        $ make clean 
        $ make bzImage

The newly compiled kernel image (e.g., bzImage) is copied to the target machine for booting up.

Compiling the kernel on the development machine

  1. In the ${BASE_DIR}/linux-2.6.7/Makefile, set the EXTRAVERSION = -kgdb
  2. make mrproper
  3. make menuconfig
    Select the options appropriate for the target machine Hardware.
    Select the options pertaining to kgdb under "Kernel hacking" .
    Remote (serial) debugging with gdb
  4. make clean
  5. make bzImage
  6. Transfer the built kernel to the Target machine from the Development machine.

    Copy the Kernel image from ${BASE_DIR}/linux-2.6.7/arch/i386/boot/bzImage to the target machine as /boot/vmlinuz-2.6.7-kgdb
    Copy the Map file from ${BASE_DIR}/linux-2.6.7/System.map to the target machine as /boot/System.map-2.6.7-kgdb
    Also create links,
    ln -s /boot/vmlinuz-2.6.7-kgdb /boot/vmlinuz
    ln -s /boot/System.map-2.6.7-kgdb /boot/System.map


  1. Edit the /boot/grub/grub.conf file in the target machine to have the kgdb enabled kernel entry.
    Sample is shown below :-

    # Sample grub.conf which will by default boot the kgdb enabled kernel
    default=1
    timeout=10
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz

    title RH
    root (hd0,0)
    kernel /boot/vmlinuz ro root=/dev/sda1
    initrd /boot/initrd

    title Linux-2.6.7-kgdb
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.7-kgdb ro root=/dev/sda1 rootfstype=ext3 kgdbwait kgdb8250=0,115200
  2. Using kgdb ethernet interface

Add following line in the grub entry :

kgdboe=@192.168.2.150/,@192.168.2.117/ (that's kgdboe=@LOCAL-IP/,@REMOTE-IP/)

# Sample grub.conf 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=@192.168.2.150/,@192.168.2.117/

console=ttyS0,115200

Then for starting the debug session give following command on gdb.

(gdb) ./vmlinux

(gdb) target remote udp:HOSTNAME:6443

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. For version 2.6 this message will not appear, it will just wait after printing message "booting linux, uncompressing linux", can connect to this form host machine,
  3. cd ${BASE_DIR}/linux-2.6.7
  4. For setting a debug session with baud rate of 115200 on /dev/ttyS0 , run as "root" user:-

    gdb ./vmlinux
    GNU gdb Red Hat Linux (6.0post-0.20040223.17rh)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

    (gdb) shell echo -e "\003" > /dev/ttyS0
    (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);
    warning: shared library handler failed to enable breakpoint
    (gdb)
  5. For further commands refer http://kgdb.linsyssoft.com/tockdebug.htm

Reference

Gdb quick ref guide.

http://users.ece.utexas.edu/~adnan/gdb-refcard.pdf

Simple how to

http://www.shakthimaan.com/downloads/glv/kgdb-howto/kgdb-howto.html

Remote debugging

http://www.linuxjournal.com/article/4525

Comments

Popular posts from this blog

www.meficai.org ICAI MEF 2008-09 Acknowledgement

www.meficai.org ICAI MEF 2008-09 Acknowledgement Institute of Chartered Accountants of India- ICAI Click here to download your acknowledgement or direct link http://www.meficai.org/mymefstatus.jsp Multipurpose Empanelment Form (MEF) 2008-09 Download Multipurpose Empanelment Form (MEF) for the year 2008-09 meficai, www.meficai.org, mef icai, bessel function, dhaka stock exchange ICAI-Multipurpose Empanelment Form (MEF) 2008-09-MEFICAI. [Last date for submission of applications on the website: 15th September, 2008. Last date for receipt of hard copy of duly signed declaration: 25th September, 2008]

Rajasthan Board 10th Results | rajedubord.nic.in | RBSE

Raj Board of Secondary Education, Rajasthan Results at rajeduboard.nic.in Board of Secondary Education, Rajasthan Ajmer declared result of secondary examination today at 4PM official site is rajedubord.nic.in check Secondary Examination- 2008 Result (To be announced on July 1st, 2008 at 4:00 PM) source http:// rajresults.nic.in / Declared result Praveshika Examination-2008 Result (Announced on June 25, 2008 at 4:00 PM) The history of the Board of Secondary Education Rajasthan (BSER) is a remarkable panorama of progressive record of the futurological vision for developing a dynamic system of various sub-systems of examinations and highlights of the academic excellence of the last four decades. The BSER took rapid strides for promotion and development of Secondary Education in Rajasthan, spread over 3,42,239 sq. km. and in more than 6000 schools located in 32 districts involving 8.5 lakhs students for Secondary and Senior Secondary Examination in the year 2000. At present the Board is

ahsec results 2008 | www.ahsec.nic.in

The official website of assam higher secondary education council Results of Assam is down seems they are uploading results , direct link to check ahsec results 2008 is http://resultsassam.nic.in/index.asp You can find results of AHSEC at the link above. current page The Website www.ahsec.nic.in Designed Developed & Hosted by NIC, Assam State Centre, Guwahati is down for result uploading. keep checking this page, I will update as soon as news comes. All the best to AHSEC - assam higher secondary education council students. Direct links http://assam.nic.in/ www.ahsec.nic.in http://resultsassam.nic.in/