Created
August 10, 2023 20:00
-
-
Save wavewave/662fcb687315002c2d3600c9c95cedbf to your computer and use it in GitHub Desktop.
ghc-debug on HeapOverflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm test.o | |
ghc -rtsopts -threaded test.hs | |
# run like the following | |
# GHC_DEBUG_SOCKET=/tmp/ghc-debug ./test +RTS -M1G |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "heapoverflow-ghc-debug-test"; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/master"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = {self, nixpkgs, flake-utils }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let pkgs = import nixpkgs { inherit system; }; | |
hspkgs = pkgs.haskell.packages.ghc962.override (old: { | |
overrides = hself: hsuper: { | |
ghc-debug-stub = pkgs.haskell.lib.doJailbreak (hself.callHackage "ghc-debug-stub" "0.4.0.0" {}); | |
ghc-debug-convention = hself.callHackage "ghc-debug-convention" "0.4.0.0" {}; | |
}; | |
}); | |
hsenv = hspkgs.ghcWithPackages (p: [ | |
p.ghc-debug-stub | |
p.cabal-install | |
]); | |
in { | |
devShells.default = | |
pkgs.mkShell { | |
buildInputs = [hsenv]; | |
}; | |
} | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NumericUnderscores #-} | |
module Main where | |
import Control.Concurrent | |
( forkIO, | |
threadDelay, | |
) | |
import Control.Exception | |
( AsyncException (HeapOverflow), | |
catch, | |
) | |
import Data.List (foldl) | |
import GHC.Debug.Stub | |
( pause, | |
withGhcDebug, | |
) | |
main' :: IO () | |
main' = do | |
forkIO $ do | |
let x = foldl (+) 0 [0..1_000_000_000] | |
print x | |
threadDelay 10_000_000 | |
main :: IO () | |
main = | |
withGhcDebug $ | |
catch main' $ \(e :: AsyncException) -> | |
case e of | |
HeapOverflow -> do | |
print "yay! HeapOverflow!" | |
print "i am pausing" | |
pause | |
_ -> pure () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment