-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug: abiltiy to debug with root privileges #558
Comments
I didn't look into how python is addressing the issue. Based on the description, |
This is a duplicate/continuation of microsoft/vscode-go#2889 -- the fix there was to: Create a script named (e.g.) #!/bin/bash
if ! which dlv ; then
PATH="${GOPATH}/bin:$PATH"
fi
if [ "$DEBUG_AS_ROOT" = "true" ]; then
exec sudo dlv "$@"
else
exec dlv "$@"
fi Make it executable: Create a user/workspace/folder setting ( {
"go.alternateTools": {
"dlv": "${env:HOME}/.local/bin/dlv-sudo.sh"
}
} And create a {
"version": "0.2.0",
"configurations": [
{
"name": "Run as root",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {
"DEBUG_AS_ROOT": "true"
}
}
]
} |
@dacut yes, I found this tutorial but this part was impossible to implement as in latest/greatest go plugin there was no "dlv" property in "go.alternateTools":
I even mentioned this in SO, but no replies on it: https://stackoverflow.com/questions/63505746/how-can-i-debug-go-file-in-vs-code-with-root-privileges. In any case this feature request is about adding 'sudo' flag naively, without extra workaround. Goland IDE has it, why VSC can't do the same? :) |
@dzvancuks you can use the above configuration @dacut mentioned - v0.16.2 fixed the misleading error message. |
@dzvancuks -- That's strange; I definitely have a But, yes, having this natively is definitely wanted. (I was just mentioning a workaround.) |
@hyangah Why is "console" a prerequisite for this? Just like in the workaround, isn't it just a matter of adding "sudo" to the dlv command we launch if the configuration has a flag for that? |
@polinasok See the sudoers file modification described here microsoft/vscode-go#2889 (comment). That is not ideal and running |
This method seems to be broken again. Using the script above (adding the -E flag to sudo and the |
Any solution for this? the suggestion above does not seem to work on WSL2, even if I change the settings.json on the remote. |
I have been fighting with this for a week now. Can someone please give the current solution? Feb 2021. Go 1.6... |
#1424 (comment) describes a current, temporary workaround. Once |
This does not work for me on Ubuntu 20.10 // VSCode 1.56.2 // Go v0.25.0 extension, and the workaround is a bit ridiculous to expect those less familiar with systems to grok. This has been suggested already, but why is adding a |
Recently re-installed Ubuntu 20.04 and VSC with latest plugins. Tried #558 (comment) one more time. go.alternateTools is now available and I was able to call script. However DLV won't launch the application. Tried with and without DEBUG_AS_ROOT flag. I hope there will be a solution for configurations as workaround is not working. |
The issue here is combination of I made it work by making sudo chown root.root <path>/dlv-dap
sudo chmod +s <path>/dlv-dap Also undo "go.alternateTools": {
"dlv-dap": "${workspaceFolder}/.vscode/dlv-sudo.sh" in The drawback is that now |
Change https://golang.org/cl/361100 mentions this issue: |
Updated workaround for dlv-dap fixing the workspaceFolder/ {
"go.alternateTools": {
"dlv-dap": "${workspaceFolder}/.vscode/dlv-override.sh"
}
} workspaceFolder/ #!/bin/sh
DLV=$(which dlv-dap)
if [ -x "${DLV}" ] ; then
PATH="/usr/local/go/bin/:$PATH"
fi
if [ "$DEBUG_AS_ROOT" = "true" ]; then
echo Run as Root
# The parameter -C 4 keeps the descriptor 3 opened
exec sudo -C 4 "$DLV" --only-same-user=false "$@"
else
echo Run as User
exec "$DLV" "$@"
fi workspaceFolder/ {
"version": "0.2.0",
"configurations": [
{
"name": "Debug as root",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"args": [],
"debugAdapter": "dlv-dap",
"env": {
"DEBUG_AS_ROOT": "true"
}
},
]
}
|
Change https://golang.org/cl/374134 mentions this issue: |
I found that dap remote debugging can be used. Open the command line and use root privileges to open the dap server:
If it says that
Configure in
Add a breakpoint in |
On Linux/MacOS, this will look up the sudo utility and prepend it to the runInTerminal args. Not updated packages.json yet. Updates #558 Change-Id: I021194e0fd8dc2ae1bdd54ddefb5ea3b6df356d8 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/361100 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org>
Currently we still clarify that they are "experimental". Updates #124 Updates #558 Change-Id: I32af4fa0e3cfc73c80bdcdbd22db51c31ccce77c Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/374134 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Suzy Mueller <suzmue@golang.org>
|
I finally got it working. I used the nightly build of the plugin but also some specific configuration of the environment before it worked for me. I think we have all been suffering not because of the plugin, but by the number of different ways we set up our development environments. Once solved, it makes perfect sense... Computers only do what they're told. I think we all owe it to each other to write better documentation. A little documentation goes a very long way... See my solution here: #1834 |
Seems that we don't need the dlv wrapper anymore ... as of VSCode version 1.65.0 I noticed a new experimental launch option For instance, in your {
"version": "0.2.0",
"configurations": [
{
"name": "Test/dbg pkg as root",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"console": "integratedTerminal",
"asRoot": true,
},
]
}
When launching this configuration by pressing F5, a new debug terminal session opens (or might get reused) and the following command executed: /usr/bin/env GOPATH=/home/foobar/go /usr/bin/sudo /home/foobar/go/bin/dlv dap --check-go-version=false --client-addr=:41945 This now automatically inserts the This now avoids having to fiddle around with remapping the |
@thediveo thanks for finding this! However, when I try, I get this: |
No, luckily not. And this is even using Go as a snap package on Ubuntu. Is you go binary accessible from the ordinary root? |
It is. However, I don't think sudo runs EDIT: I've added the Go install path to the sudoers file |
No, that's in my understanding not dirty at all ... I was about to suggest to check |
The actual work is done. The only remaining part is documentation. |
Change https://go.dev/cl/406295 mentions this issue: |
Please find instructions in https://github.com/golang/vscode-go/wiki/debugging#debugging-a-program-as-root |
Would it be possible to also document "test as root"? In my scenarious I barely ever debug programs, but instead debug code under test. I'm still unsure if this is the same configuration or if there are specific things to watch out for? |
Is there an equivalent technique to debug with elevated privileges on Windows? I have been running vscode itself as Administrator to do that. But it would be good to run just dlv with elevated privileges. How are others debugging elevated stuff on Windows? |
You need to modify /etc/sudoers and add a secure path. For me, I add another file /etc/sudoers.d/golang. This should go in the docs too.
|
#558 (comment) @precisionpete I don't know much about windows. |
Add ability to debug with Delve with
sudo
flag. Similar as it it done for Python:https://code.visualstudio.com/docs/python/debugging#_sudo
It is needed to debug modules that require root access, i.e. gopacket/pcap to capture traffic.
The text was updated successfully, but these errors were encountered: