Compounds debugging in VS Code with delayed launch - debugging

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

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.

Complementing Jason's answer
I was getting Error
OpenError: (:) [Out-File], NotSupportedException FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
On Windows (PowerShell Terminal), and have to change the ping hack command from:
"ping 127.0.0.1 -n 6 > nul"
to:
"ping 127.0.0.1 -n 6 > $null"

Related

Sfml window only show when i debug

**When i run the code, only shows the black cmd, but when i debug, show the sfml window, i already watched more than 5 tutorial on youtube, the sfml is working, but only when i debug, please please help me i do everything, i'm using codelite, the code is all right
**
please help me help me help me
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/FarmersBuilds/farmers.launcher",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

debug clang (lldb) under vscode/windows

I'm trying to debug the helloworld project
#include <stdio.h>
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
which is built using clang. I use vs-code to take these actions. Here is my task.json file:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: clang.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\clang.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
As a build task, it works but then with launch.json to debug it seems with no progress. Here is my launch.json` file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\lldb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: clang.exe build active file"
}
]
}
How to set-up debugger under vs-code with the use of clang/lldb?
It got stall within this command
PS C:\c_helloworld> & 'c:\.vscode\extensions\ms-vscode.cpptools-0.30.0-insiders5\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-2oaooq4b.u01' '--stdout=Microsoft-MIEngine-Out-ojuis1aj.kfb' '--stderr=Microsoft-MIEngine-Error-tcxqgdhj.tgp' '--pid=Microsoft-MIEngine-Pid-nam4qmgr.r4y' '--dbgExe=C:\msys64\mingw64\bin\lldb.exe' '--interpreter=mi'

How to target platforms with launch.json

The omnisharp ReadMe says this:
Operating System Specific Configurations
If there specific commands
that need to be changed per operating system, you can use the fields:
'windows', 'osx', or 'linux'. You can replace any of the fields
mentioned above for the specific operating system.
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\",
// "~/../../XunitTestLib/Steps"
],
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
When debugging I want to builds on Windows to start with the "args" entry which is uncommented, but on mac os I want it to start with the line which is commented out.
I am assuming that I would duplicate the configuration, once for Windows and mac, each, but this statement is confusing:
You can replace any of the fields mentioned above for the specific operating system.
It appears to be saying that I can replace "args" with "osx" but that obviously does not work.
How do I create a configuration for a target platform?
Turns out that targeting multiple platforms is a lot easier than I expected and is explained here with regards to the tasks.json file (but works just the same for launch.json).
My launch.json file adjusted for osx and windows would look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TestConsole/bin/Debug/netcoreapp2.1/TestConsole.dll",
"windows": {
"args": [
"c:\\git\\core\\XunitTestLib\\Steps\\"
]
},
"osx": {
"args": [
"~/../../XunitTestLib/Steps"
]
},
"cwd": "${workspaceFolder}/TestConsole",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}

Visual Studio Code Python Debugger Windows

I seem to be missing something simple, but I can't figure out why I am unable to debug python using Visual Studio Code on Windows. I've tried setting up the debugger as shown by Microsoft, and this youtube video. I've done a clean install of Visual Studio Code (including the python extension) and Python 3.6. I have no other python versions installed. I keep getting the following errors in the Python Debugger:
cd "c:\Users\xxx\Documents\Python Scripts" ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "C:\Users\xxx\AppData\Local\Programs\Python\Python36-32\python.exe" "C:\Users\xxx\.vscode\extensions\ms-python.python-2018.3.1\pythonFiles\PythonTools\visualstudio_py_launcher.py" "c:\Users\xxx\Documents\Python Scripts" 53746 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput "c:\Users\xxx\Documents\Python Scripts\.vscode\launch.json"
-bash: cd: c:\Users\xxx\Documents\Python Scripts: No such file or directory
env: ‘C:\\Users\\xxx\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe’: No such file or directory
It's complaining that it can't find the python.exe file, but it clearly can since VS code indicates that it's attached:
My launch.json file is the default, and I've tried all the configurations:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
},
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Terminal (external)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"debugOptions": [
"RedirectOutput",
"Django"
]
},
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "${workspaceFolder}/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "module.name"
},
{
"name": "Python: Pyramid",
"type": "python",
"request": "launch",
"args": [
"${workspaceFolder}/development.ini"
],
"debugOptions": [
"RedirectOutput",
"Pyramid"
]
},
{
"name": "Python: Watson",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/console.py",
"args": [
"dev",
"runserver",
"--noreload=True"
]
},
{
"name": "Python: All debug Options",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"module": "module.name",
"env": {
"VAR1": "1",
"VAR2": "2"
},
"envFile": "${workspaceFolder}/.env",
"args": [
"arg1",
"arg2"
],
"debugOptions": [
"RedirectOutput"
]
}
]
}
Pylinting works fine, and I have not custom user settings in Visual Studio Code that are related to python. I've tried setting the complete file path to python.exe in settings.json but it makes no difference.
Any help is greatly appreciated. Thanks in advance
I had the same problem but finally got out of it after several adjustment to my settings.
make sure all other settings are in place as you've mentioned especially pythonPath in settings.json and also get "python" installed from the "extension" toolbar in VS code.
Simply change your debug configuration from "Python: Scripts" (or any other configuration you've selected previously) to "Python: Terminal(external)" and you are good to go!
I know, is a pain and I'm experiencing the same.
Apparently python.exe is executing correctly. You will keep seeing that banner because "This is necessary to bootstrap the debugger."
At least this is what Microsoft says.

VScode compile C++ on windows the exe not found

I want to ask how to debug a simple hello world output from a C++ file, on the launch file I have to put the executable but I have only created a C++ file, how to compile it, I have tried everything, please help.
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
// compiles and links with debugger information
"args": ["-g", "-o", "main.exe", "main.cpp"],
// without debugger information
// "args": ["-o", "hello.exe", "hello.cpp"],
"showOutput": "always"
}
Pretty old question but here's a clear explanation for anyone in future.
Issue is that the debugger was looking for a.exe but your build file will probably be named different.
Changing the values of program variable to "${workspaceFolder}\\${fileBasenameNoExtension}.exe" will fix this issue. This should be in the tasks.json and the launch.json.
This env variable takes care that the right name is substituted. Now set a breakpoint and press f5.
Further details here and here.
Here's a full preview of a working launch.json
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGw\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
And a full preview of tasks.json.
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
NOTE: As explained here and here, you might want to set "externalConsole": true if your code needs input from user.

Resources