Debugging 延迟启动的VS代码中的复合调试

Debugging 延迟启动的VS代码中的复合调试,debugging,visual-studio-code,Debugging,Visual Studio Code,我试图在VS代码中启动多个需要在调试器中相互对话的程序,并创建了一个launch.json,其中包含一个启动每个可执行文件的复合文件。程序同时启动,所有程序都尝试同时连接到主机。在VS代码中是否有任何方法可以显式地设置每个可执行文件启动之间的某种时间延迟,比如250ms左右 { "version": "0.2.0", "configurations": [ { "name": "Host", "type": "cppdbg", "req

我试图在VS代码中启动多个需要在调试器中相互对话的程序,并创建了一个launch.json,其中包含一个启动每个可执行文件的复合文件。程序同时启动,所有程序都尝试同时连接到主机。在VS代码中是否有任何方法可以显式地设置每个可执行文件启动之间的某种时间延迟,比如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"]
    }
 ]
}

是的,您可以添加一个启动前任务,该任务将休眠x秒

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

延迟vscode上的客户机调试器在Mac OS X上的工作方式与此类似

首先在launch.json文件tasks.json所在的文件夹中创建一个任务,该文件名为tasks.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"
        }
    }
]
}

现在将以下预任务添加到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"]
    }
]
在Linux和MAC OS X上可以使用sleep命令。对于Windows,只需使用以下方法即可:

ping 127.0.0.1-N6>nul

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