Skip to content

Commit 20eae33

Browse files
committed
fix: always take local env into account when executing debug commands
1 parent 63cc5f9 commit 20eae33

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

external-stg-interpreter/lib/Stg/Interpreter.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ buildCallGraph so hoName = do
181181
builtinStgEval :: HasCallStack => StaticOrigin -> Atom -> M [Atom]
182182
builtinStgEval so a@HeapPtr{} = do
183183
o <- readHeap a
184-
Debugger.checkBreakpoint $ BkpCustom "eval"
184+
Debugger.checkBreakpoint [a] $ BkpCustom "eval"
185185
case o of
186186
ApStack{..} -> do
187187
tid <- gets ssCurrentThreadId
@@ -242,7 +242,7 @@ builtinStgEval so a@HeapPtr{} = do
242242
-- check breakpoints and region entering
243243
let closureName = binderUniqueName $ unId hoName
244244
markClosure closureName -- HINT: this list can be deleted by a debugger command, so this is not the same as `markExecutedId`
245-
Debugger.checkBreakpoint . BkpStgPoint . SP_RhsClosureExpr . binderToStgId . unId $ hoName
245+
Debugger.checkBreakpoint [a] . BkpStgPoint . SP_RhsClosureExpr . binderToStgId . unId $ hoName
246246
Debugger.checkRegion closureName
247247
GC.checkGC [a] -- HINT: add local env as GC root
248248

@@ -467,7 +467,7 @@ evalStackMachine result = do
467467
resultStr <- mapM debugPrintAtom result
468468
traceLog $ showStackCont stackCont ++ " current-result: " ++ show resultStr
469469

470-
Debugger.checkBreakpoint $ BkpCustom "stack"
470+
Debugger.checkBreakpoint result $ BkpCustom "stack"
471471
nextResult <- evalStackContinuation result stackCont
472472
case stackCont of
473473
RunScheduler{} -> pure ()
@@ -709,7 +709,7 @@ evalExpr localEnv = \case
709709
evalExpr localEnv e
710710

711711
StgOpApp (StgPrimOp op) l t tc -> do
712-
Debugger.checkBreakpoint $ BkpPrimOp op
712+
Debugger.checkBreakpoint (envToAtoms localEnv) $ BkpPrimOp op
713713
Debugger.checkRegion op
714714
markPrimOp op
715715
args <- mapM (evalArg localEnv) l
@@ -723,7 +723,7 @@ evalExpr localEnv = \case
723723
-- check foreign target region and breakpoint
724724
case foreignCTarget foreignCall of
725725
StaticTarget _ targetName _ _ -> do
726-
Debugger.checkBreakpoint $ BkpFFISymbol targetName
726+
Debugger.checkBreakpoint (envToAtoms localEnv) $ BkpFFISymbol targetName
727727
Debugger.checkRegion targetName
728728
_ -> pure ()
729729

@@ -955,7 +955,7 @@ runProgram isQuiet switchCWD progFilePath mods0 progArgs dbgChan dbgState tracin
955955

956956
exportCallGraph
957957

958-
Debugger.checkBreakpoint $ BkpCustom "program finished"
958+
Debugger.checkBreakpoint [] $ BkpCustom "program finished"
959959
-- HINT: start debugger REPL in debug mode
960960
when (dbgState == DbgStepByStep) $ do
961961
Debugger.processCommandsUntilExit

external-stg-interpreter/lib/Stg/Interpreter/Debugger.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ hasFuel = do
109109
modify' $ \s@StgState{..} -> s {ssDebugFuel = fmap pred ssDebugFuel, ssStepCounter = succ ssStepCounter}
110110
pure $ maybe True (> 0) fuel
111111

112-
checkBreakpoint :: Breakpoint -> M ()
113-
checkBreakpoint breakpoint = do
112+
checkBreakpoint :: [Atom] -> Breakpoint -> M ()
113+
checkBreakpoint localEnv breakpoint = do
114+
modify' $ \s@StgState{..} -> s {ssLocalEnv = localEnv}
114115
dbgState <- gets ssDebugState
115116
exit <- processCommandsNonBlocking
116117
shouldStep <- hasFuel

external-stg-interpreter/lib/Stg/Interpreter/Debugger/Internal.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ dbgCommands =
131131
[ ( ["gc"]
132132
, "run sync. garbage collector"
133133
, wrapWithDbgOut $ \_ -> do
134-
curClosureAddr <- gets ssCurrentClosureAddr
135-
GC.runGCSync [HeapPtr curClosureAddr]
134+
localEnv <- gets ssLocalEnv
135+
GC.runGCSync localEnv
136136
)
137137
, ( ["cleardb"]
138138
, "clear retainer db"
@@ -177,7 +177,7 @@ dbgCommands =
177177
, "[START] [END] list a given region or all regions if the arguments are omitted"
178178
, wrapWithDbgOut $ \case
179179
[] -> do
180-
regions <- Map.keys <$> gets ssRegions
180+
regions <- Map.keys <$> gets ssRegionStack
181181
liftIO $ putStrLn $ unlines $ map show regions
182182
[start] -> showRegion False start start
183183
[start, end] -> showRegion False start end
@@ -286,14 +286,14 @@ dbgCommands =
286286
, "list all trace markers and heap address state"
287287
, wrapWithDbgOut $ \_-> do
288288
markers <- gets ssTraceMarkers
289-
forM_ (reverse markers) $ \(msg, AddressState{..}) -> liftIO $ printf "%-10d %s\n" asNextHeapAddr (show msg)
289+
forM_ (reverse markers) $ \(msg, _tid, AddressState{..}) -> liftIO $ printf "%-10d %s\n" asNextHeapAddr (show msg)
290290
)
291291

292292
, ( ["?m-dump"]
293293
, "list all trace markers and the whole address state"
294294
, wrapWithDbgOut $ \_-> do
295295
markers <- gets ssTraceMarkers
296-
forM_ (reverse markers) $ \(msg, a) -> liftIO $ do
296+
forM_ (reverse markers) $ \(msg, _tid, a) -> liftIO $ do
297297
print msg
298298
print a
299299
)

external-stg-interpreter/lib/Stg/Interpreter/ThreadScheduler.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ stopIfThereIsNoRunnableThread = do
285285
putStrLn $ show (tid, tsStatus ts, tsBlockExceptions ts, tsInterruptible ts, tsBlockedExceptions ts, tsLabel ts)
286286
dumpStgState
287287
modify' $ \s@StgState{..} -> s {ssDebugState = DbgStepByStep}
288-
Debugger.checkBreakpoint $ BkpCustom "thread-scheduler"
288+
Debugger.checkBreakpoint [] $ BkpCustom "thread-scheduler"
289289

290290
{-
291291
IDEA:

0 commit comments

Comments
 (0)