我未能用NDK工具链调试本机程序。下面是我的详细步骤和输出。
环境设置:
NDK_ROOT=/opt/android/ndk
SYSROOT=$NDK_ROOT/platforms/android-8/arch-arm
TOOLCHAIN=$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
PATH=$TOOLCHAIN:$NDK_ROOT:$PATH资料来源: hello.c。
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!\n");
5 return 0;
6 }由NDK提供的独立工具链构建。
#arm-linux-androideabi-gcc -g hello.c -o hello --sysroot $SYSROOT 推送到模拟器并启动gdbserver (我已经转发了端口)
#adb push hello /data/hello
#adb shell gdbserver 10.0.2.15:10000 /data/hello在另一个终端中远程调试:
#arm-linux-androideabi-gdb
#(gdb) target remote localhost:10000
Remote debugging using :10000
0xb0001000 in ?? () ------------------------------------what is this?
#(gdb) symbol-file hello
Reading symbols from hello...done.
#(gdb) l
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!\n");
5 return 0;
6 }
#(gdb) b main
Breakpoint 1 at 0x8318: file hello.c, line 4.
#(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault. -------It should be break at main function, but segmentation falut.
0xafd0f5f0 in ?? ()
#(gdb) bt
#0 0xafd0f5f0 in ?? ()我用NDK Android.mk风格测试它,它工作得很好。这是输出
Android.mk
1. LOCAL_PATH := $(call my-dir)
2.
3. include $(CLEAR_VARS)
4.
5. LOCAL_MODULE := hello
6. LOCAL_SRC_FILES := hello.c
7. LOCAL_MODULE_TAGS := optional
8.
9. include $(BUILD_EXECUTABLE)生成,推送到模拟器,启动调试服务器
#ndk-build
#push obj/local/armeabi/hello /data/hello
#adb shell gdbserver 10.0.2.15:10000 /data/hello调试遥控器:
#arm-linux-androideabi-gdb
(gdb) target remote :10000
Remote debugging using :10000
0xb0001000 in ?? () --------------still here
(gdb) symbol-file hello
Reading symbols from hello...done.
(gdb) l
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!\n");
5 return 0;
6 }
(gdb) b main
Breakpoint 1 at 0x8372: file hello.c, line 4.
(gdb) c
Continuing.
Breakpoint 1, main () at hello.c:4
4 printf("Hello World!\n");
(gdb) c
Continuing.
Program exited normally. -------Yes, erverything is normal, Hello World is output.仍然用Android.mk构建ndk-构建,当我在gdb远程做其他事情时,仍然失败。
(gdb) target remote :10000
Remote debugging using :10000
0xb0001000 in ?? ()
(gdb) symbol-file hello
Reading symbols from hello...done.
(gdb) l
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!\n");
5 return 0;
6 }
(gdb) b main
Breakpoint 1 at 0x8372: file hello.c, line 4.
(gdb) next
Cannot access memory at address 0x0
Cannot find bounds of current function
(gdb) c
Continuing.
Breakpoint 1, main () at hello.c:4
4 printf("Hello World!\n");
(gdb) next
6 }
(gdb) next
Program received signal SIGSEGV, Segmentation fault. ------Again fault. And no "Hello World" output in gdbserver.
0x0000832c in ?? ()
(gdb) next
Cannot find bounds of current function===============================================================
我刚接触到android,任何人都能告诉我发生了什么?
发布于 2011-07-25 06:43:49
我不知道为什么gdb通过ndk构建来处理二进制文件,但是使用file命令而不是符号文件命令,它可能会工作。gdb需要知道远程执行程序的映像。
(gdb) file hellohttps://stackoverflow.com/questions/6785262
复制相似问题