1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="options-debugging">
3 <title>Debugging the compiler</title>
5 <indexterm><primary>debugging options (for GHC)</primary></indexterm>
7 <para>HACKER TERRITORY. HACKER TERRITORY. (You were warned.)</para>
9 <sect2 id="dumping-output">
10 <title>Dumping out compiler intermediate structures</title>
12 <indexterm><primary>dumping GHC intermediates</primary></indexterm>
13 <indexterm><primary>intermediate passes, output</primary></indexterm>
18 <option>-ddump-</option><replaceable>pass</replaceable>
19 <indexterm><primary><option>-ddump</option> options</primary></indexterm>
22 <para>Make a debugging dump after pass
23 <literal><pass></literal> (may be common enough to need
24 a short form…). You can get all of these at once
25 (<emphasis>lots</emphasis> of output) by using
26 <option>-v5</option>, or most of them with
27 <option>-v4</option>. You can prevent them from clogging up
28 your standard output by passing <option>-ddump-to-file</option>.
29 Some of the most useful ones are:</para>
34 <option>-ddump-parsed</option>:
35 <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
38 <para>parser output</para>
44 <option>-ddump-rn</option>:
45 <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
48 <para>renamer output</para>
54 <option>-ddump-tc</option>:
55 <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
58 <para>typechecker output</para>
64 <option>-ddump-splices</option>:
65 <indexterm><primary><option>-ddump-splices</option></primary></indexterm>
68 <para>Dump Template Haskell expressions that we splice in,
69 and what Haskell code the expression evaluates to.</para>
75 <option>-ddump-types</option>:
76 <indexterm><primary><option>-ddump-types</option></primary></indexterm>
79 <para>Dump a type signature for each value defined at
80 the top level of the module. The list is sorted
81 alphabetically. Using <option>-dppr-debug</option>
82 dumps a type signature for all the imported and
83 system-defined things as well; useful for debugging the
90 <option>-ddump-deriv</option>:
91 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
94 <para>derived instances</para>
100 <option>-ddump-ds</option>:
101 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
104 <para>desugarer output</para>
110 <option>-ddump-spec</option>:
111 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
114 <para>output of specialisation pass</para>
120 <option>-ddump-rules</option>:
121 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
124 <para>dumps all rewrite rules specified in this module;
125 see <xref linkend="controlling-rules"/>.
132 <option>-ddump-rule-firings</option>:
133 <indexterm><primary><option>-ddump-rule-firings</option></primary></indexterm>
136 <para>dumps the names of all rules that fired in this module</para>
142 <option>-ddump-rule-rewrites</option>:
143 <indexterm><primary><option>-ddump-rule-rewrites</option></primary></indexterm>
146 <para>dumps detailed information about all rules that fired in
154 <option>-ddump-vect</option>:
155 <indexterm><primary><option>-ddump-vect</option></primary></indexterm>
158 <para>dumps the output of the vectoriser.
165 <option>-ddump-simpl</option>:
166 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
169 <para>simplifier output (Core-to-Core passes)</para>
175 <option>-ddump-inlinings</option>:
176 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
179 <para>inlining info from the simplifier</para>
185 <option>-ddump-cpranal</option>:
186 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
189 <para>CPR analyser output</para>
195 <option>-ddump-stranal</option>:
196 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
199 <para>strictness analyser output</para>
205 <option>-ddump-cse</option>:
206 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
209 <para>CSE pass output</para>
215 <option>-ddump-worker-wrapper</option>:
216 <indexterm><primary><option>-ddump-worker-wrapper</option></primary></indexterm>
219 <para>worker/wrapper split output</para>
225 <option>-ddump-occur-anal</option>:
226 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
229 <para>`occurrence analysis' output</para>
235 <option>-ddump-prep</option>:
236 <indexterm><primary><option>-ddump-prep</option></primary></indexterm>
239 <para>output of core preparation pass</para>
245 <option>-ddump-stg</option>:
246 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
249 <para>output of STG-to-STG passes</para>
255 <option>-ddump-flatC</option>:
256 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
259 <para><emphasis>flattened</emphasis> Abstract C</para>
265 <option>-ddump-cmm</option>:
266 <indexterm><primary><option>-ddump-cmm</option></primary></indexterm>
269 <para>Print the C-- code out.</para>
275 <option>-ddump-opt-cmm</option>:
276 <indexterm><primary><option>-ddump-opt-cmm</option></primary></indexterm>
279 <para>Dump the results of C-- to C-- optimising passes.</para>
285 <option>-ddump-asm</option>:
286 <indexterm><primary><option>-ddump-asm</option></primary></indexterm>
289 <para>assembly language from the native-code generator</para>
295 <option>-ddump-bcos</option>:
296 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
299 <para>byte code compiler output</para>
305 <option>-ddump-foreign</option>:
306 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
309 <para>dump foreign export stubs</para>
318 <option>-ddump-simpl-phases</option>:
319 <indexterm><primary><option>-ddump-simpl-phases</option></primary></indexterm>
322 <para>Show the output of each run of the simplifier. Used when even
323 <option>-dverbose-core2core</option> doesn't cut it.</para>
329 <option>-ddump-simpl-iterations</option>:
330 <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
333 <para>Show the output of each <emphasis>iteration</emphasis>
334 of the simplifier (each run of the simplifier has a maximum
335 number of iterations, normally 4). This outputs even more information
336 than <option>-ddump-simpl-phases</option>.</para>
342 <option>-ddump-simpl-stats</option>
343 <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
346 <para>Dump statistics about how many of each kind of
347 transformation too place. If you add
348 <option>-dppr-debug</option> you get more detailed
355 <option>-ddump-if-trace</option>
356 <indexterm><primary><option>-ddump-if-trace</option></primary></indexterm>
359 <para>Make the interface loader be *real* chatty about what it is
366 <option>-ddump-tc-trace</option>
367 <indexterm><primary><option>-ddump-tc-trace</option></primary></indexterm>
370 <para>Make the type checker be *real* chatty about what it is
377 <option>-ddump-vt-trace</option>
378 <indexterm><primary><option>-ddump-tv-trace</option></primary></indexterm>
381 <para>Make the vectoriser be *real* chatty about what it is
388 <option>-ddump-rn-trace</option>
389 <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
392 <para>Make the renamer be *real* chatty about what it is
399 <option>-ddump-rn-stats</option>
400 <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
403 <para>Print out summary of what kind of information the renamer
404 had to bring in.</para>
410 <option>-dverbose-core2core</option>
411 <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
414 <option>-dverbose-stg2stg</option>
415 <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
418 <para>Show the output of the intermediate Core-to-Core and
419 STG-to-STG passes, respectively. (<emphasis>Lots</emphasis>
420 of output!) So: when we're really desperate:</para>
423 % ghc -noC -O -ddump-simpl -dverbose-core2core -dcore-lint Foo.hs
431 <option>-dshow-passes</option>
432 <indexterm><primary><option>-dshow-passes</option></primary></indexterm>
435 <para>Print out each pass name as it happens.</para>
441 <option>-ddump-core-stats</option>
442 <indexterm><primary><option>-ddump-core-stats</option></primary></indexterm>
445 <para>Print a one-line summary of the size of the Core program
446 at the end of the optimisation pipeline.</para>
452 <option>-dfaststring-stats</option>
453 <indexterm><primary><option>-dfaststring-stats</option></primary></indexterm>
456 <para>Show statistics for the usage of fast strings by the
463 <option>-dppr-debug</option>
464 <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
467 <para>Debugging output is in one of several
468 “styles.” Take the printing of types, for
469 example. In the “user” style (the default), the
470 compiler's internal ideas about types are presented in
471 Haskell source-level syntax, insofar as possible. In the
472 “debug” style (which is the default for
473 debugging output), the types are printed in with explicit
474 foralls, and variables have their unique-id attached (so you
475 can check for things that look the same but aren't). This
476 flag makes debugging output appear in the more verbose debug
483 <sect2 id="formatting dumps">
484 <title>Formatting dumps</title>
486 <indexterm><primary>formatting dumps</primary></indexterm>
491 <option>-dppr-user-length</option>
492 <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
495 <para>In error messages, expressions are printed to a
496 certain “depth”, with subexpressions beyond the
497 depth replaced by ellipses. This flag sets the
498 depth. Its default value is 5.</para>
504 <option>-dppr-colsNNN</option>
505 <indexterm><primary><option>-dppr-colsNNN</option></primary></indexterm>
508 <para>Set the width of debugging output. Use this if your code is wrapping too much.
509 For example: <option>-dppr-cols200</option>.</para>
515 <option>-dppr-case-as-let</option>
516 <indexterm><primary><option>-dppr-case-as-let</option></primary></indexterm>
519 <para>Print single alternative case expressions as though they were strict
520 let expressions. This is helpful when your code does a lot of unboxing.</para>
526 <option>-dno-debug-output</option>
527 <indexterm><primary><option>-dno-debug-output</option></primary></indexterm>
530 <para>Suppress any unsolicited debugging output. When GHC
531 has been built with the <literal>DEBUG</literal> option it
532 occasionally emits debug output of interest to developers.
533 The extra output can confuse the testing framework and
534 cause bogus test failures, so this flag is provided to
542 <sect2 id="supression">
543 <title>Suppressing unwanted information</title>
545 <indexterm><primary>suppression</primary></indexterm>
547 Core dumps contain a large amount of information. Depending on what you are doing, not all of it will be useful.
548 Use these flags to suppress the parts that you are not interested in.
553 <option>-dsuppress-all</option>
554 <indexterm><primary><option>-dsuppress-all</option></primary></indexterm>
557 <para>Suppress everything that can be suppressed, except for unique ids as this often
558 makes the printout ambiguous. If you just want to see the overall structure of
559 the code, then start here.</para>
565 <option>-dsuppress-uniques</option>
566 <indexterm><primary><option>-dsuppress-uniques</option></primary></indexterm>
569 <para>Suppress the printing of uniques. This may make
570 the printout ambiguous (e.g. unclear where an occurrence of 'x' is bound), but
571 it makes the output of two compiler runs have many fewer gratuitous differences,
572 so you can realistically apply <command>diff</command>. Once <command>diff</command>
573 has shown you where to look, you can try again without <option>-dsuppress-uniques</option></para>
579 <option>-dsuppress-idinfo</option>
580 <indexterm><primary><option>-dsuppress-idinfo</option></primary></indexterm>
583 <para>Suppress extended information about identifiers where they are bound. This includes
584 strictness information and inliner templates. Using this flag can cut the size
585 of the core dump in half, due to the lack of inliner templates</para>
591 <option>-dsuppress-module-prefixes</option>
592 <indexterm><primary><option>-dsuppress-module-prefixes</option></primary></indexterm>
595 <para>Suppress the printing of module qualification prefixes.
596 This is the <constant>Data.List</constant> in <constant>Data.List.length</constant>.</para>
602 <option>-dsuppress-type-signatures</option>
603 <indexterm><primary><option>-dsuppress-type-signatures</option></primary></indexterm>
606 <para>Suppress the printing of type signatures.</para>
612 <option>-dsuppress-type-applications</option>
613 <indexterm><primary><option>-dsuppress-type-applications</option></primary></indexterm>
616 <para>Suppress the printing of type applications.</para>
622 <option>-dsuppress-coercions</option>
623 <indexterm><primary><option>-dsuppress-coercions</option></primary></indexterm>
626 <para>Suppress the printing of type coercions.</para>
632 <sect2 id="checking-consistency">
633 <title>Checking for consistency</title>
635 <indexterm><primary>consistency checks</primary></indexterm>
636 <indexterm><primary>lint</primary></indexterm>
642 <option>-dcore-lint</option>
643 <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
646 <para>Turn on heavyweight intra-pass sanity-checking within
647 GHC, at Core level. (It checks GHC's sanity, not yours.)</para>
653 <option>-dstg-lint</option>:
654 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
657 <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
663 <option>-dcmm-lint</option>:
664 <indexterm><primary><option>-dcmm-lint</option></primary></indexterm>
667 <para>Ditto for C-- level.</para>
675 <title>How to read Core syntax (from some <option>-ddump</option>
678 <indexterm><primary>reading Core syntax</primary></indexterm>
679 <indexterm><primary>Core syntax, how to read</primary></indexterm>
681 <para>Let's do this by commenting an example. It's from doing
682 <option>-ddump-ds</option> on this code:
685 skip2 m = m : skip2 (m+2)
688 Before we jump in, a word about names of things. Within GHC,
689 variables, type constructors, etc., are identified by their
690 “Uniques.” These are of the form `letter' plus
691 `number' (both loosely interpreted). The `letter' gives some idea
692 of where the Unique came from; e.g., <literal>_</literal>
693 means “built-in type variable”; <literal>t</literal>
694 means “from the typechecker”; <literal>s</literal>
695 means “from the simplifier”; and so on. The `number'
696 is printed fairly compactly in a `base-62' format, which everyone
697 hates except me (WDP).</para>
699 <para>Remember, everything has a “Unique” and it is
700 usually printed out when debugging, in some form or another. So
701 here we go…</para>
705 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
707 --# `r1L6' is the Unique for Main.skip2;
708 --# `_4' is the Unique for the type-variable (template) `a'
709 --# `{{Num a$_4}}' is a dictionary argument
713 --# `_NI_' means "no (pragmatic) information" yet; it will later
714 --# evolve into the GHC_PRAGMA info that goes into interface files.
717 /\ _4 -> \ d.Num.t4Gt ->
720 +.t4Hg :: _4 -> _4 -> _4
722 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
724 fromInt.t4GS :: Int{-2i-} -> _4
726 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
728 --# The `+' class method (Unique: r3JH) selects the addition code
729 --# from a `Num' dictionary (now an explicit lambda'd argument).
730 --# Because Core is 2nd-order lambda-calculus, type applications
731 --# and lambdas (/\) are explicit. So `+' is first applied to a
732 --# type (`_4'), then to a dictionary, yielding the actual addition
733 --# function that we will use subsequently...
735 --# We play the exact same game with the (non-standard) class method
736 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
746 } in fromInt.t4GS ds.d4Qz
748 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
749 --# GHC defines `data Int = I# Int#', where Int# is the primitive
750 --# unboxed type. (see relevant info about unboxed types elsewhere...)
752 --# The `!' after `I#' indicates that this is a *saturated*
753 --# application of the `I#' data constructor (i.e., not partially
756 skip2.t3Ja :: _4 -> [_4]
760 let { ds.d4QQ :: [_4]
766 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
767 } in skip2.t3Ja ds.d4QY
775 <para>(“It's just a simple functional language” is an
776 unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
781 <title>Unregisterised compilation</title>
782 <indexterm><primary>unregisterised compilation</primary></indexterm>
784 <para>The term "unregisterised" really means "compile via vanilla
785 C", disabling some of the platform-specific tricks that GHC
786 normally uses to make programs go faster. When compiling
787 unregisterised, GHC simply generates a C file which is compiled
790 <para>Unregisterised compilation can be useful when porting GHC to
791 a new machine, since it reduces the prerequisite tools to
792 <command>gcc</command>, <command>as</command>, and
793 <command>ld</command> and nothing more, and furthermore the amount
794 of platform-specific code that needs to be written in order to get
795 unregisterised compilation going is usually fairly small.</para>
797 <para>Unregisterised compilation cannot be selected at
798 compile-time; you have to build GHC with the appropriate options
799 set. Consult the GHC Building Guide for details.</para>
805 ;;; Local Variables: ***
806 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***