Debugging the RTS

Jost Berthold berthold at Mathematik.Uni-Marburg.de
Thu May 14 14:21:23 UTC 2015


Hi Eric,

definitely not bit-rotted - the #if DEBUG code is what you get when you 
compile with -debug.

Short roadmap:

In general, GHC is built in many "ways", the -debug way is one.
Some ways (like -threaded, -eventlog, -debug) are RTS-only, others (like 
-prof) lead to different library code.

Ways are defined in compiler/main/DynFlags.hs as a Haskell data structure.
In _dynamic_flags_, the actual flag strings for the ghc invocation are 
defined (like -prof, -threaded), they will activate the respective _Way_.
_wayTag_, in turn, defines short names used as a suffix for *.o and *.a 
files, for instance *.p_o for profiling, *.l_o for eventlog.
A number of other functions in there customise behaviour depending on 
the ways. Note _wayOptc_ which sets some options for the C compiler, 
like -DTRACING for the -eventlog way. However, it does not define DEBUG 
for the debug way!

In mk/ways.mk you will find all the short names, and some more options 
are defined (WAY_*_HC_OPTS). These definitions are for the driver 
script, and pass on the right (long-name) options to the Haskell 
compiler to activate what is inside DynFlags (like -prof for WAY_p_HC_OPTS).
Here we find
WAY_debug_HC_OPTS= -static -optc-DDEBUG -ticky -DTICKY_TICKY
which is what you were looking for

To build a GHC with debug-way RTS, you need to add GhcRtsWays += debug 
to your build.mk (also see mk/config.mk{.in}, which gathers the default 
ways to build depending on platform and build configuration).
I guess this might produce quite a number of new warnings and errors if 
you do it on a new platform...

Once you have built this, you can compile with -debug and pass RTS 
options to get debug traces and activate sanity checks, like so:
ghc -debug -myprogram.hs -o myprogramDebug
./myprogramDebug +RTS -Ds -DS
(-DS = sanity checks on, -Ds = scheduler tracing)
The usage message (see /rts/RtsFlags.c) tells you more options you can use.

Happy debugging!
/ Jost


On 05/14/2015 10:00 PM, ghc-devs-request at haskell.org wrote:
> Date: Thu, 14 May 2015 18:36:04 +1000
> From: Erik de Castro Lopo <mle+hs at mega-nerd.com>
> To: ghc-devs at haskell.org
> Subject: Debugging the RTS
> Message-ID: <20150514183604.2476baaaacd6a85ef1430b37 at mega-nerd.com>
> Content-Type: text/plain; charset=US-ASCII
>
> Hi all,
>
> I'm trying to debug a AArch64/Linux specific RTS issue and digging
> around in the rts C code, I see a large amount of code wrapped in
> "#if DEBUG" type statements, but no way to enable in either
> mk/build.mk or it seems in any of the other build related settings
> files in the mk/ directory.
>
> The only way I have found to enable this debug code that actually
> works is to enable this DEBUG code is to edit mk/ghc.mk as follows:
>
>      -STANDARD_OPTS += -DCOMPILING_RTS
>      +STANDARD_OPTS += -DCOMPILING_RTS -DDEBUG
>
> However, once I do that I get a bunch of C synatx errors.
>
> I am doing this wrong or has the DEBUG code bit rotted?
>
> Cheers,
> Erik
>



More information about the ghc-devs mailing list