PC主机:Ubuntu 10.4

目标板:TQ2440开发板,linux内核2.6.30

NOTE:为了使用gdb进行调试,强烈建议使用nfs服务,否则调试会非常麻烦。

使用nfs服务可以参考:S3C2440挂载NFS文件系统

1. 概述

所谓远程调试,就是开发板上建立一个gdb服务端,同时待调试的程序也位于开发板,然后在PC机上使用gdb发起远程连接来进行调试。也就是说,在PC端调试开发板上的程序。请注意,在PC端需要包含被调试程序的符号调试信息(symbolic debug information),因此强烈建议使用NFS,否则需要两份被调试的应用程序,一份供gdb使用,另一份供gdbserver使用。

2. 安装GDB服务

下载gdb安装包,下载地址:http://ftp.gnu.org/gnu/gdb/

这里使用的是7.4。

解压安装包:

yj423@ubuntu:~/work_yj423$ tar -xvf gdb-7.4/

yj423@ubuntu:~/work_yj423/gdb-7.4$ pwd
/home/yj423/work_yj423/gdb-7.4

在开始编译之前,你必须知道你的交叉编译器的名字。我的交叉编译器是arm-unknown-linux-gnueabi-gcc,在下面将会用到该名字。

首先编译gdbserver,该程序运行在开发板上。

执行下列命令:

yj423@ubuntu:~/work_yj423/gdb-7.4$ cd gdb/gdbserver/
yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ ./configure --host=arm-unknown-linux-gnueabi --target=arm-unknown-linux-gnueab
yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ make

在make以后,会在当前目录下生成可执行文件gdbserver。

接着编译gdb,该程序运行在PC机上。

执行下列命令:

yj423@ubuntu:~/work_yj423/gdb-7.4/gdb/gdbserver$ cd ../../
yj423@ubuntu:~/work_yj423/gdb-7.4$ sudo ./configure --targe=arm-unknown-linux-gnueabi
yj423@ubuntu:~/work_yj423/gdb-7.4$ make

请注意执行命令时所在的目录。执行完以后会在gdb-7.4/gdb/下生成可执行文件gdb。我将gdb改命为armgdb。

3. 使用gdb调试

测试程序为hello.c,程序如下:

  1. #include <stdio.h>
  2. void main()
  3. {
  4. printf("hello world\n");
  5. printf("hello world\n");
  6. }

使用交叉编译器编译该文件,使用-g参数,生成hello。将gdbserver和hello复制到NFS的挂载点,我的挂载点为/home/yj423/nfswork。

yj423@ubuntu:~/nfswork$ ls
bin   dev  gdbserver  home  linuxrc  proc  sbin  tmp  var
boot  etc  hello      lib   mnt      root  sys   usr  welcome

可以看到gdbserver和hello。

接着,在开发板上使用NFS:
[root@yj423 /]#mount -o nolock 192.168.1.103:/home/yj423/nfswork /mnt/nfs
[root@yj423 /]#cd /mnt/nfs
[root@yj423 nfs]#ls
bin        dev        gdbserver  home       linuxrc    proc       sbin       tmp        var
boot       etc        hello      lib        mnt        root       sys        usr        welcome

然后执行gdbserver:

[root@yj423 nfs]#./gdbserver localhost:2001 hello
Process hello created; pid = 948
Listening on port 2001

2001为端口号,hello表示要调试的程序。此时gdbserver等待PC机进行链接。

在PC机上执行gdb:

yj423@ubuntu:~$ ./armgdb -q /home/yj423/nfswork/hello

Reading symbols from /home/yj423/nfswork/hello...done.

执行远程链接:

(gdb) target remote 192.168.1.6:2001
Remote debugging using 192.168.1.6:2001
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x400007b0 in ?? ()
(gdb)

这里的192.168.1.6为开发板的IP地址。

至此PC端的gdb和开发板的gdbserver已经建立连接,接下来可以调试。

