I face problem with configuring launch.json file on my Windows and it shows error message
Debug adapter process has terminated unexpectedly.
I have set up "MinGW" and configured g++ compiler, and now Visual Studio Code compiles correctly. When I press Ctrl+Shift+B, it creates a.exe file in project folder.
My launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false
},
{
"name": "C++ Attach (Windows)",
"type": "cppvsdbg",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}
My task.json file:
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"showOutput": "always",
"args": ["-std=c++11","-g", "main.cpp"]
}
It may be wrong, but I suppose you need to compile your .c/.cpp file with microsoft cl.exe compiler (not by gcc) to use microsoft debugger on it. To setup paths for cl, call the vcvarsall.bat with parameter x86 or x64 (depends on what you need) and then cast cl to your source file. By the way check this article (the part with json configuration exactly) to ensure, where you did wrong https://www.40tude.fr/blog/how-to-compile-cpp-code-with-vscode-cl/
Related
the C/C++ Extension of Microsoft for VSCode allows to set a launch.json file with which you can set how to debug and run your C++ code. By default it has lldb as debugger for MacOS.
I wonder how to set gdb as debugger instead of lldb.
I tried and it shows me:
Unable to start debugging. GDB exited unexpectedly with exit code 134 (0x86).
This is how my launch.json file looks like:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++-9 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"osx": {
"miDebuggerPath": "/usr/local/bin/gdb",
"MIMode": "gdb"
},
"preLaunchTask": "C/C++: g++-9 build active file"
}
]
}
Make sure you have gdb installed.
For that you can use:
brew install gdb
Then make the gdb binary is certified. Because:
... modern Darwin kernels restrict the capability to assume
control over another process (here, for the purpose of debugging it),
since that capability is a boon to malware. In order for said
taskgated to grant access to gdb, the latter must be fitted with
entitlements, which consist of digitally-signed metadata inside the
gdb binary.
From: https://sourceware.org/gdb/wiki/PermissionsDarwin
To create a certification follow these instructions:
https://sourceware.org/gdb/wiki/PermissionsDarwin
After doing so, certify the binary as instructed here.
Then try this for 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",
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
I have a very simple c++ project with my own Makefile that has such commands "make a.out", "make depend" and a compiling command "make submit", plus a "make clean" which deletes the a.out and any cores in the directory.
I want to configure my VSCode so that when I press run, I would see the result of "make clean" "make a.out" followed by "./a.out". I have already installed the C/C++ extension and had my gcc installed.
These are very simple command-line commands but I just can't make the VScode work. The error says a.out is not found. In my launch.json, I have below scripts
{
// 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": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
What should I change the launch.json and how should I configure my task.json? Is there anything else I need to do? Thanks!
I have to use cygwin and cmake for the build of the release and debug.
(The cygwin package has all needed tools/libs for the build process (cmake, gcc, boost))
I've already found this
Which now allows me to run cmake and the build scripts inside the console of visual studio code and the executable is generated properly.
And I've already installed the extension C/C++ for Visual Studio Code.
But how to configure visual studio code for debugging?
After building via this, all you need for debugging is a launch.json of the following structure:
{
// 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) Starten",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/PATH_2_YOUR_DEBUG.exe",//This you need to define
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwinPath\\bin\\gdb.exe",//This you need to define
"setupCommands": [
{
"description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Afterwards you can set a breakpoint in the source of PATH_2_YOUR_DEBUG.exe and press F5.
I have been trying to figure out how to receive input in Windows vscode c++ program for example using cin. I have already tried running with MingW and cl and both have the same result.
Terminal output is being sent to vscode debugconsole and I can't interact with the program.
The same program runs fine if it is run directly via terminal or cmd command prompt.
Here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "cl.exe build active file",
"type": "shell",
"command": "c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
And here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cl.exe build active file"
}
]
}
I've seen other suggestions like using "code-runner.runInTerminal": true and "terminal": "integrated" but this has not worked for me. I have already seen this other post: Visual Studio Code: Take Input From User
But so far no joy.
Here's a screen of vscode that shows the issue with a small c++ program:
You will see from above that the output is directed to the debugconsole pane and no interaction is possible from there.
Whereas, the advice from https://code.visualstudio.com/docs/cpp/config-mingw indicates the IO should go to the terminal pane.
I want to debug the c++ source code of tensorflow, e.g tensorflow/c/c_api.cc . I've found some answers about how to debug the c++ code with gdb,but I want to know if it's possible to debug it with ide like Xcode, which can be very comfortable for editing and debug.Thanks .
After much search and dig, I finally succeed to debug the tensorflow c++ source code in an acceptable way.I used bazel+vscode+lldb on mac.
bazel: build the target(Also can be done by vscode).
visual studio code: debug and read code
lldb : debug backend
my vscode lanch.json is :
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bazel-out/darwin_x86_64-dbg/bin/tensorflow/cc/example/example",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb"
}
]
}