gdb 使用

  • 编译选项
SET(CMAKE_CXX_FLAGS "-std=c++11 -g")
  • gdb 启动
gdb ./YOU_EXEC_NAME

## bt
## f 0   # 根据 实际和自己代码最有关的进入
## print var    /  p  var
## list
  • gdb coredump
gdb ./YOUR_EXEC_NAME coredump_file
  • gdb 连接在线软件
## 1
gdb -p  PID
gdb --program PID
gdb attach PID
  • gdb 与vscode
{
    // 推荐方式1和方式3
    // stopAtEntry 进入默认打断点
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            // "program": "/data/path/work/YOUR_EXEC_NAME",
            "program": "/data/path/work/YOUR_EXEC_NAME",
            "args": ["/data/path/world/xxx.sqlite", "49", "/data/path/work/xx.file", "1", "112.57501644,26.82793034"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "/data/path/work/YOUR_EXEC_NAME",
            "args": [""/data/path/world/xxx.sqlite", "49", "/data/path/work/xx.file", "1", "112.57501644,26.82793034"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "ROS Launch",
            "type": "ros",
            "request": "launch",
            "target": "/home/xxxxx/catkin_ws/src/xxx_pkg/launch/xxx.launch"
        }
    ]
}

设置条件断点

watch 监听

call stack  0 是最近的

鼠标悬停打印变量

  • ros launch 添加标签

你可能感兴趣的:(Linux,C,C++,linux)