android手机调试native c代码

6 篇文章 0 订阅
2 篇文章 0 订阅

环境:

CentOS 5.4

[root@localhost bin]# cat /etc/redhat-release
CentOS release 5.4 (Final)
[root@localhost bin]# uname -a
Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux

VMware 9.0.1 build-894247

一、前期准备工作:

1、下载ndk

http://dl.google.com/android/ndk/android-ndk-r9c-linux-x86.tar.bz2

2、下载adt

http://dl.google.com/android/adt/adt-bundle-linux-x86-20131030.zip

官网地址 http://developer.android.com/sdk/index.html

不明白什么是adt看这里

http://blog.csdn.net/aizquan/article/details/8974750

完成后,将以上两个东西解压到虚拟机上。


二、设置环境变量,将如下路径加进PATH

android-ndk-r9c
adt-bundle-linux-x86-20131030/sdk/platform-tools
adt-bundle-linux-x86-20131030/sdk/tools


三、手机上运行gdbserver(这一步可能比较费事,待补充)

将gdbserver push到手机上。并用adb启动gdbserver。留意版本号!!

130|shell@android:/ $ gdbserver --version                                      
GNU gdbserver (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "arm-eabi-linux"
shell@android:/ $ gdbserver 192.168.100.184:1234 /data/test                    
Process /data/test created; pid = 1877
Listening on port 1234



四、在虚拟机上执行

[root@localhost bin]# cd /home/randy/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin
[root@localhost bin]# ./arm-linux-androideabi-gdb /mnt/hgfs/CodeBlocks/TTS/arm-linux/test   红色部分是你的可执行文件(交叉编译得到的)

GNU gdb (GDB) 7.3.1-gg2 版本号要与gdbserver一致
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>...
Reading symbols from /mnt/hgfs/CodeBlocks/TTS/arm-linux/test...done.
(gdb) shell adb forward tcp:1234 tcp:1234
(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234
0x00008120 in _start ()
(gdb) bt
#0  0x00008120 in _start ()
(gdb) b main.c:42
Breakpoint 1 at 0x8290: file src/main.c, line 42.
(gdb) c
Continuing.


Breakpoint 1, main (argc=1, argv=0xbefc1ad4) at src/main.c:42
42    storePunctuationAndWord(cStringToExamine);
(gdb) 


补充说明下交叉编译命令的选项

[root@localhost TTS]# arm-linux-androideabi-gcc -g -o arm-linux/test src/main.c src/Table.c src/WordSegment.c src/TTS.c -L /usr/local/arm-linux/lib -static -l charset -l iconv -I /usr/local/arm-linux/include -I ./include

arm-linux-androideabi-gcc交叉编译器,在android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin下

-g 编译出的可执行文件带调试符号

-o arm-linux/test最终可执行文件叫test

src/main.c src/Table.c src/WordSegment.c src/TTS.c 几个源文件

-L /usr/local/arm-linux/lib -static -l charset -l iconv -I /usr/local/arm-linux/include -I ./include 依赖的动态库和头文件路径




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值