Skip to content

Commit

Permalink
debug: Take a number of steps as an argument to step (#1298)
Browse files Browse the repository at this point in the history
Fixes #1287
  • Loading branch information
langston-barrett authored Feb 7, 2025
1 parent 46a231e commit d9d63fd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 32 deletions.
7 changes: 6 additions & 1 deletion crucible-debug/src/Lang/Crucible/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,14 @@ dispatch ctx0 execState =
Ctxt.Running {} | C.ResultState {} <- execState -> do
let ctx = ctx0 { Ctxt.dbgState = Ctxt.Stopped }
dispatch ctx execState
Ctxt.Running Ctxt.Step -> do
Ctxt.Running (Ctxt.Step i) | i <= 1 -> do
let ctx = ctx0 { Ctxt.dbgState = Ctxt.Stopped }
dispatch ctx execState
Ctxt.Running (Ctxt.Step i) -> do
let ctx = ctx0 { Ctxt.dbgState = Ctxt.Running (Ctxt.Step (i - 1)) }
state <- stepState ctx execState
let ctx' = ctx0 { Ctxt.dbgState = state }
pure (ctx', C.ExecutionFeatureNoChange)
Ctxt.Running {} -> do
state <- stepState ctx0 execState
let ctx = ctx0 { Ctxt.dbgState = state }
Expand Down
4 changes: 2 additions & 2 deletions crucible-debug/src/Lang/Crucible/Debug/Command/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ help =
Register -> "Print registers (including block/function arguments)"
Run -> "Continue to the next breakpoint or the end of execution"
Secret -> "Maintenance commands, used for testing"
Step -> "Continue one step of execution"
Step -> "Continue N steps of execution (default: 1)"
Source -> "Execute a file containing debugger commands"
Trace -> "Print the N most recently executed basic blocks (default: 2)"
Usage -> "Display command usage hint"
Expand Down Expand Up @@ -325,7 +325,7 @@ rSecret = knownRepr
rSource :: Rgx.RegexRepr ArgTypeRepr AType.Path
rSource = knownRepr

rStep :: Rgx.RegexRepr ArgTypeRepr Rgx.Empty
rStep :: Rgx.RegexRepr ArgTypeRepr (Rgx.Empty Rgx.:| AType.Int)
rStep = knownRepr

rTrace :: Rgx.RegexRepr ArgTypeRepr (Rgx.Empty Rgx.:| AType.Int)
Expand Down
2 changes: 1 addition & 1 deletion crucible-debug/src/Lang/Crucible/Debug/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ data RunningState
-- | User issued 'Cmd.Run'
| Run
-- | User issued 'Cmd.Step'
| Step
| Step {-# UNPACK #-} !Int

data DebuggerState
= Running RunningState
Expand Down
8 changes: 6 additions & 2 deletions crucible-debug/src/Lang/Crucible/Debug/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ baseImpl =
BCmd.Step ->
Ctxt.CommandImpl
{ Ctxt.implRegex = BCmd.rStep
, Ctxt.implBody = \ctx execState Rgx.MEmpty ->
runCmd ctx execState Ctxt.Step
, Ctxt.implBody = \ctx execState m -> do
let n =
case m of
Rgx.MLeft Rgx.MEmpty -> 1
Rgx.MRight (Rgx.MLit (Arg.AInt i)) -> i
runCmd ctx execState (Ctxt.Step n)
}

BCmd.Source ->
Expand Down
2 changes: 1 addition & 1 deletion crucible-debug/test-data/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ register (reg): Print registers (including block/function arguments)
run (r): Continue to the next breakpoint or the end of execution
secret (.): Maintenance commands, used for testing
source (src): Execute a file containing debugger commands
step (s): Continue one step of execution
step (s): Continue N steps of execution (default: 1)
trace (trace): Print the N most recently executed basic blocks (default: 2)
usage (u): Display command usage hint

Expand Down
22 changes: 3 additions & 19 deletions crucible-debug/test-data/reg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@ Ok

Ok

> step

Ok

> step
> step 2

Ok

> reg



> step

Ok

> step
> step 2

Ok

Expand All @@ -52,15 +44,7 @@ cp@0:b
cx@1:i
cp@0:b

> step

Ok

> step

Ok

> step
> step 3

Ok

Expand Down
6 changes: 1 addition & 5 deletions crucible-debug/test-data/step.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

Ok

> step

Ok

> step
> step 2

Ok

Expand Down
2 changes: 1 addition & 1 deletion crucible-debug/test-data/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ help COMMAND?

> usage step

step
step INT?

> usage secret

Expand Down

0 comments on commit d9d63fd

Please sign in to comment.