delve icon indicating copy to clipboard operation
delve copied to clipboard

Can not pass a different value of XDG_CONFIG_HOME to target process because Delve needs to read its own configuration file

Open craftyguy opened this issue 2 years ago • 9 comments

Please answer the following before submitting your issue:

  1. What version of Delve are you using (dlv version)? Version: 1.9.0 Build: $Id: 69310c2f438e492f892d6af22e8e62c8ea1e9d8d

  2. What version of Go are you using? (go version)? go version go1.18.4 linux/amd64

  3. What operating system and processor architecture are you using? x86_64, Alpine Linux

I'm debugging an application that uses XDG_CONFIG_HOME, and it's convenient to set this to some temporary directory so that it doesn't smash my real XDG_CONFIG_HOME. However, since delve also uses this var to get its config, it results in delve using a "fresh" config each time:

XDG_RUNTIME_DIR=/tmp/foo dlv debug foo

(delve creates a new config in /tmp/foo and ignores my existing config in ~/.config)

It would be great to have a way for delve set arbitrary environment variables so that this, and any other potential vars that delve uses internally, can be set for the debug target and not used by delve itself. For inspiration, it could be something like docker's --env param, e.g. dlv debug foo --env XDG_RUNTIME_DIR=/tmp/foo --env HOME=/tmp/home

craftyguy avatar Jul 27 '22 00:07 craftyguy

We also would love to have that.

aviramha avatar Sep 15 '22 09:09 aviramha

Thinking more about this, IMHO the requested feature should not be implemented. The problem with XDG_CONFIG_HOME is real but the solution is overly broad, imposes extra costs on every future backend and invites further machinery (how do you unset an environment variable?). I'd rather have a way to specify the config file of delve directly, overriding XDG_CONFIG_HOME entirely: a lot of programs have that so people are likely to ask for it anyway.

aarzilli avatar Sep 19 '22 07:09 aarzilli

We have a bit of a different case where we want to use LD_PRELOAD without loading to delve as well. I am not sure why you'd need to unset a variable.. my idea for the change would be just to spawn the inferior/debuggee process with added env vars.

aviramha avatar Sep 19 '22 07:09 aviramha

I thought delve was always a static executable on linux.

aarzilli avatar Sep 19 '22 07:09 aarzilli

I thought delve was always a static executable on linux.

on macOS it isn't - also doesn't delve use cgo?

aviramha avatar Sep 19 '22 07:09 aviramha

I thought on macOS LD_PRELOAD was called something else (DYLD something?)

doesn't delve use cgo?

Not on linux.

aarzilli avatar Sep 19 '22 08:09 aarzilli

I thought on macOS LD_PRELOAD was called something else (DYLD something?)

doesn't delve use cgo?

Not on linux.

You're correct it's DYLD_INSERT_LIBRARIES but the principle is same (and more people know about LD)

aviramha avatar Sep 19 '22 08:09 aviramha

Would you accept a PR adding a flag for environment variables to set to the debugged process?

aviramha avatar Nov 03 '22 06:11 aviramha

Sent a PR - seeing how current code works I estimate it might be valuable for others (there was already code to pass DYLD/LD env to the debugged process using -e, so this just fixes an issue that would occur on newer macOS versions (not being able to inject yourself to debugserver, but anyway you'd want the child which is possible). I guess we'll run on our fork in case this can't be merged upstream, but would love to have this upstream (with current implementation, or different) https://github.com/go-delve/delve/pull/3181

aviramha avatar Nov 06 '22 10:11 aviramha