gdb远程调试示例

来源:互联网 发布:阿里云电话客服 编辑:程序博客网 时间:2024/05/23 17:37

只要把生成的gdbserver下载到目标主机上,或者是通过NFS挂载到目标板上就可能进行远程的调试了。
关于NFS的配置见http://blog.csdn.net/derkampf/article/details/70144114

下面是一段示例:

server端:(程序所在端)

ip 192.168.10.199 port:9000

client端:(调试端)

ip 192.168.10.3

1.server端示例

[root@server10 unittest]# lsMakefile        utcommand.cpp       utdirreader.cpp  utstrutils.cpputcmdutils      utconfigparser      utfsutils.cpputcmdutils.cpp  utconfigparser.cpp  utgetrlimit.cpputcommand       utdirreader         utnfsutils.cpp[root@server10 unittest]# gdbserver 192.168.10.199:9000 ./utdirreaderProcess ./utdirreader created; pid = 13816Listening on port 9000

2.client端示例:

[root@localhost unittest]# gdb ./utdirreaderGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7Copyright (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 "x86_64-redhat-linux-gnu".For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>...Reading symbols from /mnt/synctool/team2/zhangzhuo/2017.4.26/unittest/utdirreader...done.(gdb) target remote 192.168.10.199:9000Remote debugging using 192.168.10.199:9000Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.Loaded symbols for /lib64/ld-linux-x86-64.so.20x00007ffff7ddd420 in _start () from /lib64/ld-linux-x86-64.so.2Missing separate debuginfos, use: debuginfo-install glibc-2.17-55.el7.x86_64(gdb) list1   #include <iostream>2   #include <iterator>3   #include <algorithm>4   using namespace std;5   #include "../lib/dirreader.h"6   7   int main(int argc, char const* argv[])8   {9       //LaDirReader* pdir = LaDirReader::create_instatnce("/111");10      LaDirReader* pdir = new LaDirReader("/etc");(gdb) 

3.此时server端的变化

[root@server10 unittest]# gdbserver 192.168.10.199:9000 ./utdirreaderProcess ./utdirreader created; pid = 13816Listening on port 9000Remote debugging from host 192.168.10.3

调试过程跟普通gdb’调试没有出入。

4.尝试期间可能出现的错误

如果出现

root@localhost unittest]# gdb ./utdirreaderGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7Copyright (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 "x86_64-redhat-linux-gnu".For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>...Reading symbols from /mnt/synctool/team2/zhangzhuo/2017.4.26/unittest/utdirreader...done.(gdb) target remote 192.168.10.199:9000192.168.10.199:9000: No route to host.

关闭server端防火墙

[root@server10 Desktop]# systemctl stop firewalld.service 

参考http://blog.csdn.net/j6915819/article/details/6673127

http://blog.csdn.net/wendaotaoa/article/details/8152864

http://blog.163.com/danshiming@126/blog/static/1094127482014102752913921/

http://fishcried.com/2014-09-11/gdb%E8%BF%9C%E7%A8%8B%E8%B0%83%E8%AF%95/

原创粉丝点击