1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
module Main where
import GHC.Stack.CloneStack
import System.IO.Unsafe
import Control.Monad
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
assertEqual :: (Eq a, Show a) => a -> a -> IO ()
assertEqual x y =
if x == y
then return ()
else error $ "assertEqual: " ++ show x ++ " /= " ++ show y
main :: IO ()
main = do
let (_, stack) = getDeepStack 1000
assertEqual (length stack) 1003
assertEqual
(stack !! 0)
StackEntry
{ functionName = "assertEqual",
moduleName = "Main",
srcLoc = "decodeMyStack_underflowFrames.hs:23:11",
closureType = 53
}
assertEqual
(stack !! 1)
StackEntry
{ functionName = "main.(...)",
moduleName = "Main",
srcLoc = "decodeMyStack_underflowFrames.hs:29:20-36",
closureType = 53
}
forM_
[2 .. 1001]
( \i ->
assertEqual
(stack !! i)
StackEntry
{ functionName = "getDeepStack.getDeepStackCase",
moduleName = "Main",
srcLoc = "decodeMyStack_underflowFrames.hs:19:26-28",
closureType = 53
}
)
assertEqual
(stack !! 1002)
StackEntry
{ functionName = "getDeepStack.getDeepStackCase",
moduleName = "Main",
srcLoc = "decodeMyStack_underflowFrames.hs:14:7-21",
closureType = 53
}
|