I've installed visual studio code version 1.74.0 and I'm using it for some testing and development with c language and Cygwin, for building and running works fine, but the problem arises when I try to use the debugger, I have this message "The editor could not be opened because the file was not found", basically it's not able to find the source file where there are also the breakpoints.
The correct source file is: "C:\Users\PG005856\Documents\clanguage\projects\ctest\test.c" but it tries to find in this path :
"C:\Users\PG005856\Documents\clanguage\projects\ctest\C\Users\PG005856\Documents\clanguage\projects\ctest\test.c"
It tries to recreate the same path inside the workspace, this is my launch.json file :
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MyProgram/cygwin64/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
}
]
}
]
}
Anyone have any clue about this problem ? i've tried to search online but with no luck.
Thanks,
Tommaso.
Related
I am trying to use pretty-printing for debugging C++ in VS code under a Debian configuration.
Right now vectors are displayed like that : Vector display
My launch.json file is :
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/examples/005_friction/mode_III_slip_weakening",
"args": ["dumps", "100", "100"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/examples/005_friction/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
],
}
I have also tried to add in configurations
"gdb": {
"prettyPrinting": true}
In that case, I have an error "Property gdb is not allowed". But I have gdb installed on my computer. I also have the "C/C++" extension installed in VS code.
At last, I tried to type -exec -enable-pretty-printing in the Debug console without further success.
What should I do ?
Every time Intellisense says it wants to know what folder to use for debugging and I select the folder for it to work with. It updates my launch.json to the following
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "d:/programming/cs50/substitution",
"program": "d:/programming/cs50/substitution/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
I've found these settings break the running and debugging process. I can get a working result with the code below...
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": ["abc"],
"stopAtEntry": true,
"externalConsole": true,
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"MIMode": "gdb",
"miDebuggerPath": "C:/ProgramData/chocolatey/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
As far as I can see the only differences are the cwd and program properties. Is there any reason why it wants me to point the program property away from my exe file? It doesn't feel very helpful, but maybe I'm missing something in my environment that would mean the settings it suggests are beneficial.
In Linux, I would be able to type into the integrated terminal no problem. I'd be able to type in user input and it would output. On Windows, I cannot do that. The output shows in the Debug Console and I cannot type into that or the integrated terminal.
In the picture, I run without debugging in C++ and when I ask for an input, it hangs there and doesn't output. I've seen CodeRunner but I rather not use that.
The picture of the terminal when running.
EDIT
{
// 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": "C/C++: g++.exe build active file"
}
]
}
By default, the Debug Console which the C++ program is outputting to does not support user input. This means that typing your input in the Debug Console will not be read by the C++ program.
To solve this problem, change the line "externalConsole": false to "externalConsole": true in your launch.json file so that your C++ program can run in an external console. This way, you can enter your user input and get interpreted by the C++ program that is being debugged.
Your launch.json should now look something like:
{
// 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, // <-- Changed to "true" in here
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
Read more here:
How to read input when debugging in C++ in Visual Studio Code?
I tried compiling and debugging c++ programs in vscode with wsl, compiling succeeded, but when I tried to press F5 to debug, the error is that the pipe program failed to start. Here is my launch.json.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/maxu/projects/helloworld/helloworld.out",
"args": [""],
"stopAtEntry": true,
"cwd": "/home/maxu/projects/helloworld/",
"environment": [],
"externalConsole": true,
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/c": "${env:systemdrive}/",
"/usr": "C:\\Users\\maxu1\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr"
}
}
]
}
here is the error message
error message
I tried to modify the parameter "pipeProgram" to "c:\windows\system32\bash.exe", but also failed.
I have a similar problem as yours except that my pipe program is ssh.exe under c:\windows\system32\openssh.
Here is how I work through it: copy openssh folder to c:\ and add that path to my user path environment variable. You can have a try.
I don't know if the windows system folders are accessible from vscode.
I am debugging a shared C++ library called from python on Ubuntu 18.04. I can attach GDB to this using gdb -p PID (where PID is the python process ID).
I like the promises of Visual Studio Code, but the default debug launch.json requires "program" property attach, but gdb does not need this.
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
In this case, what should program be and why is it even required?
Just use python (or optionally the full path to your python executable)
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/path/to/pythonX.Y",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}