Skip to content

Commit

Permalink
cmd/dlv: require arg for trace subcommand (go-delve#2848)
Browse files Browse the repository at this point in the history
  • Loading branch information
derekparker authored Jan 29, 2022
1 parent 5b925d4 commit 5b6f8ec
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,14 @@ func traceCmd(cmd *cobra.Command, args []string) {

dlvArgs, targetArgs := splitArgs(cmd, args)
var dlvArgsLen = len(dlvArgs)
if dlvArgsLen == 1 {
switch dlvArgsLen {
case 0:
fmt.Fprintf(os.Stderr, "you must supply a regexp for functions to trace\n")
return 1
case 1:
regexp = args[0]
dlvArgs = dlvArgs[0:0]
} else if dlvArgsLen >= 2 {
default:
regexp = dlvArgs[dlvArgsLen-1]
dlvArgs = dlvArgs[:dlvArgsLen-1]
}
Expand Down Expand Up @@ -632,8 +636,7 @@ func traceCmd(cmd *cobra.Command, args []string) {
if traceUseEBPF {
err := client.CreateEBPFTracepoint(funcs[i])
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
fmt.Fprintf(os.Stderr, "unable to set tracepoint on function %s: %#v\n", funcs[i], err)
}
} else {
// Fall back to breakpoint based tracing if we get an error.
Expand All @@ -645,13 +648,11 @@ func traceCmd(cmd *cobra.Command, args []string) {
LoadArgs: &terminal.ShortLoadConfig,
})
if err != nil && !isBreakpointExistsErr(err) {
fmt.Fprintln(os.Stderr, err)
return 1
fmt.Fprintf(os.Stderr, "unable to set tracepoint on function %s: %#v\n", funcs[i], err)
}
addrs, err := client.FunctionReturnLocations(funcs[i])
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
fmt.Fprintf(os.Stderr, "unable to set tracepoint on function %s: %#v\n", funcs[i], err)
}
for i := range addrs {
_, err = client.CreateBreakpoint(&api.Breakpoint{
Expand All @@ -662,8 +663,7 @@ func traceCmd(cmd *cobra.Command, args []string) {
LoadArgs: &terminal.ShortLoadConfig,
})
if err != nil && !isBreakpointExistsErr(err) {
fmt.Fprintln(os.Stderr, err)
return 1
fmt.Fprintf(os.Stderr, "unable to set tracepoint on function %s: %#v\n", funcs[i], err)
}
}
}
Expand Down

0 comments on commit 5b6f8ec

Please sign in to comment.