跳至主要内容

【转】使用gdbserver远程调试

1.默认crosstool交叉编译器没有自带gdbserver,需要自行编译
到GNU官方FTP下载,目前最新版的是gdb-6.7.1
下载地址:http://ftp.gnu.org/gnu/gdb/
注:若已有gdbserver,可以直接跳到步骤4
 
2.编译gdbserver
编译GDB源码时只需要编译出gdbserver就可以了,交叉编译器自带arm-linux-gdb(client端)可以使用。
gdb-6.7.1
# cd gdb-6.7.1/gdb/gdbserver/
#./configure --host=arm-linux --prefix=/work/install/gdbserver
#make
#make install
这时会在/work/install/gdbserver目录下生成bin/gdbserver,将其拷贝到nfs文件系统
#cd /work/install/gdbserver
#cp bin/gdbserver /work/nfs/rootfs/bin
 
3.库问题
这里需要注意的是运行gdbserver还需要libthread_db库,若你自己做的文件系统内没有这个库的话需要从交叉编译器内拷一个过去。
# gdbserver -h (target)
gdbserver: error while loading shared libraries: libthread_db.so.1: cannot open shared object file: No such file or directory
# cp -avf lib/libthread_db* /work/nfs/rootfs_bluetooth_omap/lib/
`/lib/libthread_db-1.0.so' -> `/work/nfs/rootfs/lib/libthread_db-1.0.so'
`/lib/libthread_db.so.1' -> `/work/nfs/rootfs/lib/libthread_db.so.1'
注:若不知道缺少什么库可以根据运行时错误提示拷贝或者用先用strace跟踪一下:
#strace -f -F -o strace.log gdbserver -h
#vi strace.log 
发现如下字段:
872   writev(2, [{"gdbserver", 9}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libthread_db.so.1", 17}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2}, {"No such file or directory", 25}, {"\n", 1}], 10) = 126
872   exit_group(127)                   = ?
得知缺少libthread_db.so.1库(红色部分标出)。
 
4.调试过程
1)Target端建立远程调试服务
# gdbserver 192.168.167.170:1234 obexftp (target)
Process obexftp created; pid = 858
Listening on port 1234
 
2)Host端GDB加载要调试的程序
这里要调试的程序得是交叉编译过的,并且加了-g参数。不过大部分编译程序默认就是加了-g参数的,这点可以从编译时的log看出。
# arm-linux-gdb obexftp 
GNU gdb 6.6.50.20070301 (MontaVista 6.6.50-2.0.1.0702865 2007-03-26)
Copyright (C) 2007 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=armv5tl-montavista-linux-gnueabi"...
 
3)连接到目标板调试服务
(gdb) target remote 192.168.167.15:1234
Remote debugging using 192.168.167.15:1234
Error while reading shared library symbols:
Dwarf Error: Can't read DWARF data from '/opt/montavista/pro/devkit/arm/v5t_le/target/usr/lib/debug/lib/ld-2.5.90.so.debug'
0x400007a0 in _start () from /opt/montavista/pro/devkit/arm/v5t_le/target/lib/ld-linux.so.3
注:上面两行错误信息暂时不用管,原因还不清楚,但是暂时发现不影响使用。
连接成功后ARM板上的信息应该是这样的:
# ./gdbserver 192.168.0.29:1234 arm0702_8.out
Process arm0702_8.out created; pid = 228
Remote debugging from host 192.168.0.29  <----多出这一行
上面这行表示宿主机和开发板连接成功。现在我们就可以在Host端像调试本地程序一样调试ARM板上程序。不过,需要注意的是这里执行程序要用"c",不能用"r"。因为程序已经在Target Board上面由gdbserver启动了。

调试过程如下:
(gdb) b main
Breakpoint 1 at 0x9870: file obexftp.c, line 376.
(gdb) info b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00009870 in main at obexftp.c:376
(gdb) c
Continuing.
Error while mapping shared library sections:
/work/install/bluetooth//lib/libobexftp.so.0: No such file or directory.
Error while mapping shared library sections:
/work/install/bluetooth//lib/libc.so.6: No such file or directory.
Breakpoint 1, main (argc=1, argv=0xbed0dec4) at obexftp.c:384
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
(gdb)
若产生这个错误主要是由于该调试的应用程序使用到了额外的库,而这个库在gdb默认的搜索路径内没有
(相对与远程调试,gdb默认搜索的路径即为交叉编译器的库路径,下面我会介绍到)
因此,这里我们需要修改一下gdb默认的共享库搜索路径。
修改的办法是设置GDB的环境变量:
(gdb) show solib-absolute-prefix
The current system root is "/opt/montavista/pro/devkit/arm/v5t_le/target". 
上面这个路径即GDB默认的绝对搜索路径,即交叉编译器库路径
(gdb) show solib-search-path
The search path for loading non-absolute shared library symbol files is .
(gdb) set solib-search-path /work/install/bluetooth/lib
这个路径为若在solib-absolute-prefix指定的路径内没有搜索到库,则再继续尝试从该路径进行搜索。
这点倒有点类似于系统默认库搜索路径与LD_LIBRARY_PATH的关系。
详细参考GDB手册中相关部分:
http://wiki.chinaunix.net/index.php/GDB_Manual_15_1

