Kernel debug with kgtp on android
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 on android.
Kernel Building
General setup --->
[ * ] Prompt for development and/or incomplete code/drivers
[ * ] Kprobe
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-
error: ‘GTP_VAR_RDTSC_ID’ undeclared(latest version fixed By: teawater )
CC [M] /home/border/work/kernel/kgtp/trunk/gtp.o /home/border/work/kernel/kgtp/trunk/gtp.c: In function 'gtp_gdbrsp_qtv': /home/border/work/kernel/kgtp/trunk/gtp.c:6318: error: 'GTP_VAR_RDTSC_ID' undeclared (first use in this function) /home/border/work/kernel/kgtp/trunk/gtp.c:6318: error: (Each undeclared identifier is reported only once /home/border/work/kernel/kgtp/trunk/gtp.c:6318: error: for each function it appears in.) /home/border/work/kernel/kgtp/trunk/gtp.c:6320: error: implicit declaration of function 'rdtscll'
* solution:
diff --git a/trunk/gtp.c b/trunk/gtp.c
index 4d0c9a2..75c145e 100644
--- a/trunk/gtp.c
+++ b/trunk/gtp.c
@@ -6315,11 +6315,13 @@ gtp_gdbrsp_qtv(char *pkg)
if (num == GTP_VAR_CLOCK_ID) {
val = (uint64_t)GTP_LOCAL_CLOCK;
goto output_value;
+#ifdef CONFIG_X86
} else if (num == GTP_VAR_RDTSC_ID) {
unsigned long long a;
rdtscll(a);
val = (uint64_t)a;
goto output_value;
+#endif
} else if (num == GTP_VAR_XTIME_SEC_ID
|| num == GTP_VAR_XTIME_NSEC_ID) {
struct timespec time
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
Host 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" # if you want see the debug info (gdb) set debug remote 1 # connection your remote device (gdb) target remote 192.168.2.213:1234
USB connect to gtp
sudo su # forward socket(adb forward <local> <remote>) adb forward tcp:1234 tcp:1234 exit 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…
Very grateful for teawater
References
* kgtp Linux Kernel GDB Tracepoint module
![[Google]]( http://wifihack.net/blog/wp-content/plugins/easy-adsense-lite/google-light.gif)
Recent Comments