linux下的GDB远程调试

来源:互联网 发布:ubuntu 虚拟机mac 编辑:程序博客网 时间:2024/05/16 19:59

一、利用GDB进行远程调试,首先需要明确一下几点:

1、调试用的GDB必须是交叉编译产生的GDB;

2、调试的程序必须是交叉编译且带 “-g” 选项的可执行程序。

3、在宿主机和目标开发板上调试的必须是同一个可执行程序。

4、基于 3 ,我们必须要建立一个宿主机和开发板的NFS共享目录,以实现调试调试同一可执行程序。

5、目标开发板的gdbserver和宿主机用的GDB版本必须相同,最好是同一源文件编译同时产生的。

6、在开发板上必须开通远程调试所需要的端口,否则远程调试机无法通过端口远程连接到开发板上。

二、GDB远程调试步骤

1. 下载文件到目标板: gdbtest和gdbserver

假设 host pc ip:192.168.1.45
         board ip:192.168.1.180

将文件拷贝到目标板上:

先将gdbtest和gdbserver两个文件拷贝到主机的/tftpboot目录下

在目标板的Linux中运行:

#mount 192.168.1.108:/tftpboot /mnt/nfs
    #cd /mnt/nfs
    #ls

看是否有gdbtest和gdbserver两个文件。

3.运行调试

client board:
    #./gdbserver 192.168.1.45:1234 gdbtest // 目标板上运行gdbtest 监听端口1234
    host pc:
    #cd /usr/local/arm-gdb/bin/
    #copy gdbtest /usr/local/arm-gdb/bin/ // 将前面编译的文件gdbtest拷贝到此目录
    #./arm-linux-gdb gdbtest
    (gdb)target remote 192.168.1.180:1234 // 连接到开发板 成功后就可以进行调试
    (gdb)list or l
    (gdb)break func
    (gdb)break 22
    (gdb)info br
    (gdb)continue or c // 这里不能用 run
    (gdb)next or n
    (gdb)print or p result
    (gdb) finish // 跳出func函数
    (gdb) next
    (gdb) quit

建立连接后进行gdb远程调试和gdb本地调试方法相同

gdb/gdbserver 调试多线程

While debuging a remote multithread program by means of gdb/gdbserver, frequently I see gdb complaints like this:

Program received signal SIG32, Real-time event 32.
0x400d7e84 in ?? ()
(gdb)

Then gdb is suspended to wait for new commands, and on this occasion, typing 'c' can make the debuging continue. But instruction 'info threads' can not list correct information.

In fact, this results from stripped libpthread/libthread_db, which can be easily verified by means of '/usr/bin/file'. To remove the problem, simply refer the libs to unstripped versions via gdb instructions like:

set solib-absolute-prefix [dir]

set solib-search-path [dir1];[dir2]


原创粉丝点击