Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Enable Easier Debugging of Code Requiring Root #2610

Closed
sethRait opened this issue Jun 27, 2019 · 7 comments
Closed

Enable Easier Debugging of Code Requiring Root #2610

sethRait opened this issue Jun 27, 2019 · 7 comments
Labels

Comments

@sethRait
Copy link
Member

Currently, if one needs to run code with superuser privileges, but edits it as a standard user, the debugging process is very convoluted. Since there is no way to specify "run delve as root" in the launch.json, here is what must be done currently:
Steps to Reproduce:

  1. In launch.json, set request to "attach" and mode to "remote" and change the remotePath, host, port settings as required. Add a preLaunch task.
  2. In tasks.json, create a new task which runs the command sudo /path/to/dlv debug --headless --log --listen=:<port> -- <args to program you want to debug>
  3. Set "isBackground" to true
  4. Create a problem matcher with a "background" property including a "beginsPattern" and an "endsPattern" so VSCode knows when it's okay to begin the debug session.

launch.json:

    "configurations": [
        {
            "name": "launch",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "showLog": true,
            "preLaunchTask": "startDelve"
        }]

tasks.json:

	"version": "2.0.0",
	"tasks": [{
		"label": "startDelve",
		"command": "cd /path/to/go/code/dir; sudo /path/to/dlv debug --api-version=2 --headless --listen=:2345 --log -- <args to go program>",
		"type": "shell",
		"isBackground": true,
		"problemMatcher": {
			"pattern": {
				"regexp": "Error: ([^(]+)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\): (.*)$",
				"file": 1,
				"location": 2,
				"message": 3
			},
			"background": {
				"beginsPattern": "API server listening",
				"endsPattern": "20"
			}
		}
	}]
}

Suggested workflow:

  1. In launch.json, under the configuration you would like to run as root, add "runas": "root" or "root": true
@ramya-rao-a
Copy link
Contributor

Can you try another workaround that involves setting the go.alternateTools setting?

  • Write a script that internal calls delve with sudo and pass all the arguments as is
  • Add the below to your settings
"go.alternateTools": {
    "dlv": "absolute path to your script"
}

This will make the extension call your script instead of dlv. And internally you can call dlv with sudo

@sethRait
Copy link
Member Author

@ramya-rao-a this works perfectly! Thank you :D Is there a way this could be made more discoverable though?

@ramya-rao-a
Copy link
Contributor

Not sure...
Maybe a section in the README or FAQs?

@jadarsie
Copy link
Member

jadarsie commented Nov 6, 2019

@ramya-rao-a do you expect this approach to work with the remote development extensions?

My use case is similar, I also need to run dlv as root. I can debug a project sitting on the server just fine, but my alternateTool is not being picked-up (I do not think so). Is there a log file I can inspect to confirm that?

This is my remote settings file.

me@remote:~$ cat ~/.vscode-server/data/Machine/settings.json 
{
    "go.alternateTools": {
        "dlv": "dlvsu.sh" // this script calls: sudo -E dlv $@
    }
}

Remote host is an UbuntuServer 18.04
Am I missing anything?

@sethRait
Copy link
Member Author

sethRait commented Nov 18, 2019

I am also now having trouble with this approach using the remote development extension. After enabling debug logs I can verify that my script specified using go.alternateTools is not even being called. i have verified that the setting is set on the remote machine and an absolute path to the script is given.

As a workaround, I moved the dlv binary to dlv.old then wrote a script in the same location as the dlv binary (calling it dlv) which calls sudo /path/to/dlv.old $@ but for obvious reasons, this is non-ideal.

@stamblerre
Copy link
Contributor

This sounds like a duplicate of #2889 - please follow along with the discussion on that issue.

@stamblerre
Copy link
Contributor

Duplicate of #2889

@stamblerre stamblerre marked this as a duplicate of #2889 Feb 11, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants