debug clang (lldb) under vscode/windows - debugging

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'

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

VSCode Launch File Debug Configuration for Different Files

I am using VSCode to debug my Python files. I have two scripts, let's say a.py and b.py. These two files work with differents args. I would like to configure launch.json in such a way that, if I run a.py, it should input its corresponding args and same for other files. However, there is no if statement in launch file. And if I write two configurations, it just runs them sequentially. What should my launch.json look like? Here is my first attempt.
{
// 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": "${WorkspaceFolder}/src/data_processing/main.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"/home/gokberk/Desktop/filtered_data",
"--gdc",
"gdc-client",
"--no-download",
"--manifest",
"/home/gokberk/Desktop/filtered_data/gdc_manifest.2021-05-26.txt",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${WorkspaceFolder}/src/training.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"args": [
"--input-data-folder",
"/home/gokberk/Desktop/filtered_data",
"--alpha",
"0.2",
"--beta",
"0.2",
"--max-bag-size",
"50",
"--underlying-model-type",
"resnet18",
"--pretrained",
"--no-download",
"--source-slides-folder",
"/home/gokberk/Desktop/filtered_data"
]
}
]
}

gcc: error: unrecognized command line option ‘--interpreter=mi’ in Visual Studio Code

I just installed Visual Studio Code in Ubuntu 18.04 LTS based ElementaryOS 5.1 Hera, and set up the environment for C/C++. Launch.json and tasks.json look all fine but on debugging, the following errors are triggered:
gcc: error: unrecognized command line option ‘--interpreter=mi’
gcc: error: unrecognized command line option ‘--tty=/dev/pts/0’
gcc: fatal error: no input files compilation terminated.
launch.json
{
// 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": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gcc"
}
]
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Is there any way to fix this?

Compounds debugging in VS Code with delayed launch

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"

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