VScode configuration causes code to not execute - c

I am returning to learning C and was trying to get a basic code to print something to run, and for some reason, after debugging, and writing in the terminal ./{filename}.exe, I get no output at all, and a message in the terminal that says bash: ./test.exe: No such file or directory. attached below is the configuration of the launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/c_projects.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/cygwin64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
Thanks in advance!

Related

VSCode Debugger ignores breakpoints and runs whole program in C

My vscode debugger runs my whole program without stopping at breakpoints.
This is the message it outputs
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-grb2h0oc.w5x" 1>"/tmp/Microsoft-MIEngine-Out-mbd0kqti.hj3"
Here is my launch.json:
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/project",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
I am using C to program.
Thanks for the help.
I can mitigate this issue by deleting my launch.json and remaking it and that seems to work for some reason but only the first time I am using the debugger, after that I get the same issue.

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". VSCode with Ubuntu-22.04 using WSL

So I was trying to debug my C code using VSCode in WSL (Ubuntu 22.04) and after using different methods, I always get the same error.
Firstly I tried following this guide from this question,
Idk if I did something wrong, heres the "launch.json":
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/bin/main",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
and my "tasks.json":
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc"
}
]
}
Secondly I tried following this video which doesn't use the make file I used in the guide.
here's the "launch.json"
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main",
"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++: g++ build active file"
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/bin/main",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
and "tasks.json"
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
I also tried executing vscode in admin mode and using chmod -x [my main file] in the terminal, where [my main file] is the location of the binary output from the build.
And finally I used the vscode extension C/C++ runner to see if I was missing something.
In ALL this cases the debug console showed the same issue.
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001245
Cannot insert breakpoint 2.
Cannot access memory at address 0x8001260
And the terminal shows this warning:
&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-ri4karkl.dco" 1>"/tmp/Microsoft-MIEngine-Out-3varx35x.tnm"

Unable to start debugging. Unexpected GDB output from command"-environment-cd path to my c folder". -environment-cd: Usage DIRECTORY

So i wanted to learn c and got this error after trying to debug it:
Unable to start debugging. Unexpected GDB output from command"-environment-cd path to my c folder". -environment-cd: Usage DIRECTORY
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": "C:\\Users\\Šimon\\Desktop\\Cfiles\\HelloWorld.c",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Users\\Šimon\\Desktop\\migw64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
If you want more stuff then ask me.
I'm using visual studio code.

&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"

I'm currently using vscode on ubuntu to write and debug a simple c program.
I've updated gdb to the newest version(9.2-0ubuntu1~20.04.1). Whenever I click the debug button a "Permission Denied" error is shown.
Here's a screenshot of the error message
How do I resolve this error so that I can debug my C program with GDB and VSCode? I would appreciate it. The problem has bothered me for days and I can't figure it out myself.
This code snippet below is 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": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}

Visual Studio Code Property Console not allowed error

i am new to programming and i was doing some of these questions of a book.And got stuck in this question about area of a triangle."Property console is not allowed".Is it due to the math.h?
Because the same code is fully functional on online-gdb.
here is content of lauch.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 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
Replace
"console": "externalTerminal"
with
"externalConsole": true
Seems like "console" property is not supported in this version of auto-generated launch.json. However this does the trick to get rid of the warning message for me.
Hmm, now I'm getting "Property externalConsole is not allowed"

Resources