From ec8e6c4af3de43ee78cc09a3f64c347dce510378 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 30 May 2017 19:31:33 +0200 Subject: [PATCH] cmd/dlv: use -a flag with go1.9 By specifying the -a flag we insure that all packages are recompiled with -gcflags='-N -l'. Previously -a could not be specified because the compiler could not compile runtime without optimizations. Fixes #738 --- cmd/dlv/cmds/commands.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index 14b6be2e..59c1cdaf 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -536,6 +536,10 @@ func gobuild(debugname, pkg string) error { if BuildFlags != "" { args = append(args, splitQuotedFields(BuildFlags)...) } + if ver, _ := goversion.Installed(); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + // after go1.9 building with -gcflags='-N -l' and -a simultaneously works + args = append(args, "-a") + } args = append(args, pkg) return gocommand("build", args...) } @@ -545,6 +549,10 @@ func gotestbuild(pkg string) error { if BuildFlags != "" { args = append(args, splitQuotedFields(BuildFlags)...) } + if ver, _ := goversion.Installed(); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + // after go1.9 building with -gcflags='-N -l' and -a simultaneously works + args = append(args, "-a") + } args = append(args, pkg) return gocommand("test", args...) }