Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android手機調試native c代碼

android手機調試native c代碼

編輯:關於Android編程

環境:

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
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:
...
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 依賴的動態庫和頭文件路徑




  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved