Debugging the compiler
When compiling GHC:
- add -DDEBUG to your GhcStage1HcOpts and/or GhcStage2HcOpts in mk/build.mk. This enables assertions and extra debug code.
When compiling the program (see also the relevant User Manual section):
- Use -v3 or -v4 to get an idea about what GHC is doing when the problem occurs.
- Add -dcore-lint the GHC command line when compiling each Haskell module. This makes GHC type-check the intermediate program after every optimisation pass, which often nails a fault.
- Add -ddump-simpl to see the optimised Core output. There are a number of other -ddump-x flags; see the user manual.
- The flag -dppr-debug makes the -ddump-x flags print much more verbose output. Use this if you are getting desperate!
Adding debugging code to the compiler
- Outputable.pprTrace is a nice way to print trace messages from the compiler
- ASSERT(p), ASSERT2(p,msg), WARN(p,msg) are assertions and warning enabled only when the compiler is compiled with -DDEBUG. There are also variants of these that work better in a monad setting; see compiler/HsVersions.h.