Kernel patches to get KGDB working on the Nexus 5.
For background, please see associated blog post at http://www.contextis.com/resources/blog/kgdb-android-debugging-kernel-boss
-
Root your Nexus 5!
-
Download the stock Nexus 5 kernel (kernel/msm) using instructions from https://source.android.com/source/building.html, and then
cd msm
-
Run
git checkout 7717f76
to switch to the proper kernel version -
Download this repo
-
Run
git apply ./path/to/nexus5-7717f76-kgdb-patch
to apply patch -
Run
make hammerhead_defconfig
to create .config file -
Copy .config from this repo to replace the one in the msm directory. Or you can Run
make menuconfig
to enableCONFIG_KGDB
andCONFIG_KGDB_SERIAL_CONSOLE
options, modify optionCONFIG_STRICT_MEMORY_RWX
to n. -
Run
make
to build your kernel source. -
Create your boot image, passing console arguments (IMPORTENT!)
abootimg -u boot.img -k zImage-dtb -c 'cmdline=console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 kgdboc=ttyHSL0,115200 kgdbretry=4 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=0'
-
Boot your phone into the bootloader (
adb reboot bootloader
) -
Plug in your debug cable (see blog)
-
Boot or flash your image e.g.
fastboot flash boot boot.img
-
Open a shell (adb shell), su to root, then type:
echo -n g > /proc/sysrq-trigger
-
Hit enter
-
On your host machine fire up GDB (you'll need a working version of GDB cross-compiled for ARM):
arm-eabi-gdb ./vmlinux
(gdb) set remoteflow off
(gdb) set remotebaud 115200 # or use 'set serial baud 115200' after gdb7.7
(gdb) target remote /dev/ttyUSB0
You should hit the KGDB breakpoint and be able to continue, examine memory, etc.