VSCode does not debug when using LLDB on Windows 10 - c++

I installed the LLDB extension in VSCode, but when I am trying to debug it just does not happen. Instead the program just executes.
My tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:/MinGW64/mingw64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-Wall",
"-std=c++17",
"${fileDirname}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:/MinGW64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:/MinGW64/mingw64/bin/g++.exe"
}
]
}
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"cwd": "${fileDirname}"
}
]
}
Does anybody know what the problem is ?

Related

Running C++ using clang++ in VScode terminal (The value of miDebuggerPath is invalid)

I'm new to using C++ and have been trying to figure this out for hours. I'm using windows. I installed VScode, the extension for C++, installed MSYS2, and set up clang++. Now I'm trying to run file hello.cpp in VScode using their terminal. It's just hello world. When using the below task, it executes but then throws "Unable to start debugging. The value of miDebuggerPath is invalid." The hello world does not output and I'm at a loss. Does anyone know why this is happening and have suggestions on how to fix? Thank you and much appreciated!
Here is a pic of the commands I've been trying to run in the terminal
Executing task: C/C++: clang++.exe build active file <
Starting build...
C:\msys64\mingw64\bin\clang++.exe -fdiagnostics-color=always -g C:\Users\Daniel\Desktop\test\hello.cpp -o C:\Users\Daniel\Desktop\test\hello.exe
Build finished successfully.
My code
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;}
My 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": []}
My tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\clang++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: clang-cl.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\clang-cl.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: clang-cpp.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\clang-cpp.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.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"}

how to setup VSCode C++ to show local variables

I'm Following the Udacity´s C++ Nanodegree Program. For this course, the instructor uses VSCode, the C/C++ extension and the Clang-format.
According to the course instructions, I already installed the g++ compiler and the gdb debugger and both tools are working fine. the problem I´m having is that when I try to debug from VSC, I´m getting a completely different result from what tue instructor is showing. I'm using the following code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
std::vector<std::string> brothers{"David", "Ethan", "Adam"};
for (std::string const &brother : brothers) {
std::cout << "Hello " << brother << "!\n";
}
}
And my debugging is showing some weird information.
which is different from what the instructor gets on his screen (he is on Linux). He is getting the actual content of the local variables.
This is the launch.json I'm using for the debugger
{
// 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": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
I´m an intermediate python programmer just beginning with C++; My guess is that what my VSCode is showing is some memory allocation or type variable stuff, but that's not very usefull for software debuging. Does anybody knows how to configure VSCode or the compiler in order to show the content of the variables correctly? I'm using Windows.
Thanks!
uopdate:
here is my task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file ver(1)",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: cpp.exe build active file",
"command": "C:\\MinGW\\bin\\cpp.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file ver(2)",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
I uninstalled minGW, installed the MinGW-w64 from this site http://mingw-w64.org/doku.php/download, changed MinGW environment variables, and problem solved!
Thanks!

Pass CMake flags to VS Codes "tasks"?

So I have a CMakeLists.txt that works well and the solution runs in debug.
The tasks associated with VS Code (build active file, etc) call GCC ignoring the CMakeLists.txt. This is undesired because CMake sets required flags like the C++ standard version.
Anybody know how to pipe CMake into tasks.json?
For the default tasks look like:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-9 build active file",
"command": "/usr/bin/g++-9",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
},
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
"command": "/usr/bin/cpp",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /usr/bin/cpp"
}
],
"version": "2.0.0"
}

How do I set up C/C++ on VSCode on MacOS (2019) properly?

I am very VERY new to VSCode and C/C++, just started 10 mins ago, tried to follow the website tutorial for setting up c/c++ on VSC (https://code.visualstudio.com/docs/languages/cpp#_intellisense) but the code I copied and pasted from the site wouldn't even run. So I put some really simple code to try to see what the problem was.
I installed these extensions:
screenshot of installed extensions
I think that I have set it up incorrectly somehow.
The code runs and outputs 'hello world', but there is a permanent red squiggle at the end and to my knowledge, I haven't missed any brackets. Also, when I pasted the code from that link in, my text wasn't green for words like vector and string even though I used #include at the beginning.
Reminder that I am on MacOS (2019), and Xcode tools is installed
Main code (named helloworld.cpp):
#include <stdio.h>
int main()
{
printf("hello,world\n");
}
launch.json
{
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

My VSCode debugger dosen't show any variable value (image attached)(c++)

I recently started to use VSCode and can't seem to figure out how to use the debugger.The c++ debugger dosen't show any values which are readable.
p.s i have installed the c++ intellisense extension from microsoft.
edit:screenshot after stepping over
Variable not showing their values during debugging
my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
uninstalled MinGW-w32 and installed MinGW-W64 as instructed by #StupidMan