vscode中远程调试c++的方法是什么

在vscode中远程调试c++的方法如下:

1. 安装C/C++插件,并在vscode中配置C/C++编译环境;

2. 在vscode中新建launch.json文件,并在其中配置远程调试参数;

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Remote Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb-multiarch",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "remote build",
            "logging": {
                "moduleLoad": false,
                "trace": false
            },
            "windows": {
                "MIDebuggerPath": "gdb-multiarch.exe"
            },
            "pipeTransport": {
                "pipeCwd": "${workspaceFolder}",
                "pipeProgram": "ssh",
                "pipeArgs": [
                    "username@remotehost"
                ],
                "debuggerPath": "/usr/bin/gdb-multiarch"
            }
        }
    ]
}

3. 在vscode中新建tasks.json文件,并在其中配置远程编译参数;

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "remote build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}/a.out"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "remote": {
                "type": "ssh",
                "command": "g++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${workspaceFolder}/a.out"
                ],
                "host": "username@remotehost",
                "cwd": "${workspaceFolder}"
            }
        }
    ]
}

4. 在vscode中打开调试菜单,选择C++ Remote Debug,即可开始远程调试。

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享