C/C++调试:gdbserver的简单使用

1.角色:host和target

host是运行gdb的机器
target是运行gdbserver的机器
gdbserver提供一个网络服务,gdb remote到gdbserver上后进行调试

2. 基本要求:

  • host和target可以网络通信,ping通
  • host上的gdb和target上的gdbserver版本尽量一致(?)
  • 编译好的可执行程序a.out,放在target上;使用'-g'选项编译;
  • host上需要能访问到a.out对应的源码文件:可以是NFS共享文件,也可以是两份源码(分别放在host和target上,甚至target上不需要源码??)

3. 基本步骤

  • 编译出a.out放到target上
  • target上执行:gdbserver :7788 ./a.out,其中7788是端口号可以改
  • host上确保能访问到a.out对应的源码(如果是多个文件的工程,要保证目录结构也一致)
  • host上执行
    ```
    cgdb

    target remote xx.xx.xx.xx:7788 [args]
    ``其中xx.xx.xx.xx是target的ip地址,7788是先前在target上gdbserver对应的端口号,[args]`表示参数列表,如果a.out需要传参需要在这里传入(我测试下来,host上没法传args)
  • host上使用gdb命令调试
    set args -b ITENSOR -d ../dlc/bvlc_alexnet.dlc -i target_raw_list.txt -o output

4. 实例记录

为了调试一个ubuntu下程序crash后直接导致系统重启的bug,我的host和target都是ubuntu系统。

cgdb
target remote 172.17.122.120:7788
b 396
c
b 402
c

猜你喜欢

转载自www.cnblogs.com/zjutzz/p/10883312.html