How use debugging in VS Code - c++

I am getting error after running debugger like
c:\Users\USER.vscode\extensions\ms-vscode.cpptools-1.7.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-vomttuky.aw4' '--stdout=Microsoft-MIEngine-Out-5gcky3n5.jua' '--stderr=Microsoft-MIEngine-Error-1xr5gc00.po0' '--pid=Microsoft-MIEngine-Pid-w3xqmfyg.lmp' '--dbgExe=C:/MinGW/bin/gdb.exe' '--interpreter=mi'
whenever i try to debug simple cpp file
Hello.cpp -
#include <bits/stdc++.h>
using namespace std;
int sqr(int a){
return a*a;
}
int main (){
int a =10;
int b =2;
int c =a*b;
cout << sqr(c);
return 0;
}
I have configured my launch.json file 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}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"logging": { "engineLogging": true },
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
i am using
VSCode - 1.61.2
MiGW - 6.3.0

Related

How to Fix "End of File Expected" JSON Settings VS Code?

{
"workbench.colorTheme": "Default Dark+"
}
{ }
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"stopAtEntry": false,
"customLaunchSetupCommands": [
{ "text": "target-run", "description": "run target", "ignoreFailures": false }
],
"launchCompleteCommand": "exec-run",
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
}
}
What you have posted is not valid json. You've got several typos including:
An empty empty set of curly braces {} on line 7, followed by several key value attribute pairs not enclosed in curly braces.
This might be closer to what you want:
{
"workbench.colorTheme": "Default Dark+",
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"stopAtEntry": false,
"customLaunchSetupCommands": [
{
"text": "target-run",
"description": "run target",
"ignoreFailures": false
}
],
"launchCompleteCommand": "exec-run",
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
}
}

Errors while building and running C++ code in vscode using gcc. Tasks.json file

This is the code im trying to build and execute.
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
cout << "Hello World";
return 0;
}
i am able to compile and run it using the commands
directory path:// g++ -g hello.cpp
./a.exe
I now made a tasks.json file so that i don't have to run the above two commands everytime, and the .exe file is also named same as the .cpp file.
This is the error i'm facing:
image for build error in VSCode terminal
If anyone knows a fix for this, please help me out.
Let me know if you need the tasks.json file contents. I'll put them up here.
Tasks.json
{
"version": "2.0.0",
"tasks": [
{
"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
}
}
]
}
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ (gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "C:/Users/H.P/.vscode/CC++_gcc_Compiler/bin/gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Users/H.P/.vscode/CC++_gcc_Compiler/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Try these Its working fine on my system
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile and run",
"type": "shell",
"command": "cls",
"args": [
";",
"g++",
"-g",
"${file}",
"-o",
"ans.exe",
";",
// "cls",
// ";",
"./ans.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.):(\\d+):(\\d+):\\s+(warning|error):\\s+(.)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
]
}
and 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/ans.exe",
"args": [],
"stopAtEntry": false,
"externalConsole":true,
"cwd": "${workspaceFolder}",
"environment": [],
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

I'm Unable to debug my C++ code in VSCode

I'm trying to debug my C++ file but whenever I press the Run >> start debugging option, it just runs and quit without any errors or anything. My program is not running...
Here's my code:
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int rows, question;
std::string length;
cin >> rows;
for (int i = 0; i < rows; i++)
{
cin >> length;
}
return 0;
}
Here's what it shows in the terminal after clicking on debug:
cmd /C "c:\Users\intel\.vscode\extensions\ms-vscode.cpptools-0.29.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-oxw2rz3u.v3w --stdout=Microsoft-MIEngine-Out-5me5n3jp.wq2 --stderr=Microsoft-MIEngine-Error-wg1xnokk.ddw --pid=Microsoft-MIEngine-Pid-kfv0gezm.4wp --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
C:\Users\intel\Desktop\Python programs>
Here's what it shows in the output window:
Here's my tasks.json:
{
"version": "2.0.0",
"_runner": "terminal",
"tasks": [
{
"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": "test",
"isDefault": true
}
}
]
}
Here's 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.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
}
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
]
}
I am using a windows machine and a MinGW for C++
I use VSCode to develop in C++ too, but not tryed to use with MinGW yet. I use it with MSVC and GCC (Linux).
My launch configuration is sligh different from yours, using GCC.
{
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing",
"text": "-enable-pretty-printing"
}
]
},
"name": "Run gcc (linux) x64 debug",
"request": "launch",
"program": "/projects/CPP/GHDWS/build/gcc-linux/x64/debug/GHDWS",
"cwd": "/projects/CPP/GHDWS/build/run",
"args": [],
"preLaunchTask": "Build gcc x64 debug",
"type": "cppdbg",
"externalConsole": false
},
I made my own system build, that automatically configure VSCode to your project. If you're willing, you can try use it.
CppMagic

It's no any response after starting debugging

According to the instruction: https://code.visualstudio.com/docs/cpp/config-mingw, .vscode files are set. Then, I add the MinGW64 path to the system path. But, when I start debugging, VS Code hangs and no finish, I also scan the Console by the steps: Help->Toggle Developer Tools, and the Console displays the following error, and I don't know how to solve.
enter image description here
The followings are my source code and both JSON files:
// source code file
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
// 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": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-win32-sjlj-rt_v5-rev1\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-win32-sjlj-rt_v5-rev1\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-7.2.0-win32-sjlj-rt_v5-rev1\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

VSCode C++ - Compound debug configuration pre-launch task (c++)

I am writing a program (c/c++) that sits between some hardware and another set of software. I have written a little program that "emulates" the hardware (a radio, CSP), and that emulates the other set of software (a TCP/IP socket, CDH). I want to be able to debug all 3 at the same time. However, the issue I run into is that, when defining a pre-launch task for the compound configuration, it doesn't actually take. Is there a way to trigger that to happen, or should I just run the build in the standalone configs?
My build system is waf.
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "waf-build",
"type": "shell",
"command": "./waf build",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
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": "CSP Loopback Test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/csp_loop_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CSP Loopback Test (Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/csp_loop_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "waf-build",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CDH Loopback Test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/cdh_loop_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CDH Loopback Test (Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/cdh_loop_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "waf-build",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CSP<->CDH Only No Args",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CSP<->CDH Only No Args (Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "waf-build",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "CSP<->CDH Only, localhost, /dev/ttyUSB0 (Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main",
"args": ["localhost", "/dev/ttyS0"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "waf-build",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
],
"compounds": [
{
"name": "Full Test",
"preLaunchTask" : "waf-build",
"configurations": ["CDH Loopback Test", "CSP Loopback Test", "CSP<->CDH Only No Args"]
}
],
}