From db0bc26949ebaaec265968092785cdaade76fa20 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 7 Jul 2023 19:33:40 +0200 Subject: [PATCH] terminal,service: better printing of suspended breakpoints (#3415) Show the location expression that will be used to set a suspended breakpoint in the breakpoints list. Also change 'target' called without arguments to print a better error message and 'target follow-exec' without the last argument to print the state of follow-exec. --- pkg/proc/breakpoints.go | 1 + pkg/terminal/command.go | 18 ++++++++++++++++-- service/api/conversions.go | 5 ++++- service/api/types.go | 2 ++ service/dap/server.go | 2 +- service/debugger/debugger.go | 7 ++++--- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pkg/proc/breakpoints.go b/pkg/proc/breakpoints.go index 03fd305a..d846f204 100644 --- a/pkg/proc/breakpoints.go +++ b/pkg/proc/breakpoints.go @@ -1018,6 +1018,7 @@ type SetBreakpoint struct { File string Line int Expr func(*Target) []uint64 + ExprString string PidAddrs []PidAddr } diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 2f8731fb..aa4137b7 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -1702,8 +1702,15 @@ func breakpoints(t *Term, ctx callContext, args string) error { enabled := "(enabled)" if bp.Disabled { enabled = "(disabled)" + } else if bp.ExprString != "" { + enabled = "(suspended)" + } + fmt.Fprintf(t.stdout, "%s %s", formatBreakpointName(bp, true), enabled) + if bp.ExprString != "" { + fmt.Fprintf(t.stdout, " at %s\n", bp.ExprString) + } else { + fmt.Fprintf(t.stdout, " at %v (%d)\n", t.formatBreakpointLocation(bp), bp.TotalHitCount) } - fmt.Fprintf(t.stdout, "%s %s at %v (%d)\n", formatBreakpointName(bp, true), enabled, t.formatBreakpointLocation(bp), bp.TotalHitCount) attrs := formatBreakpointAttrs("\t", bp, false) @@ -3277,7 +3284,12 @@ func target(t *Term, ctx callContext, args string) error { return nil case "follow-exec": if len(argv) == 1 { - return errors.New("not enough arguments") + if t.client.FollowExecEnabled() { + fmt.Fprintf(t.stdout, "Follow exec is enabled.\n") + } else { + fmt.Fprintf(t.stdout, "Follow exec is disabled.\n") + } + return nil } argv = config.Split2PartsBySpace(argv[1]) switch argv[0] { @@ -3316,6 +3328,8 @@ func target(t *Term, ctx callContext, args string) error { return fmt.Errorf("could not find target %d", pid) } return nil + case "": + return errors.New("not enough arguments for 'target'") default: return fmt.Errorf("unknown command 'target %s'", argv[0]) } diff --git a/service/api/conversions.go b/service/api/conversions.go index 08eb3929..f64bd3fb 100644 --- a/service/api/conversions.go +++ b/service/api/conversions.go @@ -54,8 +54,11 @@ func ConvertLogicalBreakpoint(lbp *proc.LogicalBreakpoint) *Breakpoint { } // ConvertPhysicalBreakpoints adds informations from physical breakpoints to an API breakpoint. -func ConvertPhysicalBreakpoints(b *Breakpoint, pids []int, bps []*proc.Breakpoint) { +func ConvertPhysicalBreakpoints(b *Breakpoint, lbp *proc.LogicalBreakpoint, pids []int, bps []*proc.Breakpoint) { if len(bps) == 0 { + if lbp != nil { + b.ExprString = lbp.Set.ExprString + } return } diff --git a/service/api/types.go b/service/api/types.go index e658ad4a..13a1e8d2 100644 --- a/service/api/types.go +++ b/service/api/types.go @@ -92,6 +92,8 @@ type Breakpoint struct { // FunctionName is the name of the function at the current breakpoint, and // may not always be available. FunctionName string `json:"functionName,omitempty"` + // ExprString is the string that will be used to set a suspended breakpoint. + ExprString string // Breakpoint condition Cond string diff --git a/service/dap/server.go b/service/dap/server.go index 75a06e98..a8e7b343 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -1961,7 +1961,7 @@ func (s *Session) stoppedOnBreakpointGoroutineID(state *api.DebuggerState) (int6 return goid, nil } abp := api.ConvertLogicalBreakpoint(bp.Breakpoint.Logical) - api.ConvertPhysicalBreakpoints(abp, []int{0}, []*proc.Breakpoint{bp.Breakpoint}) + api.ConvertPhysicalBreakpoints(abp, bp.Breakpoint.Logical, []int{0}, []*proc.Breakpoint{bp.Breakpoint}) return goid, abp } diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index b666bb74..e33ed5d7 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -617,7 +617,7 @@ func (d *Debugger) state(retLoadCfg *proc.LoadConfig, withBreakpointInfo bool) ( for t.Next() { for _, bp := range t.Breakpoints().WatchOutOfScope { abp := api.ConvertLogicalBreakpoint(bp.Logical) - api.ConvertPhysicalBreakpoints(abp, []int{t.Pid()}, []*proc.Breakpoint{bp}) + api.ConvertPhysicalBreakpoints(abp, bp.Logical, []int{t.Pid()}, []*proc.Breakpoint{bp}) state.WatchOutOfScope = append(state.WatchOutOfScope, abp) } } @@ -744,6 +744,7 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint, locExpr string, } return locs[0].PCs } + setbp.ExprString = locExpr } id := requestedBp.ID @@ -805,7 +806,7 @@ func (d *Debugger) convertBreakpoint(lbp *proc.LogicalBreakpoint) *api.Breakpoin } } } - api.ConvertPhysicalBreakpoints(abp, pids, bps) + api.ConvertPhysicalBreakpoints(abp, lbp, pids, bps) return abp } @@ -1039,7 +1040,7 @@ func (d *Debugger) Breakpoints(all bool) []*api.Breakpoint { } else { abp = &api.Breakpoint{} } - api.ConvertPhysicalBreakpoints(abp, []int{t.Pid()}, []*proc.Breakpoint{bp}) + api.ConvertPhysicalBreakpoints(abp, bp.Logical, []int{t.Pid()}, []*proc.Breakpoint{bp}) abp.VerboseDescr = bp.VerboseDescr() abps = append(abps, abp) }