Hannes Siebenhandl pushed to branch wip/fendor/ghc-debug-baseline at Glasgow Haskell Compiler / GHC
Commits:
-
04894732
by fendor at 2026-05-29T10:14:27+02:00
8 changed files:
- .gitmodules
- + ghc-debug
- ghc/Main.hs
- ghc/ghc-bin.cabal.in
- hadrian/src/Packages.hs
- hadrian/src/Settings/Default.hs
- hadrian/src/Settings/Packages.hs
- + instructions.md
Changes:
| ... | ... | @@ -122,3 +122,6 @@ |
| 122 | 122 | [submodule "libraries/libffi-clib"]
|
| 123 | 123 | path = libraries/libffi-clib
|
| 124 | 124 | url = https://gitlab.haskell.org/ghc/libffi-clib.git
|
| 125 | +[submodule "ghc-debug"]
|
|
| 126 | + path = ghc-debug
|
|
| 127 | + url = git@gitlab.haskell.org:ghc/ghc-debug.git |
| 1 | +Subproject commit 2b8cf733f079af6e88eb4d9fa65b1215cc24ebc4 |
| ... | ... | @@ -32,6 +32,7 @@ import GHC.Driver.Backpack ( doBackpack ) |
| 32 | 32 | import GHC.Driver.Plugins
|
| 33 | 33 | import GHC.Driver.Config.Logger (initLogFlags)
|
| 34 | 34 | import GHC.Driver.Config.Diagnostic
|
| 35 | +import GHC.Driver.Monad
|
|
| 35 | 36 | |
| 36 | 37 | import GHC.Platform
|
| 37 | 38 | import GHC.Platform.Host
|
| ... | ... | @@ -91,6 +92,10 @@ import Data.List ( isPrefixOf, partition, intercalate ) |
| 91 | 92 | import Prelude
|
| 92 | 93 | import qualified Data.List.NonEmpty as NE
|
| 93 | 94 | |
| 95 | +#if defined(GHC_DEBUG)
|
|
| 96 | +import GHC.Debug.Stub
|
|
| 97 | +#endif
|
|
| 98 | + |
|
| 94 | 99 | -----------------------------------------------------------------------------
|
| 95 | 100 | -- ToDo:
|
| 96 | 101 | |
| ... | ... | @@ -103,6 +108,13 @@ import qualified Data.List.NonEmpty as NE |
| 103 | 108 | -----------------------------------------------------------------------------
|
| 104 | 109 | -- GHC's command-line interface
|
| 105 | 110 | |
| 111 | +debugWrapper :: IO a -> IO a
|
|
| 112 | +#if defined(GHC_DEBUG)
|
|
| 113 | +debugWrapper = withGhcDebug
|
|
| 114 | +#else
|
|
| 115 | +debugWrapper = id
|
|
| 116 | +#endif
|
|
| 117 | + |
|
| 106 | 118 | main :: IO ()
|
| 107 | 119 | main = do
|
| 108 | 120 | hSetBuffering stdout LineBuffering
|
| ... | ... | @@ -151,8 +163,10 @@ main = do |
| 151 | 163 | ShowGhcUsage -> showGhcUsage dflags
|
| 152 | 164 | ShowGhciUsage -> showGhciUsage dflags
|
| 153 | 165 | PrintWithDynFlags f -> putStrLn (f dflags)
|
| 154 | - Right postLoadMode ->
|
|
| 155 | - main' postLoadMode units dflags argv3 flagWarnings
|
|
| 166 | + Right postLoadMode -> do
|
|
| 167 | + reifyGhc $ \session -> debugWrapper $
|
|
| 168 | + reflectGhc (main' postLoadMode units dflags argv3 flagWarnings) session
|
|
| 169 | + |
|
| 156 | 170 | |
| 157 | 171 | main' :: PostLoadMode -> [String] -> DynFlags -> [Located String] -> [Warn]
|
| 158 | 172 | -> Ghc ()
|
| ... | ... | @@ -27,6 +27,11 @@ Flag interpreter |
| 27 | 27 | Default: False
|
| 28 | 28 | Manual: True
|
| 29 | 29 | |
| 30 | +Flag ghc-debug
|
|
| 31 | + Description: Build with support for ghc-debug.
|
|
| 32 | + Default: False
|
|
| 33 | + Manual: True
|
|
| 34 | + |
|
| 30 | 35 | Flag threaded
|
| 31 | 36 | Description: Link the ghc executable against the threaded RTS
|
| 32 | 37 | Default: True
|
| ... | ... | @@ -50,6 +55,10 @@ Executable ghc |
| 50 | 55 | ghc-boot == @ProjectVersionMunged@,
|
| 51 | 56 | ghc == @ProjectVersionMunged@
|
| 52 | 57 | |
| 58 | + if flag(ghc-debug)
|
|
| 59 | + build-depends: ghc-debug-stub
|
|
| 60 | + CPP-OPTIONS: -DGHC_DEBUG
|
|
| 61 | + |
|
| 53 | 62 | if os(windows)
|
| 54 | 63 | Build-Depends: Win32 >= 2.3 && < 2.15
|
| 55 | 64 | else
|
| ... | ... | @@ -12,7 +12,7 @@ module Packages ( |
| 12 | 12 | runGhc, semaphoreCompat, stm, templateHaskell, thLift, thQuasiquoter, terminfo, text, time, timeout,
|
| 13 | 13 | transformers, unlit, unix, win32, xhtml,
|
| 14 | 14 | lintersCommon, lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace,
|
| 15 | - ghcPackages, isGhcPackage,
|
|
| 15 | + ghcPackages, isGhcPackage, ghc_debug_convention, ghc_debug_stub,
|
|
| 16 | 16 | |
| 17 | 17 | -- * Package information
|
| 18 | 18 | crossPrefix, programName, nonHsMainPackage, programPath, timeoutPath,
|
| ... | ... | @@ -43,7 +43,9 @@ ghcPackages = |
| 43 | 43 | , terminfo, text, time, transformers, unlit, unix, win32, xhtml, fileio
|
| 44 | 44 | , timeout
|
| 45 | 45 | , lintersCommon
|
| 46 | - , lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace ]
|
|
| 46 | + , lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace
|
|
| 47 | + , ghc_debug_convention
|
|
| 48 | + , ghc_debug_stub ]
|
|
| 47 | 49 | |
| 48 | 50 | -- TODO: Optimise by switching to sets of packages.
|
| 49 | 51 | isGhcPackage :: Package -> Bool
|
| ... | ... | @@ -135,6 +137,8 @@ unlit = util "unlit" |
| 135 | 137 | unix = lib "unix"
|
| 136 | 138 | win32 = lib "Win32"
|
| 137 | 139 | xhtml = lib "xhtml"
|
| 140 | +ghc_debug_convention = lib "ghc-debug-convention" `setPath` "ghc-debug/convention"
|
|
| 141 | +ghc_debug_stub = lib "ghc-debug-stub" `setPath` "ghc-debug/stub"
|
|
| 138 | 142 | |
| 139 | 143 | lintersCommon = lib "linters-common" `setPath` "linters/linters-common"
|
| 140 | 144 | lintNotes = linter "lint-notes"
|
| ... | ... | @@ -188,6 +188,8 @@ stage1Packages = do |
| 188 | 188 | , xhtml
|
| 189 | 189 | , ghcToolchainBin
|
| 190 | 190 | , if winTarget then win32 else unix
|
| 191 | + , ghc_debug_convention
|
|
| 192 | + , ghc_debug_stub
|
|
| 191 | 193 | ]
|
| 192 | 194 | , when (not cross)
|
| 193 | 195 | [ hpcBin
|
| ... | ... | @@ -124,6 +124,7 @@ packageArgs = do |
| 124 | 124 | -- We build a threaded stage N, N>1 if the configuration calls
|
| 125 | 125 | -- for it.
|
| 126 | 126 | (compilerStageOption ghcThreaded `cabalFlag` "threaded")
|
| 127 | + , notStage0 `cabalFlag` "ghc-debug"
|
|
| 127 | 128 | ]
|
| 128 | 129 | ]
|
| 129 | 130 |
| 1 | +# Building GHC
|
|
| 2 | + |
|
| 3 | +* Add the following to _build/hadrian.settings
|
|
| 4 | + |
|
| 5 | +```
|
|
| 6 | +stage1.*.ghc.hs.opts += -finfo-table-map -fdistinct-constructor-tables
|
|
| 7 | +```
|
|
| 8 | + |
|
| 9 | +* Build GHC as normal
|
|
| 10 | + |
|
| 11 | +```
|
|
| 12 | +./hadrian/build -j8
|
|
| 13 | +```
|
|
| 14 | + |
|
| 15 | +* The result is a ghc-debug enabled compiler
|
|
| 16 | + |
|
| 17 | +# Building a debugger
|
|
| 18 | + |
|
| 19 | +* Use the compiler you just built to build ghc-debug
|
|
| 20 | + |
|
| 21 | +```
|
|
| 22 | +cd ghc-debug
|
|
| 23 | +cabal update
|
|
| 24 | +cabal new-build debugger -w ../_build/stage1/bin/ghc
|
|
| 25 | +```
|
|
| 26 | + |
|
| 27 | +# Running the debugger
|
|
| 28 | + |
|
| 29 | +Modify `test/Test.hs` to implement the debugging thing you want to do. Perhaps
|
|
| 30 | +start with `p30`, which is a program to generate a profile.
|
|
| 31 | + |
|
| 32 | + |
|
| 33 | +* Start the process you want to debug
|
|
| 34 | +```
|
|
| 35 | +GHC_DEBUG_SOCKET=/tmp/ghc-debug build-cabal
|
|
| 36 | +```
|
|
| 37 | + |
|
| 38 | +* Start the debugger
|
|
| 39 | +```
|
|
| 40 | +cabal new-run debugger -w ...
|
|
| 41 | +```
|
|
| 42 | + |
|
| 43 | +* Open a ticket about the memory issue you find.
|
|
| 44 | + |
|
| 45 | + |