debugger-hs: Write your GDB scripts in Haskell.

[ bsd3, debugging, library ] [ Propose Tags ]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],
Dependencies base (>=4.7 && <5), dlist (>=1 && <2), mtl (>=2 && <3), text (>=1 && <2) [details]
License BSD-3-Clause
Copyright Luc Tielen, 2021
Author Luc Tielen
Category debugging
Home page
Bug tracker
Source repo head: git clone
Uploaded by luc_tielen at 2021-12-12T18:12:34Z
Downloads 172 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for debugger-hs-

[back to package description]


A Haskell library for creating/metaprogramming GDB scripts.


GDB has Python integration, and while it is powerful, it has some problems:

  • Python code can end up interleaved in the GDB code, making it complicated really quickly.
  • Accessing variables between GDB and Python can get complicated too.

Besides that, also some things in GDB don't work as expected, such as commands that behave differently inside a user-defined command ("define"), which can lead to unexpected and buggy results.

If we use Haskell however, we get the following nice things:

  • A typesystem,
  • Can use full Haskell ecosystem for metaprogramming,
  • The generated output will be 100% GDB script only:
    • easier to use afterwards,
    • inspectable,
    • no need for this package once the script has been generated.


Partial evaluation/staged programming. You write a Haskell file that makes use of the DSL this package provides, and render it to a script that can be passed in to GDB like you would normally.

Here's an example of how you can use this library to generate a GDB script:

#!/usr/bin/env cabal
{- cabal:
build-depends: base, debugger-hs

{-# LANGUAGE OverloadedStrings #-}
module Main where

import qualified Debugger.Builder as D
import qualified Debugger.Render as D
import qualified Debugger.Statement as D

-- First we build up a Haskell value that represents our GDB scripts.
script :: D.Builder ()
script = do
  bp <- D.break (D.Function "main")
  D.command bp $ do
    D.print "42"

-- And then we can render the GDB script to stdout:
main :: IO ()
main = do
  let gdbScript = D.runBuilder script
  D.renderToStdOut gdbScript

If you save this file as "GDB.hs" and run it using cabal run GDB.hs, this will render the following GDB script:

break main
set $var0 = $bpnum
command $var0
  print "42"

Now you can use the generated script with GDB as follows:

# Replace $PROGRAM with the program you want to debug.
$ gdb $PROGRAM <<< $(< cabal run GDB.hs)
# or if your shell doesn't support the previous command:
$ cabal run GDB.hs > ./script.gdb
$ gdb $PROGRAM -ex "source ./script.gdb"


  • Create core AST datatype
  • Create builder monad for easily constructing GDB scripts using Haskell do-syntax.
  • Write function for compiling AST -> GDB script
  • Add helper functions for easily adding breakpoints (using tools like grep)
  • Extend core AST datatype to support more functionality
  • Add LLDB support also?
  • DSL (to support GDB and LLDB at same time)?