6.13. Debugging the compiler¶
HACKER TERRITORY. HACKER TERRITORY. (You were warned.)
6.13.1. Dumping out compiler intermediate structures¶
-ddump-⟨pass⟩Make a debugging dump after pass
<pass>(may be common enough to need a short form…). You can get all of these at once (lots of output) by using-v5, or most of them with-v4. You can prevent them from clogging up your standard output by passing-ddump-to-file. Some of the most useful ones are:-ddump-parsedDump parser output
-ddump-rnDump renamer output
-ddump-tcDump typechecker output
-ddump-splicesDump Template Haskell expressions that we splice in, and what Haskell code the expression evaluates to.
-ddump-typesDump a type signature for each value defined at the top level of the module. The list is sorted alphabetically. Using
-dppr-debugdumps a type signature for all the imported and system-defined things as well; useful for debugging the compiler.-ddump-derivDump derived instances
-ddump-dsDump desugarer output
-ddump-specDump output of specialisation pass
-ddump-rulesDumps all rewrite rules specified in this module; see Controlling what’s going on in rewrite rules.
-ddump-rule-firingsDumps the names of all rules that fired in this module
-ddump-rule-rewritesDumps detailed information about all rules that fired in this module
-ddump-vectDumps the output of the vectoriser.
-ddump-simplDump simplifier output (Core-to-Core passes)
-ddump-inliningsDumps inlining info from the simplifier
-ddump-stranalDump strictness analyser output
-ddump-strsigsDump strictness signatures
-ddump-cseDump common subexpression elimination (CSE) pass output
-ddump-worker-wrapperDump worker/wrapper split output
-ddump-occur-analDump “occurrence analysis” output
-ddump-prepDump output of Core preparation pass
-ddump-stgDump output of STG-to-STG passes
-ddump-cmmPrint the C– code out.
-ddump-opt-cmmDump the results of C– to C– optimising passes.
-ddump-asmDump assembly language produced by the native code generator
-ddump-llvmLLVM code from the LLVM code generator
-ddump-bcosDump byte-code compiler output
-ddump-foreigndump foreign export stubs
-ddump-simpl-iterationsShow the output of each iteration of the simplifier (each run of the simplifier has a maximum number of iterations, normally 4). This outputs even more information than
-ddump-simpl-phases.-ddump-simpl-statsDump statistics about how many of each kind of transformation too place. If you add
-dppr-debugyou get more detailed information.-ddump-if-traceMake the interface loader be real chatty about what it is up to.
-ddump-tc-traceMake the type checker be real chatty about what it is up to.
-ddump-vt-traceMake the vectoriser be real chatty about what it is up to.
-ddump-rn-traceMake the renamer be real chatty about what it is up to.
-ddump-rn-statsPrint out summary of what kind of information the renamer had to bring in.
-dverbose-core2core,-dverbose-stg2stgShow the output of the intermediate Core-to-Core and STG-to-STG passes, respectively. (lots of output!) So: when we’re really desperate:
% ghc -noC -O -ddump-simpl -dverbose-core2core -dcore-lint Foo.hs
-dshow-passesPrint out each pass name as it happens.
-ddump-core-statsPrint a one-line summary of the size of the Core program at the end of the optimisation pipeline.
-dfaststring-statsShow statistics on the usage of fast strings by the compiler.
-dppr-debugDebugging output is in one of several “styles.” Take the printing of types, for example. In the “user” style (the default), the compiler’s internal ideas about types are presented in Haskell source-level syntax, insofar as possible. In the “debug” style (which is the default for debugging output), the types are printed in with explicit foralls, and variables have their unique-id attached (so you can check for things that look the same but aren’t). This flag makes debugging output appear in the more verbose debug style.
6.13.2. Formatting dumps¶
-dppr-user-lengthIn error messages, expressions are printed to a certain “depth”, with subexpressions beyond the depth replaced by ellipses. This flag sets the depth. Its default value is 5.
-dppr-colsNNNSet the width of debugging output. Use this if your code is wrapping too much. For example:
-dppr-cols200.-dppr-case-as-letPrint single alternative case expressions as though they were strict let expressions. This is helpful when your code does a lot of unboxing.
-dno-debug-outputSuppress any unsolicited debugging output. When GHC has been built with the
DEBUGoption it occasionally emits debug output of interest to developers. The extra output can confuse the testing framework and cause bogus test failures, so this flag is provided to turn it off.
6.13.3. Suppressing unwanted information¶
Core dumps contain a large amount of information. Depending on what you are doing, not all of it will be useful. Use these flags to suppress the parts that you are not interested in.
-dsuppress-allSuppress everything that can be suppressed, except for unique ids as this often makes the printout ambiguous. If you just want to see the overall structure of the code, then start here.
-dsuppress-uniquesSuppress the printing of uniques. This may make the printout ambiguous (e.g. unclear where an occurrence of ‘x’ is bound), but it makes the output of two compiler runs have many fewer gratuitous differences, so you can realistically apply
diff. Oncediffhas shown you where to look, you can try again without-dsuppress-uniques-dsuppress-idinfoSuppress extended information about identifiers where they are bound. This includes strictness information and inliner templates. Using this flag can cut the size of the core dump in half, due to the lack of inliner templates
-dsuppress-unfoldingsSuppress the printing of the stable unfolding of a variable at its binding site.
-dsuppress-module-prefixesSuppress the printing of module qualification prefixes. This is the
Data.ListinData.List.length.-dsuppress-type-signaturesSuppress the printing of type signatures.
-dsuppress-type-applicationsSuppress the printing of type applications.
-dsuppress-coercionsSuppress the printing of type coercions.
6.13.4. Checking for consistency¶
-dcore-lintTurn on heavyweight intra-pass sanity-checking within GHC, at Core level. (It checks GHC’s sanity, not yours.)
-dstg-lintDitto for STG level. (note: currently doesn’t work).
-dcmm-lintDitto for C– level.
6.13.5. Checking for determinism¶
-dinitial-unique=⟨s⟩Start
UniqSupplyallocation from ⟨s⟩.-dunique-increment=⟨i⟩Set the increment for the generated
Unique‘s to ⟨i⟩.This is useful in combination with
-dinitial-uniqueto test if the generated files depend on the order ofUnique‘s.Some interesting values:
-dinitial-unique=0 -dunique-increment=1- current sequentialUniqSupply-dinitial-unique=16777215 -dunique-increment=-1-UniqSupplythat generates in decreasing order-dinitial-unique=1 -dunique-increment=PRIME- where PRIME big enough to overflow often - nonsequential order