benma / go-dlv.el

Go Delve - Debug Go programs interactively with the GUD.
GNU General Public License v3.0
96 stars 21 forks source link

How to specify build-flags #25

Open JensAc opened 2 years ago

JensAc commented 2 years ago

Hi,

first of all, thank you for providing go-dlv. I was able to get up and running quire quickly with it. However, I have an issue debugging an application with a more sophisticated command line call. For instance, I have a call like this:

dlv debug SOME_FOLDER --build-flags="-mod=vendor -ldflags='-X k8s.io/component-base/version.gitMajor=1'" -- FURTHER_APP_OPTIONS

This works just fine, when executed from a shell but when I paste this to the minibuffer opened by thedlv emacs function, I get

Error: unknown shorthand flag: 'm' in -mod=vendor -ldflags='-X k8s.io/component-base/version.gitMajor=1

Do you have any idea, what am I doing wrong?

benma commented 2 years ago

If I run this in a shell, I get the same error:

$ dlv debug -mod=vendor
  Error: unknown shorthand flag: 'm' in -mod=vendor

So it seems this flag is not supported by dlv in general.

JensAc commented 2 years ago

Indeed, you need to run it as part of the --build-flags arguments of dlv. Then, dlv should start as usual. I think there is something going wrong how the actual debugger command line is constructed in gud.

benma commented 2 years ago

I'm afraid you'll need to file this bug report at Emacs. in gud-common-init, split-string-and-unquote is used on the command:

https://github.com/emacs-mirror/emacs/blob/c6e079ae15002268d90869a43f66d962175e4cdb/lisp/progmodes/gud.el#L2766

(split-string-and-unquote "dlv debug --build-flags=\"-mod=vendor\"") e.g. yields ("dlv" "debug" "--build-flags=" "-mod=vendor"). I am not sure what the rest of gud-common-init is doing to these words, but the result seems wrong.

JensAc commented 2 years ago

Alright, that was also the point where I stopped investigating. I will have another look at this, when I find time. Thank you for the quick response!

JensAc commented 2 years ago

Actually, a workaround seems to be:

dlv debug SOME_FOLDER --build-flags "-mod=vendor"

(omitting the equal sign). However, I did not find a way to specify ldflags also, but I think in debugging scenarios this is not that important.