1 <Sect1 id="options-debugging">
2 <Title>Debugging the compiler
6 <IndexTerm><Primary>debugging options (for GHC)</Primary></IndexTerm>
10 HACKER TERRITORY. HACKER TERRITORY.
14 <Sect2 id="replacing-phases">
15 <Title>Replacing the program for one or more phases.
19 <IndexTerm><Primary>GHC phases, changing</Primary></IndexTerm>
20 <IndexTerm><Primary>phases, changing GHC</Primary></IndexTerm>
21 You may specify that a different program be used for one of the phases
22 of the compilation system, in place of whatever the driver <Command>ghc</Command> has
23 wired into it. For example, you might want to try a different
25 <Option>-pgm<phase-code><program-name></Option><IndexTerm><Primary>-pgm<phase><stuff>
26 option</Primary></IndexTerm> option to <Command>ghc</Command> will cause it to use <Literal><program-name></Literal>
27 for phase <Literal><phase-code></Literal>, where the codes to indicate the phases are:
33 <ColSpec Align="Left" Colsep="0">
34 <ColSpec Align="Left" Colsep="0">
37 <Entry><Emphasis>code</Emphasis> </Entry>
38 <Entry><Emphasis>phase</Emphasis> </Entry>
44 <Entry> literate pre-processor </Entry>
49 <Entry> C pre-processor (if -cpp only) </Entry>
54 <Entry> Haskell compiler </Entry>
59 <Entry> C compiler</Entry>
64 <Entry> assembler </Entry>
69 <Entry> linker </Entry>
74 <Entry> Makefile dependency generator </Entry>
85 <Sect2 id="forcing-options-through">
86 <Title>Forcing options to a particular phase.
90 <IndexTerm><Primary>forcing GHC-phase options</Primary></IndexTerm>
94 The preceding sections describe driver options that are mostly
95 applicable to one particular phase. You may also <Emphasis>force</Emphasis> a
96 specific option <Option><option></Option> to be passed to a particular phase
97 <Literal><phase-code></Literal> by feeding the driver the option
98 <Option>-opt<phase-code><option></Option>.<IndexTerm><Primary>-opt<phase><stuff>
99 option</Primary></IndexTerm> The codes to indicate the phases are the same as in the
104 So, for example, to force an <Option>-Ewurble</Option> option to the assembler, you
105 would tell the driver <Option>-opta-Ewurble</Option> (the dash before the E is
110 Besides getting options to the Haskell compiler with <Option>-optC<blah></Option>,
111 you can get options through to its runtime system with
112 <Option>-optCrts<blah></Option><IndexTerm><Primary>-optCrts<blah> option</Primary></IndexTerm>.
116 So, for example: when I want to use my normal driver but with my
117 profiled compiler binary, I use this script:
121 exec /local/grasp_tmp3/simonpj/ghc-BUILDS/working-alpha/ghc/driver/ghc \
122 -pgmC/local/grasp_tmp3/simonpj/ghc-BUILDS/working-hsc-prof/hsc \
132 <Sect2 id="dumping-output">
133 <Title>Dumping out compiler intermediate structures
137 <IndexTerm><Primary>dumping GHC intermediates</Primary></IndexTerm>
138 <IndexTerm><Primary>intermediate passes, output</Primary></IndexTerm>
145 <Term><Option>-noC</Option>:</Term>
148 <IndexTerm><Primary>-noC option</Primary></IndexTerm>
149 Don't bother generating C output <Emphasis>or</Emphasis> an interface file. Usually
150 used in conjunction with one or more of the <Option>-ddump-*</Option> options; for
151 example: <Command>ghc -noC -ddump-simpl Foo.hs</Command>
156 <Term><Option>-hi</Option>:</Term>
159 <IndexTerm><Primary>-hi option</Primary></IndexTerm>
160 <Emphasis>Do</Emphasis> generate an interface file. This would normally be used in
161 conjunction with <Option>-noC</Option>, which turns off interface generation;
162 thus: <Option>-noC -hi</Option>.
167 <Term><Option>-dshow-passes</Option>:</Term>
170 <IndexTerm><Primary>-dshow-passes option</Primary></IndexTerm>
171 Prints a message to stderr as each pass starts. Gives a warm but
172 undoubtedly misleading feeling that GHC is telling you what's
178 <Term><Option>-ddump-<pass></Option>:</Term>
181 <IndexTerm><Primary>-ddump-<pass> options</Primary></IndexTerm>
182 Make a debugging dump after pass <Literal><pass></Literal> (may be common enough to
183 need a short form…). You can get all of these at once (<Emphasis>lots</Emphasis> of
184 output) by using <Option>-ddump-all</Option>, or most of them with <Option>-ddump-most</Option>.
185 Some of the most useful ones are:
192 <Term><Option>-ddump-parsed</Option>:</Term>
201 <Term><Option>-ddump-rn</Option>:</Term>
210 <Term><Option>-ddump-minimal-imports</Option>:</Term>
213 Dump to the file "M.imports" (where M is the module being compiled)
214 a "minimal" set of import declarations. You can safely replace
215 all the import declarations in "M.hs" with those found in "M.imports".
216 Why would you want to do that? Because the "minimal" imports (a) import
217 everything explicitly, by name, and (b) import nothing that is not required.
218 It can be quite painful to maintain this property by hand, so this flag is
219 intended to reduce the labour.
225 <Term><Option>-ddump-tc</Option>:</Term>
234 <Term><Option>-ddump-types</Option>:</Term>
237 Dump a type signature for each value defined at the top level
238 of the module. The list is sorted alphabetically.
239 Using <Option>-dppr-debug</Option> dumps a type signature for
240 all the imported and system-defined things as well; useful
241 for debugging the compiler.
247 <Term><Option>-ddump-deriv</Option>:</Term>
255 <Term><Option>-ddump-ds</Option>:</Term>
263 <Term><Option>-ddump-spec</Option>:</Term>
266 output of specialisation pass
271 <Term><Option>-ddump-rules</Option>:</Term>
274 dumps all rewrite rules (including those generated by the specialisation pass)
279 <Term><Option>-ddump-simpl</Option>:</Term>
282 simplifer output (Core-to-Core passes)
287 <Term><Option>-ddump-usagesp</Option>:</Term>
290 UsageSP inference pre-inf and output
295 <Term><Option>-ddump-cpranal</Option>:</Term>
303 <Term><Option>-ddump-stranal</Option>:</Term>
306 strictness analyser output
311 <Term><Option>-ddump-workwrap</Option>:</Term>
314 worker/wrapper split output
319 <Term><Option>-ddump-occur-anal</Option>:</Term>
322 `occurrence analysis' output
327 <Term><Option>-ddump-stg</Option>:</Term>
330 output of STG-to-STG passes
335 <Term><Option>-ddump-absC</Option>:</Term>
338 <Emphasis>un</Emphasis>flattened Abstract C
343 <Term><Option>-ddump-flatC</Option>:</Term>
346 <Emphasis>flattened</Emphasis> Abstract C
351 <Term><Option>-ddump-realC</Option>:</Term>
354 same as what goes to the C compiler
359 <Term><Option>-ddump-asm</Option>:</Term>
362 assembly language from the native-code generator
367 <IndexTerm><Primary>-ddump-all option</Primary></IndexTerm>
368 <IndexTerm><Primary>-ddump-most option</Primary></IndexTerm>
369 <IndexTerm><Primary>-ddump-parsed option</Primary></IndexTerm>
370 <IndexTerm><Primary>-ddump-rn option</Primary></IndexTerm>
371 <IndexTerm><Primary>-ddump-tc option</Primary></IndexTerm>
372 <IndexTerm><Primary>-ddump-deriv option</Primary></IndexTerm>
373 <IndexTerm><Primary>-ddump-ds option</Primary></IndexTerm>
374 <IndexTerm><Primary>-ddump-simpl option</Primary></IndexTerm>
375 <IndexTerm><Primary>-ddump-cpranal option</Primary></IndexTerm>
376 <IndexTerm><Primary>-ddump-workwrap option</Primary></IndexTerm>
377 <IndexTerm><Primary>-ddump-rules option</Primary></IndexTerm>
378 <IndexTerm><Primary>-ddump-usagesp option</Primary></IndexTerm>
379 <IndexTerm><Primary>-ddump-stranal option</Primary></IndexTerm>
380 <IndexTerm><Primary>-ddump-occur-anal option</Primary></IndexTerm>
381 <IndexTerm><Primary>-ddump-spec option</Primary></IndexTerm>
382 <IndexTerm><Primary>-ddump-stg option</Primary></IndexTerm>
383 <IndexTerm><Primary>-ddump-absC option</Primary></IndexTerm>
384 <IndexTerm><Primary>-ddump-flatC option</Primary></IndexTerm>
385 <IndexTerm><Primary>-ddump-realC option</Primary></IndexTerm>
386 <IndexTerm><Primary>-ddump-asm option</Primary></IndexTerm>
391 <Term><Option>-dverbose-simpl</Option> and <Option>-dverbose-stg</Option>:</Term>
394 <IndexTerm><Primary>-dverbose-simpl option</Primary></IndexTerm>
395 <IndexTerm><Primary>-dverbose-stg option</Primary></IndexTerm>
396 Show the output of the intermediate Core-to-Core and STG-to-STG
397 passes, respectively. (<Emphasis>Lots</Emphasis> of output!) So: when we're
401 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
408 <Term><Option>-ddump-simpl-iterations</Option>:</Term>
411 <IndexTerm><Primary>-ddump-simpl-iterations option</Primary></IndexTerm>
412 Show the output of each <Emphasis>iteration</Emphasis> of the simplifier (each run of
413 the simplifier has a maximum number of iterations, normally 4). Used
414 when even <Option>-dverbose-simpl</Option> doesn't cut it.
419 <Term><Option>-dppr-{user,debug</Option>}:</Term>
422 <IndexTerm><Primary>-dppr-user option</Primary></IndexTerm>
423 <IndexTerm><Primary>-dppr-debug option</Primary></IndexTerm>
424 Debugging output is in one of several “styles.” Take the printing
425 of types, for example. In the “user” style, the compiler's internal
426 ideas about types are presented in Haskell source-level syntax,
427 insofar as possible. In the “debug” style (which is the default for
428 debugging output), the types are printed in with
429 explicit foralls, and variables have their unique-id attached (so you
430 can check for things that look the same but aren't).
435 <Term><Option>-ddump-simpl-stats</Option>:</Term>
438 <IndexTerm><Primary>-ddump-simpl-stats option</Primary></IndexTerm>
439 Dump statistics about how many of each kind
440 of transformation too place. If you add <Option>-dppr-debug</Option> you get more detailed information.
445 <Term><Option>-ddump-raw-asm</Option>:</Term>
448 <IndexTerm><Primary>-ddump-raw-asm option</Primary></IndexTerm>
449 Dump out the assembly-language stuff, before the “mangler” gets it.
454 <Term><Option>-ddump-rn-trace</Option>:</Term>
457 <IndexTerm><Primary>-ddump-rn-trace</Primary></IndexTerm>
458 Make the renamer be *real* chatty about what it is upto.
463 <Term><Option>-dshow-rn-stats</Option>:</Term>
466 <IndexTerm><Primary>-dshow-rn-stats</Primary></IndexTerm>
467 Print out summary of what kind of information the renamer had to bring
473 <Term><Option>-dshow-unused-imports</Option>:</Term>
476 <IndexTerm><Primary>-dshow-unused-imports</Primary></IndexTerm>
477 Have the renamer report what imports does not contribute.
486 <Sect2 id="checking-consistency">
487 <Title>Checking for consistency
491 <IndexTerm><Primary>consistency checks</Primary></IndexTerm>
492 <IndexTerm><Primary>lint</Primary></IndexTerm>
499 <Term><Option>-dcore-lint</Option>:</Term>
502 <IndexTerm><Primary>-dcore-lint option</Primary></IndexTerm>
503 Turn on heavyweight intra-pass sanity-checking within GHC, at Core
504 level. (It checks GHC's sanity, not yours.)
509 <Term><Option>-dstg-lint</Option>:</Term>
512 <IndexTerm><Primary>-dstg-lint option</Primary></IndexTerm>
518 <Term><Option>-dusagesp-lint</Option>:</Term>
521 <IndexTerm><Primary>-dstg-lint option</Primary></IndexTerm>
522 Turn on checks around UsageSP inference (<Option>-fusagesp</Option>). This verifies
523 various simple properties of the results of the inference, and also
524 warns if any identifier with a used-once annotation before the
525 inference has a used-many annotation afterwards; this could indicate a
526 non-worksafe transformation is being applied.
536 <Title>How to read Core syntax (from some <Option>-ddump-*</Option> flags)</Title>
539 <IndexTerm><Primary>reading Core syntax</Primary></IndexTerm>
540 <IndexTerm><Primary>Core syntax, how to read</Primary></IndexTerm>
544 Let's do this by commenting an example. It's from doing
545 <Option>-ddump-ds</Option> on this code:
548 skip2 m = m : skip2 (m+2)
554 Before we jump in, a word about names of things. Within GHC,
555 variables, type constructors, etc., are identified by their
556 “Uniques.” These are of the form `letter' plus `number' (both
557 loosely interpreted). The `letter' gives some idea of where the
558 Unique came from; e.g., <Literal>_</Literal> means “built-in type variable”;
559 <Literal>t</Literal> means “from the typechecker”; <Literal>s</Literal> means “from the
560 simplifier”; and so on. The `number' is printed fairly compactly in
561 a `base-62' format, which everyone hates except me (WDP).
565 Remember, everything has a “Unique” and it is usually printed out
566 when debugging, in some form or another. So here we go…
572 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
574 --# `r1L6' is the Unique for Main.skip2;
575 --# `_4' is the Unique for the type-variable (template) `a'
576 --# `{{Num a$_4}}' is a dictionary argument
580 --# `_NI_' means "no (pragmatic) information" yet; it will later
581 --# evolve into the GHC_PRAGMA info that goes into interface files.
584 /\ _4 -> \ d.Num.t4Gt ->
587 +.t4Hg :: _4 -> _4 -> _4
589 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
591 fromInt.t4GS :: Int{-2i-} -> _4
593 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
595 --# The `+' class method (Unique: r3JH) selects the addition code
596 --# from a `Num' dictionary (now an explicit lamba'd argument).
597 --# Because Core is 2nd-order lambda-calculus, type applications
598 --# and lambdas (/\) are explicit. So `+' is first applied to a
599 --# type (`_4'), then to a dictionary, yielding the actual addition
600 --# function that we will use subsequently...
602 --# We play the exact same game with the (non-standard) class method
603 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
613 } in fromInt.t4GS ds.d4Qz
615 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
616 --# GHC defines `data Int = I# Int#', where Int# is the primitive
617 --# unboxed type. (see relevant info about unboxed types elsewhere...)
619 --# The `!' after `I#' indicates that this is a *saturated*
620 --# application of the `I#' data constructor (i.e., not partially
623 skip2.t3Ja :: _4 -> [_4]
627 let { ds.d4QQ :: [_4]
633 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
634 } in skip2.t3Ja ds.d4QY
644 (“It's just a simple functional language” is an unregisterised
645 trademark of Peyton Jones Enterprises, plc.)
650 <Sect2 id="source-file-options">
651 <Title>Command line options in source files
655 <IndexTerm><Primary>source-file options</Primary></IndexTerm>
659 Sometimes it is useful to make the connection between a source file
660 and the command-line options it requires quite tight. For instance,
661 if a (Glasgow) Haskell source file uses <Literal>casm</Literal>s, the C back-end
662 often needs to be told about which header files to include. Rather than
663 maintaining the list of files the source depends on in a
664 <Filename>Makefile</Filename> (using the <Option>-#include</Option> command-line option), it is
665 possible to do this directly in the source file using the <Literal>OPTIONS</Literal>
666 pragma <IndexTerm><Primary>OPTIONS pragma</Primary></IndexTerm>:
671 {-# OPTIONS -#include "foo.h" #-}
679 <Literal>OPTIONS</Literal> pragmas are only looked for at the top of your source
680 files, upto the first (non-literate,non-empty) line not containing
681 <Literal>OPTIONS</Literal>. Multiple <Literal>OPTIONS</Literal> pragmas are recognised. Note
682 that your command shell does not get to the source file options, they
683 are just included literally in the array of command-line arguments
684 the compiler driver maintains internally, so you'll be desperately
685 disappointed if you try to glob etc. inside <Literal>OPTIONS</Literal>.
689 NOTE: the contents of OPTIONS are prepended to the command-line
690 options, so you *do* have the ability to override OPTIONS settings
691 via the command line.
695 It is not recommended to move all the contents of your Makefiles into
696 your source files, but in some circumstances, the <Literal>OPTIONS</Literal> pragma
697 is the Right Thing. (If you use <Option>-keep-hc-file-too</Option> and have OPTION
698 flags in your module, the OPTIONS will get put into the generated .hc
705 <title>Unregisterised compilation</title>
706 <indexterm><primary>unregisterised compilation</primary></indexterm>
708 <para>The term "unregisterised" really means "compile via vanilla
709 C", disabling some of the platform-specific tricks that GHC
710 normally uses to make programs go faster. When compiling
711 unregisterised, GHC simply generates a C file which is compiled
714 <para>Unregisterised compilation can be useful when porting GHC to
715 a new machine, since it reduces the prerequisite tools to
716 <command>gcc</command>, <command>as</command>, and
717 <command>ld</command> and nothing more, and furthermore the amount
718 of platform-specific code that needs to be written in order to get
719 unregisterised compilation going is usually fairly small.</para>
723 <term><option>-unreg</option>:</term>
724 <indexterm><primary><option>-unreg</option></primary></indexterm>
726 <para>Compile via vanilla ANSI C only, turning off
727 platform-specific optimisations. NOTE: in order to use
728 <option>-unreg</option>, you need to have a set of libraries
729 (including the RTS) built for unregisterised compilation.
730 This amounts to building GHC with way "u" enabled.</para>
739 ;;; Local Variables: ***
741 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter" "sect1") ***