Skip to content

Instantly share code, notes, and snippets.

@luochen1990
Created June 20, 2019 02:48
Show Gist options
  • Select an option

  • Save luochen1990/7b274e1e7b58250d2bb0aa4d760d3f17 to your computer and use it in GitHub Desktop.

Select an option

Save luochen1990/7b274e1e7b58250d2bb0aa4d760d3f17 to your computer and use it in GitHub Desktop.
Get Call Stack from `-xc` without `HasCallStack`
import GHC.Stack
foo :: [Int] -> Int
foo xs = last xs + 1
bar :: [Int] -> Int
bar xs = foo xs
xs :: [Int]
xs = []
main :: IO ()
main = print $ bar xs
{-
$ ghc -prof -fprof-auto-top call-stack-without-hascallstack.hs
$ ./call-stack-without-hascallstack
call-stack-without-hascallstack: Prelude.last: empty list
$ ./call-stack-without-hascallstack +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_1_0), stack trace:
GHC.List.CAF
--> evaluated by: Main.foo,
called from Main.bar,
called from Main.main,
called from Main.CAF
--> evaluated by: Main.main,
called from Main.CAF
--> evaluated by: Main.main
call-stack-without-hascallstack: Prelude.last: empty list
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment