如何将 Android 本机代码调试到内核中?
How do I debug Android native code into kernel?
我编译了 goldfish 内核:
[ ] Optimize for size,
[*] Kernel hacking
[*] Compile the kernel with debug info
[*] KGDB: kernel debugging with remote gdb —>
[*] Enable dynamic printk() call support
我用编译好的内核启动了AVD。
emulator -kernel goldfish/arch/arm/boot/zImage -avd TestAVD
我将编译好的 c 程序推送到 AVD 上。
然后我下载了库(我不确定这是不是正确的方法)
adb pull /system/lib ./debuginfo/lib
adb pull /system/bin/linker ./debuginfo/lib
运行 gdb 服务器:
gdbserver 127.0.0.1:7777 ./a
转发端口:
adb forward tcp:7777 tcp:7777
运行 gdb
gdb-multiarch ./a
指定搜索目录:
set solib-search-path ./debuginfo/lib
连接到设备
target remote :7777
我打破了,例如,关闭。
0xaf0ae228 in close () from /home/wuyihao/android_sec/debuginfo/lib/libc.so
1: x/i $pc
=> 0xaf0ae228 <close+8>: svc 0x00000000
(gdb) list
No symbol table is loaded. Use the "file" command.
我无法获取源代码。
所以我尝试用变量 CFLAG="-g"
重新编译内核
没什么不同。
谢谢!
ps: 我注意到下载的库都被剥离了。
libc.so 不是 Linux 内核。它是 C 标准库。
您不太可能需要在那里寻找问题。如果您的 close() 调用不起作用,几乎可以肯定是您使用它出了问题,而不是它的实现。
我编译了 goldfish 内核:
[ ] Optimize for size,
[*] Kernel hacking
[*] Compile the kernel with debug info
[*] KGDB: kernel debugging with remote gdb —>
[*] Enable dynamic printk() call support
我用编译好的内核启动了AVD。
emulator -kernel goldfish/arch/arm/boot/zImage -avd TestAVD
我将编译好的 c 程序推送到 AVD 上。
然后我下载了库(我不确定这是不是正确的方法)
adb pull /system/lib ./debuginfo/lib
adb pull /system/bin/linker ./debuginfo/lib
运行 gdb 服务器:
gdbserver 127.0.0.1:7777 ./a
转发端口:
adb forward tcp:7777 tcp:7777
运行 gdb
gdb-multiarch ./a
指定搜索目录:
set solib-search-path ./debuginfo/lib
连接到设备
target remote :7777
我打破了,例如,关闭。
0xaf0ae228 in close () from /home/wuyihao/android_sec/debuginfo/lib/libc.so
1: x/i $pc
=> 0xaf0ae228 <close+8>: svc 0x00000000
(gdb) list
No symbol table is loaded. Use the "file" command.
我无法获取源代码。 所以我尝试用变量 CFLAG="-g"
重新编译内核没什么不同。
谢谢!
ps: 我注意到下载的库都被剥离了。
libc.so 不是 Linux 内核。它是 C 标准库。
您不太可能需要在那里寻找问题。如果您的 close() 调用不起作用,几乎可以肯定是您使用它出了问题,而不是它的实现。