Enable stack traces with ghci -fexternal-interpreter -prof
authorSimon Marlow <marlowsd@gmail.com>
Thu, 7 Jan 2016 11:36:41 +0000 (11:36 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 8 Jan 2016 08:49:26 +0000 (08:49 +0000)
commit6be09e884730f19da6c24fc565980f515300e53c
treeb7e0e13c4b4acd138d4da91013562cd5637db865
parentc78fedde7055490ca6f6210ada797190f3c35d87
Enable stack traces with ghci -fexternal-interpreter -prof

Summary:
The main goal here is enable stack traces in GHCi.  After this change,
if you start GHCi like this:

  ghci -fexternal-interpreter -prof

(which requires packages to be built for profiling, but not GHC
itself) then the interpreter manages cost-centre stacks during
execution and can produce a stack trace on request.  Call locations
are available for all interpreted code, and any compiled code that was
built with the `-fprof-auto` familiy of flags.

There are a couple of ways to get a stack trace:

* `error`/`undefined` automatically get one attached
* `Debug.Trace.traceStack` can be used anywhere, and prints the current
  stack

Because the interpreter is running in a separate process, only the
interpreted code is running in profiled mode and the compiler itself
isn't slowed down by profiling.

The GHCi debugger still doesn't work with -fexternal-interpreter,
although this patch gets it a step closer.  Most of the functionality
of breakpoints is implemented, but the runtime value introspection is
still not supported.

Along the way I also did some refactoring and added type arguments to
the various remote pointer types in `GHCi.RemotePtr`, so there's
better type safety and documentation in the bridge code between GHC
and ghc-iserv.

Test Plan: validate

Reviewers: bgamari, ezyang, austin, hvr, goldfire, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1747

GHC Trac Issues: #11047, #11100
39 files changed:
compiler/deSugar/Coverage.hs
compiler/deSugar/Desugar.hs
compiler/ghc.cabal.in
compiler/ghc.mk
compiler/ghci/ByteCodeAsm.hs
compiler/ghci/ByteCodeGen.hs
compiler/ghci/ByteCodeInstr.hs
compiler/ghci/ByteCodeItbls.hs
compiler/ghci/ByteCodeLink.hs
compiler/ghci/ByteCodeTypes.hs
compiler/ghci/Debugger.hs
compiler/ghci/GHCi.hs
compiler/ghci/Linker.hs
compiler/main/DriverPipeline.hs
compiler/main/GHC.hs
compiler/main/HscMain.hs
compiler/main/HscTypes.hs
compiler/main/InteractiveEval.hs
compiler/main/InteractiveEvalTypes.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSplice.hs
ghc.mk
ghc/GHCi/UI.hs
ghc/GHCi/UI/Monad.hs
libraries/ghci/GHCi/BreakArray.hs [moved from compiler/main/BreakArray.hs with 88% similarity]
libraries/ghci/GHCi/CreateBCO.hs
libraries/ghci/GHCi/FFI.hsc
libraries/ghci/GHCi/InfoTable.hsc
libraries/ghci/GHCi/Message.hs
libraries/ghci/GHCi/ObjLink.hs
libraries/ghci/GHCi/RemoteTypes.hs
libraries/ghci/GHCi/ResolvedBCO.hs
libraries/ghci/GHCi/Run.hs
libraries/ghci/GHCi/TH.hs
libraries/ghci/ghci.cabal.in
rts/Exception.cmm
rts/Interpreter.c
rules/build-prog.mk
testsuite/tests/ghci.debugger/scripts/break021.stdout