gdb远程调试示例

只要把生成的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]# ls
Makefile        utcommand.cpp       utdirreader.cpp  utstrutils.cpp
utcmdutils      utconfigparser      utfsutils.cpp
utcmdutils.cpp  utconfigparser.cpp  utgetrlimit.cpp
utcommand       utdirreader         utnfsutils.cpp
[root@server10 unittest]# gdbserver 192.168.10.199:9000 ./utdirreader
Process ./utdirreader created; pid = 13816
Listening on port 9000

2.client端示例:

[root@localhost unittest]# gdb ./utdirreader
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later //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:
//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:9000
Remote debugging using 192.168.10.199:9000
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007ffff7ddd420 in _start () from /lib64/ld-linux-x86-64.so.2
Missing separate debuginfos, use: debuginfo-install glibc-2.17-55.el7.x86_64
(gdb) list
1   #include 
2   #include 
3   #include 
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 ./utdirreader
Process ./utdirreader created; pid = 13816
Listening on port 9000
Remote debugging from host 192.168.10.3

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

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

如果出现

root@localhost unittest]# gdb ./utdirreader
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-51.el7
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 "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:9000
192.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/

你可能感兴趣的:(//【工具】)