设置好solib-search-path后再运行程序:
(gdb) set solib-search-path /work/install/bluetooth/lib/
(gdb) c
Continuing.
Error while reading shared library symbols:
Dwarf Error: Can't read DWARF data from '/opt/montavista/pro/devkit/arm/v5t_le/target/usr/lib/debug/lib/ld-2.5.90.so.debug'
Breakpoint 1, main (argc=1, argv=0xbe896eb4) at obexftp.c:384
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
(gdb) l
379             char *output_file = NULL;
380             char *move_src = NULL;
381             /* char *inbox; */
382
383             /* preset mode of operation depending on our name */
384             if (strstr(argv[0], "ls") != NULL)      most_recent_cmd = 'l';
385             if (strstr(argv[0], "get") != NULL)     most_recent_cmd = 'g';
386             if (strstr(argv[0], "put") != NULL)     most_recent_cmd = 'p';
387             if (strstr(argv[0], "rm") != NULL)      most_recent_cmd = 'k';
388
(gdb)
运行成功
 
 
注:使用GDB调试时查看代码不是很方便。CLWEN使用VIM作为GDB前端界面,结合gdb的远程调试功能,动态的将程序当前运行的代码显示在VIM上,查看起来十分方便。其远程调试方法和GDB+GDB Server一样,但是多了一个GUI界面(VIM)。
参考:《使用CLEWN远程调试》

评论

此博客中的热门博文

【转】VxWorks中的地址映射

在运用嵌入式系统VxWorks和MPC860进行通信系统设计开发时,会遇到一个映射地址不能访问的问题。 缺省情况下,VxWorks系统已经进行了如下地址的映射:   memory地址、bcsr(Board Control and Status)地址、PC_BASE_ADRS(PCMCIA)地址、Internal Memory地址、rom(Flach memory)地址等,但是当你的硬件开发中要加上别的外设时,如(falsh、dsp、FPGA等),对这些外设的访问也是通过地址形式进行读写,如果你没有加相应的地址映射,那么是无法访问这些外设的。   和VxWorks缺省地址映射类似,你也可以进行相应的地址映射。   如下是地址映射原理及实现:   1、 地址映射结构 在Tornado\target\h\vmLib.h文件中 typedef struct phys_mem_desc { void *virtualAddr; void *physicalAddr; UINT len; UINT initialStateMask; /* mask parameter to vmStateSet */ UINT initialState; /* state parameter to vmStateSet */ } PHYS_MEM_DESC; virtualAddr:你要映射的虚拟地址 physicalAddr:硬件设计时定义的实际物理地址 len;要进行映射的地址长度 initialStateMask:可以初始化的地址状态: 有如下状态: #define VM_STATE_MASK_VALID 0x03 #define VM_STATE_MASK_WRITABLE 0x0c #define VM_STATE_MASK_CACHEABLE 0x30 #define VM_STATE_MASK_MEM_COHERENCY 0x40 #define VM_STATE_MASK_GUARDED 0x80 不同的CPU芯片类型还有其特殊状态 initialState:实际初始化的地址状态: 有如下状态: #define VM_STATE_VALID 0x01 #define VM_STATE_VALID_NOT 0x00 #define VM_STATE_WRITA

【转】多迷人Gtkmm啊

前边已经说过用glade设计界面然后动态装载,接下来再来看看怎么改变程序的皮肤(主题)     首先从 http://art.gnome.org/themes/gtk2 下载喜欢的主题,从压缩包里提取gtk-2.0文件夹让它和我们下边代码生成的可执行文件放在同一个目录下,这里我下载的的 http://art.gnome.org/download/themes/gtk2/1317/GTK2-CillopMidnite.tar.gz     然后用glade设计界面,命名为main.glade,一会让它和我们下边代码生成的可执行程序放在同一个目录下边     然后开始写代码如下: //main.cc #include <gtkmm.h> #include <libglademm/xml.h> int main(int argc, char *argv[]) {     Gtk::Main kit(argc,argv);         Gtk::Window *pWnd;        gtk_rc_parse("E:\\theme-viewer\\themes\\gtk-2.0\\gtkrc");       Glib::RefPtr<Gnome::Glade::Xml> refXml;     try     {         refXml = Gnome::Glade::Xml::create("main.glade");     }     catch(const Gnome::Glade::XmlError& ex)     {         Gtk::MessageDialog dialog("Load glade file failed!", false,       \                                   Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);         dialog.run();               return 1;     }         refXml->get_widget("main", pWnd);     if(pW

【转】https客户端的实现(libcurl)

一、              概念 1.         为什么要使用libcurl 1)        作为http的客户端,可以直接用socket连接服务器,然后对到的数据进行http解析,但要分析协议头,实现代理…这样太麻烦了。 2)        libcurl是一个开源的客户端url传输库,支持FTP,FTPS,TFTP,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE和LDAP,支持Windows,Unix,Linux等平台,简单易用,且库文件占用空间不到200K 2.         get和post方式 客户端在http连接时向服务提交数据的方式分为get和post两种 1)        Get方式将所要传输的数据附在网址后面,然后一起送达服务器,它的优点是效率比较高;缺点是安全性差、数据不超过1024个字符、必须是7位的ASCII编码;查询时经常用此方法。 2)        Post通过Http post处理发送数据,它的优点是安全性较强、支持数据量大、支持字符多;缺点是效率相对低;编辑修改时多使用此方法。 3.         cookie与session 1)        cookie cookie是发送到客户浏览器的文本串句柄,并保存在客户机硬盘上,可以用来在某个Web站点会话之间持久地保持数据。cookie在客户端。 2)        session session是访问者从到达某个特定主页到离开为止的那段时间。每一访问者都会单独获得一个session,实现站点多个用户之间在所有页面中共享信息。session在服务器上。 3)        libcurl中使用cookie 保存cookie, 使之后的链接与此链接使用相同的cookie a)         在关闭链接的时候把cookie写入指定的文件 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt"); b)        取用现在有的cookie,而不重新得到cookie curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); b)        ht