summaryrefslogtreecommitdiff
path: root/libraries/ghc-heap/GHC/Exts/Stack.hs
diff options
context:
space:
mode:
authorSven Tennie <sven.tennie@gmail.com>2023-05-08 18:29:32 +0000
committerSven Tennie <sven.tennie@gmail.com>2023-05-08 18:29:32 +0000
commite778d8320606726a820f7f351b87f94e0f5a9888 (patch)
tree000d130b73c71b71e58c550979cb8a3bcf1ab5c4 /libraries/ghc-heap/GHC/Exts/Stack.hs
parent2c9f1a364f278299d2a89fb884c471d2d7883e8c (diff)
downloadhaskell-wip/decode_cloned_stack.tar.gz
ghc-heap: Decode StgStack and its stack frameswip/decode_cloned_stack
Previously, ghc-heap could only decode heap closures. The approach is explained in detail in note [Decoding the stack].
Diffstat (limited to 'libraries/ghc-heap/GHC/Exts/Stack.hs')
-rw-r--r--libraries/ghc-heap/GHC/Exts/Stack.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/libraries/ghc-heap/GHC/Exts/Stack.hs b/libraries/ghc-heap/GHC/Exts/Stack.hs
new file mode 100644
index 0000000000..90081a522a
--- /dev/null
+++ b/libraries/ghc-heap/GHC/Exts/Stack.hs
@@ -0,0 +1,37 @@
+{-# LANGUAGE CPP #-}
+#if MIN_TOOL_VERSION_ghc(9,7,0)
+{-# LANGUAGE RecordWildCards #-}
+
+module GHC.Exts.Stack
+ ( -- * Stack inspection
+ decodeStack,
+ stackFrameSize,
+ )
+where
+
+import GHC.Exts.Heap.Closures
+import GHC.Exts.Stack.Constants
+import GHC.Exts.Stack.Decode
+import Prelude
+
+-- | Get the size of the `StackFrame` in words.
+--
+-- Includes header and payload. Does not follow pointers.
+stackFrameSize :: StackFrame -> Int
+stackFrameSize (UpdateFrame {}) = sizeStgUpdateFrame
+stackFrameSize (CatchFrame {}) = sizeStgCatchFrame
+stackFrameSize (CatchStmFrame {}) = sizeStgCatchSTMFrame
+stackFrameSize (CatchRetryFrame {}) = sizeStgCatchRetryFrame
+stackFrameSize (AtomicallyFrame {}) = sizeStgAtomicallyFrame
+stackFrameSize (RetSmall {..}) = sizeStgClosure + length stack_payload
+stackFrameSize (RetBig {..}) = sizeStgClosure + length stack_payload
+stackFrameSize (RetFun {..}) = sizeStgRetFunFrame + length retFunPayload
+-- The one additional word is a pointer to the StgBCO in the closure's payload
+stackFrameSize (RetBCO {..}) = sizeStgClosure + 1 + length bcoArgs
+-- The one additional word is a pointer to the next stack chunk
+stackFrameSize (UnderflowFrame {}) = sizeStgClosure + 1
+stackFrameSize _ = error "Unexpected stack frame type"
+
+#else
+module GHC.Exts.Stack where
+#endif