Jim*_*mah 14 debugging visual-studio-code
我正在尝试启动多个程序,这些程序需要在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"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
是的,您可以添加一个将休眠 x 秒的预启动任务。
因此,假设您在 Node.js 上有一个客户端和服务器,并且服务器 db 连接需要更长的时间来加载这会导致客户端出现问题。
在 vscode 上延迟客户端调试器在 Mac OS X 上是这样工作的
首先在与 launch.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"
}
}
]
Run Code Online (Sandbox Code Playgroud)
}
现在将以下 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"]
}
]
Run Code Online (Sandbox Code Playgroud)
sleep 命令在 Linux 和 MAC OS X 上可用。对于 Windows,只需使用这个 hack 代替它:
平 127.0.0.1 -n 6 > 空
现在您有一个简单的方法可以在服务器之前延迟客户端的启动。
| 归档时间: |
|
| 查看次数: |
885 次 |
| 最近记录: |