VS Code: local variables not showing correctly - c++

Sorry if this has been asked before, but I don't get the previous given answers. I'm new to VS Code and know a bit of c++ coding. I tried the tutorial for windows/mingw :
https://code.visualstudio.com/docs/cpp/config-mingw#_step-through-the-code
and done everything so far. The sample code has been build and I want to debug now, but my variables view is showing something different when stepping through the application when debugging. (see attached image)
The word should contain any of the strings, as well as msg should show something different. My watch for a self made i int shows correctly, though. Whats'up? I did everything as in the tutorial.
also: the terminal tab does not output the msg from cout, but I see it in the debug console instead. (see image in tutorial just above the chapter 'set a watch')
launch.json is:
{
// 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 - Aktive Datei erstellen und debuggen",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
sorry, i'm a newb to vs code :-/

I re-installed using the 64bit version of MinGW from sourceforge as I had an old 32 bit version running via mingw-get.

One possible cause is that pretty-printing did not display UTF-8 content correctly. You can either:
Set it to UTF-8 charset (VSCode debugger having issues with character encoding)
Disable pretty-printing (Cannot see any variable values while debugging)

Related

Unable to start debugging. Not implemented. Error on VS code

Hi i recently started using VS code for my C++ course. I am trying to get the debugger to work but even with hours of trying to figure out what's wrong i still get the following error "Unable to start debugging. Not implemented." I am a bit unsure on what that means let alone how to solve it. My launch.json file looks like this. Thank you in advance for the help.
{
// 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": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "Assigment_1.C++",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
}
]
}
I don't have enough Karma to post in the comment thread but I wanted to say that I don't think it matters that you're using vs code instead of visual studio. It says in the debug console that the C/C++ extionsion is compatible with both, and this is the .json that is automatically generated by vs code. I'm having the same issue trying to run C. I've reached out to microsoft support. Let me know if you've figured it out, thanks.
Alternatively, it seems to work if you just download the code runner extension and then right click and choose run code instead. At least it did for me using C. Still trying to figure out how to use it with the debugger however.
I had the same problem and I have solved this problem using these steps.
First create your C++ folder (mine is cpp test) and create the main.cpp file.
Then after making the main method just click f5 and the vs code will pop up a box asking whether C++(GDB) or C++(Windows).
refer the photo
Now click on C++(GDB/LLDB).
Now click on g++.exe (Build and Debug active file).
Now the vs code will generate the lanch.json file.
Then go to the main.cpp file, Just click f5 and it will run without any problem. It worked for me.
(Please make sure that you have installed cygwin64 on your computer, mingw is also possible)
The json file below worked for me
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/mingw/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]

dbg not working on VScode with WSL2 - Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04..'

I've installed WSL2 and build tool and everything is working well on linux console (including a test c++ program I was able to debug with dbg).
I'm now trying to have a working development environment on my windows10 machine, by installing VSCode and a couple of extensions (c/c++ and Remote WSL).
Build works just fine, but when I try to debug, after executing (F10) a couple of lines I get the error:
Unable to open 'libc-start.c': Unable to read file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c').
From that point on debugger basically doesn't work anymore, every time I press F10 (or F11) I get a new popup with the same error
screenshot of error and dev environment
Pressing the "Create File" button results in an "Unable to write file 'vscode-remote://wsl+ubuntu-20.04...." (same file as above).
here following 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
and my tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C++ Compile",
"command": "/usr/bin/g++",
"args": ["-g","*.cpp","-o","${fileDirname}/${fileBasenameNoExtension}"],
"options": {"cwd": "${workspaceFolder}"},
"problemMatcher": ["$gcc"],
"group": {"kind": "build","isDefault": true}
}
]
}
I've searched quite a bit before posting. Other have had similar problems in older posts but most of them claimed that being an old bug and they say the problem was solved with the upgrade. I'm running latest version of everything I'm using (including VSCode and the plugins).
thank you in advance to anyone helping out.
Adding
"sourceFileMap": { "//wsl$/Ubuntu-20.04" : "/" }
to the launch.json resolved the problem for me.

Debugging with GDB in VSCode on Windows

