主题 : tiny4412 android gdb调试问题,不能打断点(已解决) 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 99274
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2013-12-24
最后登录: 2014-07-09
楼主  发表于: 2014-06-06 13:40

 tiny4412 android gdb调试问题,不能打断点(已解决)

板子上我使用的是自带的gdbserver,版本信息:
gdbserver --version                                      
GNU gdbserver (GDB) 7.1-android-gg2
Copyright (C) 2010 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "arm-elf-linux"


linux系统里我下载了gdb,自己编译的,版本信息:
GNU gdb (GDB) 7.1
Copyright (C) 2010 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-unknown-linux-gnu --target=arm-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.


连接调试如下:
Adb shell进入安卓系统:启动gdbserver:
# gdbserver :2222 ./$yourAPP;                   //启动adbserver
服务器运行gdb:
         # arm-linux-gdb                 //启动gpdb
         (gdb) shell adb forward tcp:2222 tcp:2222               //完成端口映射的任务,靠前的那个为local端的端口,靠后的那个为remote端的。
(gdb) target remote localhost:2222                  //连接adbserver
         (gdb) file $youAPP                                                  //加载将要调试的可执行文件(带符号表)
(gdb)…      //开始调试


现在gdb可以连接上,可以list代码,但是不能打断点,提示
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x15f9694: Input/output error.

断点我是在文件的某行上打的,但最后报错这个地址不是我想要的,所以断点打不起报错也正常;
但是我也不知道怎么解决这个问题,请给我一些帮助~~~谢谢!
[ 此帖被zdcspace在2014-06-13 09:34重新编辑 ]
级别: 新手上路
UID: 99274
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2013-12-24
最后登录: 2014-07-09
1楼  发表于: 2014-06-09 11:13
我写一个简单的helloword的程序,使用arm-linux-gcc交叉编译后,放到安卓板子里可以正常打断点单步调试;
同样的helloword程序,我写Android.mk(是这个调用的交叉编译不同于arm-linux-gcc ??)在安卓源码下编译后,放到安卓板子里可以list代码,但不能打断点;提示如下:
(gdb) target remote localhost:9999
Remote debugging using localhost:9999
warning: Can not parse XML target description; XML support was disabled at compile time
0x40047220 in ?? ()
(gdb) file ./hello.default.symb
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /opt/FriendlyARM/tiny4412/Android/android-4.2.2_r1/hello/hello.default.symb...done.
(gdb) l
Cannot access memory at address 0x0
1       #include "stdio.h"
2
3       void main()
4       {
5               printf("hello word!\n");
6               char c = getchar();
7
8               return;
9       }
(gdb) b 5
Breakpoint 1 at 0x446: file hello/hello.c, line 5.
(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x446: 输入/输出错误.
[ 此帖被zdcspace在2014-06-09 11:29重新编辑 ]
级别: 新手上路
UID: 99274
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2013-12-24
最后登录: 2014-07-09
2楼  发表于: 2014-06-09 17:28
继续测试中,我打了断点在main函数上,但断点的地址没在main函数上,所以当我c的时候不会停下来;
为什么我这个断点地址会错误偏移了呢??


(gdb) target remote :9999      
Remote debugging using :9999
Cannot access memory at address 0x0
Reading symbols from /opt/FriendlyARM/tiny4412/Android/android-4.2.2_r1/out/target/product/tiny4412/symbols/system/bin/linker...done.
Loaded symbols for /opt/FriendlyARM/tiny4412/Android/android-4.2.2_r1/out/target/product/tiny4412/symbols/system/bin/linker
__dl__start () at bionic/linker/arch/arm/begin.S:35
35              mov     r0, sp
(gdb) i b
Num     Type           Disp Enb Address    What
3       breakpoint     keep y   0x400d0470 in main at hello/hellotest.c:5
(gdb) d
删除所有断点吗? (y or n) y
(gdb) b hello/hellotest.c :main
Breakpoint 4 at 0x400d0470: file hello/hellotest.c, line 5.
(gdb) c
Continuing.
级别: 新手上路
UID: 99274
精华: 0
发帖: 17
金钱: 85 两
威望: 17 点
综合积分: 34 分
注册时间: 2013-12-24
最后登录: 2014-07-09
3楼  发表于: 2014-06-12 16:52
结贴!!!

这些天一直在搞android gdb调试,现在所有的问题都解决了,gdb可以正常调试,可以调试中间链接的静态库,可以调多线程。
现在回头看,一路过来其实都是些小问题,但第一次都是这样,摸索中总会犯很多的错误;最终能够调试成功这都是时间换来的,在此我详细描述共享出来,希望让大家少走弯路;
再强调下GDB的重要性,对于一个大的工程,没有GDB调试是不行的。

之前的问题是因为GDB client工具不对的原因,导致gdb调试断点错误,以下是我现在调试正常的配置:
Linux ubuntu 12.04.3;
tiny4412安卓调试平板;
安卓源码tiny4412提供4.2版本;
    GDB server使用源码自带的gdb server,板子里边已经有了;
    GDB client使用源码目录下:
.../android-4.2.2_r1/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gdb,可以用;
    NDK里的GDB client工具:
.../android-ndk-r9b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gdb,可以用;

注:其他GDB client工具不能正常使用:如用源码自己gcc-arm-linux编译等,不同的平台和安卓版本请自己多测试;


GDB调试中需要注意的问题:
1.    Gdb调试时要导入带符号表的调试文件:
file ./gps.default.symb
2.    gdb端口映射:
    shell adb forward tcp:9999 tcp:9999    //第一个为gdb服务器端口,第二个为本地端口
3.    gdb连接:
target remote :9999
4.    gdb多线程及动态库调试,需要手动导入带符号表的库路径,可以查看当前已导入的库:
set solib-absolute-prefix ../out/target/product/tiny4412/symbols
set solib-search-path ../out/target/product/tiny4412/symbols/system/lib
info sharedlibrary
5.    中间有链接静态库需要调试时,在编译静态库时需要去掉编译优化,否则单步调试会乱跳;
LOCAL_CFLAGS += -g -O0