pkg/terminal: add '-clear' option to 'condition' command (#2882)

This change adds the '-clear' to 'condition' which will clear
condtion on the breakpoint.

Co-authored-by: qianhailong <qianhailong@bytedance.com>
This commit is contained in:
chainhelen 2022-02-16 01:41:23 +08:00 committed by GitHub
parent cec23c0aa1
commit bb88e8b52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 2 deletions

@ -179,7 +179,8 @@ If called with the linespec argument it will delete all the breakpoints matching
Set breakpoint condition.
condition <breakpoint name or id> <boolean expression>.
condition -hitcount <breakpoint name or id> <operator> <argument>
condition -hitcount <breakpoint name or id> <operator> <argument>.
condition -clear <breakpoint name or id>.
Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true.
@ -194,12 +195,15 @@ With the -hitcount option a condition on the breakpoint hit count can be set, th
condition -hitcount bp == n
condition -hitcount bp != n
condition -hitcount bp % n
With the -clear option a condtion on the breakpoint can removed.
The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n.
Examples:
cond 2 i == 10 breakpoint 2 will stop when variable i equals 10
cond name runtime.curg.goid == 5 breakpoint 'name' will stop only on goroutine 5
cond -clear 2 the condition on breakpoint 2 will be removed
Aliases: cond

@ -450,7 +450,8 @@ The command 'on x -edit' can be used to edit the list of commands executed when
{aliases: []string{"condition", "cond"}, group: breakCmds, cmdFn: conditionCmd, allowedPrefixes: onPrefix, helpMsg: `Set breakpoint condition.
condition <breakpoint name or id> <boolean expression>.
condition -hitcount <breakpoint name or id> <operator> <argument>
condition -hitcount <breakpoint name or id> <operator> <argument>.
condition -clear <breakpoint name or id>.
Specifies that the breakpoint, tracepoint or watchpoint should break only if the boolean expression is true.
@ -465,12 +466,15 @@ With the -hitcount option a condition on the breakpoint hit count can be set, th
condition -hitcount bp == n
condition -hitcount bp != n
condition -hitcount bp % n
With the -clear option a condtion on the breakpoint can removed.
The '% n' form means we should stop at the breakpoint when the hitcount is a multiple of n.
Examples:
cond 2 i == 10 breakpoint 2 will stop when variable i equals 10
cond name runtime.curg.goid == 5 breakpoint 'name' will stop only on goroutine 5
cond -clear 2 the condition on breakpoint 2 will be removed
`},
{aliases: []string{"config"}, cmdFn: configureCmd, helpMsg: `Changes configuration parameters.
@ -2832,6 +2836,15 @@ func conditionCmd(t *Term, ctx callContext, argstr string) error {
return t.client.AmendBreakpoint(bp)
}
if args[0] == "-clear" {
bp, err := getBreakpointByIDOrName(t, args[1])
if err != nil {
return err
}
bp.Cond = ""
return t.client.AmendBreakpoint(bp)
}
if ctx.Prefix == onPrefix {
ctx.Breakpoint.Cond = argstr
return nil

@ -1160,6 +1160,26 @@ func TestHitCondBreakpoint(t *testing.T) {
})
}
func TestClearCondBreakpoint(t *testing.T) {
withTestTerminal("break", t, func(term *FakeTerminal) {
term.MustExec("break main.main:4")
term.MustExec("condition 1 i%3==2")
listIsAt(t, term, "continue", 7, -1, -1)
out := term.MustExec("print i")
t.Logf("%q", out)
if !strings.Contains(out, "2\n") {
t.Fatalf("wrong value of i")
}
term.MustExec("condition -clear 1")
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")
}
})
}
func TestBreakpointEditing(t *testing.T) {
term := &FakeTerminal{
t: t,