VS Code中的化合物调试延迟启动

问题描述 投票:14回答:1

我正在尝试启动多个程序,这些程序需要在VS Code中的调试器中相互通信,并创建一个launch.json,其中包含一个启动每个可执行文件的化合物。程序同时启动,并且所有程序都尝试同时连接到主机。在VS Code中是否有任何方法可以在每个可执行文件的启动之间明确设置某种时间延迟,比如250ms左右?

{
 "version": "0.2.0",
 "configurations": [
    {
        "name": "Host",
        "type": "cppdbg",
        "request": "launch",
        "program": "/home/user/build/bin/host",
        "args": [],
        "stopAtEntry": false,
        "cwd": "/home/user/build/bin",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    },
    {
        "name": "Node A",
        "type": "cppdbg",
        "request": "launch",
        "program": "/home/user/build/bin/Node_A",
        "args": ["ArgA","ArgB","ArgC"],
        "stopAtEntry": false,
        "cwd": "/home/user/build/bin",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    },
    {
        "name": "Node B",
        "type": "cppdbg",
        "request": "launch",
        "program": "/home/user/build/bin/Node_B",
        "args": ["ArgA","ArgB","ArgC"],
        "stopAtEntry": false,
        "cwd": "/home/user/build/bin",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    }
 ],
 "compounds": [
    {
        "name": "System",
        "configurations": ["Host","Node A","Node B"]
    }
 ]
}
debugging visual-studio-code
1个回答
0
投票

是的,你可以添加一个睡前x秒的预启动任务。

因此,假设您在Node.js上有客户端和服务器,并且服务器数据库连接需要更长时间才能加载,这会导致客户端出现问题。

在vscode上延迟客户端调试器在Mac OS X上可以这样工作

首先在与名为tasks.json的launch.json文件相同的文件夹中创建一个任务,该文件将在启动客户端之前构建一个shell命令。

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "Sleepdelay",
        "type": "shell",
        "command": "sleep 6",
        "windows": {
            "command": "ping 127.0.0.1 -n 6 > nul"
        },
        "group": "none",
        "presentation": {
            "reveal": "silent",
            "panel": "new"
        }
    }
]

}

现在将以下pretask添加到launch.json文件中以调用该任务

"configurations": [
    {
        "type": "chrome",
        "request": "launch",
        "name": "Client",
        "url": "http://localhost:9090",
        "webRoot": "${workspaceFolder}/client/src",
        "breakOnLoad": true,
        "sourceMapPathOverrides": {
            "webpack:///./src/*": "${webRoot}/*"
        },
        "preLaunchTask": "Sleepdelay"
        //"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    },
    {
        "type": "node",
        "request": "launch",
        "name": "Server",
        "program": "${workspaceFolder}/server/server.js",
        "envFile": "${workspaceFolder}/server/.env",
        "cwd": "${workspaceFolder}/server/"

    }
],
"compounds": [
    {
        "name": "Server/Client",
        "configurations": ["Server", "Client"]
    }
]

sleep命令在Linux和MAC OS X上可用。对于Windows,只需使用此hack代替它:

ping 127.0.0.1 -n 6> nul

现在,您有一种简单的方法可以在服务器之前延迟客户端的启动。

© www.soinside.com 2019 - 2024. All rights reserved.