Visual Studio Code - C++ Debugger doesn't start - c++

I've been using Visual Studio Code to debug C++ on Linux for a while now.
In a sample project I've got the following launch.json:
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
I've successfully compiled and run main.c, so debugging should work fine.
When I start the debugger, a blue loading bar appears under the arrow and nothing happens. On my laptop, with the exact same configuration, the loading bar would disappear after a couple of seconds and the debugger would start.
Looking at ps aux I can see two new processes:
mono.linux-x86_640 with the command /home/guyyst/.vscode/extensions/ms-vscode.cpptools-0.20.1/debugAdapters/mono.linux-x86_64 --config /home/guyyst/.vscode/extensions/ms-vscode.cpptools-0.20.1/debugAdapters/framework/config.linux /home/guyyst/.vscode/extensions/ms-vscode.cpptools-0.20.1/debugAdapters/bin/OpenDebugAD7.exe
bash with the command bash /home/guyyst/.vscode/extensions/ms-vscode.cpptools-0.20.1/debugAdapters/OpenDebugAD7
Debugging on my laptop spawns the same processes, but they disappear when the debugging actually starts. The two processes on my PC stick around even after closing VSCode. When I first noticed this I had 15+ copies running from previous attempts.
All of this worked fine yesterday, and I don't remember making any changes to my configuration since then.
I've tried reinstalling VSCode several times through either the AUR version visual-studio-code-bin or the open source package code.
Debugging some Python code worked just fine.

Turns out it was as easy as setting externalConsole in launch.json to false. Should've probably thought of trying that before.
I'm constrained to the VSCode console, which isn't that big a deal.
I still can't explain why it won't work with an external console, since that's how I'm still doing it on my laptop and used to do it on my PC too.

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

No client URI found in getBuildTasks() - VSCode - C++

On trying to debug a C++ code on VSCode, I am getting the error, "No client URI found in getBuildTasks()"
I am an absolute beginner and am just learning C++ and just set up my VSCode from a tutorial to run C++ on VSCode with minGW-w64. But the debug button just won't work like it should have and is instead throwing that error.
This is what my launch.json looks like:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
And these are the options that show up when I press Run and Debug with a.cpp opened in the folder with the .vscode subfolder containing the aforementioned launch.json file along with c_cpp_properties.json and tasks.json files.
Any and all help will be appreciated.
You need to open the Folder that you're working in, into the Workspace.
To do this, select Explorer from the left side bar and click on the big blue Open Folder button over there and open the Folder that you're working on and containing the .vscode subfolder.
.
.
The Desktop is where I build most of my smaller, quicker programs at. I removed the Desktop from the WorkSpace open, in order to stop the Source Control from suggesting me to commit changes to GitHub and hence VSCode had no directory to find the .vscode folder from. This never was a problem when I would debug and run python files but for C++ it was.
It was an absolute nooby dumbo mistake of mine but it literally took me 2 days to figure out and I've written the answer down, hoping it helps some other noob. :)

Error while debugging using gdb debugger on VS Code using Windows 10 and MINGW complier

I was following the documentation on https://code.visualstudio.com/docs/cpp/config-mingw to set up my C++ development environment on VS code.
I succesfully created my build task and ran my build task, but when i tried to set up my debugger (GDB debugger), i got the following output on the terminal.
C:\Users\Ayon\c++\helloworld> cmd /C "c:\Users\Ayon\.vscode\extensions\ms-vscode.cpptools-0.28.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-shlwrnf5.x12 --stdout=Microsoft-MIEngine-Out-vg12hskh.c52 --stderr=Microsoft-MIEngine-Error-nrcvh0zz.0u0 --pid=Microsoft-MIEngine-Pid-m1nmxyvs.qk2 --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Im curious as to how the "cmd /" came about in the output. Please help me fix this error.
Thanks in advance.
For reference, here is 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": [
{
"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": "g++.exe build active file"
}
]
}
Did you add mingw64/bin to your system path? Here's how to do so:
Control panel -> Edit path -> Environment variables -> Path -> New
You can also find more guidance on
vscode official website.
I believe the problem is with the MinGW installation. I also faced this problem for a long time, solved it by doing the following:
Completely removing the current MinGW Video tutorial
Installing MinGW-w64 from the site mentioned in vscode documentation. installation video tutorial
After this, I followed the configuration mentioned in this video. The video is for c code, but you can make the required changes to c++ code. Now I'm able to debug in vscode.
By this way, you will also be able to use the latest versions of gdb and g++ available.

How can Visual Studio Code be used to debug applications tested with Google Test?