(gdb) b main
Cannot access memory at address 0x0
Breakpoint 1 at 0x83e0: file hello.c, line 5.
(gdb) c
Continuing.
warning: `/lib/libc.so.6': Shared library architecture unknown is not compatible with target architecture arm.
warning: Could not load shared library symbols for /lib/ld-linux.so.3.
Do you need "set solib-search-path" or "set sysroot"?
Breakpoint 1, main () at hello.c:5
5        printf("hello world\n");
(gdb) n
6        printf("hello world\n");
(gdb) n
7    }

这里只是简单的调试。后面还会有共享库调试和多进程调试,尽请期待!

未完待续~~~~~~~~~

使用GDB进行嵌入式远程调试的更多相关文章

  1. Gdb远程调试Linux内核遇到的Bug

    知识共享许可协议本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/gdb-bug 本博客同步在http://www.cn ...

  2. 学习4412开发板gdb和gdbserver的调试

    因为有很多的小伙伴是从单片机转过来的,用惯了单片机上的JLINK调试程序,换到Linux上非常的不习惯.确实,如果能设置断点,单步调试,查看变量,那确实是太爽了,那么在我们的Linux可以做到吗,答案 ...

  3. DM368 arm板GDB远程调试

    参考: http://www.erchashu.com/wiki/eclipse-cdt-gdb-arm-app-cross-debug 远程调试环境由宿主机GDB和目标机调试stub共同构成,两者通 ...

  4. GDB + gdbserver 远程调试android native code

    原文地址:GDB + gdbserver 远程调试android native code 作者:tq08g2z 以调试模拟器中的native library code为例. Host: ubuntuT ...

  5. 使用Visual Studio 利用WinGDB编译和远程调试嵌入式Linux的程序

    写这篇文章的目的在于帮助那些既要使用Visual Studio编写程序又要开发和调试嵌入式Linux 程序的苦命程序员们! 第一步, 安装 WinGDB ,下载位置  http://www.wingd ...

  6. gdbserver远程调试嵌入式linux应用程序方法

    此处所讲的是基于gdb和gdbsever的远程调试方法.环境为:PC机:win7.虚拟机:10.04.下位机:飞嵌TE2440开发板. 嵌入式linux应用程序的开发一般都是在linux里面编写好代码 ...

  7. Qtcreator远程调试出现“The selected build of GDB does not support Python scripting.It cannot be used .."

      版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/aristolto/article/details/77370853 之前使用的是Qt4.7后来换 ...

  8. CLion远程调试嵌入式开发板程序

    CLion远程调试嵌入式开发板程序 目录 CLion远程调试嵌入式开发板程序 1. 目的 2. 前提条件 3. CLion设置 3.1 设置一个Deployment 3.2 上传需要的目录到目标板子 ...

  9. ARM平台如何玩转GDB远程调试?

    前  言 关于GDB工具 GDB工具是GNU项目调试器,基于命令行使用.和其他的调试器一样,可使用GDB工具单步运行程序.单步执行.跳入/跳出函数.设置断点.查看变量等等,它是UNIX/LINUX操作 ...

随机推荐

  1. 去除inline-block元素间距

  2. offSet和client和scroll

    这三个是是js盒模型属性 client clientWidth 内容宽度加上左右padding clientHeight 内容高度加上上下padding clientTop 上边框的宽度 client ...

  3. C++异常实现与longjmp, setjmp,栈指针EBP, Active Record

    这篇讲的不错: http://blog.csdn.net/smstong/article/details/50728022 首先Active Record 然后EBP,ESP等指针 2 通过setjm ...

  4. 在OSG 实现的 oculus rift 效果

    在OSG 实现的oculus rift 效果,还不错 这个是Delta3d中实现的 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh1eWluZ3Fpb ...

  5. ubuntu-查看iso文件的md5

    直接使用命令md5sum +文件名就可以了.例如 md5sum ~/YLMF_GHOSTWIN7SP1_X86_YN2015.iso 执行结果如下 cdbb7fdc8bbc30e5e0a398f71b ...

  6. 21. Node.Js Buffer类(缓冲区)-(一)

    转自:https://blog.csdn.net/u011127019/article/details/52512242

  7. 为RecyclerView添加item的点击事件

    RecyclerView侧重的是布局的灵活性,虽说可以替代ListView但是连基本的点击事件都没有,这篇文章就来详细讲解如何为RecyclerView的item添加点击事件,顺便复习一下观察者模式. ...

  8. MFC中对话框的各种消息触发时间

    小结:WM_CREATE是所有窗口都能响应的消息,表明本窗口已经创建完毕.可以安全的使用这个窗口了,例如在它上面画控件等等.这个状态肯定是在调用ShowWindows()显示窗口之前.WM_WM_IN ...

  9. JavaScript学习总结(4)——JavaScript数组

    JavaScript中的Array对象就是数组,首先是一个动态数组,无需预先制定大小,而且是一个像Java中数组.ArrayList.Hashtable等的超强综合体. 一.数组的声明 常规方式声明: ...

  10. android开发者要懂得问题答案

    我在网上看了一下有些人在博客上提出一些什么android开发者必须懂得问题,可是就是没有答案,所以我就把这些问题拷贝过来了.顺便也把全部的答案加上,为了让很多其它的开发者高速的找到答案,谢谢! 以下的 ...