首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gdb在android上调试本机程序(而不是jni)

Gdb在android上调试本机程序(而不是jni)
EN

Stack Overflow用户
提问于 2011-07-22 03:12:44
回答 1查看 7.5K关注 0票数 5

我未能用NDK工具链调试本机程序。下面是我的详细步骤和输出。

环境设置:

代码语言:javascript
复制
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。

代码语言:javascript
复制
 1    #include <stdio.h>
 2   
 3    int main() {
 4      printf("Hello World!\n");
 5      return 0;
 6    }

由NDK提供的独立工具链构建。

代码语言:javascript
复制
#arm-linux-androideabi-gcc -g hello.c -o hello --sysroot $SYSROOT 

推送到模拟器并启动gdbserver (我已经转发了端口)

代码语言:javascript
复制
#adb push hello /data/hello
#adb shell gdbserver 10.0.2.15:10000 /data/hello

在另一个终端中远程调试:

代码语言:javascript
复制
#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

代码语言:javascript
复制
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)

生成,推送到模拟器,启动调试服务器

代码语言:javascript
复制
   #ndk-build
   #push obj/local/armeabi/hello /data/hello
   #adb shell gdbserver 10.0.2.15:10000 /data/hello

调试遥控器:

代码语言:javascript
复制
#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远程做其他事情时,仍然失败。

代码语言:javascript
复制
(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,任何人都能告诉我发生了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-25 06:43:49

我不知道为什么gdb通过ndk构建来处理二进制文件,但是使用file命令而不是符号文件命令,它可能会工作。gdb需要知道远程执行程序的映像。

代码语言:javascript
复制
(gdb) file hello
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6785262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档