[GHC] #14634: Add print stacktrace to exception handler in runtime system

#14634: Add print stacktrace to exception handler in runtime system -------------------------------------+------------------------------------- Reporter: flip101 | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs main :: IO () main = do someIO putStrLn "hello world" someIO :: IO () someIO = ioError $ IOError Nothing IllegalOperation "a" "b" Nothing Nothing }}} This code prints the following {{{ exception: a: illegal operation (b) }}} I think there is something in the runtime system which takes this exception and prints this text to the terminal. I will call this the "runtime exception handler" (for i don't know any better). {{{#!hs main :: IO () main = do ex <- try someIO :: IO (Either IOException ()) case ex of Left e -> error (show e) Right _ -> putStrLn "hello world" someIO :: IO () someIO = ioError $ IOError Nothing IllegalOperation "a" "b" Nothing Nothing }}} output: {{{ exception: a: illegal operation (b) CallStack (from HasCallStack): error, called at src/Main.hs:10:15 in main:Main }}} Now i use an explicit handler in my code and show the stacktrace with `error`. Could this handler be moved into the RTS so that i can stacktraces with exceptions just like with error? I think this issue is related to, but not the same as https://ghc.haskell.org/trac/ghc/ticket/12096 Because "Attach stacktrace information to SomeException" -- whatever there is being attached right now (with lts-10.2 ghc 8.2.2) is good enough to provide the information, it's just the print option in the handler that seems to be missing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14634 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14634: Add print stacktrace to exception handler in runtime system -------------------------------------+------------------------------------- Reporter: flip101 | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari):
Could this handler be moved into the RTS so that i can stacktraces with exceptions just like with error?
Not easily; `HasCallStack` is implemented entirely in Haskell and the RTS has no knowledge of if. Perhaps you could teach the compiler to put the "current" `CallStack` in a known location where the RTS can find it; however, at this point you arguably might as well just build with profilng as the latter is significantly less ad-hoc and likely only slightly less efficient. If the exception you are trying to identify is produced by code that you control then you could easily capture the `CallStack` from the the throwing context. This won't work for exceptions arising from, e.g., `base`, however. One alternative that is currently unimplemented is to use DWARF stack unwinding to produce callstacks. In principle we have the ability to do this now (see wiki:DWARF/Status) and wiring it up to the exception handling subsystem is "merely" a matter of deciding an approach. See wiki:Exceptions/StackTraces and #12096 for some possible options. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14634#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC