Skip to content

Commit d495a1a

Browse files
committed
debug: do not remove gcflags
Updates #128
1 parent 6f98706 commit d495a1a

File tree

2 files changed

+0
-118
lines changed

2 files changed

+0
-118
lines changed

src/goDebugConfiguration.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,6 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
220220
debugConfiguration['cwd'] = resolveHomeDir(debugConfiguration['cwd']);
221221
}
222222

223-
// Remove any '--gcflags' entries and show a warning
224-
if (debugConfiguration['buildFlags']) {
225-
const resp = this.removeGcflags(debugConfiguration['buildFlags']);
226-
if (resp.removed) {
227-
debugConfiguration['buildFlags'] = resp.args;
228-
this.showWarning(
229-
'ignoreDebugGCFlagsWarning',
230-
"User specified build flag '--gcflags' in 'buildFlags' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)"
231-
);
232-
}
233-
}
234-
if (debugConfiguration['env'] && debugConfiguration['env']['GOFLAGS']) {
235-
const resp = this.removeGcflags(debugConfiguration['env']['GOFLAGS']);
236-
if (resp.removed) {
237-
debugConfiguration['env']['GOFLAGS'] = resp.args;
238-
this.showWarning(
239-
'ignoreDebugGCFlagsWarning',
240-
"User specified build flag '--gcflags' in 'GOFLAGS' is being ignored (see [debugging with build flags](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#specifying-other-build-flags) documentation)"
241-
);
242-
}
243-
}
244-
245223
const dlvToolPath = getBinPath(debugAdapter);
246224
if (!path.isAbsolute(dlvToolPath)) {
247225
// If user has not already declined to install this tool,
@@ -324,43 +302,6 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
324302
return debugConfiguration;
325303
}
326304

327-
public removeGcflags(args: string): { args: string; removed: boolean } {
328-
// From `go help build`
329-
// ...
330-
// -gcflags '[pattern=]arg list'
331-
// arguments to pass on each go tool compile invocation.
332-
//
333-
// The -asmflags, -gccgoflags, -gcflags, and -ldflags flags accept a
334-
// space-separated list of arguments to pass to an underlying tool
335-
// during the build. To embed spaces in an element in the list, surround
336-
// it with either single or double quotes. The argument list may be
337-
// preceded by a package pattern and an equal sign, which restricts
338-
// the use of that argument list to the building of packages matching
339-
// that pattern (see 'go help packages' for a description of package
340-
// patterns). Without a pattern, the argument list applies only to the
341-
// packages named on the command line. The flags may be repeated
342-
// with different patterns in order to specify different arguments for
343-
// different sets of packages. If a package matches patterns given in
344-
// multiple flags, the latest match on the command line wins.
345-
// For example, 'go build -gcflags=-S fmt' prints the disassembly
346-
// only for package fmt, while 'go build -gcflags=all=-S fmt'
347-
// prints the disassembly for fmt and all its dependencies.
348-
349-
// Regexp Explanation:
350-
// 1. (^|\s): the flag is preceded by a white space or is at the start of the line.
351-
// 2. -gcflags: the name of the flag.
352-
// 3. (=| ): the name of the flag is followed by = or a space.
353-
// 4. ('[^']*'|"[^"]*"|[^'"\s]+)+: the value of the flag is a combination of nonwhitespace
354-
// characters and quoted strings which may contain white space.
355-
const gcflagsRegexp = /(^|\s)(-gcflags)(=| )('[^']*'|"[^"]*"|[^'"\s]+)+/;
356-
let removed = false;
357-
while (args.search(gcflagsRegexp) >= 0) {
358-
args = args.replace(gcflagsRegexp, '');
359-
removed = true;
360-
}
361-
return { args, removed };
362-
}
363-
364305
public resolveDebugConfigurationWithSubstitutedVariables(
365306
folder: vscode.WorkspaceFolder | undefined,
366307
debugConfiguration: vscode.DebugConfiguration,

test/integration/goDebugConfiguration.test.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -369,65 +369,6 @@ suite('Debug Configuration Modify User Config', () => {
369369
const debugConfigProvider = new GoDebugConfigurationProvider();
370370

371371
suite('remove gcflags', () => {
372-
test('remove gcflags from string args', () => {
373-
const tt = [
374-
{
375-
input: '-gcflags=all=-l',
376-
want: { args: '', removed: true }
377-
},
378-
{
379-
input: '-gcflags all=-l',
380-
want: { args: '', removed: true }
381-
},
382-
// Preserve other flags
383-
{
384-
input: '-race -gcflags=all=-l -mod=mod',
385-
want: { args: '-race -mod=mod', removed: true }
386-
},
387-
{
388-
input: '-race -gcflags all=-l -mod=mod',
389-
want: { args: '-race -mod=mod', removed: true }
390-
},
391-
// Test with quoted value
392-
{
393-
input: "-mod=mod -gcflags=test/...='hello goodbye' -race",
394-
want: { args: '-mod=mod -race', removed: true }
395-
},
396-
{
397-
input: '-mod=mod -gcflags test/...="hello goodbye" -race',
398-
want: { args: '-mod=mod -race', removed: true }
399-
},
400-
{
401-
input: "-mod=mod -gcflags='test/...=hello goodbye' -race",
402-
want: { args: '-mod=mod -race', removed: true }
403-
},
404-
{
405-
input: '-mod=mod -gcflags "test/...=hello goodbye" -race',
406-
want: { args: '-mod=mod -race', removed: true }
407-
},
408-
// Multiple -gcflags present
409-
{
410-
input: '-mod=mod -gcflags "test/...=hello goodbye" -race -gcflags=all="hello goodbye"',
411-
want: { args: '-mod=mod -race', removed: true }
412-
},
413-
// No gcflags are present
414-
{
415-
input: '',
416-
want: { args: '', removed: false }
417-
},
418-
{
419-
input: '-race -mod=gcflags',
420-
want: { args: '-race -mod=gcflags', removed: false }
421-
}
422-
];
423-
424-
tt.forEach((tc) => {
425-
const got = debugConfigProvider.removeGcflags(tc.input);
426-
427-
assert.strictEqual(got.args, tc.want.args, `args for ${tc.input} do not match expected`);
428-
assert.strictEqual(got.removed, tc.want.removed, `removed for ${tc.input} does not match expected`);
429-
});
430-
});
431372
test('remove user set -gcflags in buildFlags', () => {
432373
const config = {
433374
name: 'Launch',

0 commit comments

Comments
 (0)