pipeTransport program can't be found when debugging with vscode and wsl - 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.

Related

Pretty-printing not working in VS Code for C++ debugging using GDB

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 ?

Problem using debugging with c language and cygwin

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.

vscode cpp build tasks.json type:"cppbuild" error

VSCode : 1.61.0
Linux: Ubuntu 20.04.3 LTS
I'm trying to build c++ program using by VSCode.
when the run build, VSCode showing this message.
I know build tasking need matching launch.json file's preLaunchTask with tasks.json file's label. and I'm already set it.
tasks.json
{
"tasks": [
{
"type": "cppbuild", // but "shell" is working
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
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++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"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",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
The problem is, if I change the "type" value in tasks.json, from shell to cppbuild, It doesn't work and show the error message like to.
showing error message when the run build
what is different "cppbuild" and "shell"? and What should I do how using "cppbuild" value?
Te values of cppbuild are fine. Try changing in launch.json the value:
"preLaunchTask": "C/C++: g++ build active file",
to:
"preLaunchTask": "cppbuild",
The difference between shell and cppbuild is that the first open the BASH and runs a command you write, the second, cppbuild, runs an specific binary (or program).

How to type into the integrated terminal on VS Code in Windows?

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?

Is it possible to set a task.json for all c++ files in VSCode?

I'd like to give VSCode a try.
Is it possible to set compile and build commands for all .cpp files? Just like in Geany? And it is possible to do that for every supported language?
Searching here and there it seems that I have to set it in task.json for each project (even the link to iostream)
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "Example:/Your/path/to/gdb",
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe"
],
"problemMatcher": { "owner": "cpp", "fileLocation": ["relative", "${workspaceRoot}"],
"pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5 }
}
}
That's the solution for C/C++ Extension. Maybe you have to set a breakpoint at the end of the .cpp file.
Or you can install the code-runner Extension.
You can add the two files to C:/Users/someone/AppData/Roming/Code/User/ so that you can compile for all .cpp files.
From here: https://github.com/Microsoft/vscode/issues/1435#issuecomment-433324050
Global tasks in a task.json file are still on the agenda (to get parity with launch.json). However it is a matter of priorities when they will come.
So the answer is: not yet.