summaryrefslogtreecommitdiff
path: root/testsuite/tests/rts/decodeMyStack.hs
blob: b0c330ee34647325d7f5f91e364c4efc0653dca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Main where

import GHC.Stack.CloneStack
import System.IO.Unsafe

getDeepStack :: Int -> (Int, [StackEntry])
getDeepStack deepness = case getDeepStackCase deepness of
  [] -> (0, [])
  s -> (deepness, s)
  where
    getDeepStackCase :: Int -> [StackEntry]
    getDeepStackCase 0 =
      unsafePerformIO $
        ( do
            stack <- cloneMyStack
            GHC.Stack.CloneStack.decode stack
        )
    getDeepStackCase n = snd $ getDeepStack $ n - 1

main :: IO ()
main = do
  let (_, stackEntries) = getDeepStack 10
  mapM_ (putStrLn . show) stackEntries