forked from go-delve/delve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service/dap: Add support for debug and test modes (go-delve#1901)
* service/dap: Add support for debug and test modes * Address code review comments * Remove //dap comment * OptFlags() => optfalgs() * If mode => switch mode
- Loading branch information
1 parent
c1a681f
commit 4ebaa26
Showing
6 changed files
with
250 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(m.Run()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Package gobuild provides utilities for building programs and tests | ||
// for the debugging session. | ||
package gobuild | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/go-delve/delve/pkg/config" | ||
"github.com/go-delve/delve/pkg/goversion" | ||
) | ||
|
||
// Remove the file at path and issue a warning to stderr if this fails. | ||
// This can be used to remove the temporary binary generated for the session. | ||
func Remove(path string) { | ||
err := os.Remove(path) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "could not remove %v: %v\n", path, err) | ||
} | ||
} | ||
|
||
// optflags generates default build flags to turn off optimization and inlining. | ||
func optflags(args []string) []string { | ||
// after go1.9 building with -gcflags='-N -l' and -a simultaneously works. | ||
// after go1.10 specifying -a is unnecessary because of the new caching strategy, | ||
// but we should pass -gcflags=all=-N -l to have it applied to all packages | ||
// see https://github.com/golang/go/commit/5993251c015dfa1e905bdf44bdb41572387edf90 | ||
|
||
ver, _ := goversion.Installed() | ||
switch { | ||
case ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}): | ||
args = append(args, "-gcflags", "all=-N -l") | ||
case ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}): | ||
args = append(args, "-gcflags", "-N -l", "-a") | ||
default: | ||
args = append(args, "-gcflags", "-N -l") | ||
} | ||
return args | ||
} | ||
|
||
// GoBuild builds non-test files in 'pkgs' with the specified 'buildflags' | ||
// and writes the output at 'debugname'. | ||
func GoBuild(debugname string, pkgs []string, buildflags string) error { | ||
args := []string{"-o", debugname} | ||
args = optflags(args) | ||
if buildflags != "" { | ||
args = append(args, config.SplitQuotedFields(buildflags, '\'')...) | ||
} | ||
args = append(args, pkgs...) | ||
return gocommand("build", args...) | ||
} | ||
|
||
// GoBuild builds test files 'pkgs' with the specified 'buildflags' | ||
// and writes the output at 'debugname'. | ||
func GoTestBuild(debugname string, pkgs []string, buildflags string) error { | ||
args := []string{"-c", "-o", debugname} | ||
args = optflags(args) | ||
if buildflags != "" { | ||
args = append(args, config.SplitQuotedFields(buildflags, '\'')...) | ||
} | ||
args = append(args, pkgs...) | ||
return gocommand("test", args...) | ||
} | ||
|
||
func gocommand(command string, args ...string) error { | ||
allargs := []string{command} | ||
allargs = append(allargs, args...) | ||
goBuild := exec.Command("go", allargs...) | ||
goBuild.Stderr = os.Stderr | ||
return goBuild.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.