I would like to run a command for my C++ project such as ./unittests_feature1 --gtest_filter=Feature1.test_int
using Visual Studio Code Debugger.
When setting up a debugger session in Visual Studio, my configuration looks like this:
{
"name": "Test_int",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/unittests_feature1",
"args": ["--gtest_filter=Feature1.test_int"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
But when I start the Debugger, it runs everything for unittests_feature1, and not only Feature1.test_int.
If I run manually in command line:
gdb --args ./unittests_feature1 --gtest_filter=Feature1.test_int
It works, so some Visual Studio Code configurations might be the problem.
I got a similar problem today and I'de like to post some experience here to help.
I am using WSL2/Ubuntu & VSCode Remote-WSL to debug a C++ program with GTest code. The default terminal in WSL2/Ubuntu is zsh. I want to pass the argument "--gtest_filter=OneD* to the test executable.
For me, the successful config for the args field of the launch.json is:
"args": [
"--gtest_filter=OneD\\*"
],
Examples of problematic configs include:
[--gtest_filter=\"OneD\\*\"]
[--gtest_filter=\"OneD*\"]
[--gtest_filter=OneD*]
It seems zsh contributed a little to the problem since * is parsed by zsh firstly before gdb & my executable.

VSCode: Debugger for C++ does not launch nor attach properly

I am using:
Ubuntu 16.04 (I know it is not supported officially)
Latest VSCode version
Latest "C/C++ for VSCode" version
My project is a C++ project and the structure looks like this:
/home/lvier/mainProject/fooProject (source code)
/home/lvier/mainProject/build/fooProject (binaries)
I am working in the sub-project "/home/lvier/mainProject/fooProject" and in "/home/lvier/mainProject/build/fooProject" there are many sub programs (lets say "foo", "foo_sub1", "foo_sub2" ...).
My goal:
I want to start the program "foo" (which starts all other foo_sub-programs) and then, I want to debug a certain sub program (let's say "foo_sub1") by attaching to it. I am also fine with starting and debugging in the same time as long as I can debug the sub-program "foo_sub1". The main project itself does not contain any executables.
Some months ago, debugging was working with "attach". For me it is not working anymore (because of VSCode updates and/or C/C++ extension updates). Here are my problems:
Assume that "foo" is running.
When using the "C++ Attach"-config and setting "request": "attach" (which is getting highlighted as "not an accepted value"), it will ask for the property "processId" if it is not set. If I set "processId", the error "Attach not supported" pops up.
If I use the "C++ Attach"-config with "request": "launch" (in the beginning this was autogenerated by the C/C++-extension), then the program finds the process id, tries to attach but then aborts with the message "Unable to start debugging. Commands are only accepted when the process is stopped." - what a surprise.
Assume that "foo" is not running yet.
When using the "C++ Launch"-config, the program starts but no UI elements appear. Instead, it starts with a new terminal popping up which says "warning gdb failed to set controlling terminal operation not permitted" for a brief moment and in the internal console of VSCode, it states that it stops at a certain line of code (a breakpoint not defined by me) and prints
"Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1"."
From there I can't continue further and I have to manually terminate the program.
When I use GDB without VSCode, i.e. just by native terminal, my program is starting properly but with VSCode, there seem to be some issues currently.
This is my current, autogenerated config where I only edited the "cwd" and "program" paths (assume that the environment variable "${env.build_foo}" is set to "/home/lvier/mainProject/build/fooProject"):
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${env.build_foo}/foo",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"targetArchitecture": "x64",
"request": "launch", // <-- "attach" is not allowed (anymore)! :(
"program": "${env.build_foo}/foo_sub1",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"processId": "${command.pickProcess}",
"externalConsole": false,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
}
]
}
So far I am really frustrated and still don't want to give up on VSCode (I don't want to switch to another IDE yet). I have searched a lot for other issues and also tried to set some other config-properties but none of it helped.
Does anyone else also have such issues with the debugger or is this a general problem with the extension (... and Ubuntu 16.04)?
I am happy for any help or convenient workaround. Thanks in advance!
Note:
I have also created a thread on the related github page (see https://github.com/Microsoft/vscppsamples/issues/115)
Update 07/26/2016:
It seems like there is a bug with the C/C++ extension (see comments in the github link above). It is still being investigated though.
Here solution:
...Debugging works for me now after I removed the GCC -s flag (strip symbol table and relocation information) from the linker settings...
Got it from last answer of the next link (thanks HorstBaerbel):
https://github.com/Microsoft/vscode-cpptools/issues/115#issuecomment-299334301