microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 446 forks source link

How to debug using sudo #2463

Open bobbrow opened 2 years ago

bobbrow commented 2 years ago

Discussed in https://github.com/microsoft/vscode-cmake-tools/discussions/2445

Originally posted by **Giancarlo-Ma** March 20, 2022 Some code are required sudo permission, so when click the debug button, It just shows that I have no permission as a regular user
tadams42 commented 2 years ago

Similar situation here and I think this is not really vscode-cmake-tools issue. gdb is not supposed to run elevated executable - unless debugger itself is also started with elevated permissions.

So, I start gdb from vscode via shell script. In that script I elevate gdb, requesting sudo password. It all works like this:

launch.json entry:

{
  "name": "sudo myapp",
  "type": "cppdbg",
  "request": "launch",
  "program": "${command:cmake.launchTargetPath}",
  "args": [
    "-C",
    "${workspaceFolder}/config/development.ini"
  ],
  "stopAtEntry": false,
  "cwd": "${workspaceFolder}",
  "environment": [],
  "externalConsole": false,
  "miDebuggerPath": "${workspaceFolder}/bin/sudo_gdb.sh",
  "MIMode": "gdb"
}

bin/sudo_gdb.sh contents:

pkexec /usr/bin/gdb "$@"

Hope it helps.

rabee05 commented 9 months ago

this was working for me until recent updates which broke everything. still unable to find away to run the debugger using sudo. Any idea?

https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md

update: for some reason C/C++ required re-install Name: C/C++ Id: ms-vscode.cpptools Description: C/C++ IntelliSense, debugging, and code browsing. Version: 1.18.5 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools