diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go
index <HASH>..<HASH> 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...)
 }
cmd/dlv: use -a flag with go<I>

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 #<I>