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.
This commit is contained in:
Alessandro Arzilli
2023-07-07 19:33:40 +02:00
committed by GitHub
parent c1482ca911
commit db0bc26949
6 changed files with 28 additions and 7 deletions

View File

@ -1018,6 +1018,7 @@ type SetBreakpoint struct {
File string File string
Line int Line int
Expr func(*Target) []uint64 Expr func(*Target) []uint64
ExprString string
PidAddrs []PidAddr PidAddrs []PidAddr
} }

View File

@ -1702,8 +1702,15 @@ func breakpoints(t *Term, ctx callContext, args string) error {
enabled := "(enabled)" enabled := "(enabled)"
if bp.Disabled { if bp.Disabled {
enabled = "(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) attrs := formatBreakpointAttrs("\t", bp, false)
@ -3277,7 +3284,12 @@ func target(t *Term, ctx callContext, args string) error {
return nil return nil
case "follow-exec": case "follow-exec":
if len(argv) == 1 { 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]) argv = config.Split2PartsBySpace(argv[1])
switch argv[0] { 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 fmt.Errorf("could not find target %d", pid)
} }
return nil return nil
case "":
return errors.New("not enough arguments for 'target'")
default: default:
return fmt.Errorf("unknown command 'target %s'", argv[0]) return fmt.Errorf("unknown command 'target %s'", argv[0])
} }

View File

@ -54,8 +54,11 @@ func ConvertLogicalBreakpoint(lbp *proc.LogicalBreakpoint) *Breakpoint {
} }
// ConvertPhysicalBreakpoints adds informations from physical breakpoints to an API 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 len(bps) == 0 {
if lbp != nil {
b.ExprString = lbp.Set.ExprString
}
return return
} }

View File

@ -92,6 +92,8 @@ type Breakpoint struct {
// FunctionName is the name of the function at the current breakpoint, and // FunctionName is the name of the function at the current breakpoint, and
// may not always be available. // may not always be available.
FunctionName string `json:"functionName,omitempty"` FunctionName string `json:"functionName,omitempty"`
// ExprString is the string that will be used to set a suspended breakpoint.
ExprString string
// Breakpoint condition // Breakpoint condition
Cond string Cond string

View File

@ -1961,7 +1961,7 @@ func (s *Session) stoppedOnBreakpointGoroutineID(state *api.DebuggerState) (int6
return goid, nil return goid, nil
} }
abp := api.ConvertLogicalBreakpoint(bp.Breakpoint.Logical) 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 return goid, abp
} }

View File

@ -617,7 +617,7 @@ func (d *Debugger) state(retLoadCfg *proc.LoadConfig, withBreakpointInfo bool) (
for t.Next() { for t.Next() {
for _, bp := range t.Breakpoints().WatchOutOfScope { for _, bp := range t.Breakpoints().WatchOutOfScope {
abp := api.ConvertLogicalBreakpoint(bp.Logical) 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) state.WatchOutOfScope = append(state.WatchOutOfScope, abp)
} }
} }
@ -744,6 +744,7 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint, locExpr string,
} }
return locs[0].PCs return locs[0].PCs
} }
setbp.ExprString = locExpr
} }
id := requestedBp.ID 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 return abp
} }
@ -1039,7 +1040,7 @@ func (d *Debugger) Breakpoints(all bool) []*api.Breakpoint {
} else { } else {
abp = &api.Breakpoint{} 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() abp.VerboseDescr = bp.VerboseDescr()
abps = append(abps, abp) abps = append(abps, abp)
} }