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/gdb

2.      解压文件

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/

安装可以下载固件包,也可以用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/bin

source /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提示没权限,加sudoarm-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.37

7. gdbserver启动调试文件

◇ /usr/local/gdbserver 188.188.187.38:2345 led2

Process 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

9. 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.txt

To 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/ttyb

communicates with the server via serial line /dev/ttyb, and:

      (gdb) target remote the-target:2345

猜你喜欢

转载自www.linuxidc.com/Linux/2016-03/129599.htm