summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
authorRoland Senn <rsx@bluewin.ch>2021-01-16 17:31:45 +0100
committerBen Gamari <ben@smart-cactus.org>2021-03-10 16:59:05 -0500
commitfcfc66e59c81277c1f7c079ad4e0ccd9a69e1fb6 (patch)
tree378b6b8bebea928fe5fafad2dcf7920253ecbaeb /compiler/GHC
parent115cd3c85a8c38f1fe2a10d4ee515f92c96dd5a2 (diff)
downloadhaskell-fcfc66e59c81277c1f7c079ad4e0ccd9a69e1fb6.tar.gz
Ignore breakpoint for a specified number of iterations. (#19157)
* Implement new debugger command `:ignore` to set an `ignore count` for a specified breakpoint. * Allow new optional parameter on `:continue` command to set an `ignore count` for the current breakpoint. * In the Interpreter replace the current `Word8` BreakArray with an `Int` array. * Change semantics of values in `BreakArray` to: n < 0 : Breakpoint is disabled. n == 0 : Breakpoint is enabled. n > 0 : Breakpoint is enabled, but ignore next `n` iterations. * Rewrite `:enable`/`:disable` processing as a special case of `:ignore`. * Remove references to `BreakArray` from `ghc/UI.hs`.
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Runtime/Eval.hs21
-rw-r--r--compiler/GHC/Runtime/Interpreter.hs8
2 files changed, 23 insertions, 6 deletions
diff --git a/compiler/GHC/Runtime/Eval.hs b/compiler/GHC/Runtime/Eval.hs
index fc2f8b8ab3..94a4e775ad 100644
--- a/compiler/GHC/Runtime/Eval.hs
+++ b/compiler/GHC/Runtime/Eval.hs
@@ -23,6 +23,7 @@ module GHC.Runtime.Eval (
getHistorySpan,
getModBreaks,
getHistoryModule,
+ setupBreakpoint,
back, forward,
setContext, getContext,
getNamesInScope,
@@ -397,8 +398,9 @@ handleRunStatus step expr bindings final_ids status history
#endif
-resumeExec :: GhcMonad m => (SrcSpan->Bool) -> SingleStep -> m ExecResult
-resumeExec canLogSpan step
+resumeExec :: GhcMonad m => (SrcSpan->Bool) -> SingleStep -> Maybe Int
+ -> m ExecResult
+resumeExec canLogSpan step mbCnt
= do
hsc_env <- getSession
let ic = hsc_IC hsc_env
@@ -433,6 +435,10 @@ resumeExec canLogSpan step
, resumeSpan = span
, resumeHistory = hist } ->
withVirtualCWD $ do
+ when (isJust mb_brkpt && isJust mbCnt) $ do
+ setupBreakpoint hsc_env (fromJust mb_brkpt) (fromJust mbCnt)
+ -- When the user specified a break ignore count, set it
+ -- in the interpreter
status <- liftIO $ GHCi.resumeStmt hsc_env (isStep step) fhv
let prevHistoryLst = fromListBL 50 hist
hist' = case mb_brkpt of
@@ -443,6 +449,17 @@ resumeExec canLogSpan step
fromListBL 50 hist
handleRunStatus step expr bindings final_ids status hist'
+setupBreakpoint :: GhcMonad m => HscEnv -> BreakInfo -> Int -> m () -- #19157
+setupBreakpoint hsc_env brkInfo cnt = do
+ let modl :: Module = breakInfo_module brkInfo
+ breaks hsc_env modl = getModBreaks $ expectJust "setupBreakpoint" $
+ lookupHpt (hsc_HPT hsc_env) (moduleName modl)
+ ix = breakInfo_number brkInfo
+ modBreaks = breaks hsc_env modl
+ breakarray = modBreaks_flags modBreaks
+ _ <- liftIO $ GHCi.storeBreakpoint hsc_env breakarray ix cnt
+ pure ()
+
back :: GhcMonad m => Int -> m ([Name], Int, SrcSpan, String)
back n = moveHist (+n)
diff --git a/compiler/GHC/Runtime/Interpreter.hs b/compiler/GHC/Runtime/Interpreter.hs
index cb13089571..cc5f289f48 100644
--- a/compiler/GHC/Runtime/Interpreter.hs
+++ b/compiler/GHC/Runtime/Interpreter.hs
@@ -19,7 +19,7 @@ module GHC.Runtime.Interpreter
, mkCostCentres
, costCentreStackInfo
, newBreakArray
- , enableBreakpoint
+ , storeBreakpoint
, breakpointStatus
, getBreakpointVar
, getClosure
@@ -379,10 +379,10 @@ newBreakArray hsc_env size = do
breakArray <- iservCmd hsc_env (NewBreakArray size)
mkFinalizedHValue hsc_env breakArray
-enableBreakpoint :: HscEnv -> ForeignRef BreakArray -> Int -> Bool -> IO ()
-enableBreakpoint hsc_env ref ix b =
+storeBreakpoint :: HscEnv -> ForeignRef BreakArray -> Int -> Int -> IO ()
+storeBreakpoint hsc_env ref ix cnt = do -- #19157
withForeignRef ref $ \breakarray ->
- iservCmd hsc_env (EnableBreakpoint breakarray ix b)
+ iservCmd hsc_env (SetupBreakpoint breakarray ix cnt)
breakpointStatus :: HscEnv -> ForeignRef BreakArray -> Int -> IO Bool
breakpointStatus hsc_env ref ix =