debugger-hs: Write your GDB scripts in Haskell.

[ bsd3, debugging, library ] [ Propose Tags ]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0
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
Maintainer luc.tielen@gmail.com
Category debugging
Home page https://github.com/luc-tielen/debugger-hs#readme
Bug tracker https://github.com/luc-tielen/debugger-hs/issues
Source repo head: git clone https://github.com/luc-tielen/debugger-hs
Uploaded by luc_tielen at 2021-12-12T17:21:41Z
Distributions NixOS:0.1.1.0
Downloads 75 total (1 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-0.1.0.0

[back to package description]

debugger-hs

A Haskell library for creating/metaprogramming GDB scripts.

Why?

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.

How?

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:

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"
    D.continue

-- And then we can render the GDB script to a file:
main :: IO ()
main = do
  let gdbScript = D.runBuilder script
  D.renderIO gdbScript "./script.gdb"

This will render the following GDB scripts:

break main
set $var0 = $bpnum
command $var0
  print "42"
  continue
end
# Replace $PROGRAM with the program you want to debug.
$ gdb $PROGRAM <<< $(< /path/to/stack-script)
# or if your shell doesn't support the previous command:
$ /path/to/stack-script > ./script.gdb
$ gdb $PROGRAM -ex "source ./script.gdb"

TODO

  • Create core AST datatype
  • Create builder monad for easily constructing GDB scripts using Haskell do-syntax.
  • Write function for compiling AST -> GDB script
  • Create CLI application (stack/nix?) that takes the DSL and outputs GDB to stdout.
  • 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)?