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>. Some of the most useful ones
33 <option>-ddump-parsed</option>:
34 <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
37 <para>parser output</para>
43 <option>-ddump-rn</option>:
44 <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
47 <para>renamer output</para>
53 <option>-ddump-tc</option>:
54 <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
57 <para>typechecker output</para>
63 <option>-ddump-splices</option>:
64 <indexterm><primary><option>-ddump-splices</option></primary></indexterm>
67 <para>Dump Template Haskell expressions that we splice in,
68 and what Haskell code the expression evaluates to.</para>
74 <option>-ddump-types</option>:
75 <indexterm><primary><option>-ddump-types</option></primary></indexterm>
78 <para>Dump a type signature for each value defined at
79 the top level of the module. The list is sorted
80 alphabetically. Using <option>-dppr-debug</option>
81 dumps a type signature for all the imported and
82 system-defined things as well; useful for debugging the
89 <option>-ddump-deriv</option>:
90 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
93 <para>derived instances</para>
99 <option>-ddump-ds</option>:
100 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
103 <para>desugarer output</para>
109 <option>-ddump-spec</option>:
110 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
113 <para>output of specialisation pass</para>
119 <option>-ddump-rules</option>:
120 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
123 <para>dumps all rewrite rules (including those generated
124 by the specialisation pass)</para>
130 <option>-ddump-simpl</option>:
131 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
134 <para>simplifier output (Core-to-Core passes)</para>
140 <option>-ddump-inlinings</option>:
141 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
144 <para>inlining info from the simplifier</para>
150 <option>-ddump-cpranal</option>:
151 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
154 <para>CPR analyser output</para>
160 <option>-ddump-stranal</option>:
161 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
164 <para>strictness analyser output</para>
170 <option>-ddump-cse</option>:
171 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
174 <para>CSE pass output</para>
180 <option>-ddump-workwrap</option>:
181 <indexterm><primary><option>-ddump-workwrap</option></primary></indexterm>
184 <para>worker/wrapper split output</para>
190 <option>-ddump-occur-anal</option>:
191 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
194 <para>`occurrence analysis' output</para>
200 <option>-ddump-prep</option>:
201 <indexterm><primary><option>-ddump-prep</option></primary></indexterm>
204 <para>output of core preparation pass</para>
210 <option>-ddump-stg</option>:
211 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
214 <para>output of STG-to-STG passes</para>
220 <option>-ddump-flatC</option>:
221 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
224 <para><emphasis>flattened</emphasis> Abstract C</para>
230 <option>-ddump-cmm</option>:
231 <indexterm><primary><option>-ddump-cmm</option></primary></indexterm>
234 <para>Print the C-- code out.</para>
240 <option>-ddump-opt-cmm</option>:
241 <indexterm><primary><option>-ddump-opt-cmm</option></primary></indexterm>
244 <para>Dump the results of C-- to C-- optimising passes.</para>
250 <option>-ddump-asm</option>:
251 <indexterm><primary><option>-ddump-asm</option></primary></indexterm>
254 <para>assembly language from the native-code generator</para>
260 <option>-ddump-bcos</option>:
261 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
264 <para>byte code compiler output</para>
270 <option>-ddump-foreign</option>:
271 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
274 <para>dump foreign export stubs</para>
283 <option>-ddump-simpl-phases</option>:
284 <indexterm><primary><option>-ddump-simpl-phases</option></primary></indexterm>
287 <para>Show the output of each run of the simplifier. Used when even
288 <option>-dverbose-simpl</option> doesn't cut it.</para>
294 <option>-ddump-simpl-iterations</option>:
295 <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
298 <para>Show the output of each <emphasis>iteration</emphasis>
299 of the simplifier (each run of the simplifier has a maximum
300 number of iterations, normally 4). This outputs even more information
301 than <option>-ddump-simpl-phases</option>.</para>
307 <option>-ddump-simpl-stats</option>
308 <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
311 <para>Dump statistics about how many of each kind of
312 transformation too place. If you add
313 <option>-dppr-debug</option> you get more detailed
320 <option>-ddump-if-trace</option>
321 <indexterm><primary><option>-ddump-if-trace</option></primary></indexterm>
324 <para>Make the interface loader be *real* chatty about what it is
331 <option>-ddump-tc-trace</option>
332 <indexterm><primary><option>-ddump-tc-trace</option></primary></indexterm>
335 <para>Make the type checker be *real* chatty about what it is
342 <option>-ddump-rn-trace</option>
343 <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
346 <para>Make the renamer be *real* chatty about what it is
353 <option>-ddump-rn-stats</option>
354 <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
357 <para>Print out summary of what kind of information the renamer
358 had to bring in.</para>
364 <option>-dverbose-core2core</option>
365 <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
368 <option>-dverbose-stg2stg</option>
369 <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
372 <para>Show the output of the intermediate Core-to-Core and
373 STG-to-STG passes, respectively. (<emphasis>Lots</emphasis>
374 of output!) So: when we're really desperate:</para>
377 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
385 <option>-dshow-passes</option>
386 <indexterm><primary><option>-dshow-passes</option></primary></indexterm>
389 <para>Print out each pass name as it happens.</para>
395 <option>-dfaststring-stats</option>
396 <indexterm><primary><option>-dfaststring-stats</option></primary></indexterm>
399 <para>Show statistics for the usage of fast strings by the
406 <option>-dppr-debug</option>
407 <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
410 <para>Debugging output is in one of several
411 “styles.” Take the printing of types, for
412 example. In the “user” style (the default), the
413 compiler's internal ideas about types are presented in
414 Haskell source-level syntax, insofar as possible. In the
415 “debug” style (which is the default for
416 debugging output), the types are printed in with explicit
417 foralls, and variables have their unique-id attached (so you
418 can check for things that look the same but aren't). This
419 flag makes debugging output appear in the more verbose debug
426 <option>-dppr-user-length</option>
427 <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
430 <para>In error messages, expressions are printed to a
431 certain “depth”, with subexpressions beyond the
432 depth replaced by ellipses. This flag sets the
433 depth. Its default value is 5.</para>
439 <option>-dno-debug-output</option>
440 <indexterm><primary><option>-dno-debug-output</option></primary></indexterm>
443 <para>Suppress any unsolicited debugging output. When GHC
444 has been built with the <literal>DEBUG</literal> option it
445 occasionally emits debug output of interest to developers.
446 The extra output can confuse the testing framework and
447 cause bogus test failures, so this flag is provided to
454 <sect2 id="checking-consistency">
455 <title>Checking for consistency</title>
457 <indexterm><primary>consistency checks</primary></indexterm>
458 <indexterm><primary>lint</primary></indexterm>
464 <option>-dcore-lint</option>
465 <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
468 <para>Turn on heavyweight intra-pass sanity-checking within
469 GHC, at Core level. (It checks GHC's sanity, not yours.)</para>
475 <option>-dstg-lint</option>:
476 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
479 <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
485 <option>-dcmm-lint</option>:
486 <indexterm><primary><option>-dcmm-lint</option></primary></indexterm>
489 <para>Ditto for C-- level.</para>
497 <title>How to read Core syntax (from some <option>-ddump</option>
500 <indexterm><primary>reading Core syntax</primary></indexterm>
501 <indexterm><primary>Core syntax, how to read</primary></indexterm>
503 <para>Let's do this by commenting an example. It's from doing
504 <option>-ddump-ds</option> on this code:
507 skip2 m = m : skip2 (m+2)
510 Before we jump in, a word about names of things. Within GHC,
511 variables, type constructors, etc., are identified by their
512 “Uniques.” These are of the form `letter' plus
513 `number' (both loosely interpreted). The `letter' gives some idea
514 of where the Unique came from; e.g., <literal>_</literal>
515 means “built-in type variable”; <literal>t</literal>
516 means “from the typechecker”; <literal>s</literal>
517 means “from the simplifier”; and so on. The `number'
518 is printed fairly compactly in a `base-62' format, which everyone
519 hates except me (WDP).</para>
521 <para>Remember, everything has a “Unique” and it is
522 usually printed out when debugging, in some form or another. So
523 here we go…</para>
527 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
529 --# `r1L6' is the Unique for Main.skip2;
530 --# `_4' is the Unique for the type-variable (template) `a'
531 --# `{{Num a$_4}}' is a dictionary argument
535 --# `_NI_' means "no (pragmatic) information" yet; it will later
536 --# evolve into the GHC_PRAGMA info that goes into interface files.
539 /\ _4 -> \ d.Num.t4Gt ->
542 +.t4Hg :: _4 -> _4 -> _4
544 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
546 fromInt.t4GS :: Int{-2i-} -> _4
548 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
550 --# The `+' class method (Unique: r3JH) selects the addition code
551 --# from a `Num' dictionary (now an explicit lambda'd argument).
552 --# Because Core is 2nd-order lambda-calculus, type applications
553 --# and lambdas (/\) are explicit. So `+' is first applied to a
554 --# type (`_4'), then to a dictionary, yielding the actual addition
555 --# function that we will use subsequently...
557 --# We play the exact same game with the (non-standard) class method
558 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
568 } in fromInt.t4GS ds.d4Qz
570 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
571 --# GHC defines `data Int = I# Int#', where Int# is the primitive
572 --# unboxed type. (see relevant info about unboxed types elsewhere...)
574 --# The `!' after `I#' indicates that this is a *saturated*
575 --# application of the `I#' data constructor (i.e., not partially
578 skip2.t3Ja :: _4 -> [_4]
582 let { ds.d4QQ :: [_4]
588 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
589 } in skip2.t3Ja ds.d4QY
597 <para>(“It's just a simple functional language” is an
598 unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
603 <title>Unregisterised compilation</title>
604 <indexterm><primary>unregisterised compilation</primary></indexterm>
606 <para>The term "unregisterised" really means "compile via vanilla
607 C", disabling some of the platform-specific tricks that GHC
608 normally uses to make programs go faster. When compiling
609 unregisterised, GHC simply generates a C file which is compiled
612 <para>Unregisterised compilation can be useful when porting GHC to
613 a new machine, since it reduces the prerequisite tools to
614 <command>gcc</command>, <command>as</command>, and
615 <command>ld</command> and nothing more, and furthermore the amount
616 of platform-specific code that needs to be written in order to get
617 unregisterised compilation going is usually fairly small.</para>
619 <para>Unregisterised compilation cannot be selected at
620 compile-time; you have to build GHC with the appropriate options
621 set. Consult the GHC Building Guide for details.</para>
627 ;;; Local Variables: ***
629 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***