cmd/dlv: support multifile when dlv debug, trace and test
This changes make `dlv` support multifile specifically when dlv `debug`, `trace` and `test`. Just like `dlv debug a.go b.go`. Corresponding to `go build a.go b.go`.(a.go and b.go are belong to `main` package). Fix #984.
This commit is contained in:
parent
c3f50742b9
commit
0af7d6d362
@ -297,13 +297,8 @@ func debugCmd(cmd *cobra.Command, args []string) {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkg string
|
|
||||||
dlvArgs, targetArgs := splitArgs(cmd, args)
|
dlvArgs, targetArgs := splitArgs(cmd, args)
|
||||||
|
err = gobuild(debugname, dlvArgs)
|
||||||
if len(dlvArgs) > 0 {
|
|
||||||
pkg = args[0]
|
|
||||||
}
|
|
||||||
err = gobuild(debugname, pkg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
return 1
|
return 1
|
||||||
@ -334,15 +329,14 @@ func traceCmd(cmd *cobra.Command, args []string) {
|
|||||||
dlvArgs, targetArgs := splitArgs(cmd, args)
|
dlvArgs, targetArgs := splitArgs(cmd, args)
|
||||||
|
|
||||||
if traceAttachPid == 0 {
|
if traceAttachPid == 0 {
|
||||||
var pkg string
|
var dlvArgsLen = len(dlvArgs)
|
||||||
switch len(dlvArgs) {
|
if dlvArgsLen == 1 {
|
||||||
case 1:
|
|
||||||
regexp = args[0]
|
regexp = args[0]
|
||||||
case 2:
|
} else if dlvArgsLen >= 2 {
|
||||||
pkg = args[0]
|
regexp = dlvArgs[dlvArgsLen-1]
|
||||||
regexp = args[1]
|
dlvArgs = dlvArgs[:dlvArgsLen-1]
|
||||||
}
|
}
|
||||||
if err := gobuild(debugname, pkg); err != nil {
|
if err := gobuild(debugname, dlvArgs); err != nil {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
defer remove(debugname)
|
defer remove(debugname)
|
||||||
@ -404,13 +398,8 @@ func testCmd(cmd *cobra.Command, args []string) {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkg string
|
|
||||||
dlvArgs, targetArgs := splitArgs(cmd, args)
|
dlvArgs, targetArgs := splitArgs(cmd, args)
|
||||||
|
err = gotestbuild(debugname, dlvArgs)
|
||||||
if len(dlvArgs) > 0 {
|
|
||||||
pkg = args[0]
|
|
||||||
}
|
|
||||||
err = gotestbuild(debugname, pkg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -585,23 +574,23 @@ func optflags(args []string) []string {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func gobuild(debugname, pkg string) error {
|
func gobuild(debugname string, pkgs []string) error {
|
||||||
args := []string{"-o", debugname}
|
args := []string{"-o", debugname}
|
||||||
args = optflags(args)
|
args = optflags(args)
|
||||||
if BuildFlags != "" {
|
if BuildFlags != "" {
|
||||||
args = append(args, config.SplitQuotedFields(BuildFlags, '\'')...)
|
args = append(args, config.SplitQuotedFields(BuildFlags, '\'')...)
|
||||||
}
|
}
|
||||||
args = append(args, pkg)
|
args = append(args, pkgs...)
|
||||||
return gocommand("build", args...)
|
return gocommand("build", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func gotestbuild(debugname, pkg string) error {
|
func gotestbuild(debugname string, pkgs []string) error {
|
||||||
args := []string{"-c", "-o", debugname}
|
args := []string{"-c", "-o", debugname}
|
||||||
args = optflags(args)
|
args = optflags(args)
|
||||||
if BuildFlags != "" {
|
if BuildFlags != "" {
|
||||||
args = append(args, config.SplitQuotedFields(BuildFlags, '\'')...)
|
args = append(args, config.SplitQuotedFields(BuildFlags, '\'')...)
|
||||||
}
|
}
|
||||||
args = append(args, pkg)
|
args = append(args, pkgs...)
|
||||||
return gocommand("test", args...)
|
return gocommand("test", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user