首页
社区
课程
招聘
[讨论]有关ndk编译native程序的符号表的问题
发表于: 2016-12-16 19:37 5473

[讨论]有关ndk编译native程序的符号表的问题

2016-12-16 19:37
5473
1、写了一个简单的 test.c
2、写了Android.mk:
LOCAL_PATH := $(call my-dir)
	include $(CLEAR_VARS)
	LOCAL_CFLAGS += -fPIE
	LOCAL_LDFLAGS += -fPIE -pie
	LOCAL_MODULE := test
	LOCAL_SRC_FILES := test.c
	include $(BUILD_EXECUTABLE)

       
3、建立jni目录,将test.c和Android.mk都放入其中

4、在jni目录下,使用 ndk-build 编译
>ndk-build NDK_DEBUG=1
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Compile thumb  : test <= test.c
Executable     : test
Install        : test => libs/armeabi/test


5、符号表在哪?即传说中的 *.so.....

6、我使用的gdb为:arm-linux-androideabi-gdb(GNU gdb (GDB) 7.3.1-gg2),ndk为:android_ndk_r8e

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 74
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
.......................
2016-12-17 09:28
0
雪    币: 9479
活跃值: (757)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
最后一行改为
include $(BUILD_SHARED_LIBRARY)
.so是动态链接库,相当于dll
2016-12-17 10:23
0
雪    币: 74
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
楼上,我按照你的方式修改Android.mk(注释了 include $(BUILD_EXECUTABLE))
jni>vi Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -fPIE
LOCAL_LDFLAGS += -fPIE -pie
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.c
#include $(BUILD_EXECUTABLE)
include $(BUILD_SHARED_LIBRARY)


然后重新编译,如下:
jni>ndk-build NDK_DEBUG=1

Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Compile thumb  : test <= test.c
SharedLibrary  : libtest.so
Install        : libtest.so => libs/armeabi/libtest.so


结果输出了没有了之前的可执行文件test,而变为libtest.so,这对吗?

我尝试启动本地arm-linux-androideabi-gdb连接android模拟器里的gdbserver,但问题依旧(即:找不到符号表),具体如下:
libs/armeabi>adb forward tcp:12345 tcp:12345
libs/armeabi>arm-linux-androideabi-gdb
.........
.........
(gdb) target remote:12345
Remote debugging using :12345
0xb5f5d750 in ?? ()

(gdb) disass main
No symbol table is loaded.  Use the "file" command.

(gdb) file libtest.so
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /test_dir/libs/armeabi/libtest.so...done.

WARNING: no debugging symbols found in /test_dir/libs/armeabi/libtest.so.
Either the binary was compiled without debugging information
or the debugging information was removed (e.g., with strip or strip -g).
Debugger capabilities will be very limited.
For further information: http://wiki/Main/GdbFaq#No_debugging_symbols_found

(gdb) disass main
No symbol table is loaded.  Use the "file" command.
2016-12-17 18:20
0
雪    币: 4425
活跃值: (3587)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
obj/local/armeabi/目录下是包含符号表信息的文件,你去看看
2016-12-19 13:01
0
雪    币: 53
活跃值: (136)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
楼主多去看点ndk linux相关的书籍吧,,先不说问题太简单,连基本的概念都不对。
2016-12-19 14:00
0
游客
登录 | 注册 方可回帖
返回