Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compounds debugging in VS Code with delayed launch

Tags:

I'm trying to launch multiple programs that need to talk to each other in the debugger in VS Code and created a launch.json with a compound that launches each of the executables. The programs launch simultaneously and all try to connect to the host at the same time. Is there any way in VS Code to explicitly set some sort of time delay between launch of each of the executables, say 250ms or so?

{   "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"]     }   ] } 
like image 383
Jimmmah Avatar asked Mar 17 '17 22:03

Jimmmah


People also ask

Is VS code good for debugging?

One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile, and debug loop.

What is launch json in vscode?

A launch. json file is used to configure the debugger in Visual Studio Code. Visual Studio Code generates a launch. json (under a . vscode folder in your project) with almost all of the required information.

What is launch configuration in vscode?

This vscode extension allows you to create settings to launch any number of your launch. json configurations or compound configurations via separate keybindings. These launch configs can be in any root folder in a multi-root workspace.

What does breakpoint do in VS code?

Set a Temporary breakpoint This breakpoint lets you break the code only once. When debugging, the Visual Studio debugger only pauses the running application once for this breakpoint and then removes it immediately after it has been hit.


1 Answers

Yes, you can add a prelaunch task which will sleep for x seconds.

So say you have a client and server on Node.js and the server db connection takes longer to load this causes problems with the client.

Delaying the client debugger on vscode would work like this on a Mac OS X

First create a task in the same folder as the launch.json file called tasks.json which will build out a shell command before launching the client.

{   // 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"       }     }   ] } 

Add the following pretask to your launch.json file now to call the task

{   "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"]     }   ] } 

The sleep command is available on Linux and MAC OS X. For Windows just use this hack in place of it:

ping 127.0.0.1 -n 6 > nul

Now you have a simple method to delay the launch of the client before the server.

like image 96
Jason Avatar answered Sep 27 '22 22:09

Jason