基于andy的patch:https://github.com/mono-man实现手机的kgdb连接。
手机端配置如下:
1.配置内核kgd选项:
+CONFIG_SERIAL_MSM_HS=y
+CONFIG_SERIAL_MSM_HSL=y
+CONFIG_SERIAL_MSM_HSL_CONSOLE=y
+CONFIG_KGDB=y
+CONFIG_KGDB_SERIAL_CONSOLE=y
+CONFIG_KGDB_KDB=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_RODATA=n
+CONFIG_HAVE_ARCH_KGDB=y
+CONFIG_CONSOLE_POLL=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_CONSOLE_POLL=y
+CONFIG_FRAME_POINTER=y
+CONFIG_KALLSYMS=y
2.合并andy patch并关闭看门狗定时
基于8916平台drivers/soc/qcom/watchdog_v2.c文件中的默认enable定义为0即可。
3.更新cmdline增加:device/qcom/msm8916_64/BoardConfig.mk
添加:kgdboc=ttyHSL0,115200 kgdbretry=4
4.编译boot.img下载注意保留vmlinux
PC端配置:
注意编译环境使用的gdb工具链:
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gdb //32bit devices
prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gdb //64bit devices
1.启动gdb
prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-gdb out/target/product/msm8916_64/obj/KERNEL_OBJ/vmlinux
GNU gdb (GDB) 7.7
Copyright (C) 2014 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 "--host=x86_64-linux-gnu --target=aarch64-elf-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from out/target/product/msm8916_64/obj/KERNEL_OBJ/vmlinux...done.
(gdb) set remoteflow off
(gdb) set serial baud 115200
(gdb) set debug remote 1
2.开启另一个shell执行:
adb shell setenforce 0 //关闭selinux
adb shell "echo 0 > /proc/sys/kernel/printk" //禁止过多log从console中输出
adb shell "echo g > /proc/sysrq-trigger"//触发kgdb调试
3.在原窗口继续执行
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
arch_kgdb_breakpoint () at /hd2/8939la/kernel/arch/arm64/include/asm/kgdb.h:32
32 asm ("brk %0" : : "I" (KDBG_COMPILED_DBG_BRK_IMM));
看到此调试窗即已经调试通了kgdb,后续的调试方式更多的需要gdb相关的命令,后续调试某些模块在后续补充。
工欲善其事必先利其器,后续就要进入kernel调试的深化阶段,相同志向的人继续加油。