Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Linux下嵌入式目标程序的在线仿真调试方法(GDB)

嵌入式Linux的GDB调试环境由Host端(PC机)和Target端(ARM实验板)两部分组成,Host端使用arm-Linux-gdb调试工具,而Target端需要运行gdbserver,两者之间可通过串口或网口连接,把ARM应用程序在Target端的执行情况返回Host。调试跟踪命令从Host端中的arm-Linux-gdb中发出。1.      下载最新的gdb软件包下载地址:http://ftp.gnu.org/gnu/gdb2.      解压文件sudo tar -vxzf gdb-7.9.tar.gz -C /usr/local/3. 安装arm-linux-gdb cd /usr/local/gdb-7.9
sudo ./configure --target=arm-linux --prefix=/usr/local/gdb-7.9/arm-gdb //安装路径 sudo make sudo make install提示安装出错:WARNING: "makeinfo" is missing on your system.       You should only need it if you modified a ".texi" file, or       any other file indirectly affecting the aspect of the manual.       You might want to install the Texinfo package:       http://www.gnu.org/software/texinfo/从提示的错误来看,应该是Ubuntu 没有安装txtinfo(makeinfo包含在texinfo里面)。可以看到configure的时候,运行makeinfo --version,if下面的判断为 texinfo的版本为4.7以上的版本才行, 小于这个版本或者没有安装texinfo,则MAKEINFO为 $MISSING makeinfo。安装可以下载固件包,也可以用sudo apt-get install texinfo来安装。最后,重新configure,make,make install,一切OK。添加变量:arm-linux-gdb添加环境变量,在/etc/profile中最后一行添加:export PATH=$PATH: /usr/local/gdb-7.9/arm-gdb/binsource /etc/profile使用命令使环境变量生效注:我用root,但是用户无法查看,只能先改权限,用用户修改,再改回权限至此,Host端的arm-Linux-gdb调试器安装结束4. 安装gdbserver◇ cd /usr/local/gdb-7.9/gdb/gdbserver◇ sudo ./configure --host=arm-linux --target=arm-linux --prefix=/usr/local/gdb-7.9/gdb/gdbserver◇ sudo make CC=arm-linux-gcc注:此处不加sudo提示没权限,加sudo则arm-linux-gcc说无此命令,所以我用的root用户执行的,也可以使用arm-linux-gcc的绝对路径。注:make之后不需要执行安装:sudo make install。◇ sudo arm-linux-strip gdbserver去除调试信息在目录/usr/local/gdb-7.10/gdb/gdbserver/bin下就生成了gdbserver可执行文件5. 配置ARM板和PC在同一网段内配置ARM IP:ifconfig eth0 192.168.1.10 netmask 255.255.255.0 或者直接修改rcS里的配置文件。6. 登陆开发板◇ telnet 188.188.187.377. gdbserver启动调试文件◇ /usr/local/gdbserver 188.188.187.38:2345 led2Process led2 created; pid = 1004                                               Listening on port 2345                                                         Remote debugging from host 188.188.187.38此时ARM开发板就在等待远端的调试连接了。其中188.188.187.38是远端的IP,2345是监听端口,led2是编译的文件(编译条件包括-g)。8. PC端开启调试◇ sudo /usr/local/gdb-7.9/arm-gdb/bin/arm-linux-gdb -tui /mnt/share/example/led2-gdb/led2◇ gdb>target remote 188.188.187.37:2345此时ARM端显示Remote debugging from host 188.188.187.38,Debug便建立连接了,可以调试了,具体的调试命令参考下面连接,这是GDB的命令,可能其中会有些不同:http://www.linuxidc.com/Linux/2016-03/129600.htm9. GDB远程调试错误解决使用GDB 7.2版本进行远程调试时出现:Remote ‘g’ packet reply is too long错误,需要修改gdb代码解决,办法是:修改gdb/remote.c文件,屏蔽process_g_packet函数中的下列两行:
  //if (buf_len > 2 * rsa->sizeof_g_packet)
  //error (_(“Remote ‘g’ packet reply is too long: %s”), rs->buf);

在其后添加:
  if (buf_len > 2 * rsa->sizeof_g_packet)  {              rsa->sizeof_g_packet = buf_len ;              for (i = 0; i < gdbarch_num_regs (gdbarch); i++)              {                   if (rsa->regs[i].pnum == -1)                            continue;                    if (rsa->regs[i].offset >= rsa->sizeof_g_packet)                            rsa->regs[i].in_g_packet = 0;                   else                            rsa->regs[i].in_g_packet = 1;          }         } 以上方法是通过网络仿真的,也可以通过串口也,具体可以看gdb-7.9/gdb/gdbserver下的README,以下截取部分:Usage (server (target) side):For example, using a serial port, you might say:     target> gdbserver /dev/com1 emacs foo.txtTo use a TCP connection, you could say:     target> gdbserver host:2345 emacs foo.txt Usage (host side):For example, using a serial port, you might say:     (gdb) target remote /dev/ttybcommunicates with the server via serial line /dev/ttyb, and:     (gdb) target remote the-target:2345本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/129599.htm