I am trying to debug a program in VSCODE. The program needs to be launched as root or with "sudo" on Ubuntu. What's the best way to achieve this? An example launch configuration would be helpful. Thanks.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
I have been in a similar situation recently- I have solved it by adding {"sudo": true} in launch.json file under .vscode directory.
just added the following line in .vscode>launch.json
{
"version": "0.2.0",
"configurations": [
{
"other..." : "configs...",
"request": "launch",
"console": "integratedTerminal",
"args": [
"${file}"
],
"sudo": true
}
]
}
VS code version I'm using is -
Version: 1.49.1 OS: Ubuntu 16.04 LTS, 64-bit
This appears to not work on all languages. For me it worked for python 3.x Other users reported it doesn't work for C/C++.
I did the following:
pkexec /usr/bin/gdb "$@"
...
"externalConsole": false,
"miDebuggerPath": "/home/<username>/gdb",
"MIMode": "gdb",
...
top
or such like to verify the process is running as root.That should be enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With