Support the GHCi debugger with -fexternal-interpreter

Authored by simonmar on Jul 11 2018, 8:41 AM.


  • All the tests in tests/ghci.debugger now pass with -fexternal-interpreter. These tests are now run with the ghci-ext way in addition to the normal way so we won't break it in the future.
  • I removed all the unsafeCoerce# calls from RtClosureInspect. Yay!

The main changes are:

  • New messages: GetClosure and Seq. GetClosure is a remote interface to GHC.Exts.Heap.getClosureData, which required Binary instances for various datatypes. Fortunately this wasn't too painful thanks to DeriveGeneric.
  • No cheating by unsafeCoercing values when printing them. Now we have to turn the Closure representation back into the native representation when printing Int, Float, Double, Integer and Char. Of these, Integer was the most painful - we now have a dependency on integer-gmp due to needing access to the representation.
  • Fixed a bug in rts/Heap.c - it was bogusly returning stack content as pointers for an AP_STACK closure.
Test Plan
  • cd testsuite/tests/ghci.debugger && make
  • validate

Diff Detail

rGHC Glasgow Haskell Compiler
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
simonmar created this revision.Jul 11 2018, 8:41 AM
simonmar updated this revision to Diff 17271.Jul 11 2018, 9:19 AM

fix various minor wibbles

I'm glad to see the Box/HValue flipping resolved. I think that reduces a lot of the friction between GHCi and the heap code.

You have my approval, though that probably shouldn't count for much ;)

I'm very happy to see these unsafeCoerces gone.


Let's write this in terms of ifTerm'. It took me a bit of staring to work out how these differed.


Does this work on 32-bit? valRaw looks to be a [Word] and we are matching on a singleton list above yet Double will be two words on a 32-bit machine.


Is there a particular test you have in mind here?


Indeed this is pretty yucky but fair enough. Perhaps we should at least add a comment alongside the Integer definition in integer-gmp to make the connection clear?

Also, don't we need to do the same for Natural?

@snowleopard & @alpmestan: this will require Hadrian modification.


Wibble: perhaps fromIntegral . wordToPtr and ptrToWord . fromIntegral would be better here?


We probably ought to open a ticket for this.

bgamari requested changes to this revision.Jul 12 2018, 10:03 AM
This revision now requires changes to proceed.Jul 12 2018, 10:03 AM
simonmar updated this revision to Diff 17309.Jul 13 2018, 11:28 AM

address comments; rebase

simonmar marked 4 inline comments as done.Jul 13 2018, 11:29 AM

@bgamari thanks for the review - all done I think.

bgamari accepted this revision.Jul 16 2018, 6:58 PM

Great, looks good to me!

This revision is now accepted and ready to land.Jul 16 2018, 6:58 PM
This revision was automatically updated to reflect the committed changes.