Rearrange docs to have all the -ddump-* options together
[ghc-hetmet.git] / docs / users_guide / debugging.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="options-debugging">
3   <title>Debugging the compiler</title>
4
5   <indexterm><primary>debugging options (for GHC)</primary></indexterm>
6
7   <para>HACKER TERRITORY. HACKER TERRITORY.  (You were warned.)</para>
8
9   <sect2 id="dumping-output">
10     <title>Dumping out compiler intermediate structures</title>
11     
12     <indexterm><primary>dumping GHC intermediates</primary></indexterm>
13     <indexterm><primary>intermediate passes, output</primary></indexterm>
14     
15     <variablelist>
16       <varlistentry>
17         <term>
18           <option>-ddump-</option><replaceable>pass</replaceable>
19           <indexterm><primary><option>-ddump</option> options</primary></indexterm>
20         </term>
21         <listitem>
22           <para>Make a debugging dump after pass
23         <literal>&lt;pass&gt;</literal> (may be common enough to need
24         a short form&hellip;).  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
28         are:</para>
29
30           <variablelist>
31             <varlistentry>
32               <term>
33                 <option>-ddump-parsed</option>:
34                 <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
35               </term>
36               <listitem>
37                 <para>parser output</para>
38               </listitem>
39             </varlistentry>
40
41             <varlistentry>
42               <term>
43                 <option>-ddump-rn</option>:
44                 <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
45               </term>
46               <listitem>
47                 <para>renamer output</para>
48               </listitem>
49             </varlistentry>
50
51             <varlistentry>
52               <term>
53                 <option>-ddump-tc</option>:
54                 <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
55               </term>
56               <listitem>
57                 <para>typechecker output</para>
58               </listitem>
59             </varlistentry>
60
61             <varlistentry>
62               <term>
63                 <option>-ddump-types</option>:
64                 <indexterm><primary><option>-ddump-types</option></primary></indexterm>
65               </term>
66               <listitem>
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
72               compiler.</para>
73               </listitem>
74             </varlistentry>
75
76             <varlistentry>
77               <term>
78                 <option>-ddump-deriv</option>:
79                 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
80               </term>
81               <listitem>
82                 <para>derived instances</para>
83               </listitem>
84             </varlistentry>
85
86             <varlistentry>
87               <term>
88                 <option>-ddump-ds</option>:
89                 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
90               </term>
91               <listitem>
92                 <para>desugarer output</para>
93               </listitem>
94             </varlistentry>
95
96             <varlistentry>
97               <term>
98                 <option>-ddump-spec</option>:
99                 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
100               </term>
101               <listitem>
102                 <para>output of specialisation pass</para>
103               </listitem>
104             </varlistentry>
105
106             <varlistentry>
107               <term>
108                 <option>-ddump-rules</option>:
109                 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
110               </term>
111               <listitem>
112                 <para>dumps all rewrite rules (including those generated
113               by the specialisation pass)</para>
114               </listitem>
115             </varlistentry>
116
117             <varlistentry>
118               <term>
119                 <option>-ddump-simpl</option>:
120                 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
121               </term>
122               <listitem>
123                 <para>simplifier output (Core-to-Core passes)</para>
124               </listitem>
125             </varlistentry>
126
127             <varlistentry>
128               <term>
129                 <option>-ddump-inlinings</option>:
130                 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
131               </term>
132               <listitem>
133                 <para>inlining info from the simplifier</para>
134               </listitem>
135             </varlistentry>
136
137             <varlistentry>
138               <term>
139                 <option>-ddump-cpranal</option>:
140                 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
141               </term>
142               <listitem>
143                 <para>CPR analyser output</para>
144               </listitem>
145             </varlistentry>
146
147             <varlistentry>
148               <term>
149                 <option>-ddump-stranal</option>:
150                 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
151               </term>
152               <listitem>
153                 <para>strictness analyser output</para>
154               </listitem>
155             </varlistentry>
156
157             <varlistentry>
158               <term>
159                 <option>-ddump-cse</option>:
160                 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
161               </term>
162               <listitem>
163                 <para>CSE pass output</para>
164               </listitem>
165             </varlistentry>
166
167             <varlistentry>
168               <term>
169                 <option>-ddump-workwrap</option>:
170                 <indexterm><primary><option>-ddump-workwrap</option></primary></indexterm>
171               </term>
172               <listitem>
173                 <para>worker/wrapper split output</para>
174               </listitem>
175             </varlistentry>
176
177             <varlistentry>
178               <term>
179                 <option>-ddump-occur-anal</option>:
180                 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
181               </term>
182               <listitem>
183                 <para>`occurrence analysis' output</para>
184               </listitem>
185             </varlistentry>
186
187             <varlistentry>
188               <term>
189                 <option>-ddump-stg</option>:
190                 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
191               </term>
192               <listitem>
193                 <para>output of STG-to-STG passes</para>
194               </listitem>
195             </varlistentry>
196
197             <varlistentry>
198               <term>
199                 <option>-ddump-flatC</option>:
200                 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
201               </term>
202               <listitem>
203                 <para><emphasis>flattened</emphasis> Abstract&nbsp;C</para>
204               </listitem>
205             </varlistentry>
206
207             <varlistentry>
208               <term>
209                 <option>-ddump-asm</option>:
210                 <indexterm><primary><option>-ddump-asm</option></primary></indexterm>
211               </term>
212               <listitem>
213                 <para>assembly language from the native-code generator</para>
214               </listitem>
215             </varlistentry>
216
217             <varlistentry>
218               <term>
219                 <option>-ddump-bcos</option>:
220                 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
221               </term>
222               <listitem>
223                 <para>byte code compiler output</para>
224               </listitem>
225             </varlistentry>
226
227             <varlistentry>
228               <term>
229                 <option>-ddump-foreign</option>:
230                 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
231               </term>
232               <listitem>
233                 <para>dump foreign export stubs</para>
234               </listitem>
235             </varlistentry>
236           </variablelist>
237         </listitem>
238       </varlistentry>
239       
240       <varlistentry>
241         <term>
242           <option>-ddump-simpl-iterations</option>:
243           <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
244         </term>
245         <listitem>
246           <para>Show the output of each <emphasis>iteration</emphasis>
247         of the simplifier (each run of the simplifier has a maximum
248         number of iterations, normally 4).  Used when even
249         <option>-dverbose-simpl</option> doesn't cut it.</para>
250         </listitem>
251       </varlistentry>
252
253       <varlistentry>
254         <term>
255           <option>-ddump-simpl-stats</option>
256           <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
257         </term>
258         <listitem>
259           <para>Dump statistics about how many of each kind of
260         transformation too place.  If you add
261         <option>-dppr-debug</option> you get more detailed
262         information.</para>
263         </listitem>
264       </varlistentry>
265
266       <varlistentry>
267         <term>
268           <option>-ddump-rn-trace</option>
269           <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
270         </term>
271         <listitem>
272           <para>Make the renamer be *real* chatty about what it is
273         upto.</para>
274         </listitem>
275       </varlistentry>
276
277       <varlistentry>
278         <term>
279           <option>-ddump-rn-stats</option>
280           <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
281         </term>
282         <listitem>
283           <para>Print out summary of what kind of information the renamer
284         had to bring in.</para>
285         </listitem>
286       </varlistentry>
287
288       <varlistentry>
289         <term>
290           <option>-dverbose-core2core</option>
291           <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
292         </term>
293         <term>
294           <option>-dverbose-stg2stg</option>
295           <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
296         </term>
297         <listitem>
298           <para>Show the output of the intermediate Core-to-Core and
299         STG-to-STG passes, respectively.  (<emphasis>Lots</emphasis>
300         of output!) So: when we're really desperate:</para>
301
302           <screen>
303 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
304 </screen>
305
306         </listitem>
307       </varlistentry>
308       
309       <varlistentry>
310         <term>
311           <option>-dppr-debug</option>
312           <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
313         </term>
314         <listitem>
315           <para>Debugging output is in one of several
316           &ldquo;styles.&rdquo; Take the printing of types, for
317           example.  In the &ldquo;user&rdquo; style (the default), the
318           compiler's internal ideas about types are presented in
319           Haskell source-level syntax, insofar as possible.  In the
320           &ldquo;debug&rdquo; style (which is the default for
321           debugging output), the types are printed in with explicit
322           foralls, and variables have their unique-id attached (so you
323           can check for things that look the same but aren't).  This
324           flag makes debugging output appear in the more verbose debug
325           style.</para>
326         </listitem>
327       </varlistentry>
328
329       <varlistentry>
330         <term>
331           <option>-dppr-user-length</option>
332           <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
333         </term>
334         <listitem>
335           <para>In error messages, expressions are printed to a
336           certain &ldquo;depth&rdquo;, with subexpressions beyond the
337           depth replaced by ellipses.  This flag sets the
338           depth.</para>
339         </listitem>
340       </varlistentry>
341
342       <varlistentry>
343         <term>
344           <option>-dshow-unused-imports</option>
345           <indexterm><primary><option>-dshow-unused-imports</option></primary></indexterm>
346         </term>
347         <listitem>
348           <para>Have the renamer report what imports does not
349         contribute.</para>
350         </listitem>
351       </varlistentry>
352     </variablelist>
353   </sect2>
354
355   <sect2 id="checking-consistency">
356     <title>Checking for consistency</title>
357
358     <indexterm><primary>consistency checks</primary></indexterm>
359     <indexterm><primary>lint</primary></indexterm>
360
361     <variablelist>
362
363       <varlistentry>
364         <term>
365           <option>-dcore-lint</option>
366           <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
367         </term>
368         <listitem>
369           <para>Turn on heavyweight intra-pass sanity-checking within
370           GHC, at Core level.  (It checks GHC's sanity, not yours.)</para>
371         </listitem>
372       </varlistentry>
373
374       <varlistentry>
375         <term>
376           <option>-dstg-lint</option>:
377           <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
378         </term>
379         <listitem>
380           <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
381         </listitem>
382       </varlistentry>
383
384     </variablelist>
385   </sect2>
386
387   <sect2>
388     <title>How to read Core syntax (from some <option>-ddump</option>
389     flags)</title>
390
391     <indexterm><primary>reading Core syntax</primary></indexterm>
392     <indexterm><primary>Core syntax, how to read</primary></indexterm>
393
394     <para>Let's do this by commenting an example.  It's from doing
395     <option>-ddump-ds</option> on this code:
396
397 <programlisting>
398 skip2 m = m : skip2 (m+2)
399 </programlisting>
400
401     Before we jump in, a word about names of things.  Within GHC,
402     variables, type constructors, etc., are identified by their
403     &ldquo;Uniques.&rdquo; 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>&lowbar;</literal>
406     means &ldquo;built-in type variable&rdquo;; <literal>t</literal>
407     means &ldquo;from the typechecker&rdquo;; <literal>s</literal>
408     means &ldquo;from the simplifier&rdquo;; and so on.  The `number'
409     is printed fairly compactly in a `base-62' format, which everyone
410     hates except me (WDP).</para>
411
412     <para>Remember, everything has a &ldquo;Unique&rdquo; and it is
413     usually printed out when debugging, in some form or another.  So
414     here we go&hellip;</para>
415
416 <programlisting>
417 Desugared:
418 Main.skip2{-r1L6-} :: _forall_ a$_4 =&#62;{{Num a$_4}} -&#62; a$_4 -&#62; [a$_4]
419
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
423
424 _NI_
425
426 --# `_NI_' means "no (pragmatic) information" yet; it will later
427 --# evolve into the GHC_PRAGMA info that goes into interface files.
428
429 Main.skip2{-r1L6-} =
430     /\ _4 -&#62; \ d.Num.t4Gt -&#62;
431         let {
432           {- CoRec -}
433           +.t4Hg :: _4 -&#62; _4 -&#62; _4
434           _NI_
435           +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
436
437           fromInt.t4GS :: Int{-2i-} -&#62; _4
438           _NI_
439           fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
440
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...
447
448 --# We play the exact same game with the (non-standard) class method
449 --# `fromInt'.  Unsurprisingly, the type `Int' is wired into the
450 --# compiler.
451
452           lit.t4Hb :: _4
453           _NI_
454           lit.t4Hb =
455               let {
456                 ds.d4Qz :: Int{-2i-}
457                 _NI_
458                 ds.d4Qz = I#! 2#
459               } in  fromInt.t4GS ds.d4Qz
460
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...)
464
465 --# The `!' after `I#' indicates that this is a *saturated*
466 --# application of the `I#' data constructor (i.e., not partially
467 --# applied).
468
469           skip2.t3Ja :: _4 -&#62; [_4]
470           _NI_
471           skip2.t3Ja =
472               \ m.r1H4 -&#62;
473                   let { ds.d4QQ :: [_4]
474                         _NI_
475                         ds.d4QQ =
476                     let {
477                       ds.d4QY :: _4
478                       _NI_
479                       ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
480                     } in  skip2.t3Ja ds.d4QY
481                   } in
482                   :! _4 m.r1H4 ds.d4QQ
483
484           {- end CoRec -}
485         } in  skip2.t3Ja
486 </programlisting>
487
488     <para>(&ldquo;It's just a simple functional language&rdquo; is an
489     unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
490
491   </sect2>
492
493   <sect2 id="unreg">
494     <title>Unregisterised compilation</title>
495     <indexterm><primary>unregisterised compilation</primary></indexterm>
496
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
501     via gcc.</para>
502
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>
509
510     <variablelist>
511       <varlistentry>
512         <term>
513           <option>-unreg</option>:
514           <indexterm><primary><option>-unreg</option></primary></indexterm>
515         </term>
516         <listitem>
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>
522         </listitem>
523       </varlistentry>
524     </variablelist>
525   </sect2>
526
527 </sect1>
528
529 <!-- Emacs stuff:
530      ;;; Local Variables: ***
531      ;;; mode: xml ***
532      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
533      ;;; End: ***
534  -->