Fast-Dds源码调试方案

发布时间 2023-10-05 15:24:41作者: 墨尔基阿德斯

1、虚拟机安装:参考ubuntu fastdds安装 - 墨尔基阿德斯 - 博客园 (cnblogs.com)

2、Ubuntu安装gdb:

sudo apt install gdb

3、查看gdb的安装路径(默认安装在 /usr/bin/gdb):

which gdb

4、配置调试参数,以示例程序HelloWorldExample为例:

  1)、重新编译fastdds库(只编译一次就行,更换调试示例程序后无需重新编译):

    第1步虚拟机安装中的【5.编译安装Fast-DDS】,重新执行4、5命令,其中第4步改为:

cmake ..  -DCMAKE_INSTALL_PREFIX=~/Fast-DDS/install -DCMAKE_BUILD_TYPE=Debug ..

  2)、重新编译示例程序:

1 cd ~/Fast-DDS/Fast-DDS/examples/cpp/dds/HelloWorldExample/
2 mkdir build && cd build
3 cmake .. -DCMAKE_PREFIX_PATH=~/Fast-DDS/install/  -DCMAKE_BUILD_TYPE=Debug ..
4 make

5、使用vscode安装ssh工具远程打开虚拟机源码(略)

6、添加如下配置:

 1 {
 2     // 使用 IntelliSense 了解相关属性。 
 3     // 悬停以查看现有属性的描述。
 4     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
 5     "version": "0.2.0",
 6     "configurations": [
 7         
 8         {
 9             "name": "(gdb) 启动",
10             "type": "cppdbg",
11             "request": "launch",
12             "program": "${workspaceFolder}/examples/cpp/dds/HelloWorldExample/build/DDSHelloWorldExample",
13             "args": ["publisher"],
14             "stopAtEntry": false,
15             "cwd": "${workspaceFolder}/",
16             "environment": [],
17             "externalConsole": false,
18             "MIMode": "gdb",
19             "setupCommands": [
20                 {
21                     "description": "为 gdb 启用整齐打印",
22                     "text": "-enable-pretty-printing",
23                     "ignoreFailures": true
24                 },
25                 {
26                     "description": "将反汇编风格设置为 Intel",
27                     "text": "-gdb-set disassembly-flavor intel",
28                     "ignoreFailures": true
29                 }
30             ],
31             "miDebuggerPath":"/usr/bin/gdb"
32         }
33 
34     ]
35 }
launch.json

 

  注意:

    12行为要调试的进程路径:

    13行为执行进程时的参数,执行订阅端时改为"subscriber",(较为不便,未找到解决方案)

    31行为gdb的安装路径。

7、添加必要的断点,然后点击【运行】->【启动调试】或直接按F5.