From c0cbfe2fad7cd8bf73514a50bbfa9b739da31957 Mon Sep 17 00:00:00 2001 From: Liu Cong Date: Thu, 19 Feb 2026 03:10:53 +0800 Subject: [PATCH] breakpoint: fix a bug #196 Signed-off-by: Liu Cong --- pkg/core/execute/breakpoint_test.go | 62 +++++++++++++++++++++++++++++ pkg/core/execute/interactive.go | 8 ++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/pkg/core/execute/breakpoint_test.go b/pkg/core/execute/breakpoint_test.go index 727e702d..fef9872e 100644 --- a/pkg/core/execute/breakpoint_test.go +++ b/pkg/core/execute/breakpoint_test.go @@ -373,6 +373,68 @@ func TestBreakPointQuietCommand(t *testing.T) { } } +func TestBreakPointQuietCommandWithStepOver(t *testing.T) { + hook := &mockTestingHook{actions: []string{"c"}} + cc := newTestCliWithHook(hook) + env := newTestEnv() + + tree := model.NewCmdTree(model.CmdTreeStrsForTest()) + sub := tree.GetOrAddSub("quietcmd") + sub.RegEmptyCmd("quiet command").SetQuiet() + + cmd := model.ParsedCmd{ + Segments: []model.ParsedCmdSeg{ + { + Matched: model.MatchedCmd{ + Name: "quietcmd", + Cmd: sub, + }, + }, + }, + } + + env.SetBool("sys.breakpoint.at-next", true) + + bpa := tryWaitSecAndBreakBefore(cc, env, cmd, nil, false, false, false, func() {}) + + if bpa != BPAContinue { + t.Errorf("expected BPAContinue after user choice, got %s", bpa) + } + if len(hook.recordReason) != 1 { + t.Errorf("expected breakpoint to trigger for quiet command when stepping over, got %d triggers", len(hook.recordReason)) + } +} + +func TestBreakPointQuietCommandWithBreakByPrev(t *testing.T) { + hook := &mockTestingHook{actions: []string{"c"}} + cc := newTestCliWithHook(hook) + env := newTestEnv() + + tree := model.NewCmdTree(model.CmdTreeStrsForTest()) + sub := tree.GetOrAddSub("quietcmd") + sub.RegEmptyCmd("quiet command").SetQuiet() + + cmd := model.ParsedCmd{ + Segments: []model.ParsedCmdSeg{ + { + Matched: model.MatchedCmd{ + Name: "quietcmd", + Cmd: sub, + }, + }, + }, + } + + bpa := tryWaitSecAndBreakBefore(cc, env, cmd, nil, true, false, false, func() {}) + + if bpa != BPAContinue { + t.Errorf("expected BPAContinue after user choice, got %s", bpa) + } + if len(hook.recordReason) != 1 { + t.Errorf("expected breakpoint to trigger for quiet command with breakByPrev, got %d triggers", len(hook.recordReason)) + } +} + func TestMultipleBreakPoints(t *testing.T) { hook := &mockTestingHook{actions: []string{"c", "c", "c"}} cc := newTestCliWithHook(hook) diff --git a/pkg/core/execute/interactive.go b/pkg/core/execute/interactive.go index a6c2e22b..ac4a4340 100644 --- a/pkg/core/execute/interactive.go +++ b/pkg/core/execute/interactive.go @@ -30,9 +30,11 @@ func tryWaitSecAndBreakBefore(cc *model.Cli, env *model.Env, cmd model.ParsedCmd return BPAContinue } - // Not sure why we need to checke "sys.breakpoint.here.now" originally, it cause a bug - //if cmd.IsQuiet() && !env.GetBool("sys.breakpoint.here.now") { - if cmd.IsQuiet() { + stepIn := env.GetBool("sys.breakpoint.status.step-in") + stepOut := env.GetBool("sys.breakpoint.status.step-out") + breakByNext := breakByPrev || env.GetBool("sys.breakpoint.at-next") + + if cmd.IsQuiet() && !stepIn && !stepOut && !breakByNext { return BPAContinue }