ARM-linux 下GDB的移植
- 格式:doc
- 大小:60.50 KB
- 文档页数:6
编译make
安装make install
o应该是安装在/home/hxy/gdb/output/x86-linux/bin/,名字是arm-linux-gdb
../configure --target=arm-linux --enable-shared --prefix=$PWD/../../output/x86-linux --without-x --disable-gdbtk --without-included-regex --without-include-gettext
编译make
安装make install
o这里应该在/home/hxy/gdb/output/arm-linux/bin有gdbserver
至于如何使用交叉调试参见相关博文,附件是已经编译好直接在eabi库环境下使用的版本
3.测试ARM本机调试
我们用一个有段错误的源码来测试本地调试的性能,参见如下代码,这里在f2()产生段错误
o刚刚编译出来的gdb尺寸相当大,10M多,因此必须要用arm-linux-strip gdb来把尺寸减少.strip后大约2M多.
2.交叉版本的gdb移植
交叉版本中,arm-linux-gcc3.3.2只能成功编译gdb 5.2.1.gdb 6.x需要更gcc 3.4.4以上版本。
eabi arm-linux-gcc4.3.3编译可以成功编译gdb 6.8.
License GPLv3+: GNU GPL version 3 or later </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"
|
|--libs
|-- ncurse
因其中cross-gdb是手工创建为了存放x86的目标代码
2。1编译cross调试的gdb 6.8
在/home/hxy/gdb/gdb-6.8清除上一次结果make distclean
创建/home/hxy/gdb/gdb-6.8/cross-gdb
在上述目录生成Makefile
生成Makefile
o./configure --host=arm-linux --enable-shared --prefix="$PWD/../output/arm-linux" --without-x --disable-gdbtk --disable-tui --without-included-regex --without-included-gettext LDFLAGS="-L$PWD/../output/arm-linux/lib" CPPFLAGS="-I$PWD/../output/arm-linux/include"
0x4009852cin strcpy () from /lib/libc.so.6
(gdb)bt
#0 0x4009852cin strcpy () from /lib/libc.so.6
#1 0x000083a8 inf2 (str=0x0) at test.c:8
#2 0x000083d4 inf1 () at test.c:14
还有一种是干脆把整个gdb移植成一个ARM的本地版。在开发板上直接用gdb来调试。
前一种方法是比较正统的方法。它gdbserver可以通过arm-linux-gdb直接在host上单步调试target的应用程序。.并且可以与图形界面调试器配合进行图形界面调试。缺点就是target资源较少。因此单步调试的速度并不是太快。因此实用性不算太强。
and "show warranty" for details.
This GDB was configured as "arm-linux"...
(gdb)r
Starting program: /mnt/nfs/gdb/output/arm-linux/bin/test
Program received signal SIGSEGV, Segmentation fault.
编译make
o如果gdb 6.7有一个警告会当成bug处理symtab.c: In function 'find_line_symtab':
symtab.c:2252: error: 'exact' may be used uninitialized in this function
o只要简单把int exact;变成int exactable-shared动态编译
o--host=arm-linux用arm-linux-gcc编译
o--prefix="$PWD/../output/arm-linux"安装目录
o--without-x取消x windows支持
o--disable-gdbtk取消gdbtk,应该也是图形界面相关的
安装make install
o最终的arm的程序gdb应该在home/hxy/gdb/output/arm-linux/bin下面,将其拷贝和libncurses.so拷贝到开发板上即可运行,象x86的GDB一样运行即可
o注意这个样编译能同时把ARM版gdbserver也同时编译出来并在安装目录看到.而且一般eabi的gcc编译器都自带了arm-linux-gdb.所以交叉版本的gdb移植很多时候可以省略.
}
voidtest1()
{
f1();
}
intmain()
{
test1();
}
编译arm-linux-gcc test.c -o test -g
在NFS路径上测试它的调用gdb和test.速度相当快。以下是它的测试结果
[root@EmbedSky bin]# ./run.sh
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
因为交叉版等于要移植两个平台程序.(x86的arm-linux-gdb和arm版的gdb server)
这里目录结构调整如下
/home/hxy/gdb
|
+--output
| |_arm-linux
| |_x86-linux
|-- gdb 6.8
| |-- cross-gdb #保存x86 gdb
| |- -gdb/gdbserver #原有目录,在此编译arm gdbserver,
o其中--enable-termcap比较关键gdb需要这个库
编译make
安装make install
olibncurses.so库应该在/home/hxy/gdb/output/arm-linux/lib
1.2 gdb本身的移植。
解压tar xvjf gdb-6.8.tar.bz2
ocd gdb-6.8
因此在这里我们把两种版本的gdb都移植一下。
1.本地版本的gdb的移植
ARM本地版需要ncurse的支持。这里移植是gdb 6.8.
编译器是arm-linux-gcc4.3.3.
操作系统是arm-linux2.30.4
ncurse 5.6。
按照移植规范,ncurse放入libs目录,gdb解压在项目目录下
2.2生成arm版gdbserver
生成Makefile在/home/hxy/gdb/gdb-6.8/gdb/gdbserver执行如下脚本
o./configure --host=arm-linux --prefix=$PWD/../../../output/arm-linux --without-include-regex --without-included-gettext
如何交叉调试
arm-linux的本地版一般只能做字符界面的。界面没有支持GUI的交叉调试版友好。而且单步调试速度也不算快。但是有几大大优点:
1.定位程序退出所在函数.
2.判断程序退出的原因
3.通过条件断点分析异常情况时运行环境.
用本地版gdb运行程序时,当程序因段错误或其它原因退出程序时。可以通过gdb bt(即backtrace)来查看最后运行的堆栈。来判断出错时是在哪一个函数里退出。这样会大大加快定位错误的速度,这样有时需要几天的定位的错误,可能只需要几分钟即可定位,这在嵌入式开发里有很强实际效用。
/home/hxy/gdb (项目目录)
|
+--output
| |_arm-linux
|-- gdb 6.8|
|--
|--libs
|-- ncurse
1.1 ncurse库的移植
解压tar xvzf ncurses-5.6.tar.gz
cd ncurses-5.6
生成makefile
o./configure --host=arm-linux --prefix="$PWD/../../output/arm-linux" --without-ada --enable-termcap --with-shared
#3 0x000083ec in test1 () at test.c:19
#4 0x00008408 inmain () at test.c:24
(gdb)
可以看到很快能测试出段错语的位置。我也试了一下单步调试程序,发现居然比交叉调试速度还快。这个倒出乎我的意料之外