ANN: GhciExt 0.7

Peter Hercek phercek at
Thu Oct 20 17:47:37 CEST 2011

I finally moved to GHC 7.0.3, a rather late update :)
I updated GhciExt for it and if you want to script ghci commands a bit 
you can grab it as an example and use. It probably works well enough. I 
was lucky and did not use debugger a lot lately, so I'm not sure.

It redefines some standard commands (like e.g. :break to output hit 
count) and adds some new commands (the most useful are probably :grep 
and :watch (conditional breakpoint)). Here is the list of the added 

Prelude> :defs long
:. <file> -- source commands from <file>
:* <count> <cmd>... -- run <cmd> <count> times
:x <cmd>... -- run <cmd> with stdout suppressed
:output -- restore ghci output (stdout and stderr) back
Restores stdout and stderr of ghci as it was during startup. You should not
ever need this command. It is here only if something would go wrong in 
and you need to recover (console) manually.
:redir <var> <cmd>... -- execute <cmd> redirecting stdout to <var>
:grep <args> < <cmd>... -- run grep <args> on <cmd> output
Runs grep from your OS on the output of <cmd>. This means all the options
of your OS grep are available. '<' separates grep options from the command.
:find <cmd> [-]<var> -- step with <cmd> until <var> is found
Prepend variable name with '-' to disable printing of its value.
:locate <cmd> <bpArgs> -- step with <cmd> until location <bpArgs> is hit
:repeat <cmd> <cond> -- repeat <cmd> until <cond> is true
:inject <cc> <c> <sc> <b> -- at location <b> run <c> if <cc> and stop if 
There are two special identifiers which can be used in the breakpoint
code (<c>) and the breakpoint stop condition (<sc>); but which are not
usable in the breakpoint code condition (<cc>). These are:
- ġė_BpId - macro name; translates to breakpoint id
- ġė_HitCnt - macro name; translates to breakpoint hit count
:strobe [&<c>] <b> -- at location <b> show hit count if <c>
:monitor [&<c>] <e> <b> -- :force expression <e> at location <b> if <c>
:watch <cond> <bpArgs> -- break at location <bpArgs> when <cond> is True
:count [<R>]<N> [<bp>] -- count/stop execution at <bp> or query bp hits
There are four ways how to use this command:
- :count 0 <bp> - never stops; counts hits and extends trace history
- :count N <bp> - stops when location <bp> is hit N-th time
- :count RN <bp> - stops when hitCount at bp is in Ord relation R with N
- :count N - shows hit count of a ghciExt breakpoint with number N.
:class <classId> -- show class methods
:defs [long] -- list user commands (possibly with long help)
General information for all GhciExt commands:
- Most arguments may be in quotation marks (to allow spaces in them).
- Instead of a regular quotation mark, @x can be used to start a string
argument too. In such a case the argument is finished when character
x appears again after `@x' string. Use any character in place of x.
- Most commands can have an end-line comment. The comment starts with
this sequence: "d--", where d is the argument delimiter; i.e. it
is '"', the x after '@' or whitespace based on the previous argument.
- GhciExt calls :init any time GHCi may have cleared your top level symbols.
Redefine :init to reintroduce the symbols you want always available.

More information about the Glasgow-haskell-users mailing list