gdb安装与远程调试

   为了在pc端调试开发板中的程序,需要通过gdb远程调试来实现,具体步骤如下:

    1、正确安装arm-linux-gdb

          下载源文件:http://ftp.gnu.org/gnu/gdb/

          解压:# tar -zxvf gdb-7.6.1.tar.gz 

         进入解压后的目录,配置编译参数:

         # ./configure --target=arm-linux --prefix=/usr/local/arm/4.5.1 

         # make

         # sudo make install

        一定要确保install 否则输入arm-linux-gdb后会出现找不到该文件。安装完成后可以找到arm-linux-gdb文件。

            

         也可以通过命令查看是否安装成功:

         root@width-virtual-machine:/opt/gdb# arm-linux-gdb --version
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 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=i686-pc-linux-gnu --target=arm-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.


    2、gdb调试

        (1)  准备程序如下,程序名为hello2.c

            #include<stdio.h>
             void main()
             {
                 printf("1111111111111\n");
                 printf("123456789\n");
             }

         

        (2) 编译程序:

        

       (3) 从开发板运行程序

            首先安装好gdbserver,并将gdbserver拷贝到运行程序所在的目录。

            从开发板挂载虚拟机中的目录,

           挂载前:

           

          挂载后:

          

                 ip:192.168.0.2为pc端的ip地址。

          进入运行文件所在文件夹:

          

         运行开发板端程序:

         

         PC端进行调试:

        

       连接开发板:

           输入:target remote 192.168.0.7:2345 

           其中开发板ip为:192.168.0.7, 另外要保证开发板启动时的端口号与PC调试时的端口号一致。

       

    开始调试:

    (gdb) list
Cannot access memory at address 0x0
1 #include<stdio.h>
2 void main()
3 {
4    printf("1111111111111\n");
5   printf("123456789\n");
6 }
(gdb) c

    运行结果为:

    /mnt/hello # ./gdbserver 192.168.0.2:2345 hello2
Process hello2 created; pid = 1084
Listening on port 2345
Remote debugging from host 192.168.0.2
1111111111111
123456789

Child exited with status 10
GDBserver exiting
/mnt/hello # 


    3、ddd调试

        (1)  先安装好ddd软件;

        (2)  开发板端启动和前面是一样的;

        (3)  以debug方式启动ddd软件

             

             一定要记得加中间的参数:-debugger , 否则图像框中就没有办法进行单步调试。

             ddd启动时的路径应该为源文件所在目录,否则可能找不到程序,启动后界面为:

            

            在最下面输入框(gdb)后面输入连接开发板的命令,格式和gdb调试时一样,如下:

        

         退出ddd软件:

        (gdb)q


猜你喜欢

转载自blog.csdn.net/try2find/article/details/16889027