I'm at a bit of a loss here, I hadn't really expected this to be difficult. I usually work on Linux, but today I had some work that I needed to do and only had a Windows machine. I thought this would be no problem, I can install git for windows, clone my project, and get right to work. Its just been a huge mess. I'm really hoping someone can help me understand where I went wrong in setting all this up on Windows. It isn't something I plan to do frequently, but definitely something I want to be able to do on a Windows machine in a reasonable amount of time.
I'm using WSL and have set my default VSCode Windows integrated terminal to C:\WINDOWS\System32\bash.exe
I installed Windows 10 SDK to fix crtdbg.h include errors as a dependency against <iostream>
I installed gdb with MinGW -
I set the path environment variable
I created a 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": "(gdb) CDLL Driver",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/driver",
"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
}
]
}
]
}
My MinGW bin contains the following
I launch my debug task in VSCode and I get the following error
cmd /C "c:\Users\shaun\.vscode\extensions\ms-vscode.cpptools-0.28.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-4n4ohh2f.ibt --stdout=Microsoft-MIEngine-Out-1irudlfy.q5x --stderr=Microsoft-MIEngine-Error-fg20cagk.ynl --pid=Microsoft-MIEngine-Pid-kzdzn4p4.lro --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
Command 'cmd' not found, but there are 16 similar ones.
I can provide more information if needed. I'm really hoping I missed something simple here that would be obvious to someone who works on Windows.. Thank you in advance, I really appreciate the help!
If you are using WSL to compile the project you should not use MinGW gdb.
You need to install gdb on you Linux subsystem (using native tools like apt if you are using Ubuntu WSL), reopen your project in WSL and configure the WSL path to gdb.
I was able to successfully debug using this setup on WSL.
Replace your launch.json file with this file
{
"version": "0.2.0",
"configurations": [
{
"args": ["1"],
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"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": "C/C++: gcc.exe build active file"
}
]
}
Make Sure you have installed MinGw Compiler and gdb debugger

How to solve : "launch : program "executable.out" does not exist" in VS Code when debugging with gdb

I am following that tutorial from the VScode team :
https://code.visualstudio.com/docs/cpp/config-wsl#_debug-helloworldcpp
I have run and built another c++ project.
It compiles but the project kraches at runtime, so I decide to debug it.
So i want to debug and I use gdb as proposed by this good tutorial.
When I execute the debugging with "F5", I have that 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": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "executable.out",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I have modified the "program" section to put the name of my executable ( executable.out) , which is located in the "workspaceFolder"
So I don't understand the error message I get when I do "F5" :
launch : program "executable.out" does not exist
Could someone explain to me how to solve that ?
I thought a lot before posting this question.
Thanks a lot in advance.
Best regards
Use absolute path in program:
"program": "${workspaceFolder}/executable.out"
I assume you are using Linux, since you are using g++ compiler.
Did you compile your cpp file to "executable.out", e.g.
g++ main.cpp -o executable.out
Your launch.json configuration look fine to me. It should work.

Debug GNU using VS Code without GDB

Over the weekend I had installed a gcc through the MSYS2 bash. I set it up in VS code and have it working properly. I even had the GDB working (yes I know this is a debugger). But, my main question is, is it possible to use the debugging function in VS code to debug rather then GDB. Pressing F5 it pulls up the launch.json file and gives me launch: program 'enter program name, for example c:\School\a.exe' does not exist .After some research I see you give it a file to the args to allow it run in debugger. When I do this though I can't seem to either give it the right file or make it work overall. I am also using a.exe rather than a.out. I'm unsure if this has effect.
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": ["C:\\School\\CSE340\\project2\\main.cpp"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
VS Code does not have an internal debugger (see here). You need to use GDB or the visual studio debugger (if you have the latter).
In your launch.json you need to modify the entries:
"program": this is the path to the program you want to debug, i.e. your compiled program (can be a relative path to your project folder)
"miDebuggerPath": this is the path to GDB
"args": these are arguments, you want to pass to your programm for debugging purposes, i.e. you can leave this blank
So the launch.json file for you would look something like this:
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\CSE340\\project2\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", // Path where your gdb.exe is located
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
${workspaceFolder} is a path variable to your workspace and seems to point to C:\\School\\, so maybe you'll need to modify the value of "program" to point to the application that you want to debug. You could also specify the absolute path to your program.
Also, do not forget to compile your code with debug-flags (-g), these are needed by GDB in order to step through the code. For example:
g++ -g main.cpp -o main.exe