C++ for VS code: Unable to start debugging [duplicate] - c++

I just switch from Netbeans to visual studio code, and i cannot debug c++, the error was Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path....
I tried to follow the c/c++ debug guide from visual studio code website that i searched from google, but it failed to run the application, but i can compile c++ from Ctrl + Shift + B so my task.json file is correct, so here are my task.json file and launch.json file.
{
//Task.json
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": ["-pipe", "-std=c++14", "${fileBasename}", "-lm"],
"showOutput": "always"
}
//Launch.json
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},

I just fixed it by doing the following (under windows)
Installed TDM-GCC MinGW Compiler from https://sourceforge.net/projects/tdm-gcc/?source=typ_redirect
use default installation path options.
Added these folders to PATH environment variable
C:\TDM-GCC-64\bin
C:\TDM-GCC-64\gdb64\bin
In your launch.json add the path to gdb debugger, your windows section should look like the code below
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:/TDM-GCC-64/gdb64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
Restart Visual Studio Code and try compile (ctrl+shift+b) and run the debugger (f5)
Remark: Like others had mentioned you should add the -g option in your tasks.json args so that the executable will be built with debugging information.

Related

Set C/C++ Runner to use integrated terminal by default

The C/C++ Runnner extension (link here) automatically creates debug configurations for C/C++ projects, and for example generates a .json file like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/Otávio Augusto Silva/Documents/Code/C++/dynamic_array",
"program": "c:/Users/Otávio Augusto Silva/Documents/Code/C++/dynamic_array/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
My question is, how do I make the extension set the externalConsole option to false by default? It always creates the config file to use an external console.
Go to Extensions search for Code Runner and then select Manage it's the settings icon directly to the right of Disable, Uninstall and select Extension Settings.
Search for code-runner.runInTerminal and set it true.

Visual Studio Code C++ debug break on exception

I am running visual studio code with the C++ v1.7.1 extension installed
The launch.json file specifies cppdbg
{
// 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}/bin/test.exe",
"args": ["windex"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
//"miDebuggerPath": "C:/msys64/mingw64/bin",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
}
]
}
I want to break when and where an exception occurs. However, I cannot find where to enable this. There are no exception checkboxes in the breakpoint panel.
Running on windows 10 using mingw g++ v11.2
How do I enable break on exception?

I can't debug C in VSCode/CodeBlocks or Any IDE

This 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": "gcc.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:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\gdb32.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
It was GDB.exe here earlier, But it said it couldn't find it , Even I couldn't find it..
So I put gdb32.exe as i was able to find that out , But it still didn't debug anything
i am fed up of this problem now...
Code Blocks says Please specify executable path,It can't be found
Please help, Thanks
Code::Blocks can be installed without MinGW, which is okay as MinGW-w64 is much better maintained. But MinGW-w64 needs to be installed separately.
You can download a standalone MinGW-w64 from https://winlibs.com/ and the site also explains on how to add this compiler and debugger to the settings.

VSCode not compiling c++

Im running Ubuntu MATE and i program in C++. I wanted to transfer to vscode so i installed it. But overall i cant really compile or debug anything. This works in terminal to run a code.
g++ HelloWorld.cpp -o HelloWorld.o
./HelloWorld.o
But if i want to go through button to compile this thing happens. What should i do? Im adding launch.json down below.
{
// 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": "cpp - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: cpp build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
If anybody in the future wonder what was the solution, compile c++ under linux with g++ and then press ctrl+f5. That one solved my problem, couldnt figure it out for 2 days.

Proble in debuging c++ code with visual studio code, with lunch.json file

I have Problem in debugging c++ programs in Visual studio code. Although, debugging was working before. I had not change any configuration or setting. When i opened visual studio code today then i saw that error.
Image
lunch.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": true,
"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"
}
]
}
I have not changed anything in system/vc code/ configuration etc.
Then, why debugging stops working.
The program setting specifies the program you want to debug. Here it is set to the active file folder ${fileDirname} and active filename with the .exe extension ${fileBasenameNoExtension}.exe, which if helloworld.cpp is the active file will be helloworld.exe.
The main problem is vccode is not able to find the current file for debugging.
These are some links that might work for you.
Docs
Configuration