terminal: support setting hitcount conditions on breakpoints (#2518)
Adds a -hitcount argument to condition that sets a hitcount condition on breakpoints.
This commit is contained in:
parent
585c711ce5
commit
d72b03b846
@ -174,8 +174,21 @@ If called with the linespec argument it will delete all the breakpoints matching
|
|||||||
Set breakpoint condition.
|
Set breakpoint condition.
|
||||||
|
|
||||||
condition <breakpoint name or id> <boolean expression>.
|
condition <breakpoint name or id> <boolean expression>.
|
||||||
|
condition -hitcount <breakpoint name or id> <operator> <argument>
|
||||||
|
|
||||||
Specifies that the breakpoint or tracepoint should break only if the boolean expression is true.
|
Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true.
|
||||||
|
|
||||||
|
With the -hitcount option a condition on the breakpoint hit count can be set, the following operators are supported
|
||||||
|
|
||||||
|
condition -hitcount bp > n
|
||||||
|
condition -hitcount bp >= n
|
||||||
|
condition -hitcount bp < n
|
||||||
|
condition -hitcount bp <= n
|
||||||
|
condition -hitcount bp == n
|
||||||
|
condition -hitcount bp != n
|
||||||
|
condition -hitcount bp % n
|
||||||
|
|
||||||
|
The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n.
|
||||||
|
|
||||||
Aliases: cond
|
Aliases: cond
|
||||||
|
|
||||||
|
|||||||
@ -387,8 +387,21 @@ Supported commands: print, stack and goroutine)`},
|
|||||||
{aliases: []string{"condition", "cond"}, group: breakCmds, cmdFn: conditionCmd, helpMsg: `Set breakpoint condition.
|
{aliases: []string{"condition", "cond"}, group: breakCmds, cmdFn: conditionCmd, helpMsg: `Set breakpoint condition.
|
||||||
|
|
||||||
condition <breakpoint name or id> <boolean expression>.
|
condition <breakpoint name or id> <boolean expression>.
|
||||||
|
condition -hitcount <breakpoint name or id> <operator> <argument>
|
||||||
|
|
||||||
Specifies that the breakpoint or tracepoint should break only if the boolean expression is true.`},
|
Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true.
|
||||||
|
|
||||||
|
With the -hitcount option a condition on the breakpoint hit count can be set, the following operators are supported
|
||||||
|
|
||||||
|
condition -hitcount bp > n
|
||||||
|
condition -hitcount bp >= n
|
||||||
|
condition -hitcount bp < n
|
||||||
|
condition -hitcount bp <= n
|
||||||
|
condition -hitcount bp == n
|
||||||
|
condition -hitcount bp != n
|
||||||
|
condition -hitcount bp % n
|
||||||
|
|
||||||
|
The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n.`},
|
||||||
{aliases: []string{"config"}, cmdFn: configureCmd, helpMsg: `Changes configuration parameters.
|
{aliases: []string{"config"}, cmdFn: configureCmd, helpMsg: `Changes configuration parameters.
|
||||||
|
|
||||||
config -list
|
config -list
|
||||||
@ -1533,6 +1546,9 @@ func breakpoints(t *Term, ctx callContext, args string) error {
|
|||||||
if bp.Cond != "" {
|
if bp.Cond != "" {
|
||||||
attrs = append(attrs, fmt.Sprintf("\tcond %s", bp.Cond))
|
attrs = append(attrs, fmt.Sprintf("\tcond %s", bp.Cond))
|
||||||
}
|
}
|
||||||
|
if bp.HitCond != "" {
|
||||||
|
attrs = append(attrs, fmt.Sprintf("\tcond -hitcount %s", bp.HitCond))
|
||||||
|
}
|
||||||
if bp.Stacktrace > 0 {
|
if bp.Stacktrace > 0 {
|
||||||
attrs = append(attrs, fmt.Sprintf("\tstack %d", bp.Stacktrace))
|
attrs = append(attrs, fmt.Sprintf("\tstack %d", bp.Stacktrace))
|
||||||
}
|
}
|
||||||
@ -2666,6 +2682,22 @@ func conditionCmd(t *Term, ctx callContext, argstr string) error {
|
|||||||
return fmt.Errorf("not enough arguments")
|
return fmt.Errorf("not enough arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if args[0] == "-hitcount" {
|
||||||
|
// hitcount breakpoint
|
||||||
|
args = split2PartsBySpace(args[1])
|
||||||
|
if len(args) < 2 {
|
||||||
|
return fmt.Errorf("not enough arguments")
|
||||||
|
}
|
||||||
|
bp, err := getBreakpointByIDOrName(t, args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bp.HitCond = args[1]
|
||||||
|
|
||||||
|
return t.client.AmendBreakpoint(bp)
|
||||||
|
}
|
||||||
|
|
||||||
bp, err := getBreakpointByIDOrName(t, args[0])
|
bp, err := getBreakpointByIDOrName(t, args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -1178,3 +1178,16 @@ func TestPrintFormat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHitCondBreakpoint(t *testing.T) {
|
||||||
|
withTestTerminal("break", t, func(term *FakeTerminal) {
|
||||||
|
term.MustExec("break bp1 main.main:4")
|
||||||
|
term.MustExec("condition -hitcount bp1 > 2")
|
||||||
|
listIsAt(t, term, "continue", 7, -1, -1)
|
||||||
|
out := term.MustExec("print i")
|
||||||
|
t.Logf("%q", out)
|
||||||
|
if !strings.Contains(out, "3\n") {
|
||||||
|
t.Fatalf("wrong value of i")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user