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"
}
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.