老是忘,记个笔记吧。

刚好最近做一个项目,同时涉及c++/python/nodejs,且数据处理逻辑复杂,需要多语言同步断点调试。vscode按如下方法配置后可丝滑的断点debug,不再一行行打log调试代码。

调试C++

在根目录.vscode下创建launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "2.0.0",
    "configurations": [
        {
            "name": "xxx服务调试",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/XXXServer",
            "args": ["--config=/xxx/xxx.conf"],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "make"
        }
    ]
}

在根目录.vscode下创建tasks.json

{
    "version": "2.0.0",
    "command": "make",
    "args": ["-j8"]
}

注意args里边填上正确的编译参数。

调试nodejs

在根目录.vscode下创建launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "启动程序",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/bin/www",
            "runtimeExecutable": "/root/.nvm/versions/node/v12.13.0/bin/node"
        },
        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 3030,
            "skipFiles": [
                "<node_internals>/**"
            ]
        }
    ]
}
  • program:调试入口代码
  • runtimeExecutable:node地址

调试python

同样在根目录.vscode下创建launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "句子评测",
            "type": "python",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "program": "total_score_model.py",
            "args": ["-f","test_data/", "-k","0", "-rf","result/sentence"],
            "console": "integratedTerminal"
        },
        {
            "name": "段落评测",
            "type": "python",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "program": "total_score_model.py",
            "args": ["-f","test_data/", "-k","1", "-sp","test_data/script", "-rf","result/paragraph"],
            "console": "integratedTerminal"
        }
    ]
}

值得注意的是args传入的格式,比较容易搞错

☞ 参与评论