GDB调试原生(未JNI)程序在Android [英] Gdb debug the native (not jni) program on android
问题描述
我无法调试与NDK工具链的本地程序。以下是我的详细步骤和输出。
I failed to debug the native program with NDK toolchain. Follows are my detailed steps and output.
信封设置:
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的
Source: hello.c
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!\n");
5 return 0;
6 }
由独立的工具链由NDK provied建设。
Build by the standalone toolchain provied by NDK.
#arm-linux-androideabi-gcc -g hello.c -o hello --sysroot $SYSROOT
一键仿真器和启动gdbserver的(我转发端口的话)
Push to the emulator and start the gdbserver (I forward the port already)
#adb push hello /data/hello
#adb shell gdbserver 10.0.2.15:10000 /data/hello
调试远程的另一端:
Debug remotely in another terminal:
#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风格测试了一下,炒菜锅罚款。下面是输出
And I test it with NDK Android.mk style, it woks fine. Here is the output
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)
打造,推到仿真器,启动调试服务器
Build, push to emulator, start debug server
#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.
仍然NDK建造建立与Android.mk,当我做别的事情在gdb远程,还是失败了。
Still build with Android.mk by ndk-build, when i do something else in gdb remote, still failed.
(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上,任何人都可以告诉我发生了什么事?
I am fresh on android, anyone can tell me what is happening ?
推荐答案
我不知道为什么gdb的作品与二进制由NDK建造,但使用文件的命令,而不是符号文件的命令,它可能工作。的gdb需要知道远程执行的程序的图象。
I don't know why gdb works with the binary by ndk-build, but use file command instead of symbol-file command, it might work. gdb needs to know the image of the remote executed program.
(gdb) file hello
这篇关于GDB调试原生(未JNI)程序在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!