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-types</option>:
64 <indexterm><primary><option>-ddump-types</option></primary></indexterm>
67 <para>Dump a type signature for each value defined at
68 the top level of the module. The list is sorted
69 alphabetically. Using <option>-dppr-debug</option>
70 dumps a type signature for all the imported and
71 system-defined things as well; useful for debugging the
78 <option>-ddump-deriv</option>:
79 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
82 <para>derived instances</para>
88 <option>-ddump-ds</option>:
89 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
92 <para>desugarer output</para>
98 <option>-ddump-spec</option>:
99 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
102 <para>output of specialisation pass</para>
108 <option>-ddump-rules</option>:
109 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
112 <para>dumps all rewrite rules (including those generated
113 by the specialisation pass)</para>
119 <option>-ddump-simpl</option>:
120 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
123 <para>simplifier output (Core-to-Core passes)</para>
129 <option>-ddump-inlinings</option>:
130 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
133 <para>inlining info from the simplifier</para>
139 <option>-ddump-cpranal</option>:
140 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
143 <para>CPR analyser output</para>
149 <option>-ddump-stranal</option>:
150 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
153 <para>strictness analyser output</para>
159 <option>-ddump-cse</option>:
160 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
163 <para>CSE pass output</para>
169 <option>-ddump-workwrap</option>:
170 <indexterm><primary><option>-ddump-workwrap</option></primary></indexterm>
173 <para>worker/wrapper split output</para>
179 <option>-ddump-occur-anal</option>:
180 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
183 <para>`occurrence analysis' output</para>
189 <option>-ddump-stg</option>:
190 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
193 <para>output of STG-to-STG passes</para>
199 <option>-ddump-flatC</option>:
200 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
203 <para><emphasis>flattened</emphasis> Abstract C</para>
209 <option>-ddump-asm</option>:
210 <indexterm><primary><option>-ddump-asm</option></primary></indexterm>
213 <para>assembly language from the native-code generator</para>
219 <option>-ddump-bcos</option>:
220 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
223 <para>byte code compiler output</para>
229 <option>-ddump-foreign</option>:
230 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
233 <para>dump foreign export stubs</para>
242 <option>-dverbose-core2core</option>
243 <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
246 <option>-dverbose-stg2stg</option>
247 <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
250 <para>Show the output of the intermediate Core-to-Core and
251 STG-to-STG passes, respectively. (<emphasis>Lots</emphasis>
252 of output!) So: when we're really desperate:</para>
255 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
263 <option>-ddump-simpl-iterations</option>:
264 <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
267 <para>Show the output of each <emphasis>iteration</emphasis>
268 of the simplifier (each run of the simplifier has a maximum
269 number of iterations, normally 4). Used when even
270 <option>-dverbose-simpl</option> doesn't cut it.</para>
276 <option>-dppr-debug</option>
277 <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
280 <para>Debugging output is in one of several
281 “styles.” Take the printing of types, for
282 example. In the “user” style (the default), the
283 compiler's internal ideas about types are presented in
284 Haskell source-level syntax, insofar as possible. In the
285 “debug” style (which is the default for
286 debugging output), the types are printed in with explicit
287 foralls, and variables have their unique-id attached (so you
288 can check for things that look the same but aren't). This
289 flag makes debugging output appear in the more verbose debug
296 <option>-dppr-user-length</option>
297 <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
300 <para>In error messages, expressions are printed to a
301 certain “depth”, with subexpressions beyond the
302 depth replaced by ellipses. This flag sets the
309 <option>-ddump-simpl-stats</option>
310 <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
313 <para>Dump statistics about how many of each kind of
314 transformation too place. If you add
315 <option>-dppr-debug</option> you get more detailed
322 <option>-ddump-rn-trace</option>
323 <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
326 <para>Make the renamer be *real* chatty about what it is
333 <option>-ddump-rn-stats</option>
334 <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
337 <para>Print out summary of what kind of information the renamer
338 had to bring in.</para>
344 <option>-dshow-unused-imports</option>
345 <indexterm><primary><option>-dshow-unused-imports</option></primary></indexterm>
348 <para>Have the renamer report what imports does not
355 <sect2 id="checking-consistency">
356 <title>Checking for consistency</title>
358 <indexterm><primary>consistency checks</primary></indexterm>
359 <indexterm><primary>lint</primary></indexterm>
365 <option>-dcore-lint</option>
366 <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
369 <para>Turn on heavyweight intra-pass sanity-checking within
370 GHC, at Core level. (It checks GHC's sanity, not yours.)</para>
376 <option>-dstg-lint</option>:
377 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
380 <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
388 <title>How to read Core syntax (from some <option>-ddump</option>
391 <indexterm><primary>reading Core syntax</primary></indexterm>
392 <indexterm><primary>Core syntax, how to read</primary></indexterm>
394 <para>Let's do this by commenting an example. It's from doing
395 <option>-ddump-ds</option> on this code:
398 skip2 m = m : skip2 (m+2)
401 Before we jump in, a word about names of things. Within GHC,
402 variables, type constructors, etc., are identified by their
403 “Uniques.” These are of the form `letter' plus
404 `number' (both loosely interpreted). The `letter' gives some idea
405 of where the Unique came from; e.g., <literal>_</literal>
406 means “built-in type variable”; <literal>t</literal>
407 means “from the typechecker”; <literal>s</literal>
408 means “from the simplifier”; and so on. The `number'
409 is printed fairly compactly in a `base-62' format, which everyone
410 hates except me (WDP).</para>
412 <para>Remember, everything has a “Unique” and it is
413 usually printed out when debugging, in some form or another. So
414 here we go…</para>
418 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
420 --# `r1L6' is the Unique for Main.skip2;
421 --# `_4' is the Unique for the type-variable (template) `a'
422 --# `{{Num a$_4}}' is a dictionary argument
426 --# `_NI_' means "no (pragmatic) information" yet; it will later
427 --# evolve into the GHC_PRAGMA info that goes into interface files.
430 /\ _4 -> \ d.Num.t4Gt ->
433 +.t4Hg :: _4 -> _4 -> _4
435 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
437 fromInt.t4GS :: Int{-2i-} -> _4
439 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
441 --# The `+' class method (Unique: r3JH) selects the addition code
442 --# from a `Num' dictionary (now an explicit lambda'd argument).
443 --# Because Core is 2nd-order lambda-calculus, type applications
444 --# and lambdas (/\) are explicit. So `+' is first applied to a
445 --# type (`_4'), then to a dictionary, yielding the actual addition
446 --# function that we will use subsequently...
448 --# We play the exact same game with the (non-standard) class method
449 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
459 } in fromInt.t4GS ds.d4Qz
461 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
462 --# GHC defines `data Int = I# Int#', where Int# is the primitive
463 --# unboxed type. (see relevant info about unboxed types elsewhere...)
465 --# The `!' after `I#' indicates that this is a *saturated*
466 --# application of the `I#' data constructor (i.e., not partially
469 skip2.t3Ja :: _4 -> [_4]
473 let { ds.d4QQ :: [_4]
479 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
480 } in skip2.t3Ja ds.d4QY
488 <para>(“It's just a simple functional language” is an
489 unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
494 <title>Unregisterised compilation</title>
495 <indexterm><primary>unregisterised compilation</primary></indexterm>
497 <para>The term "unregisterised" really means "compile via vanilla
498 C", disabling some of the platform-specific tricks that GHC
499 normally uses to make programs go faster. When compiling
500 unregisterised, GHC simply generates a C file which is compiled
503 <para>Unregisterised compilation can be useful when porting GHC to
504 a new machine, since it reduces the prerequisite tools to
505 <command>gcc</command>, <command>as</command>, and
506 <command>ld</command> and nothing more, and furthermore the amount
507 of platform-specific code that needs to be written in order to get
508 unregisterised compilation going is usually fairly small.</para>
513 <option>-unreg</option>:
514 <indexterm><primary><option>-unreg</option></primary></indexterm>
517 <para>Compile via vanilla ANSI C only, turning off
518 platform-specific optimisations. NOTE: in order to use
519 <option>-unreg</option>, you need to have a set of libraries
520 (including the RTS) built for unregisterised compilation.
521 This amounts to building GHC with way "u" enabled.</para>
530 ;;; Local Variables: ***
532 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***