Artur
Artur

Reputation: 21

How to debug your application with root permissions on VSCODE?

I'm trying to debug dotnet core web app, however it's not possible to do it without having root permissions.

An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.Private.CoreLib.dll: 'Permission denied'

The naive approach would be launching VSCode with root permissions, which is generally not a recommended (and I would like to avoid it).

Is there any way to configure launch.json to execute the debugger with root permissions?

I've tried already creating a pre-launch task executing sudo or sudo su commands. I tried running the application and trying to attach to the process (also got declined because of insufficient permissions)

Upvotes: 2

Views: 3090

Answers (1)

user11909
user11909

Reputation: 1265

For C#:

  1. Locate vsdbg-ui (in my case: ~/.vscode/extensions/ms-dotnettools.csharp-1.23.17/.debugger)

  2. Rename "vsdbg-ui" to "vsdbg-ui2"

  3. Create a new file in the same folder called "vsdbg-ui" with following content:

    pkexec [yourhomefolder]/.vscode/extensions/ms-dotnettools.csharp-1.23.17/.debugger/vsdbg-ui2

  4. Make the new file "vsdbg-ui" executable

  5. Launch the debugging session in VSCode. You will get a prompt to enter your sudo password. You are debugging with sudo now.

Upvotes: 2

Related Questions