大龙的博客
导航
C++博客
首页
新随笔
联系
聚合
管理
<
2006年9月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
留言簿
(43)
给我留言
查看公开留言
查看私人留言
收藏夹
ps
(rss)
随笔档案
2014年10月 (1)
2014年8月 (4)
2014年6月 (1)
2013年12月 (6)
2013年11月 (2)
2013年10月 (5)
2013年9月 (4)
2013年7月 (1)
2013年6月 (2)
2013年3月 (1)
2013年2月 (20)
2013年1月 (10)
2012年12月 (8)
2012年11月 (5)
2012年10月 (9)
2012年9月 (4)
2012年8月 (16)
2012年7月 (8)
2012年6月 (10)
2012年5月 (11)
2012年4月 (3)
2012年3月 (10)
2012年2月 (6)
2012年1月 (4)
2011年12月 (6)
2011年11月 (16)
2011年10月 (32)
2011年9月 (13)
2011年8月 (6)
2011年7月 (27)
2011年6月 (18)
2011年5月 (12)
2011年4月 (2)
2011年3月 (1)
2011年2月 (5)
2011年1月 (24)
2010年12月 (5)
2010年11月 (2)
2010年10月 (3)
2010年9月 (4)
2010年8月 (7)
2010年6月 (13)
2010年5月 (18)
2010年4月 (21)
2010年3月 (6)
2010年2月 (7)
2010年1月 (7)
2009年12月 (7)
2009年11月 (2)
2009年10月 (8)
2009年9月 (19)
2009年8月 (11)
2009年6月 (28)
2009年5月 (35)
2009年4月 (18)
2009年3月 (24)
2009年2月 (13)
2009年1月 (10)
2008年12月 (2)
2008年11月 (6)
2008年10月 (4)
2008年9月 (11)
2008年8月 (18)
2008年7月 (8)
2008年6月 (19)
2008年5月 (9)
2008年4月 (6)
2008年3月 (2)
2008年2月 (4)
2008年1月 (21)
2007年12月 (14)
2007年11月 (4)
2007年10月 (7)
2007年9月 (17)
2007年8月 (10)
2007年7月 (20)
2007年6月 (11)
2007年5月 (8)
2007年4月 (13)
2007年3月 (2)
2007年2月 (6)
2007年1月 (14)
2006年12月 (23)
2006年11月 (15)
2006年10月 (5)
2006年9月 (4)
文章档案
2007年11月 (1)
2006年12月 (1)
阅读排行榜
1. LinuxShell算术运算(49275)
2. Windows XP DDK 的有效下载地址(44958)
3. WinDBG教程(40834)
4. Android 打包签名 从生成keystore到完成签名 -- 转(40620)
5. 在Cygwin上安装编辑器vim (38906)
评论排行榜
1. Windows XP DDK 的有效下载地址(116)
2. 在Cygwin上安装编辑器vim (24)
3. (TCP-over-UDP library):基于UDP协议之上实现通用、可靠、高效的TCP协议 ---------- 转(14)
4. Compuware DriverStudio V3.2(10)
5. 经典好书 (10)
常用链接
我的随笔
我的评论
我参与的随笔
统计
随笔 - 864
文章 - 2
评论 - 378
引用 - 0
最新评论
1. re: 安装Nexus私服
谢谢博主。我刚学搭建nexus,挺不错的。
--做有为青年
2. re: 用slf4j+logback实现多功能日志解决方案 --- 转
谢谢楼主,整个流程非常清楚,照着做了一遍就会了。另外我分享一个logback目前尚存在的bug:当你发现INFO级和ERROR级的日志没有写成功时,上下移动一下配置文件中appender的位置就好了。
--welldone
3. re: LinuxShell算术运算
你这些都验证过吗
--是是是
4. re: 用slf4j+logback实现多功能日志解决方案 --- 转
写的非常好!
--Hello
5. re: (TCP-over-UDP library):基于UDP协议之上实现通用、可靠、高效的TCP协议 ---------- 转
评论内容较长,点击标题查看
--pcplayer
Debug Native c/c++ Application for Android(Step by Step)
调试Android上的c/c++程序一直是个难题,以前我经常靠输出log来解决问题,对于稍复杂一些的工程,这几乎是个不可能完成的任务,尤其有些错误,在wincewindows下都没事,只在android上出现,就更难找了。后来看了些资料,知道可以用gdbserver来调试,今天决定必须把这个先弄清楚,不然以后干活效率实在是太低了,找了很多网站,终于成功了。这里把整个过程整理一下,以备以后查阅。
1. 准备gdbserver。
android 1.0 代码刚开放到时候,里面并没有带gdbserver,有些强人就自己编译了gdbserver来使用。不过现在好了,android的新源码里已经包含了gdbserver,就在prebuilt目录下。如果想在android 1.0里使用,可以到如下地址下载:
http://android.git.kernel.org/?p=platform/prebuilt.git;a=tree
。gdbserver的二进制文件就在android-arm/gdbserver/gdbserver,我们只需要把gdbserver这个可执行文件放到模拟器上即可。
准备把它放在/system/bin,这样它就在默认的PATH里了。启动模拟器后:
adb push gdbserver /system/bin
如果提示文件系统不可写的话,执行一下“adb remount”,因为默认是用只读模式挂载的。
2. 编译程序。
默认情况下,android的编译系统在编译程序时已经使用了“-g”选项,即已经生成了调试信息。但是在生成最终的文件时,是经过strip的,去除了所有到调试信息。所以最终我们到调试目标要使用strip之前的文件。用make showcommands查看详细的命令信息,下面是其中某次的输出:
target Executable: libomstts (out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/LINKED/libomstts)
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/LINKED/libomstts -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -llog -lcutils -lutils -landroid_runtime -lnativehelper -lstdc++ -lz -lc -lstdc++ -lm out/target/product/generic/obj/lib/crtbegin_dynamic.o out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/src/tts.o out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/src/TTSWrapper.o out/target/product/generic/obj/lib/crtend_android.o
target Non-prelinked: libomstts (out/target/product/generic/symbols/system/bin/libomstts)
out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/LINKED/libomstts out/target/product/generic/symbols/system/bin/libomstts
target Strip: libomstts (out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/libomstts)
out/host/linux-x86/bin/soslim --strip --shady --quiet out/target/product/generic/symbols/system/bin/libomstts --outfile out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/libomstts
Install: out/target/product/generic/system/bin/libomstts
out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/libomstts out/target/product/generic/system/bin/libomstts
生成的可执行文件是libomstts,可以看到,初次链接的目标文件是“out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/LINKED/libomstts”,然后拷贝到“out/target/product/generic/symbols/system/bin/libomstts”,strip后的文件是“out/target/product/generic/obj/EXECUTABLES/libomstts_intermediates/libomstts”和“out/target/product/generic/system/bin/libomstts”。调试只能使用前两个文件。
把带调试信息到可执行文件放到模拟器上,我用到是“out/target/product/generic/symbols/system/bin/libomstts”:
adb push out/target/product/generic/symbols/system/bin/libomstts /system/bin
3. 启动调试器
首先在模拟器上启动gdbserver:
adb shell
进入模拟器的控制台后
gdbserver 10.0.2.2:1234 /system/bin/libomstts
10.0.2.2是模拟器的默认ip地址,让gdbserver在模拟器上监听1234端口。如果启动成功会显示以下信息:
Process /system/bin/libomstts created; pid = 1025
Listening on port 1234
为来让gdb能连接到模拟器上到gdbserver,必须进行数据转发:
telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK
redir add tcp:1234:1234
OK
exit
上面的telnet localhost 5554,redir add tcp:1234:1234,exit是自己输入的命令,其他的是输出信息。5554是模拟器控制台的监听端口,这些命令是将所有到localhost:1234的数据转发到模拟器的1234端口。
最后在本机启动gdb:
arm-eabi-gdb out/target/product/generic/symbols/system/bin/libomstts
arm-eabi-gdb是android自带的toolchain里的,注意后面的可执行文件是strip之前的。
gdb启动后,在gdb里输入命令连接gdbserver:
target remote localhost:1234
连接到gdbserver成功后,就可以使用所有的gdb调试命令啦
现在的这个gdbserver还不能调试动态链接库,只能先编译成可执行文件调试。
posted on 2010-10-10 16:24
大龙
阅读(265)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
BlogJava
知识库
博问
管理
Powered by:
C++博客
Copyright © 大龙