A preprocessor for the debug package.
A preprocessor to automate the instrumentation of a module for the debug package
debug-pp
A preprocessor for streamlining the debug instrumentation of a module or a package.
Description
debug-pp is a Haskell source preprocessor that performs the steps a programmer would need to follow in order to debug a module with the debug package. That is:
- append an import for the 
Debugmodule, and - wrap the body in a 
debugsplice using a TH declaration quasiquote. 
Usage
usage: debug-pp [FILENAME] [SOURCE] [DEST]
Instrument Haskell module for debugging from SOURCE (derived from FILENAME) and write
standard Haskell to DEST.
If no FILENAME, use SOURCE as the original name.
If no DEST or if DEST is `-', write to standard output.
If no SOURCE or if SOURCE is `-', read standard input.
To instrument a module, add the following pragma to the top of the file:
{-# OPTIONS -F -pgmF debug-pp #-}
To instrument an entire program, add the following line to your stack descriptor, or if you don't use stack, to your cabal descriptor:
ghc-options: -F -pgmF debug-pp
In both cases you will also need to modify your Cabal descriptor in order to:
- add a dependency on the 
debugpackage, and - add a build tool depends on 
debug-pp(required Cabal 2.0) : 
Library
  ...
  build-tool-depends: debug-pp:debug-pp
Configuration
The tool is customizable to some extent. It tries to find a config file in the following order:
.debug-pp.yamlin the current directory (useful for per-directory settings).debug-pp.yamlin the nearest ancestor directory (useful for per-project settings)debug-pp/config.yamlin the platform’s configuration directory (on Windows, it is %APPDATA%, elsewhere it defaults to~/.configand can be overridden by theXDG_CONFIG_HOMEenvironment variable; useful for user-wide settings).debug-pp.yamlin your home directory (useful for user-wide settings)- The default settings.
 
Use debug-pp --defaults > .debug-pp.yaml to dump a well-documented default configuration to a file, this way you can get started quickly.
The configuration options include:
- Exclude modules by name.
 - Instrument the 
mainfunction to launch a web browser upon completion. - Select which language extensions are included automatically.
 - Configure the 
debug-hoedinstrumentation to include e.g. derivingGenericandObservableinstances 
Motivation
Debugging individual functions is often impractical due to the declaration groups restriction of Template Haskell. Therefore, it's often easier to debug an entire module.
However, error messages are much worse for TH quoted code. Errors like
Not in scope: data constructor Foo in line XbecomeNot in scope: Foo, in the TH quotation ENTIRE MODULE HERE.Personally, quoting/unquoting the module by hand is annoying. Having a preprocessor do this for me is convenient, and can be easily tied to a Cabal flag or a stack command line arg.