My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HowToUseKGTPinAndroid  

Phase-QA, Phase-Deploy
Updated Nov 3, 2011 by bord...@gmail.com

Update in 2011-11-02

Introduction

KGTP is a realtime and lightweight Linux Kernel GDB debugger and tracer. It makes Linux Kernel supply a GDB remote debug interface. Then GDB in current machine or remote machine can debug and trace Linux through GDB tracepoint without stopping the Linux Kernel. And even if the board doesn’t have GDB on it and doesn’t have interface for remote debug. It can debug the Linux Kernel using offline debug. Now, it supports X86-32, X86-64, MIPS and ARM.

This article describes how to use kgtp debug linux kernel in android.

Building Kernel

 General setup  ---> 
     [ * ] Prompt for development and/or incomplete code/drivers
     [ * ] Kprobes
Kernel hacking  --->
     [ * ] Compile the kernel with debug info
     [ * ] Compile the kernel with frame pointers

Building KGTP

Config KGTP Makefile

KERNELDIR := /work/vc1000/src/kernel-vc1000-2.3
ARCH=arm
CROSS_COMPILE=/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-

Complie and Install KGTP

make
sudo su
adb push gtp.ko /system/vendor/lib
exit

KGTP Running On Android

#Open the KGTP interface in current machine.
su
cd /system/vendor/lib
insmod gtp.ko
lsmod
nc -l -p 1234 < /sys/kernel/debug/gtp > /sys/kernel/debug/gtp
(nc -l 1234 </sys/kernel/debug/gtp >/sys/kernel/debug/gtp for later version netcat.)

Host Your PC

cd /work/vc1000/src/kernel-vc1000-2.3
make -j8

Network connect to gtp

# symbian use "set gnutarget elf32-littlearm-symbian"
# vxworks use "set gnutarget elf32-littlearm-vxworks"
gdb-release -ex "set gnutarget elf32-littlearm" -ex "file ./vmlinux"

# connection your remote device
(gdb) target remote 192.168.2.213:1234

USB connect to gtp

  • HOST PC
  • sudo su
    
    # forward socket(adb forward <local> <remote>)
    adb forward tcp:1234 tcp:1234
    gdb-release -ex "set gnutarget elf32-littlearm" -ex "file ./vmlinux"
    # connection your remote device
    (gdb) target remote 127.0.0.1:1234

Debugging with gtp

(gdb) trace vfs_readdir
Tracepoint 1 at 0xc02289f0: file /build/buildd/linux-2.6.35/fs/readdir.c, line 23.
(gdb) actions 
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect $reg
>end
(gdb) tstart 

Change To Android Device Shell And Run ls Command

  • Android Device
  • $ ls

Back To Host PC GDB Shell

  • Host PC
  • (gdb) shell ls
    vmlinux-2.6.35-30-generic
    (gdb) tstop 
    (gdb) tfind 
    Found trace frame 0, tracepoint 1
    #0  vfs_readdir (file=0x0, filler=0x163d8ae3, buf=0x18c0) at /build/buildd/linux-2.6.35/fs/readdir.c:23
    23      {

Good luck, Happy Hacking…

References


Sign in to add a comment
Powered by Google Project Hosting