delve icon indicating copy to clipboard operation
delve copied to clipboard

dap: consider []string for Launch BuildFlags

Open hyangah opened this issue 4 years ago • 8 comments
trafficstars

DAP LaunchConfig.BuildFlags is defined as string type. It is string because VS Code Go defined the buildFlags in that way in its legacy debug adapter that invokes dlv debug or dlv test, and dlv command line takes the build flags (--build-flags) as a string.

DAP can take Launch configuration in JSON, which can support more rich types than a simple command line flag. Historically, the subtle difference between how dlv is parsing the build flags and how go command is parsing the flags was annoying and sometimes frustrating (e.g. https://github.com/golang/vscode-go/issues/1027).

Please consider to take []string and bypass delve's flag parsing.

hyangah avatar Sep 23 '21 17:09 hyangah

I believe if you bypass config.SplitQuotedFields completely and users write this:

buildFlags: [ "-ldflags='-X main.V=Hello'" ],

they will have the same problem.

aarzilli avatar Sep 24 '21 06:09 aarzilli

I wonder if it's better to just add double-quote handling to SplitQuotedFields

aarzilli avatar Sep 24 '21 06:09 aarzilli

I guess users should write If []string is allowed

buildFlags: ["-ldflags=-X main.V=Hello"]

Right? Launching go commands in node.js seems fine with both ["-ldflags='-X main.V=Hello'"] and ["-dlflags=-X main.V=Hello"], but it looks like go command doesn't seem happy with the former as you guessed.

Currently vscode-go and gopls both use []string for buildFlags. So, the flag plumbing from vscode-go to gopls is a bit easier. For delve, if we want to the the flag plumbing, is it ok to simply concatenate buildFlags setting with ' '?

hyangah avatar Sep 24 '21 15:09 hyangah

is it ok to simply concatenate buildFlags setting with ' '?

With a space? No it will not work if they contain spaces themselves. They need to be quoted and then concatenated with spaces if they are to be passed to SplitQuotedFields, or just call SplitQuotedFields on each. Regardless if double quotes are used it won't work.

It probably works with node.js because it's doing some shell-like quote processing magic (or just going through the shell).

aarzilli avatar Sep 24 '21 15:09 aarzilli

or just call SplitQuotedFields on each.

This would actually be wrong, BTW. But something like it that strips quotes. OTOH I think doing nothing and letting

buildFlags: [ "-ldflags='-X main.V=Hello'" ],

fail would also be ok.

aarzilli avatar Sep 24 '21 16:09 aarzilli

@aarzilli We are currently debating whether you're against this feature request completely or not. Can you please clarify to end our confusion :-)?

hyangah avatar Oct 13 '21 13:10 hyangah

No, it's fine. I was just pointing out that:

Historically, the subtle difference between how dlv is parsing the build flags and how go command is parsing the flags was annoying and sometimes frustrating

is really about the subtle difference between dlv parsing and the shell parsing and it wouldn't really go away and:

buildFlags: [ "-ldflags='-X main.V=Hello'" ],

which is the naive thing to write, wouldn't work. But maybe it's fine that it doesn't.

aarzilli avatar Oct 14 '21 07:10 aarzilli

Sorry for the confusion.

aarzilli avatar Oct 14 '21 07:10 aarzilli