Andreas Klebinger pushed to branch wip/ghc-with-debug at Glasgow Haskell Compiler / GHC
Commits:
-
d2bf0f6a
by Matthew Pickering at 2025-10-09T16:28:40+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:
... | ... | @@ -118,3 +118,6 @@ |
118 | 118 | [submodule "libraries/file-io"]
|
119 | 119 | path = libraries/file-io
|
120 | 120 | url = https://gitlab.haskell.org/ghc/packages/file-io.git
|
121 | +[submodule "ghc-debug"]
|
|
122 | + path = ghc-debug
|
|
123 | + url = git@gitlab.haskell.org:ghc/ghc-debug.git |
1 | +Subproject commit 1b0f36fab86e9baa9734c88dcc1dbe17d10d8c93 |
... | ... | @@ -33,6 +33,7 @@ import GHC.Driver.Backpack ( doBackpack ) |
33 | 33 | import GHC.Driver.Plugins
|
34 | 34 | import GHC.Driver.Config.Logger (initLogFlags)
|
35 | 35 | import GHC.Driver.Config.Diagnostic
|
36 | +import GHC.Driver.Monad
|
|
36 | 37 | |
37 | 38 | import GHC.Platform
|
38 | 39 | import GHC.Platform.Host
|
... | ... | @@ -92,6 +93,10 @@ import Data.List ( isPrefixOf, partition, intercalate ) |
92 | 93 | import Prelude
|
93 | 94 | import qualified Data.List.NonEmpty as NE
|
94 | 95 | |
96 | +#if defined(GHC_DEBUG)
|
|
97 | +import GHC.Debug.Stub
|
|
98 | +#endif
|
|
99 | + |
|
95 | 100 | -----------------------------------------------------------------------------
|
96 | 101 | -- ToDo:
|
97 | 102 | |
... | ... | @@ -104,6 +109,13 @@ import qualified Data.List.NonEmpty as NE |
104 | 109 | -----------------------------------------------------------------------------
|
105 | 110 | -- GHC's command-line interface
|
106 | 111 | |
112 | +debugWrapper :: IO a -> IO a
|
|
113 | +#if defined(GHC_DEBUG)
|
|
114 | +debugWrapper = withGhcDebug
|
|
115 | +#else
|
|
116 | +debugWrapper = id
|
|
117 | +#endif
|
|
118 | + |
|
107 | 119 | main :: IO ()
|
108 | 120 | main = do
|
109 | 121 | hSetBuffering stdout LineBuffering
|
... | ... | @@ -152,8 +164,10 @@ main = do |
152 | 164 | ShowGhcUsage -> showGhcUsage dflags
|
153 | 165 | ShowGhciUsage -> showGhciUsage dflags
|
154 | 166 | PrintWithDynFlags f -> putStrLn (f dflags)
|
155 | - Right postLoadMode ->
|
|
156 | - main' postLoadMode units dflags argv3 flagWarnings
|
|
167 | + Right postLoadMode -> do
|
|
168 | + reifyGhc $ \session -> debugWrapper $
|
|
169 | + reflectGhc (main' postLoadMode units dflags argv3 flagWarnings) session
|
|
170 | + |
|
157 | 171 | |
158 | 172 | main' :: PostLoadMode -> [String] -> DynFlags -> [Located String] -> [Warn]
|
159 | 173 | -> Ghc ()
|
... | ... | @@ -22,6 +22,11 @@ Flag internal-interpreter |
22 | 22 | Default: False
|
23 | 23 | Manual: True
|
24 | 24 | |
25 | +Flag ghc-debug
|
|
26 | + Description: Build with support for ghc-debug.
|
|
27 | + Default: False
|
|
28 | + Manual: True
|
|
29 | + |
|
25 | 30 | Flag threaded
|
26 | 31 | Description: Link the ghc executable against the threaded RTS
|
27 | 32 | Default: True
|
... | ... | @@ -45,6 +50,10 @@ Executable ghc |
45 | 50 | ghc-boot == @ProjectVersionMunged@,
|
46 | 51 | ghc == @ProjectVersionMunged@
|
47 | 52 | |
53 | + if flag(ghc-debug)
|
|
54 | + build-depends: ghc-debug-stub
|
|
55 | + CPP-OPTIONS: -DGHC_DEBUG
|
|
56 | + |
|
48 | 57 | if os(windows)
|
49 | 58 | Build-Depends: Win32 >= 2.3 && < 2.15
|
50 | 59 | else
|
... | ... | @@ -12,7 +12,7 @@ module Packages ( |
12 | 12 | runGhc, semaphoreCompat, stm, templateHaskell, 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
|
... | ... | @@ -133,6 +135,8 @@ unlit = util "unlit" |
133 | 135 | unix = lib "unix"
|
134 | 136 | win32 = lib "Win32"
|
135 | 137 | xhtml = lib "xhtml"
|
138 | +ghc_debug_convention = lib "ghc-debug-convention" `setPath` "ghc-debug/convention"
|
|
139 | +ghc_debug_stub = lib "ghc-debug-stub" `setPath` "ghc-debug/stub"
|
|
136 | 140 | |
137 | 141 | lintersCommon = lib "linters-common" `setPath` "linters/linters-common"
|
138 | 142 | lintNotes = linter "lint-notes"
|
... | ... | @@ -174,6 +174,8 @@ stage1Packages = do |
174 | 174 | , unlit
|
175 | 175 | , xhtml
|
176 | 176 | , if winTarget then win32 else unix
|
177 | + , ghc_debug_convention
|
|
178 | + , ghc_debug_stub
|
|
177 | 179 | ]
|
178 | 180 | , when (not cross)
|
179 | 181 | [ hpcBin
|
... | ... | @@ -55,6 +55,11 @@ packageArgs = do |
55 | 55 | , package cabal ?
|
56 | 56 | stage0 ? builder Ghc ? arg "-O0"
|
57 | 57 | |
58 | + , package ghc_debug_stub ?
|
|
59 | + builder (Cabal Flags) ? mconcat
|
|
60 | + [ arg "+eras"
|
|
61 | + ]
|
|
62 | + |
|
58 | 63 | ------------------------------- compiler -------------------------------
|
59 | 64 | , package compiler ? mconcat
|
60 | 65 | [ builder Alex ? arg "--latin1"
|
... | ... | @@ -116,6 +121,7 @@ packageArgs = do |
116 | 121 | |
117 | 122 | , builder (Cabal Flags) ? mconcat
|
118 | 123 | [ (expr (ghcWithInterpreter stage)) `cabalFlag` "internal-interpreter"
|
124 | + , notStage0 `cabalFlag` "ghc-debug"
|
|
119 | 125 | , ifM stage0
|
120 | 126 | -- We build a threaded stage 1 if the bootstrapping compiler
|
121 | 127 | -- supports it.
|
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 | + |