Rodrigo Mesquita pushed to branch wip/romes/step-out-11 at Glasgow Haskell Compiler / GHC
Commits:
-
bccb2147
by Rodrigo Mesquita at 2025-07-28T17:59:50+01:00
-
6a546b33
by Rodrigo Mesquita at 2025-07-28T18:16:25+01:00
18 changed files:
- compiler/GHC/ByteCode/Breakpoints.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Runtime/Debugger/Breakpoints.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/StgToByteCode.hs
- ghc/GHCi/UI.hs
- libraries/ghci/GHCi/Run.hs
- rts/Interpreter.c
- testsuite/tests/ghci.debugger/scripts/T26042b.stdout
- testsuite/tests/ghci.debugger/scripts/T26042c.script
- testsuite/tests/ghci.debugger/scripts/T26042c.stdout
- + testsuite/tests/ghci.debugger/scripts/T26042d2.hs
- + testsuite/tests/ghci.debugger/scripts/T26042d2.script
- + testsuite/tests/ghci.debugger/scripts/T26042d2.stdout
- testsuite/tests/ghci.debugger/scripts/T26042e.stdout
- testsuite/tests/ghci.debugger/scripts/T26042f2.stdout
- testsuite/tests/ghci.debugger/scripts/T26042g.stdout
- testsuite/tests/ghci.debugger/scripts/all.T
Changes:
| 1 | 1 | {-# LANGUAGE RecordWildCards #-}
|
| 2 | +{-# LANGUAGE DerivingStrategies #-}
|
|
| 2 | 3 | |
| 3 | 4 | -- | Breakpoint information constructed during ByteCode generation.
|
| 4 | 5 | --
|
| ... | ... | @@ -15,6 +16,7 @@ module GHC.ByteCode.Breakpoints |
| 15 | 16 | |
| 16 | 17 | -- ** Internal breakpoint identifier
|
| 17 | 18 | , InternalBreakpointId(..), BreakInfoIndex
|
| 19 | + , InternalBreakLoc(..)
|
|
| 18 | 20 | |
| 19 | 21 | -- * Operations
|
| 20 | 22 | |
| ... | ... | @@ -23,7 +25,7 @@ module GHC.ByteCode.Breakpoints |
| 23 | 25 | |
| 24 | 26 | -- ** Source-level information operations
|
| 25 | 27 | , getBreakLoc, getBreakVars, getBreakDecls, getBreakCCS
|
| 26 | - , getBreakSourceId
|
|
| 28 | + , getBreakSourceId, getBreakSourceMod
|
|
| 27 | 29 | |
| 28 | 30 | -- * Utils
|
| 29 | 31 | , seqInternalModBreaks
|
| ... | ... | @@ -165,7 +167,7 @@ data CgBreakInfo |
| 165 | 167 | { cgb_tyvars :: ![IfaceTvBndr] -- ^ Type variables in scope at the breakpoint
|
| 166 | 168 | , cgb_vars :: ![Maybe (IfaceIdBndr, Word)]
|
| 167 | 169 | , cgb_resty :: !IfaceType
|
| 168 | - , cgb_tick_id :: !BreakpointId
|
|
| 170 | + , cgb_tick_id :: !(Either InternalBreakLoc BreakpointId)
|
|
| 169 | 171 | -- ^ This field records the original breakpoint tick identifier for this
|
| 170 | 172 | -- internal breakpoint info. It is used to convert a breakpoint
|
| 171 | 173 | -- *occurrence* index ('InternalBreakpointId') into a *definition* index
|
| ... | ... | @@ -173,9 +175,19 @@ data CgBreakInfo |
| 173 | 175 | --
|
| 174 | 176 | -- The modules of breakpoint occurrence and breakpoint definition are not
|
| 175 | 177 | -- necessarily the same: See Note [Breakpoint identifiers].
|
| 178 | + --
|
|
| 179 | + -- If there is no original tick identifier (that is, the breakpoint was
|
|
| 180 | + -- created during code generation), instead refer directly to the SrcSpan
|
|
| 181 | + -- we want to use for it. See Note [Internal Breakpoint Locations]
|
|
| 176 | 182 | }
|
| 177 | 183 | -- See Note [Syncing breakpoint info] in GHC.Runtime.Eval
|
| 178 | 184 | |
| 185 | +-- | Breakpoints created during code generation don't have a source-level tick
|
|
| 186 | +-- location. Instead, we come up with one ourselves.
|
|
| 187 | +-- See Note [Internal Breakpoint Locations]
|
|
| 188 | +newtype InternalBreakLoc = InternalBreakLoc SrcSpan
|
|
| 189 | + deriving newtype (Eq, Show, NFData, Outputable)
|
|
| 190 | + |
|
| 179 | 191 | -- | Get an internal breakpoint info by 'InternalBreakpointId'
|
| 180 | 192 | getInternalBreak :: InternalBreakpointId -> InternalModBreaks -> CgBreakInfo
|
| 181 | 193 | getInternalBreak (InternalBreakpointId mod ix) imbs =
|
| ... | ... | @@ -196,27 +208,36 @@ assert_modules_match ibi_mod imbs_mod = |
| 196 | 208 | |
| 197 | 209 | -- | Get the source module and tick index for this breakpoint
|
| 198 | 210 | -- (as opposed to the module where this breakpoint occurs, which is in 'InternalBreakpointId')
|
| 199 | -getBreakSourceId :: InternalBreakpointId -> InternalModBreaks -> BreakpointId
|
|
| 211 | +getBreakSourceId :: InternalBreakpointId -> InternalModBreaks -> Either InternalBreakLoc BreakpointId
|
|
| 200 | 212 | getBreakSourceId (InternalBreakpointId ibi_mod ibi_ix) imbs =
|
| 201 | 213 | assert_modules_match ibi_mod (imodBreaks_module imbs) $
|
| 202 | 214 | let cgb = imodBreaks_breakInfo imbs IM.! ibi_ix
|
| 203 | 215 | in cgb_tick_id cgb
|
| 204 | 216 | |
| 217 | +-- | Get the source module for this breakpoint (where the breakpoint is defined)
|
|
| 218 | +getBreakSourceMod :: InternalBreakpointId -> InternalModBreaks -> Module
|
|
| 219 | +getBreakSourceMod (InternalBreakpointId ibi_mod ibi_ix) imbs =
|
|
| 220 | + assert_modules_match ibi_mod (imodBreaks_module imbs) $
|
|
| 221 | + let cgb = imodBreaks_breakInfo imbs IM.! ibi_ix
|
|
| 222 | + in case cgb_tick_id cgb of
|
|
| 223 | + Left InternalBreakLoc{} -> imodBreaks_module imbs
|
|
| 224 | + Right BreakpointId{bi_tick_mod} -> bi_tick_mod
|
|
| 225 | + |
|
| 205 | 226 | -- | Get the source span for this breakpoint
|
| 206 | 227 | getBreakLoc :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO SrcSpan
|
| 207 | -getBreakLoc = getBreakXXX modBreaks_locs
|
|
| 228 | +getBreakLoc = getBreakXXX modBreaks_locs (\(InternalBreakLoc x) -> x)
|
|
| 208 | 229 | |
| 209 | 230 | -- | Get the vars for this breakpoint
|
| 210 | 231 | getBreakVars :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO [OccName]
|
| 211 | -getBreakVars = getBreakXXX modBreaks_vars
|
|
| 232 | +getBreakVars = getBreakXXX modBreaks_vars (const [])
|
|
| 212 | 233 | |
| 213 | 234 | -- | Get the decls for this breakpoint
|
| 214 | 235 | getBreakDecls :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO [String]
|
| 215 | -getBreakDecls = getBreakXXX modBreaks_decls
|
|
| 236 | +getBreakDecls = getBreakXXX modBreaks_decls (const [])
|
|
| 216 | 237 | |
| 217 | 238 | -- | Get the decls for this breakpoint
|
| 218 | -getBreakCCS :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO (String, String)
|
|
| 219 | -getBreakCCS = getBreakXXX modBreaks_ccs
|
|
| 239 | +getBreakCCS :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO (Maybe (String, String))
|
|
| 240 | +getBreakCCS = getBreakXXX (fmap Just . modBreaks_ccs) (const Nothing)
|
|
| 220 | 241 | |
| 221 | 242 | -- | Internal utility to access a ModBreaks field at a particular breakpoint index
|
| 222 | 243 | --
|
| ... | ... | @@ -228,14 +249,17 @@ getBreakCCS = getBreakXXX modBreaks_ccs |
| 228 | 249 | -- 'ModBreaks'. When the tick module is different, we need to look up the
|
| 229 | 250 | -- 'ModBreaks' in the HUG for that other module.
|
| 230 | 251 | --
|
| 252 | +-- When there is no tick module (the breakpoint was generated at codegen), use
|
|
| 253 | +-- the function on internal mod breaks.
|
|
| 254 | +--
|
|
| 231 | 255 | -- To avoid cyclic dependencies, we instead receive a function that looks up
|
| 232 | 256 | -- the 'ModBreaks' given a 'Module'
|
| 233 | -getBreakXXX :: (ModBreaks -> Array BreakTickIndex a) -> (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO a
|
|
| 234 | -getBreakXXX view lookupModule (InternalBreakpointId ibi_mod ibi_ix) imbs =
|
|
| 257 | +getBreakXXX :: (ModBreaks -> Array BreakTickIndex a) -> (InternalBreakLoc -> a) -> (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO a
|
|
| 258 | +getBreakXXX view viewInternal lookupModule (InternalBreakpointId ibi_mod ibi_ix) imbs =
|
|
| 235 | 259 | assert_modules_match ibi_mod (imodBreaks_module imbs) $ do
|
| 236 | 260 | let cgb = imodBreaks_breakInfo imbs IM.! ibi_ix
|
| 237 | 261 | case cgb_tick_id cgb of
|
| 238 | - BreakpointId{bi_tick_mod, bi_tick_index}
|
|
| 262 | + Right BreakpointId{bi_tick_mod, bi_tick_index}
|
|
| 239 | 263 | | bi_tick_mod == ibi_mod
|
| 240 | 264 | -> do
|
| 241 | 265 | let these_mbs = imodBreaks_modBreaks imbs
|
| ... | ... | @@ -244,6 +268,8 @@ getBreakXXX view lookupModule (InternalBreakpointId ibi_mod ibi_ix) imbs = |
| 244 | 268 | -> do
|
| 245 | 269 | other_mbs <- lookupModule bi_tick_mod
|
| 246 | 270 | return $ view other_mbs ! bi_tick_index
|
| 271 | + Left l ->
|
|
| 272 | + return $ viewInternal l
|
|
| 247 | 273 | |
| 248 | 274 | --------------------------------------------------------------------------------
|
| 249 | 275 | -- Instances
|
| ... | ... | @@ -58,6 +58,7 @@ import GHCi.RemoteTypes |
| 58 | 58 | import GHC.Iface.Load
|
| 59 | 59 | import GHCi.Message (ConInfoTable(..), LoadedDLL)
|
| 60 | 60 | |
| 61 | +import GHC.ByteCode.Breakpoints
|
|
| 61 | 62 | import GHC.ByteCode.Linker
|
| 62 | 63 | import GHC.ByteCode.Asm
|
| 63 | 64 | import GHC.ByteCode.Types
|
| ... | ... | @@ -1711,8 +1712,10 @@ allocateCCS interp ce mbss |
| 1711 | 1712 | let count = 1 + (maybe 0 fst $ IM.lookupMax imodBreaks_breakInfo)
|
| 1712 | 1713 | let ccs = IM.map
|
| 1713 | 1714 | (\info ->
|
| 1714 | - fromMaybe (toRemotePtr nullPtr)
|
|
| 1715 | - (M.lookup (cgb_tick_id info) ccss)
|
|
| 1715 | + case cgb_tick_id info of
|
|
| 1716 | + Right bi -> fromMaybe (toRemotePtr nullPtr)
|
|
| 1717 | + (M.lookup bi ccss)
|
|
| 1718 | + Left InternalBreakLoc{} -> toRemotePtr nullPtr
|
|
| 1716 | 1719 | )
|
| 1717 | 1720 | imodBreaks_breakInfo
|
| 1718 | 1721 | assertPpr (count == length ccs)
|
| ... | ... | @@ -253,8 +253,11 @@ mkBreakpointOccurrences = do |
| 253 | 253 | let imod = modBreaks_module $ imodBreaks_modBreaks ibrks
|
| 254 | 254 | IntMap.foldrWithKey (\info_ix cgi bmp -> do
|
| 255 | 255 | let ibi = InternalBreakpointId imod info_ix
|
| 256 | - let BreakpointId tick_mod tick_ix = cgb_tick_id cgi
|
|
| 257 | - extendModuleEnvWith (IntMap.unionWith (S.<>)) bmp tick_mod (IntMap.singleton tick_ix [ibi])
|
|
| 256 | + case cgb_tick_id cgi of
|
|
| 257 | + Right (BreakpointId tick_mod tick_ix)
|
|
| 258 | + -> extendModuleEnvWith (IntMap.unionWith (S.<>)) bmp tick_mod (IntMap.singleton tick_ix [ibi])
|
|
| 259 | + Left _
|
|
| 260 | + -> bmp
|
|
| 258 | 261 | ) bmp0 (imodBreaks_breakInfo ibrks)
|
| 259 | 262 | |
| 260 | 263 | --------------------------------------------------------------------------------
|
| ... | ... | @@ -287,7 +290,7 @@ getCurrentBreakModule = do |
| 287 | 290 | Nothing -> pure Nothing
|
| 288 | 291 | Just ibi -> do
|
| 289 | 292 | brks <- readIModBreaks hug ibi
|
| 290 | - return $ Just $ bi_tick_mod $ getBreakSourceId ibi brks
|
|
| 293 | + return $ Just $ getBreakSourceMod ibi brks
|
|
| 291 | 294 | ix ->
|
| 292 | 295 | Just <$> getHistoryModule hug (resumeHistory r !! (ix-1))
|
| 293 | 296 |
| ... | ... | @@ -151,7 +151,7 @@ getHistoryModule :: HUG.HomeUnitGraph -> History -> IO Module |
| 151 | 151 | getHistoryModule hug hist = do
|
| 152 | 152 | let ibi = historyBreakpointId hist
|
| 153 | 153 | brks <- readIModBreaks hug ibi
|
| 154 | - return $ bi_tick_mod $ getBreakSourceId ibi brks
|
|
| 154 | + return $ getBreakSourceMod ibi brks
|
|
| 155 | 155 | |
| 156 | 156 | getHistorySpan :: HUG.HomeUnitGraph -> History -> IO SrcSpan
|
| 157 | 157 | getHistorySpan hug hist = do
|
| ... | ... | @@ -63,7 +63,7 @@ import GHC.StgToCmm.Closure ( NonVoid(..), fromNonVoid, idPrimRepU, |
| 63 | 63 | assertNonVoidIds, assertNonVoidStgArgs )
|
| 64 | 64 | import GHC.StgToCmm.Layout
|
| 65 | 65 | import GHC.Runtime.Heap.Layout hiding (WordOff, ByteOff, wordsToBytes)
|
| 66 | -import GHC.Runtime.Interpreter ( interpreterProfiled )
|
|
| 66 | +import GHC.Runtime.Interpreter ( interpreterProfiled, readIModModBreaks )
|
|
| 67 | 67 | import GHC.Data.Bitmap
|
| 68 | 68 | import GHC.Data.FlatBag as FlatBag
|
| 69 | 69 | import GHC.Data.OrdList
|
| ... | ... | @@ -99,6 +99,7 @@ import GHC.CoreToIface |
| 99 | 99 | import Control.Monad.IO.Class
|
| 100 | 100 | import Control.Monad.Trans.Reader (ReaderT(..))
|
| 101 | 101 | import Control.Monad.Trans.State (StateT(..))
|
| 102 | +import Data.Array ((!))
|
|
| 102 | 103 | |
| 103 | 104 | -- -----------------------------------------------------------------------------
|
| 104 | 105 | -- Generating byte code for a complete module
|
| ... | ... | @@ -393,26 +394,28 @@ schemeR_wrk fvs nm original_body (args, body) |
| 393 | 394 | -- | Introduce break instructions for ticked expressions.
|
| 394 | 395 | -- If no breakpoint information is available, the instruction is omitted.
|
| 395 | 396 | schemeER_wrk :: StackDepth -> BCEnv -> CgStgExpr -> BcM BCInstrList
|
| 396 | -schemeER_wrk d p (StgTick (Breakpoint tick_ty tick_id fvs) rhs) = do
|
|
| 397 | - code <- schemeE d 0 p rhs
|
|
| 398 | - mb_current_mod_breaks <- getCurrentModBreaks
|
|
| 399 | - case mb_current_mod_breaks of
|
|
| 400 | - -- if we're not generating ModBreaks for this module for some reason, we
|
|
| 401 | - -- can't store breakpoint occurrence information.
|
|
| 402 | - Nothing -> pure code
|
|
| 403 | - Just current_mod_breaks -> do
|
|
| 404 | - platform <- profilePlatform <$> getProfile
|
|
| 405 | - let idOffSets = getVarOffSets platform d p fvs
|
|
| 406 | - ty_vars = tyCoVarsOfTypesWellScoped (tick_ty:map idType fvs)
|
|
| 407 | - toWord :: Maybe (Id, WordOff) -> Maybe (Id, Word)
|
|
| 408 | - toWord = fmap (\(i, wo) -> (i, fromIntegral wo))
|
|
| 409 | - breakInfo = dehydrateCgBreakInfo ty_vars (map toWord idOffSets) tick_ty tick_id
|
|
| 397 | +schemeER_wrk d p (StgTick bp@(Breakpoint tick_ty tick_id fvs) rhs) = do
|
|
| 398 | + platform <- profilePlatform <$> getProfile
|
|
| 399 | + |
|
| 400 | + -- When we find a tick surrounding a case expression we introduce a new BRK_FUN
|
|
| 401 | + -- instruction at the start of the case *continuation*, in addition to the
|
|
| 402 | + -- usual BRK_FUN surrounding the StgCase)
|
|
| 403 | + -- TODO: FIX COMMENT
|
|
| 404 | + code <- withBreakTick bp $
|
|
| 405 | + schemeE d 0 p rhs
|
|
| 406 | + |
|
| 407 | + let idOffSets = getVarOffSets platform d p fvs
|
|
| 408 | + ty_vars = tyCoVarsOfTypesWellScoped (tick_ty:map idType fvs)
|
|
| 409 | + toWord :: Maybe (Id, WordOff) -> Maybe (Id, Word)
|
|
| 410 | + toWord = fmap (\(i, wo) -> (i, fromIntegral wo))
|
|
| 411 | + breakInfo = dehydrateCgBreakInfo ty_vars (map toWord idOffSets) tick_ty (Right tick_id)
|
|
| 412 | + |
|
| 413 | + mibi <- newBreakInfo breakInfo
|
|
| 410 | 414 | |
| 411 | - let info_mod = modBreaks_module current_mod_breaks
|
|
| 412 | - infox <- newBreakInfo breakInfo
|
|
| 415 | + return $ case mibi of
|
|
| 416 | + Nothing -> code
|
|
| 417 | + Just ibi -> BRK_FUN ibi `consOL` code
|
|
| 413 | 418 | |
| 414 | - let breakInstr = BRK_FUN (InternalBreakpointId info_mod infox)
|
|
| 415 | - return $ breakInstr `consOL` code
|
|
| 416 | 419 | schemeER_wrk d p rhs = schemeE d 0 p rhs
|
| 417 | 420 | |
| 418 | 421 | getVarOffSets :: Platform -> StackDepth -> BCEnv -> [Id] -> [Maybe (Id, WordOff)]
|
| ... | ... | @@ -1140,43 +1143,34 @@ doCase d s p scrut bndr alts |
| 1140 | 1143 | -- When an alt is entered, it assumes the returned value is
|
| 1141 | 1144 | -- on top of the itbl; see Note [Return convention for non-tuple values]
|
| 1142 | 1145 | -- for details.
|
| 1143 | - ret_frame_size_b :: StackDepth
|
|
| 1144 | - ret_frame_size_b | ubx_tuple_frame =
|
|
| 1145 | - (if profiling then 5 else 4) * wordSize platform
|
|
| 1146 | - | otherwise = 2 * wordSize platform
|
|
| 1146 | + ret_frame_size_w :: WordOff
|
|
| 1147 | + ret_frame_size_w | ubx_tuple_frame =
|
|
| 1148 | + if profiling then 5 else 4
|
|
| 1149 | + | otherwise = 2
|
|
| 1147 | 1150 | |
| 1148 | 1151 | -- The stack space used to save/restore the CCCS when profiling
|
| 1149 | 1152 | save_ccs_size_b | profiling &&
|
| 1150 | 1153 | not ubx_tuple_frame = 2 * wordSize platform
|
| 1151 | 1154 | | otherwise = 0
|
| 1152 | 1155 | |
| 1153 | - -- The size of the return frame info table pointer if one exists
|
|
| 1154 | - unlifted_itbl_size_b :: StackDepth
|
|
| 1155 | - unlifted_itbl_size_b | ubx_tuple_frame = wordSize platform
|
|
| 1156 | - | otherwise = 0
|
|
| 1157 | - |
|
| 1158 | 1156 | (bndr_size, call_info, args_offsets)
|
| 1159 | 1157 | | ubx_tuple_frame =
|
| 1160 | 1158 | let bndr_reps = typePrimRep (idType bndr)
|
| 1161 | 1159 | (call_info, args_offsets) =
|
| 1162 | 1160 | layoutNativeCall profile NativeTupleReturn 0 id bndr_reps
|
| 1163 | - in ( wordsToBytes platform (nativeCallSize call_info)
|
|
| 1161 | + in ( nativeCallSize call_info
|
|
| 1164 | 1162 | , call_info
|
| 1165 | 1163 | , args_offsets
|
| 1166 | 1164 | )
|
| 1167 | - | otherwise = ( wordsToBytes platform (idSizeW platform bndr)
|
|
| 1165 | + | otherwise = ( idSizeW platform bndr
|
|
| 1168 | 1166 | , voidTupleReturnInfo
|
| 1169 | 1167 | , []
|
| 1170 | 1168 | )
|
| 1171 | 1169 | |
| 1172 | - -- depth of stack after the return value has been pushed
|
|
| 1170 | + -- Depth of stack after the return value has been pushed
|
|
| 1171 | + -- This is the stack depth at the continuation.
|
|
| 1173 | 1172 | d_bndr =
|
| 1174 | - d + ret_frame_size_b + bndr_size
|
|
| 1175 | - |
|
| 1176 | - -- depth of stack after the extra info table for an unlifted return
|
|
| 1177 | - -- has been pushed, if any. This is the stack depth at the
|
|
| 1178 | - -- continuation.
|
|
| 1179 | - d_alts = d + ret_frame_size_b + bndr_size + unlifted_itbl_size_b
|
|
| 1173 | + d + wordsToBytes platform bndr_size
|
|
| 1180 | 1174 | |
| 1181 | 1175 | -- Env in which to compile the alts, not including
|
| 1182 | 1176 | -- any vars bound by the alts themselves
|
| ... | ... | @@ -1188,13 +1182,13 @@ doCase d s p scrut bndr alts |
| 1188 | 1182 | -- given an alt, return a discr and code for it.
|
| 1189 | 1183 | codeAlt :: CgStgAlt -> BcM (Discr, BCInstrList)
|
| 1190 | 1184 | codeAlt GenStgAlt{alt_con=DEFAULT,alt_bndrs=_,alt_rhs=rhs}
|
| 1191 | - = do rhs_code <- schemeE d_alts s p_alts rhs
|
|
| 1185 | + = do rhs_code <- schemeE d_bndr s p_alts rhs
|
|
| 1192 | 1186 | return (NoDiscr, rhs_code)
|
| 1193 | 1187 | |
| 1194 | 1188 | codeAlt alt@GenStgAlt{alt_con=_, alt_bndrs=bndrs, alt_rhs=rhs}
|
| 1195 | 1189 | -- primitive or nullary constructor alt: no need to UNPACK
|
| 1196 | 1190 | | null real_bndrs = do
|
| 1197 | - rhs_code <- schemeE d_alts s p_alts rhs
|
|
| 1191 | + rhs_code <- schemeE d_bndr s p_alts rhs
|
|
| 1198 | 1192 | return (my_discr alt, rhs_code)
|
| 1199 | 1193 | | isUnboxedTupleType bndr_ty || isUnboxedSumType bndr_ty =
|
| 1200 | 1194 | let bndr_ty = idPrimRepU . fromNonVoid
|
| ... | ... | @@ -1206,7 +1200,7 @@ doCase d s p scrut bndr alts |
| 1206 | 1200 | bndr_ty
|
| 1207 | 1201 | (assertNonVoidIds bndrs)
|
| 1208 | 1202 | |
| 1209 | - stack_bot = d_alts
|
|
| 1203 | + stack_bot = d_bndr
|
|
| 1210 | 1204 | |
| 1211 | 1205 | p' = Map.insertList
|
| 1212 | 1206 | [ (arg, tuple_start -
|
| ... | ... | @@ -1224,7 +1218,7 @@ doCase d s p scrut bndr alts |
| 1224 | 1218 | (addIdReps (assertNonVoidIds real_bndrs))
|
| 1225 | 1219 | size = WordOff tot_wds
|
| 1226 | 1220 | |
| 1227 | - stack_bot = d_alts + wordsToBytes platform size
|
|
| 1221 | + stack_bot = d_bndr + wordsToBytes platform size
|
|
| 1228 | 1222 | |
| 1229 | 1223 | -- convert offsets from Sp into offsets into the virtual stack
|
| 1230 | 1224 | p' = Map.insertList
|
| ... | ... | @@ -1324,22 +1318,53 @@ doCase d s p scrut bndr alts |
| 1324 | 1318 | alt_stuff <- mapM codeAlt alts
|
| 1325 | 1319 | alt_final0 <- mkMultiBranch maybe_ncons alt_stuff
|
| 1326 | 1320 | |
| 1327 | - let alt_final1
|
|
| 1328 | - | ubx_tuple_frame = SLIDE 0 2 `consOL` alt_final0
|
|
| 1329 | - | otherwise = alt_final0
|
|
| 1330 | - alt_final
|
|
| 1331 | - | gopt Opt_InsertBreakpoints (hsc_dflags hsc_env)
|
|
| 1332 | - -- See Note [Debugger: BRK_ALTS]
|
|
| 1333 | - = BRK_ALTS False `consOL` alt_final1
|
|
| 1334 | - | otherwise = alt_final1
|
|
| 1321 | + let
|
|
| 1322 | + |
|
| 1323 | + -- drop the stg_ctoi_*_info header...
|
|
| 1324 | + alt_final1 = SLIDE bndr_size ret_frame_size_w `consOL` alt_final0
|
|
| 1325 | + |
|
| 1326 | + -- after dropping the stg_ret_*_info header
|
|
| 1327 | + alt_final2
|
|
| 1328 | + | ubx_tuple_frame = SLIDE 0 3 `consOL` alt_final1
|
|
| 1329 | + | otherwise = SLIDE 0 1 `consOL` alt_final1
|
|
| 1330 | + |
|
| 1331 | + -- When entering a case continuation BCO, the stack is always headed
|
|
| 1332 | + -- by the stg_ret frame and the stg_ctoi frame that returned to it.
|
|
| 1333 | + -- See Note [Stack layout when entering run_BCO]
|
|
| 1334 | + --
|
|
| 1335 | + -- Right after the breakpoint instruction, a case continuation BCO
|
|
| 1336 | + -- drops the stg_ret and stg_ctoi frame headers (see alt_final1,
|
|
| 1337 | + -- alt_final2), leaving the stack with the scrutinee followed by the
|
|
| 1338 | + -- free variables (with depth==d_bndr)
|
|
| 1339 | + alt_final <- getLastBreakTick >>= \case
|
|
| 1340 | + Just (Breakpoint tick_ty tick_id fvs)
|
|
| 1341 | + | gopt Opt_InsertBreakpoints (hsc_dflags hsc_env)
|
|
| 1342 | + -- Construct an internal breakpoint to put at the start of this case
|
|
| 1343 | + -- continuation BCO.
|
|
| 1344 | + -- See Note [TODO]
|
|
| 1345 | + -> do
|
|
| 1346 | + internal_tick_loc <- makeCaseInternalBreakLoc tick_id
|
|
| 1347 | + |
|
| 1348 | + -- same fvs available in the case expression are available in the case continuation
|
|
| 1349 | + let idOffSets = getVarOffSets platform d p fvs
|
|
| 1350 | + ty_vars = tyCoVarsOfTypesWellScoped (tick_ty:map idType fvs)
|
|
| 1351 | + toWord :: Maybe (Id, WordOff) -> Maybe (Id, Word)
|
|
| 1352 | + toWord = fmap (\(i, wo) -> (i, fromIntegral wo))
|
|
| 1353 | + breakInfo = dehydrateCgBreakInfo ty_vars (map toWord idOffSets) tick_ty (Left internal_tick_loc)
|
|
| 1354 | + |
|
| 1355 | + mibi <- newBreakInfo breakInfo
|
|
| 1356 | + return $ case mibi of
|
|
| 1357 | + Nothing -> alt_final2
|
|
| 1358 | + Just ibi -> BRK_FUN ibi `consOL` alt_final2
|
|
| 1359 | + _ -> pure alt_final2
|
|
| 1335 | 1360 | |
| 1336 | 1361 | add_bco_name <- shouldAddBcoName
|
| 1337 | 1362 | let
|
| 1338 | 1363 | alt_bco_name = getName bndr
|
| 1339 | 1364 | alt_bco = mkProtoBCO platform add_bco_name alt_bco_name alt_final (Left alts)
|
| 1340 | 1365 | 0{-no arity-} bitmap_size bitmap True{-is alts-}
|
| 1341 | - scrut_code <- schemeE (d + ret_frame_size_b + save_ccs_size_b)
|
|
| 1342 | - (d + ret_frame_size_b + save_ccs_size_b)
|
|
| 1366 | + scrut_code <- schemeE (d + wordsToBytes platform ret_frame_size_w + save_ccs_size_b)
|
|
| 1367 | + (d + wordsToBytes platform ret_frame_size_w + save_ccs_size_b)
|
|
| 1343 | 1368 | p scrut
|
| 1344 | 1369 | if ubx_tuple_frame
|
| 1345 | 1370 | then do let tuple_bco = tupleBCO platform call_info args_offsets
|
| ... | ... | @@ -1351,6 +1376,24 @@ doCase d s p scrut bndr alts |
| 1351 | 1376 | _ -> panic "schemeE(StgCase).push_alts"
|
| 1352 | 1377 | in return (PUSH_ALTS alt_bco scrut_rep `consOL` scrut_code)
|
| 1353 | 1378 | |
| 1379 | +makeCaseInternalBreakLoc :: BreakpointId -> BcM InternalBreakLoc
|
|
| 1380 | +makeCaseInternalBreakLoc bid = do
|
|
| 1381 | + hug <- hsc_HUG <$> getHscEnv
|
|
| 1382 | + curr_mod <- getCurrentModule
|
|
| 1383 | + mb_mod_brks <- getCurrentModBreaks
|
|
| 1384 | + |
|
| 1385 | + -- TODO: Subtract the scrutinee loc from the case loc to get continuation loc
|
|
| 1386 | + InternalBreakLoc <$> case bid of
|
|
| 1387 | + BreakpointId{bi_tick_mod, bi_tick_index}
|
|
| 1388 | + | bi_tick_mod == curr_mod
|
|
| 1389 | + , Just these_mbs <- mb_mod_brks
|
|
| 1390 | + -> do
|
|
| 1391 | + return $ modBreaks_locs these_mbs ! bi_tick_index
|
|
| 1392 | + | otherwise
|
|
| 1393 | + -> do
|
|
| 1394 | + other_mbs <- liftIO $ readIModModBreaks hug bi_tick_mod
|
|
| 1395 | + return $ modBreaks_locs other_mbs ! bi_tick_index
|
|
| 1396 | + |
|
| 1354 | 1397 | {-
|
| 1355 | 1398 | Note [Debugger: BRK_ALTS]
|
| 1356 | 1399 | ~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -2619,6 +2662,7 @@ data BcM_Env |
| 2619 | 2662 | { bcm_hsc_env :: !HscEnv
|
| 2620 | 2663 | , bcm_module :: !Module -- current module (for breakpoints)
|
| 2621 | 2664 | , modBreaks :: !(Maybe ModBreaks)
|
| 2665 | + , last_bp_tick :: !(Maybe StgTickish)
|
|
| 2622 | 2666 | }
|
| 2623 | 2667 | |
| 2624 | 2668 | data BcM_State
|
| ... | ... | @@ -2637,7 +2681,7 @@ newtype BcM r = BcM (BcM_Env -> BcM_State -> IO (r, BcM_State)) |
| 2637 | 2681 | |
| 2638 | 2682 | runBc :: HscEnv -> Module -> Maybe ModBreaks -> BcM r -> IO (r, BcM_State)
|
| 2639 | 2683 | runBc hsc_env this_mod mbs (BcM m)
|
| 2640 | - = m (BcM_Env hsc_env this_mod mbs) (BcM_State 0 0 IntMap.empty)
|
|
| 2684 | + = m (BcM_Env hsc_env this_mod mbs Nothing) (BcM_State 0 0 IntMap.empty)
|
|
| 2641 | 2685 | |
| 2642 | 2686 | instance HasDynFlags BcM where
|
| 2643 | 2687 | getDynFlags = hsc_dflags <$> getHscEnv
|
| ... | ... | @@ -2667,14 +2711,19 @@ getLabelsBc n = BcM $ \_ st -> |
| 2667 | 2711 | let ctr = nextlabel st
|
| 2668 | 2712 | in return (coerce [ctr .. ctr+n-1], st{nextlabel = ctr+n})
|
| 2669 | 2713 | |
| 2670 | -newBreakInfo :: CgBreakInfo -> BcM Int
|
|
| 2671 | -newBreakInfo info = BcM $ \_ st ->
|
|
| 2672 | - let ix = breakInfoIdx st
|
|
| 2673 | - st' = st
|
|
| 2674 | - { breakInfo = IntMap.insert ix info (breakInfo st)
|
|
| 2675 | - , breakInfoIdx = ix + 1
|
|
| 2676 | - }
|
|
| 2677 | - in return (ix, st')
|
|
| 2714 | +newBreakInfo :: CgBreakInfo -> BcM (Maybe InternalBreakpointId)
|
|
| 2715 | +newBreakInfo info = BcM $ \env st -> do
|
|
| 2716 | + -- if we're not generating ModBreaks for this module for some reason, we
|
|
| 2717 | + -- can't store breakpoint occurrence information.
|
|
| 2718 | + case modBreaks env of
|
|
| 2719 | + Nothing -> pure (Nothing, st)
|
|
| 2720 | + Just modBreaks -> do
|
|
| 2721 | + let ix = breakInfoIdx st
|
|
| 2722 | + st' = st
|
|
| 2723 | + { breakInfo = IntMap.insert ix info (breakInfo st)
|
|
| 2724 | + , breakInfoIdx = ix + 1
|
|
| 2725 | + }
|
|
| 2726 | + return (Just $ InternalBreakpointId (modBreaks_module modBreaks) ix, st')
|
|
| 2678 | 2727 | |
| 2679 | 2728 | getCurrentModule :: BcM Module
|
| 2680 | 2729 | getCurrentModule = BcM $ \env st -> return (bcm_module env, st)
|
| ... | ... | @@ -2682,12 +2731,20 @@ getCurrentModule = BcM $ \env st -> return (bcm_module env, st) |
| 2682 | 2731 | getCurrentModBreaks :: BcM (Maybe ModBreaks)
|
| 2683 | 2732 | getCurrentModBreaks = BcM $ \env st -> return (modBreaks env, st)
|
| 2684 | 2733 | |
| 2734 | +withBreakTick :: StgTickish -> BcM a -> BcM a
|
|
| 2735 | +withBreakTick bp (BcM act) = BcM $ \env st ->
|
|
| 2736 | + act env{last_bp_tick=Just bp} st
|
|
| 2737 | + |
|
| 2738 | +getLastBreakTick :: BcM (Maybe StgTickish)
|
|
| 2739 | +getLastBreakTick = BcM $ \env st ->
|
|
| 2740 | + pure (last_bp_tick env, st)
|
|
| 2741 | + |
|
| 2685 | 2742 | tickFS :: FastString
|
| 2686 | 2743 | tickFS = fsLit "ticked"
|
| 2687 | 2744 | |
| 2688 | 2745 | -- Dehydrating CgBreakInfo
|
| 2689 | 2746 | |
| 2690 | -dehydrateCgBreakInfo :: [TyVar] -> [Maybe (Id, Word)] -> Type -> BreakpointId -> CgBreakInfo
|
|
| 2747 | +dehydrateCgBreakInfo :: [TyVar] -> [Maybe (Id, Word)] -> Type -> Either InternalBreakLoc BreakpointId -> CgBreakInfo
|
|
| 2691 | 2748 | dehydrateCgBreakInfo ty_vars idOffSets tick_ty bid =
|
| 2692 | 2749 | CgBreakInfo
|
| 2693 | 2750 | { cgb_tyvars = map toIfaceTvBndr ty_vars
|
| ... | ... | @@ -45,7 +45,7 @@ import GHC.Runtime.Eval (mkTopLevEnv) |
| 45 | 45 | import GHC.Runtime.Eval.Utils
|
| 46 | 46 | |
| 47 | 47 | -- The GHC interface
|
| 48 | -import GHC.ByteCode.Breakpoints (imodBreaks_modBreaks, InternalBreakpointId(..), getBreakSourceId)
|
|
| 48 | +import GHC.ByteCode.Breakpoints (imodBreaks_modBreaks, InternalBreakpointId(..), getBreakSourceId, getBreakSourceMod)
|
|
| 49 | 49 | import GHC.Runtime.Interpreter
|
| 50 | 50 | import GHCi.RemoteTypes
|
| 51 | 51 | import GHCi.BreakArray( breakOn, breakOff )
|
| ... | ... | @@ -1621,7 +1621,7 @@ toBreakIdAndLocation (Just inf) = do |
| 1621 | 1621 | brks <- liftIO $ readIModBreaks hug inf
|
| 1622 | 1622 | let bi = getBreakSourceId inf brks
|
| 1623 | 1623 | return $ listToMaybe [ id_loc | id_loc@(_,loc) <- IntMap.assocs (breaks st),
|
| 1624 | - breakId loc == bi ]
|
|
| 1624 | + Right (breakId loc) == bi ]
|
|
| 1625 | 1625 | |
| 1626 | 1626 | printStoppedAtBreakInfo :: GHC.GhcMonad m => Resume -> [Name] -> m ()
|
| 1627 | 1627 | printStoppedAtBreakInfo res names = do
|
| ... | ... | @@ -3825,7 +3825,7 @@ pprStopped res = do |
| 3825 | 3825 | hug <- hsc_HUG <$> GHC.getSession
|
| 3826 | 3826 | brks <- liftIO $ readIModBreaks hug ibi
|
| 3827 | 3827 | return $ Just $ moduleName $
|
| 3828 | - bi_tick_mod $ getBreakSourceId ibi brks
|
|
| 3828 | + getBreakSourceMod ibi brks
|
|
| 3829 | 3829 | return $
|
| 3830 | 3830 | text "Stopped in"
|
| 3831 | 3831 | <+> ((case mb_mod_name of
|
| ... | ... | @@ -362,6 +362,14 @@ withBreakAction opts breakMVar statusMVar mtid act |
| 362 | 362 | info_mod_uid <- BS.packCString (Ptr info_mod_uid#)
|
| 363 | 363 | pure (Just (EvalBreakpoint info_mod info_mod_uid (I# infox#)))
|
| 364 | 364 | putMVar statusMVar $ EvalBreak apStack_r breakpoint resume_r ccs
|
| 365 | + |
|
| 366 | + -- Block until this thread is resumed (by the thread which took the
|
|
| 367 | + -- `ResumeContext` from the `statusMVar`).
|
|
| 368 | + --
|
|
| 369 | + -- The `onBreak` function must have been called from `rts/Interpreter.c`
|
|
| 370 | + -- when interpreting a `BRK_FUN`. After taking from the MVar, the function
|
|
| 371 | + -- returns to the continuation on the stack which is where the interpreter
|
|
| 372 | + -- was stopped.
|
|
| 365 | 373 | takeMVar breakMVar
|
| 366 | 374 | |
| 367 | 375 | resetBreakAction stablePtr = do
|
| ... | ... | @@ -284,6 +284,30 @@ allocate_NONUPD (Capability *cap, int n_words) |
| 284 | 284 | return allocate(cap, stg_max(sizeofW(StgHeader)+MIN_PAYLOAD_SIZE, n_words));
|
| 285 | 285 | }
|
| 286 | 286 | |
| 287 | +STATIC_INLINE int
|
|
| 288 | +is_ctoi_nontuple_frame(const StgPtr frame_head) {
|
|
| 289 | + return (
|
|
| 290 | + (W_)frame_head == (W_)&stg_ctoi_R1p_info ||
|
|
| 291 | + (W_)frame_head == (W_)&stg_ctoi_R1n_info ||
|
|
| 292 | + (W_)frame_head == (W_)&stg_ctoi_F1_info ||
|
|
| 293 | + (W_)frame_head == (W_)&stg_ctoi_D1_info ||
|
|
| 294 | + (W_)frame_head == (W_)&stg_ctoi_L1_info ||
|
|
| 295 | + (W_)frame_head == (W_)&stg_ctoi_V_info
|
|
| 296 | + );
|
|
| 297 | +}
|
|
| 298 | + |
|
| 299 | +STATIC_INLINE int
|
|
| 300 | +is_ret_bco_frame(const StgPtr frame_head) {
|
|
| 301 | + return ( (W_)frame_head == (W_)&stg_ret_t_info
|
|
| 302 | + || (W_)frame_head == (W_)&stg_ret_v_info
|
|
| 303 | + || (W_)frame_head == (W_)&stg_ret_p_info
|
|
| 304 | + || (W_)frame_head == (W_)&stg_ret_n_info
|
|
| 305 | + || (W_)frame_head == (W_)&stg_ret_f_info
|
|
| 306 | + || (W_)frame_head == (W_)&stg_ret_d_info
|
|
| 307 | + || (W_)frame_head == (W_)&stg_ret_l_info
|
|
| 308 | + );
|
|
| 309 | +}
|
|
| 310 | + |
|
| 287 | 311 | int rts_stop_on_exception = 0;
|
| 288 | 312 | |
| 289 | 313 | /* ---------------------------------------------------------------------------
|
| ... | ... | @@ -692,8 +716,13 @@ interpretBCO (Capability* cap) |
| 692 | 716 | StgPtr restoreStackPointer = Sp;
|
| 693 | 717 | |
| 694 | 718 | /* The first BCO on the stack is the one we are already stopped at.
|
| 695 | - * Skip it. */
|
|
| 696 | - Sp = SafeSpWP(stack_frame_sizeW((StgClosure *)Sp));
|
|
| 719 | + * Skip it. In the case of returning to a case cont. BCO, there are two
|
|
| 720 | + * frames to skip before we reach the first continuation frame.
|
|
| 721 | + * */
|
|
| 722 | + int to_skip = is_ret_bco_frame((StgPtr)SpW(0)) ? 2 : 1;
|
|
| 723 | + for (int i = 0; i < to_skip; i++) {
|
|
| 724 | + Sp = SafeSpWP(stack_frame_sizeW((StgClosure *)Sp));
|
|
| 725 | + }
|
|
| 697 | 726 | |
| 698 | 727 | /* Traverse upwards until continuation BCO, or the end */
|
| 699 | 728 | while ((type = get_itbl((StgClosure*)Sp)->type) != RET_BCO
|
| ... | ... | @@ -844,7 +873,6 @@ eval_obj: |
| 844 | 873 | debugBelch("\n\n");
|
| 845 | 874 | );
|
| 846 | 875 | |
| 847 | -// IF_DEBUG(sanity,checkStackChunk(Sp, cap->r.rCurrentTSO->stack+cap->r.rCurrentTSO->stack_size));
|
|
| 848 | 876 | IF_DEBUG(sanity,checkStackFrame(Sp));
|
| 849 | 877 | |
| 850 | 878 | switch ( get_itbl(obj)->type ) {
|
| ... | ... | @@ -1086,11 +1114,33 @@ do_return_pointer: |
| 1086 | 1114 | // Returning to an interpreted continuation: put the object on
|
| 1087 | 1115 | // the stack, and start executing the BCO.
|
| 1088 | 1116 | INTERP_TICK(it_retto_BCO);
|
| 1089 | - Sp_subW(1);
|
|
| 1090 | - SpW(0) = (W_)tagged_obj;
|
|
| 1091 | - obj = (StgClosure*)ReadSpW(2);
|
|
| 1117 | + obj = (StgClosure*)ReadSpW(1);
|
|
| 1092 | 1118 | ASSERT(get_itbl(obj)->type == BCO);
|
| 1093 | - goto run_BCO_return_pointer;
|
|
| 1119 | + |
|
| 1120 | + // Heap check
|
|
| 1121 | + if (doYouWantToGC(cap)) {
|
|
| 1122 | + Sp_subW(2);
|
|
| 1123 | + SpW(1) = (W_)tagged_obj;
|
|
| 1124 | + SpW(0) = (W_)&stg_ret_p_info;
|
|
| 1125 | + RETURN_TO_SCHEDULER(ThreadInterpret, HeapOverflow);
|
|
| 1126 | + }
|
|
| 1127 | + else {
|
|
| 1128 | + |
|
| 1129 | + // Stack checks aren't necessary at return points, the stack use
|
|
| 1130 | + // is aggregated into the enclosing function entry point.
|
|
| 1131 | + |
|
| 1132 | + // Make sure stack is headed by a ctoi R1p frame when returning a pointer
|
|
| 1133 | + ASSERT(ReadSpW(0) == (W_)&stg_ctoi_R1p_info);
|
|
| 1134 | + |
|
| 1135 | + // Add the return frame on top of the args
|
|
| 1136 | + Sp_subW(2);
|
|
| 1137 | + SpW(1) = (W_)tagged_obj;
|
|
| 1138 | + SpW(0) = (W_)&stg_ret_p_info;
|
|
| 1139 | + }
|
|
| 1140 | + |
|
| 1141 | + /* Keep the ret frame and the ctoi frame for run_BCO.
|
|
| 1142 | + * See Note [Stack layout when entering run_BCO] */
|
|
| 1143 | + goto run_BCO;
|
|
| 1094 | 1144 | |
| 1095 | 1145 | default:
|
| 1096 | 1146 | do_return_unrecognised:
|
| ... | ... | @@ -1159,8 +1209,9 @@ do_return_nonpointer: |
| 1159 | 1209 | |
| 1160 | 1210 | // get the offset of the header of the next stack frame
|
| 1161 | 1211 | offset = stack_frame_sizeW((StgClosure *)Sp);
|
| 1212 | + StgClosure* next_frame = (StgClosure*)(SafeSpWP(offset));
|
|
| 1162 | 1213 | |
| 1163 | - switch (get_itbl((StgClosure*)(SafeSpWP(offset)))->type) {
|
|
| 1214 | + switch (get_itbl(next_frame)->type) {
|
|
| 1164 | 1215 | |
| 1165 | 1216 | case RET_BCO:
|
| 1166 | 1217 | // Returning to an interpreted continuation: pop the return frame
|
| ... | ... | @@ -1168,8 +1219,58 @@ do_return_nonpointer: |
| 1168 | 1219 | // executing the BCO.
|
| 1169 | 1220 | INTERP_TICK(it_retto_BCO);
|
| 1170 | 1221 | obj = (StgClosure*)ReadSpW(offset+1);
|
| 1222 | + |
|
| 1171 | 1223 | ASSERT(get_itbl(obj)->type == BCO);
|
| 1172 | - goto run_BCO_return_nonpointer;
|
|
| 1224 | + |
|
| 1225 | + // Heap check
|
|
| 1226 | + if (doYouWantToGC(cap)) {
|
|
| 1227 | + RETURN_TO_SCHEDULER(ThreadInterpret, HeapOverflow);
|
|
| 1228 | + }
|
|
| 1229 | + else {
|
|
| 1230 | + // Stack checks aren't necessary at return points, the stack use
|
|
| 1231 | + // is aggregated into the enclosing function entry point.
|
|
| 1232 | + |
|
| 1233 | +#if defined(PROFILING)
|
|
| 1234 | + /*
|
|
| 1235 | + Restore the current cost centre stack if a tuple is being returned.
|
|
| 1236 | + |
|
| 1237 | + When a "simple" unlifted value is returned, the cccs is restored with
|
|
| 1238 | + an stg_restore_cccs frame on the stack, for example:
|
|
| 1239 | + |
|
| 1240 | + ...
|
|
| 1241 | + stg_ctoi_D1
|
|
| 1242 | + <CCCS>
|
|
| 1243 | + stg_restore_cccs
|
|
| 1244 | + |
|
| 1245 | + But stg_restore_cccs cannot deal with tuples, which may have more
|
|
| 1246 | + things on the stack. Therefore we store the CCCS inside the
|
|
| 1247 | + stg_ctoi_t frame.
|
|
| 1248 | + |
|
| 1249 | + If we have a tuple being returned, the stack looks like this:
|
|
| 1250 | + |
|
| 1251 | + ...
|
|
| 1252 | + <CCCS> <- to restore, Sp offset <next frame + 4 words>
|
|
| 1253 | + tuple_BCO
|
|
| 1254 | + tuple_info
|
|
| 1255 | + cont_BCO
|
|
| 1256 | + stg_ctoi_t <- next frame
|
|
| 1257 | + tuple_data_1
|
|
| 1258 | + ...
|
|
| 1259 | + tuple_data_n
|
|
| 1260 | + tuple_info
|
|
| 1261 | + tuple_BCO
|
|
| 1262 | + stg_ret_t <- Sp
|
|
| 1263 | + */
|
|
| 1264 | + |
|
| 1265 | + if(SpW(0) == (W_)&stg_ret_t_info) {
|
|
| 1266 | + cap->r.rCCCS = (CostCentreStack*)ReadSpW(offset + 4);
|
|
| 1267 | + }
|
|
| 1268 | +#endif
|
|
| 1269 | + |
|
| 1270 | + /* Keep the ret frame and the ctoi frame for run_BCO.
|
|
| 1271 | + * See Note [Stack layout when entering run_BCO] */
|
|
| 1272 | + goto run_BCO;
|
|
| 1273 | + }
|
|
| 1173 | 1274 | |
| 1174 | 1275 | default:
|
| 1175 | 1276 | {
|
| ... | ... | @@ -1332,111 +1433,90 @@ do_apply: |
| 1332 | 1433 | RETURN_TO_SCHEDULER_NO_PAUSE(ThreadRunGHC, ThreadYielding);
|
| 1333 | 1434 | }
|
| 1334 | 1435 | |
| 1335 | - // ------------------------------------------------------------------------
|
|
| 1336 | - // Ok, we now have a bco (obj), and its arguments are all on the
|
|
| 1337 | - // stack. We can start executing the byte codes.
|
|
| 1338 | - //
|
|
| 1339 | - // The stack is in one of two states. First, if this BCO is a
|
|
| 1340 | - // function:
|
|
| 1341 | - //
|
|
| 1342 | - // | .... |
|
|
| 1343 | - // +---------------+
|
|
| 1344 | - // | arg2 |
|
|
| 1345 | - // +---------------+
|
|
| 1346 | - // | arg1 |
|
|
| 1347 | - // +---------------+
|
|
| 1348 | - //
|
|
| 1349 | - // Second, if this BCO is a continuation:
|
|
| 1350 | - //
|
|
| 1351 | - // | .... |
|
|
| 1352 | - // +---------------+
|
|
| 1353 | - // | fv2 |
|
|
| 1354 | - // +---------------+
|
|
| 1355 | - // | fv1 |
|
|
| 1356 | - // +---------------+
|
|
| 1357 | - // | BCO |
|
|
| 1358 | - // +---------------+
|
|
| 1359 | - // | stg_ctoi_ret_ |
|
|
| 1360 | - // +---------------+
|
|
| 1361 | - // | retval |
|
|
| 1362 | - // +---------------+
|
|
| 1363 | - //
|
|
| 1364 | - // where retval is the value being returned to this continuation.
|
|
| 1365 | - // In the event of a stack check, heap check, or context switch,
|
|
| 1366 | - // we need to leave the stack in a sane state so the garbage
|
|
| 1367 | - // collector can find all the pointers.
|
|
| 1368 | - //
|
|
| 1369 | - // (1) BCO is a function: the BCO's bitmap describes the
|
|
| 1370 | - // pointerhood of the arguments.
|
|
| 1371 | - //
|
|
| 1372 | - // (2) BCO is a continuation: BCO's bitmap describes the
|
|
| 1373 | - // pointerhood of the free variables.
|
|
| 1374 | - //
|
|
| 1375 | - // Sadly we have three different kinds of stack/heap/cswitch check
|
|
| 1376 | - // to do:
|
|
| 1377 | - |
|
| 1378 | - |
|
| 1379 | -run_BCO_return_pointer:
|
|
| 1380 | - // Heap check
|
|
| 1381 | - if (doYouWantToGC(cap)) {
|
|
| 1382 | - Sp_subW(1); SpW(0) = (W_)&stg_ret_p_info;
|
|
| 1383 | - RETURN_TO_SCHEDULER(ThreadInterpret, HeapOverflow);
|
|
| 1384 | - }
|
|
| 1385 | - // Stack checks aren't necessary at return points, the stack use
|
|
| 1386 | - // is aggregated into the enclosing function entry point.
|
|
| 1387 | - |
|
| 1388 | - goto run_BCO;
|
|
| 1389 | - |
|
| 1390 | -run_BCO_return_nonpointer:
|
|
| 1391 | - // Heap check
|
|
| 1392 | - if (doYouWantToGC(cap)) {
|
|
| 1393 | - RETURN_TO_SCHEDULER(ThreadInterpret, HeapOverflow);
|
|
| 1394 | - }
|
|
| 1395 | - // Stack checks aren't necessary at return points, the stack use
|
|
| 1396 | - // is aggregated into the enclosing function entry point.
|
|
| 1397 | - |
|
| 1398 | -#if defined(PROFILING)
|
|
| 1399 | - /*
|
|
| 1400 | - Restore the current cost centre stack if a tuple is being returned.
|
|
| 1401 | - |
|
| 1402 | - When a "simple" unlifted value is returned, the cccs is restored with
|
|
| 1403 | - an stg_restore_cccs frame on the stack, for example:
|
|
| 1404 | - |
|
| 1405 | - ...
|
|
| 1406 | - stg_ctoi_D1
|
|
| 1407 | - <CCCS>
|
|
| 1408 | - stg_restore_cccs
|
|
| 1409 | - |
|
| 1410 | - But stg_restore_cccs cannot deal with tuples, which may have more
|
|
| 1411 | - things on the stack. Therefore we store the CCCS inside the
|
|
| 1412 | - stg_ctoi_t frame.
|
|
| 1413 | - |
|
| 1414 | - If we have a tuple being returned, the stack looks like this:
|
|
| 1415 | - |
|
| 1416 | - ...
|
|
| 1417 | - <CCCS> <- to restore, Sp offset <next frame + 4 words>
|
|
| 1418 | - tuple_BCO
|
|
| 1419 | - tuple_info
|
|
| 1420 | - cont_BCO
|
|
| 1421 | - stg_ctoi_t <- next frame
|
|
| 1422 | - tuple_data_1
|
|
| 1423 | - ...
|
|
| 1424 | - tuple_data_n
|
|
| 1425 | - tuple_info
|
|
| 1426 | - tuple_BCO
|
|
| 1427 | - stg_ret_t <- Sp
|
|
| 1428 | - */
|
|
| 1429 | - |
|
| 1430 | - if(SpW(0) == (W_)&stg_ret_t_info) {
|
|
| 1431 | - cap->r.rCCCS = (CostCentreStack*)ReadSpW(stack_frame_sizeW((StgClosure *)Sp) + 4);
|
|
| 1432 | - }
|
|
| 1433 | -#endif
|
|
| 1434 | - |
|
| 1435 | - if (SpW(0) != (W_)&stg_ret_t_info) {
|
|
| 1436 | - Sp_addW(1);
|
|
| 1437 | - }
|
|
| 1438 | - goto run_BCO;
|
|
| 1436 | +/*
|
|
| 1437 | +Note [Stack layout when entering run_BCO]
|
|
| 1438 | +-----------------------------------------
|
|
| 1439 | +We have a bco (obj), and its arguments are all on the stack. We can start
|
|
| 1440 | +executing the byte codes.
|
|
| 1441 | + |
|
| 1442 | +The stack is in one of two states. First, if this BCO is a
|
|
| 1443 | +function (in run_BCO_fun or run_BCO)
|
|
| 1444 | + |
|
| 1445 | + | .... |
|
|
| 1446 | + +---------------+
|
|
| 1447 | + | arg2 |
|
|
| 1448 | + +---------------+
|
|
| 1449 | + | arg1 |
|
|
| 1450 | + +---------------+
|
|
| 1451 | + |
|
| 1452 | +Second, if this BCO is a case cont., as per Note [Case continuation BCOs] (only
|
|
| 1453 | +in run_BCO):
|
|
| 1454 | + |
|
| 1455 | + | .... |
|
|
| 1456 | + +---------------+
|
|
| 1457 | + | fv2 |
|
|
| 1458 | + +---------------+
|
|
| 1459 | + | fv1 |
|
|
| 1460 | + +---------------+
|
|
| 1461 | + | BCO |
|
|
| 1462 | + +---------------+
|
|
| 1463 | + | stg_ctoi_ret_ |
|
|
| 1464 | + +---------------+
|
|
| 1465 | + | retval |
|
|
| 1466 | + +---------------+
|
|
| 1467 | + | stg_ret_..... |
|
|
| 1468 | + +---------------+
|
|
| 1469 | + |
|
| 1470 | +where retval is the value being returned to this continuation.
|
|
| 1471 | +In the event of a stack check, heap check, context switch,
|
|
| 1472 | +or breakpoint, we need to leave the stack in a sane state so
|
|
| 1473 | +the garbage collector can find all the pointers.
|
|
| 1474 | + |
|
| 1475 | + (1) BCO is a function: the BCO's bitmap describes the
|
|
| 1476 | + pointerhood of the arguments.
|
|
| 1477 | + |
|
| 1478 | + (2) BCO is a continuation: BCO's bitmap describes the
|
|
| 1479 | + pointerhood of the free variables.
|
|
| 1480 | + |
|
| 1481 | +To reconstruct a valid stack state for yielding (such that when we return to
|
|
| 1482 | +the interpreter we end up in the same place from where we yielded), we need to
|
|
| 1483 | +differentiate the two cases again:
|
|
| 1484 | + |
|
| 1485 | + (1) For function BCOs, the arguments are directly on top of the stack, so it
|
|
| 1486 | + suffices to add a `stg_apply_interp_info` frame header using the BCO that is
|
|
| 1487 | + being applied to these arguments (i.e. the `obj` being run)
|
|
| 1488 | + |
|
| 1489 | + (2) For continuation BCOs, the stack is already consistent -- that's why we
|
|
| 1490 | + keep the ret and ctoi frame on top of the stack when we start executing it.
|
|
| 1491 | + |
|
| 1492 | + We couldn't reconstruct a valid stack that resumes the case continuation
|
|
| 1493 | + execution just from the return and free vars values alone because we wouldn't
|
|
| 1494 | + know what kind of result it was (are we returning a pointer, non pointer int,
|
|
| 1495 | + a tuple? etc.); especially considering some frames have different sizes,
|
|
| 1496 | + notably unboxed tuple return frames (see Note [unboxed tuple bytecodes and tuple_BCO]).
|
|
| 1497 | + |
|
| 1498 | + For consistency, the first instructions in a case continuation BCO, right
|
|
| 1499 | + after a possible BRK_FUN heading it, are two SLIDEs to remove the stg_ret_
|
|
| 1500 | + and stg_ctoi_ frame headers, leaving only the return value followed by the
|
|
| 1501 | + free vars. Theses slides use statically known offsets computed in StgToByteCode.hs.
|
|
| 1502 | + Following the continuation BCO diagram above, SLIDING would result in:
|
|
| 1503 | + |
|
| 1504 | + | .... |
|
|
| 1505 | + +---------------+
|
|
| 1506 | + | fv2 |
|
|
| 1507 | + +---------------+
|
|
| 1508 | + | fv1 |
|
|
| 1509 | + +---------------+
|
|
| 1510 | + | retval |
|
|
| 1511 | + +---------------+
|
|
| 1512 | +*/
|
|
| 1439 | 1513 | |
| 1514 | +// Ok, we now have a bco (obj), and its arguments are all on the stack as
|
|
| 1515 | +// described by Note [Stack layout when entering run_BCO].
|
|
| 1516 | +// We can start executing the byte codes.
|
|
| 1517 | +//
|
|
| 1518 | +// Sadly we have three different kinds of stack/heap/cswitch check
|
|
| 1519 | +// to do:
|
|
| 1440 | 1520 | run_BCO_fun:
|
| 1441 | 1521 | IF_DEBUG(sanity,
|
| 1442 | 1522 | Sp_subW(2);
|
| ... | ... | @@ -1466,6 +1546,7 @@ run_BCO_fun: |
| 1466 | 1546 | |
| 1467 | 1547 | // Now, actually interpret the BCO... (no returning to the
|
| 1468 | 1548 | // scheduler again until the stack is in an orderly state).
|
| 1549 | + // See also Note [Stack layout when entering run_BCO]
|
|
| 1469 | 1550 | run_BCO:
|
| 1470 | 1551 | INTERP_TICK(it_BCO_entries);
|
| 1471 | 1552 | {
|
| ... | ... | @@ -1519,7 +1600,7 @@ run_BCO: |
| 1519 | 1600 | |
| 1520 | 1601 | switch (bci & 0xFF) {
|
| 1521 | 1602 | |
| 1522 | - /* check for a breakpoint on the beginning of a let binding */
|
|
| 1603 | + /* check for a breakpoint on the beginning of a BCO */
|
|
| 1523 | 1604 | case bci_BRK_FUN:
|
| 1524 | 1605 | {
|
| 1525 | 1606 | W_ arg1_brk_array, arg2_info_mod_name, arg3_info_mod_id, arg4_info_index;
|
| ... | ... | @@ -1572,6 +1653,13 @@ run_BCO: |
| 1572 | 1653 | {
|
| 1573 | 1654 | breakPoints = (StgArrBytes *) BCO_PTR(arg1_brk_array);
|
| 1574 | 1655 | |
| 1656 | + StgPtr stack_head = (StgPtr)SpW(0);
|
|
| 1657 | + |
|
| 1658 | + // When the BRK_FUN is at the start of a case continuation BCO,
|
|
| 1659 | + // the stack is headed by the frame returning the value at the start.
|
|
| 1660 | + // See Note [Stack layout when entering run_BCO]
|
|
| 1661 | + int is_case_cont_BCO = is_ret_bco_frame(stack_head);
|
|
| 1662 | + |
|
| 1575 | 1663 | // stop the current thread if either `stop_next_breakpoint` is
|
| 1576 | 1664 | // true OR if the ignore count for this particular breakpoint is zero
|
| 1577 | 1665 | StgInt ignore_count = ((StgInt*)breakPoints->payload)[arg4_info_index];
|
| ... | ... | @@ -1580,36 +1668,96 @@ run_BCO: |
| 1580 | 1668 | // decrement and write back ignore count
|
| 1581 | 1669 | ((StgInt*)breakPoints->payload)[arg4_info_index] = --ignore_count;
|
| 1582 | 1670 | }
|
| 1583 | - else if (stop_next_breakpoint == true || ignore_count == 0)
|
|
| 1671 | + else if (
|
|
| 1672 | + /* Doing step-in (but don't stop at case continuation BCOs,
|
|
| 1673 | + * those are only useful when stepping out) */
|
|
| 1674 | + (stop_next_breakpoint == true && !is_case_cont_BCO)
|
|
| 1675 | + /* Or breakpoint is explicitly enabled */
|
|
| 1676 | + || ignore_count == 0)
|
|
| 1584 | 1677 | {
|
| 1585 | 1678 | // make sure we don't automatically stop at the
|
| 1586 | 1679 | // next breakpoint
|
| 1587 | 1680 | rts_stop_next_breakpoint = 0;
|
| 1588 | 1681 | cap->r.rCurrentTSO->flags &= ~TSO_STOP_NEXT_BREAKPOINT;
|
| 1589 | 1682 | |
| 1590 | - // allocate memory for a new AP_STACK, enough to
|
|
| 1591 | - // store the top stack frame plus an
|
|
| 1592 | - // stg_apply_interp_info pointer and a pointer to
|
|
| 1593 | - // the BCO
|
|
| 1594 | - size_words = BCO_BITMAP_SIZE(obj) + 2;
|
|
| 1595 | - new_aps = (StgAP_STACK *) allocate(cap, AP_STACK_sizeW(size_words));
|
|
| 1596 | - new_aps->size = size_words;
|
|
| 1597 | - new_aps->fun = &stg_dummy_ret_closure;
|
|
| 1598 | - |
|
| 1599 | - // fill in the payload of the AP_STACK
|
|
| 1600 | - new_aps->payload[0] = (StgClosure *)&stg_apply_interp_info;
|
|
| 1601 | - new_aps->payload[1] = (StgClosure *)obj;
|
|
| 1602 | - |
|
| 1603 | - // copy the contents of the top stack frame into the AP_STACK
|
|
| 1604 | - for (i = 2; i < size_words; i++)
|
|
| 1605 | - {
|
|
| 1606 | - new_aps->payload[i] = (StgClosure *)ReadSpW(i-2);
|
|
| 1683 | + /* To yield execution we need to come up with a consistent AP_STACK
|
|
| 1684 | + * to store in the :history data structure.
|
|
| 1685 | + */
|
|
| 1686 | + if (is_case_cont_BCO) {
|
|
| 1687 | + |
|
| 1688 | + // If the BCO is a case cont. then the stack is headed by the
|
|
| 1689 | + // stg_ret and a stg_ctoi frames which caused this same BCO
|
|
| 1690 | + // to be run. This stack is already well-formed, so it
|
|
| 1691 | + // needs only to be copied to the AP_STACK.
|
|
| 1692 | + // See Note [Stack layout when entering run_BCO]
|
|
| 1693 | + |
|
| 1694 | + // stg_ret_*
|
|
| 1695 | + int size_returned_frame =
|
|
| 1696 | + ((W_)stack_head == (W_)&stg_ret_t_info)
|
|
| 1697 | + ? 2 /* ret_t + tuple_BCO */
|
|
| 1698 | + + /* Sp(2) is call_info which records the offset to the next frame
|
|
| 1699 | + * See also Note [unboxed tuple bytecodes and tuple_BCO] */
|
|
| 1700 | + ((ReadSpW(2) & 0xFF))
|
|
| 1701 | + : 2; /* ret_* + return value */
|
|
| 1702 | + |
|
| 1703 | + StgPtr cont_frame_head
|
|
| 1704 | + = (StgPtr)(SpW(size_returned_frame));
|
|
| 1705 | + ASSERT(obj == UNTAG_CLOSURE((StgClosure*)ReadSpW(size_returned_frame+1)));
|
|
| 1706 | + |
|
| 1707 | + // stg_ctoi_*
|
|
| 1708 | + int size_cont_frame_head =
|
|
| 1709 | + is_ctoi_nontuple_frame(cont_frame_head)
|
|
| 1710 | + ? 2 // info+bco
|
|
| 1711 | +#if defined(PROFILING)
|
|
| 1712 | + : 5; // or info+bco+tuple_info+tuple_BCO+CCS
|
|
| 1713 | +#else
|
|
| 1714 | + : 4; // or info+bco+tuple_info+tuple_BCO
|
|
| 1715 | +#endif
|
|
| 1716 | + |
|
| 1717 | + // Continuation stack is already well formed,
|
|
| 1718 | + // so just copy it whole to the AP_STACK
|
|
| 1719 | + size_words = size_returned_frame
|
|
| 1720 | + + size_cont_frame_head
|
|
| 1721 | + + BCO_BITMAP_SIZE(obj) /* payload of cont_frame */;
|
|
| 1722 | + new_aps = (StgAP_STACK *) allocate(cap, AP_STACK_sizeW(size_words));
|
|
| 1723 | + new_aps->size = size_words;
|
|
| 1724 | + new_aps->fun = &stg_dummy_ret_closure;
|
|
| 1725 | + |
|
| 1726 | + // (1) Fill in the payload of the AP_STACK:
|
|
| 1727 | + for (i = 0; i < size_words; i++) {
|
|
| 1728 | + new_aps->payload[i] = (StgClosure *)ReadSpW(i);
|
|
| 1729 | + }
|
|
| 1730 | + }
|
|
| 1731 | + else {
|
|
| 1732 | + |
|
| 1733 | + // The BCO is a function, therefore the arguments are
|
|
| 1734 | + // directly on top of the stack.
|
|
| 1735 | + // To construct a valid stack chunk simply add an
|
|
| 1736 | + // stg_apply_interp and the current BCO to the stack.
|
|
| 1737 | + // See also Note [Stack layout when entering run_BCO]
|
|
| 1738 | + |
|
| 1739 | + // (1) Allocate memory for a new AP_STACK, enough to store
|
|
| 1740 | + // the top stack frame plus an stg_apply_interp_info pointer
|
|
| 1741 | + // and a pointer to the BCO
|
|
| 1742 | + size_words = BCO_BITMAP_SIZE(obj) + 2;
|
|
| 1743 | + new_aps = (StgAP_STACK *) allocate(cap, AP_STACK_sizeW(size_words));
|
|
| 1744 | + new_aps->size = size_words;
|
|
| 1745 | + new_aps->fun = &stg_dummy_ret_closure;
|
|
| 1746 | + |
|
| 1747 | + // (1.1) the continuation frame
|
|
| 1748 | + new_aps->payload[0] = (StgClosure *)&stg_apply_interp_info;
|
|
| 1749 | + new_aps->payload[1] = (StgClosure *)obj;
|
|
| 1750 | + |
|
| 1751 | + // (1.2.1) copy the args/free vars of the top stack frame into the AP_STACK
|
|
| 1752 | + for (i = 2; i < size_words; i++) {
|
|
| 1753 | + new_aps->payload[i] = (StgClosure *)ReadSpW(i-2);
|
|
| 1754 | + }
|
|
| 1607 | 1755 | }
|
| 1608 | 1756 | |
| 1609 | 1757 | // No write barrier is needed here as this is a new allocation
|
| 1610 | 1758 | SET_HDR(new_aps,&stg_AP_STACK_info,cap->r.rCCCS);
|
| 1611 | 1759 | |
| 1612 | - // Arrange the stack to call the breakpoint IO action, and
|
|
| 1760 | + // (2) Arrange the stack to call the breakpoint IO action, and
|
|
| 1613 | 1761 | // continue execution of this BCO when the IO action returns.
|
| 1614 | 1762 | //
|
| 1615 | 1763 | // ioAction :: Addr# -- the breakpoint info module
|
| ... | ... | @@ -1622,12 +1770,27 @@ run_BCO: |
| 1622 | 1770 | ioAction = (StgClosure *) deRefStablePtr (
|
| 1623 | 1771 | rts_breakpoint_io_action);
|
| 1624 | 1772 | |
| 1625 | - Sp_subW(13);
|
|
| 1626 | - SpW(12) = (W_)obj;
|
|
| 1627 | - SpW(11) = (W_)&stg_apply_interp_info;
|
|
| 1773 | + // (2.1) Construct the continuation to which we'll return in
|
|
| 1774 | + // this thread after the `rts_breakpoint_io_action` returns.
|
|
| 1775 | + //
|
|
| 1776 | + // For case cont. BCOs, the continuation to re-run this BCO
|
|
| 1777 | + // is already first on the stack. For function BCOs we need
|
|
| 1778 | + // to add an `stg_apply_interp` apply to the current BCO.
|
|
| 1779 | + // See Note [Stack layout when entering run_BCO]
|
|
| 1780 | + if (!is_case_cont_BCO) {
|
|
| 1781 | + Sp_subW(2); // stg_apply_interp_info + StgBCO*
|
|
| 1782 | + |
|
| 1783 | + // (2.1.2) Write the continuation frame (above the stg_ret
|
|
| 1784 | + // frame if one exists)
|
|
| 1785 | + SpW(1) = (W_)obj;
|
|
| 1786 | + SpW(0) = (W_)&stg_apply_interp_info;
|
|
| 1787 | + }
|
|
| 1788 | + |
|
| 1789 | + // (2.2) The `rts_breakpoint_io_action` call
|
|
| 1790 | + Sp_subW(11);
|
|
| 1628 | 1791 | SpW(10) = (W_)new_aps;
|
| 1629 | - SpW(9) = (W_)False_closure; // True <=> an exception
|
|
| 1630 | - SpW(8) = (W_)&stg_ap_ppv_info;
|
|
| 1792 | + SpW(9) = (W_)False_closure; // True <=> an exception
|
|
| 1793 | + SpW(8) = (W_)&stg_ap_ppv_info;
|
|
| 1631 | 1794 | SpW(7) = (W_)arg4_info_index;
|
| 1632 | 1795 | SpW(6) = (W_)&stg_ap_n_info;
|
| 1633 | 1796 | SpW(5) = (W_)BCO_LIT(arg3_info_mod_id);
|
| ... | ... | @@ -8,35 +8,32 @@ _result :: |
| 8 | 8 | 10 foo True i = return i
|
| 9 | 9 | ^^^^^^^^
|
| 10 | 10 | 11 foo False _ = do
|
| 11 | -Stopped in Main.bar, T26042b.hs:21:3-10
|
|
| 11 | +Stopped in Main., T26042b.hs:20:3-17
|
|
| 12 | 12 | _result ::
|
| 13 | 13 | GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
| 14 | 14 | -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
| 15 | 15 | Int #) = _
|
| 16 | -y :: Int = _
|
|
| 16 | +19 let t = z * 2
|
|
| 17 | 17 | 20 y <- foo True t
|
| 18 | + ^^^^^^^^^^^^^^^
|
|
| 18 | 19 | 21 return y
|
| 19 | - ^^^^^^^^
|
|
| 20 | -22
|
|
| 21 | -Stopped in Main.foo, T26042b.hs:15:3-10
|
|
| 20 | +Stopped in Main., T26042b.hs:14:3-18
|
|
| 22 | 21 | _result ::
|
| 23 | 22 | GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
| 24 | 23 | -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
| 25 | 24 | Int #) = _
|
| 26 | -n :: Int = _
|
|
| 25 | +13 y = 4
|
|
| 27 | 26 | 14 n <- bar (x + y)
|
| 27 | + ^^^^^^^^^^^^^^^^
|
|
| 28 | 28 | 15 return n
|
| 29 | - ^^^^^^^^
|
|
| 30 | -16
|
|
| 31 | -Stopped in Main.main, T26042b.hs:6:3-9
|
|
| 29 | +Stopped in Main., T26042b.hs:5:3-26
|
|
| 32 | 30 | _result ::
|
| 33 | 31 | GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
| 34 | 32 | -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
| 35 | 33 | () #) = _
|
| 36 | -a :: Int = _
|
|
| 34 | +4 main = do
|
|
| 37 | 35 | 5 a <- foo False undefined
|
| 36 | + ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
| 38 | 37 | 6 print a
|
| 39 | - ^^^^^^^
|
|
| 40 | -7 print a
|
|
| 41 | 38 | 14
|
| 42 | 39 | 14 |
| ... | ... | @@ -14,15 +14,7 @@ main |
| 14 | 14 | -- we go straight to `main`.
|
| 15 | 15 | :stepout
|
| 16 | 16 | :list
|
| 17 | --- stepping out from here will stop in the thunk (TODO: WHY?)
|
|
| 18 | -:stepout
|
|
| 19 | -:list
|
|
| 20 | - |
|
| 21 | --- bring us back to main from the thunk (why were we stopped there?...)
|
|
| 22 | -:stepout
|
|
| 23 | -:list
|
|
| 24 | - |
|
| 25 | --- and finally out
|
|
| 17 | +-- stepping out from here will exit main
|
|
| 26 | 18 | :stepout
|
| 27 | 19 | |
| 28 | 20 | -- this test is also run with optimisation to make sure the IO bindings inline and we can stop at them |
| ... | ... | @@ -8,17 +8,14 @@ _result :: |
| 8 | 8 | 10 foo True i = return i
|
| 9 | 9 | ^^^^^^^^
|
| 10 | 10 | 11 foo False _ = do
|
| 11 | -Stopped in Main.main, T26042c.hs:6:3-9
|
|
| 11 | +Stopped in Main., T26042c.hs:5:3-26
|
|
| 12 | 12 | _result ::
|
| 13 | 13 | GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
| 14 | 14 | -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
| 15 | 15 | () #) = _
|
| 16 | -a :: Int = _
|
|
| 16 | +4 main = do
|
|
| 17 | 17 | 5 a <- foo False undefined
|
| 18 | + ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
| 18 | 19 | 6 print a
|
| 19 | - ^^^^^^^
|
|
| 20 | -7 print a
|
|
| 21 | 20 | 14
|
| 22 | 21 | 14 |
| 23 | -not stopped at a breakpoint
|
|
| 24 | -not stopped at a breakpoint |
| 1 | + |
|
| 2 | +module Main where
|
|
| 3 | + |
|
| 4 | +main = do
|
|
| 5 | + putStrLn "hello1"
|
|
| 6 | + f
|
|
| 7 | + putStrLn "hello3"
|
|
| 8 | + putStrLn "hello4"
|
|
| 9 | + |
|
| 10 | +f = do
|
|
| 11 | + putStrLn "hello2.1"
|
|
| 12 | + putStrLn "hello2.2"
|
|
| 13 | +{-# NOINLINE f #-} |
| 1 | +:load T26042d2.hs
|
|
| 2 | + |
|
| 3 | +:break 11
|
|
| 4 | +main
|
|
| 5 | +:list
|
|
| 6 | +:stepout
|
|
| 7 | +:list
|
|
| 8 | +:stepout
|
|
| 9 | + |
|
| 10 | +-- should exit! we compile this test case with -O1 to make sure the monad >> are inlined
|
|
| 11 | +-- and thus the test relies on the filtering behavior based on SrcSpans for stepout
|
|
| 12 | + |
| 1 | +Breakpoint 0 activated at T26042d2.hs:11:3-21
|
|
| 2 | +hello1
|
|
| 3 | +Stopped in Main.f, T26042d2.hs:11:3-21
|
|
| 4 | +_result ::
|
|
| 5 | + GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
|
| 6 | + -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
|
| 7 | + () #) = _
|
|
| 8 | +10 f = do
|
|
| 9 | +11 putStrLn "hello2.1"
|
|
| 10 | + ^^^^^^^^^^^^^^^^^^^
|
|
| 11 | +12 putStrLn "hello2.2"
|
|
| 12 | +hello2.1
|
|
| 13 | +hello2.2
|
|
| 14 | +Stopped in Main., T26042d2.hs:6:3
|
|
| 15 | +_result ::
|
|
| 16 | + GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld
|
|
| 17 | + -> (# GHC.Internal.Prim.State# GHC.Internal.Prim.RealWorld,
|
|
| 18 | + () #) = _
|
|
| 19 | +5 putStrLn "hello1"
|
|
| 20 | +6 f
|
|
| 21 | + ^
|
|
| 22 | +7 putStrLn "hello3"
|
|
| 23 | +hello3
|
|
| 24 | +hello4 |
| ... | ... | @@ -7,14 +7,12 @@ y :: [a1] -> Int = _ |
| 7 | 7 | 11 let !z = y x
|
| 8 | 8 | ^^^^^^^^^^^^
|
| 9 | 9 | 12 let !t = y ['b']
|
| 10 | -Stopped in T7.main, T26042e.hs:19:3-11
|
|
| 10 | +Stopped in T7., T26042e.hs:18:3-17
|
|
| 11 | 11 | _result :: IO () = _
|
| 12 | -x :: Int = _
|
|
| 13 | -y :: Int = _
|
|
| 12 | +17 main = do
|
|
| 14 | 13 | 18 let !(x, y) = a
|
| 14 | + ^^^^^^^^^^^^^^^
|
|
| 15 | 15 | 19 print '1'
|
| 16 | - ^^^^^^^^^
|
|
| 17 | -20 print '2'
|
|
| 18 | 16 | '1'
|
| 19 | 17 | '2'
|
| 20 | 18 | '3'
|
| ... | ... | @@ -8,18 +8,16 @@ x :: Int = 450 |
| 8 | 8 | 21 pure (x + 3)
|
| 9 | 9 | ^^
|
| 10 | 10 | 22 {-# OPAQUE t #-}
|
| 11 | -Stopped in T8.g, T26042f.hs:15:3-17
|
|
| 11 | +Stopped in T8., T26042f.hs:14:3-14
|
|
| 12 | 12 | _result :: Identity Int = _
|
| 13 | -a :: Int = 453
|
|
| 13 | +13 g x = do
|
|
| 14 | 14 | 14 a <- t (x*2)
|
| 15 | + ^^^^^^^^^^^^
|
|
| 15 | 16 | 15 n <- pure (a+a)
|
| 16 | - ^^^^^^^^^^^^^^^
|
|
| 17 | -16 return (n+n)
|
|
| 18 | -Stopped in T8.f, T26042f.hs:9:3-17
|
|
| 17 | +Stopped in T8., T26042f.hs:8:3-14
|
|
| 19 | 18 | _result :: Identity Int = _
|
| 20 | -b :: Int = 1812
|
|
| 19 | +7 f x = do
|
|
| 21 | 20 | 8 b <- g (x*x)
|
| 21 | + ^^^^^^^^^^^^
|
|
| 22 | 22 | 9 y <- pure (b+b)
|
| 23 | - ^^^^^^^^^^^^^^^
|
|
| 24 | -10 return (y+y)
|
|
| 25 | 23 | 7248 |
| ... | ... | @@ -6,10 +6,13 @@ x :: Int = 14 |
| 6 | 6 | 11 succ x = (-) (x - 2) (x + 1)
|
| 7 | 7 | ^^^^^^^^^^^^^^^^^^^
|
| 8 | 8 | 12
|
| 9 | -Stopped in T9.top, T26042g.hs:8:10-21
|
|
| 9 | +Stopped in T9., T26042g.hs:(6,3)-(8,21)
|
|
| 10 | 10 | _result :: Int = _
|
| 11 | +5 top = do
|
|
| 12 | + vv
|
|
| 13 | +6 case succ 14 of
|
|
| 11 | 14 | 7 5 -> 5
|
| 12 | 15 | 8 _ -> 6 + other 55
|
| 13 | - ^^^^^^^^^^^^
|
|
| 16 | + ^^
|
|
| 14 | 17 | 9
|
| 15 | 18 | 171 |
| ... | ... | @@ -147,8 +147,9 @@ test('T25932', extra_files(['T25932.hs']), ghci_script, ['T25932.script']) |
| 147 | 147 | |
| 148 | 148 | # Step out tests
|
| 149 | 149 | test('T26042b', [extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042b.hs'])], ghci_script, ['T26042b.script'])
|
| 150 | -test('T26042c', [expect_broken(26042),extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042c.hs'])], ghci_script, ['T26042c.script'])
|
|
| 150 | +test('T26042c', [extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042c.hs'])], ghci_script, ['T26042c.script'])
|
|
| 151 | 151 | test('T26042d', [extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042d.hs'])], ghci_script, ['T26042d.script'])
|
| 152 | +test('T26042d2', [extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042d2.hs'])], ghci_script, ['T26042d2.script'])
|
|
| 152 | 153 | test('T26042e', extra_files(['T26042e.hs']), ghci_script, ['T26042e.script'])
|
| 153 | 154 | test('T26042f1', extra_files(['T26042f.hs', 'T26042f.script']), ghci_script, ['T26042f.script']) # >> is not inlined, so stepout has nowhere to stop
|
| 154 | 155 | test('T26042f2', [extra_hc_opts('-O -fno-unoptimized-core-for-interpreter'), extra_files(['T26042f.hs', 'T26042f.script'])], ghci_script, ['T26042f.script'])
|