我想用GDB在android系統調試HelloWorld的C程序,通過本教程:
http://www.kandroid.org/online-pdk/guide/debugging_gdb.htmlGDB未能在asm中調試android-native-c-program?
臂EABI-GDB,成功運行我的HelloWorld無斷點,但是當我把一些斷點並運行它'ni'或'si'表示「程序接收信號SIGSEGV,分段錯誤」。我實在無法理解......
這是我的步驟:
1 testmain.c & Android.mk(在cm_gingerbread /開發/測試2 /)
// testmain.c
#include <stdio.h>
void myfn() {
printf("okkkkkkkkkkkkkkkk...\n");
}
int main() {
myfn();
return 0;
}
// Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := testmain
LOCAL_SRC_FILES := testmain.c
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
include $(BUILD_EXECUTABLE)
2編譯
[email protected]:~/dev/cm_gingerbread/development/test2$ mm
target thumb C: testmain <= development/test2/testmain.c
target Executable: testmain (out/target/product/bravo/obj/EXECUTABLES/testmain_intermediates/LINKED/testmain)
target Non-prelinked: testmain (out/target/product/bravo/symbols/system/bin/testmain)
target Strip: testmain (out/target/product/bravo/obj/EXECUTABLES/testmain_intermediates/testmain)
Install: out/target/product/bravo/system/bin/testmain
3推&運行
[email protected]:~$ adb push ~/dev/cm_gingerbread/out/target/product/bravo/system/bin/testmain /system/bin
[email protected]:~$ adb shell
# cd system/bin
# chmod a+x testmain
# ./testmain
okkkkkkkkkkkkkkkk...
4運行gdbserver的
[email protected]:~$ adb shell
# gdbserver :5039 /system/bin/testmain
Process /system/bin/testmain created; pid = 2862
Listening on port 5039
5運行gdbclient
[email protected]:~/dev/cm_gingerbread$ adb forward tcp:5039 tcp:5039
[email protected]:~/dev/cm_gingerbread$ prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb ~/dev/cm_gingerbread/out/target/product/bravo/symbols/system/bin/testmain
(gdb) set solib-absolute-prefix /home/neil/dev/cm_gingerbread/out/target/product/bravo/symbols
(gdb) set solib-search-path /home/neil/dev/cm_gingerbread/out/target/product/bravo/symbols/system/lib
(gdb) target remote :5039
(gdb) x/10i 0x8430
0x8430 <myfn>: ldr r0, [pc, #8] ; (0x843c <myfn+12>)
0x8432 <myfn+2>: push {r4, lr}
0x8434 <myfn+4>: add r0, pc
0x8436 <myfn+6>: blx 0x83f0
0x843a <myfn+10>: pop {r4, pc}
...
(gdb) b *0x8436
Breakpoint 1 at 0x8436: file development/test2/testmain.c, line 4.
(gdb) b *0x83f0
Breakpoint 2 at 0x83f0
(gdb) c
Continuing.
Breakpoint 1, 0x00008436 in myfn() at development/test2/testmain.c:4
(gdb) ni
Program received signal SIGSEGV, Segmentation fault.
0x000083f8 in ??()
當我只是不帶任何斷點運行 'C' 的命令,它的確定:
(gdb) target remote :5039
Remote debugging using :5039
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0xb0001000 in ??()
(gdb) c
Continuing.
Cannot access memory at address 0x0
Error while mapping shared library sections:
/system/bin/linker: No such file or directory.
Error while mapping shared library sections:
libc.so: No such file or directory.
...
Program exited normally.
解構看起來有點不對勁 - 它每次遞增兩個字節表示拇指模式,但是它會跳轉四個字節到彈出指令。也許你有一輛越野車gdb。 –
較新的拇指指令集包括4字節指令,即'blx 0x83f0'看起來像一個。 –