[Git][ghc/ghc][wip/ghc-with-debug] Add support for ghc-debug to ghc executable
fendor (@fendor)
gitlab at gitlab.haskell.org
Wed Jan 24 08:28:13 UTC 2024
fendor pushed to branch wip/ghc-with-debug at Glasgow Haskell Compiler / GHC
Commits:
9a09777f by Matthew Pickering at 2024-01-24T09:28:04+01:00
Add support for ghc-debug to ghc executable
- - - - -
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:
=====================================
.gitmodules
=====================================
@@ -117,3 +117,6 @@
[submodule "utils/hpc"]
path = utils/hpc
url = https://gitlab.haskell.org/hpc/hpc-bin.git
+[submodule "ghc-debug"]
+ path = ghc-debug
+ url = git at gitlab.haskell.org:ghc/ghc-debug.git
=====================================
ghc-debug
=====================================
@@ -0,0 +1 @@
+Subproject commit 537e462a5c987537725d95caa10fa6d7b30abf37
=====================================
ghc/Main.hs
=====================================
@@ -33,6 +33,7 @@ import GHC.Driver.Backpack ( doBackpack )
import GHC.Driver.Plugins
import GHC.Driver.Config.Logger (initLogFlags)
import GHC.Driver.Config.Diagnostic
+import GHC.Driver.Monad
import GHC.Platform
import GHC.Platform.Ways
@@ -101,6 +102,10 @@ import Data.Bifunctor
import GHC.Data.Graph.Directed
import qualified Data.List.NonEmpty as NE
+#if defined(GHC_DEBUG)
+import GHC.Debug.Stub
+#endif
+
-----------------------------------------------------------------------------
-- ToDo:
@@ -113,6 +118,13 @@ import qualified Data.List.NonEmpty as NE
-----------------------------------------------------------------------------
-- GHC's command-line interface
+debugWrapper :: IO a -> IO a
+#if defined(GHC_DEBUG)
+debugWrapper = withGhcDebug
+#else
+debugWrapper = id
+#endif
+
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
@@ -161,8 +173,10 @@ main = do
ShowGhcUsage -> showGhcUsage dflags
ShowGhciUsage -> showGhciUsage dflags
PrintWithDynFlags f -> putStrLn (f dflags)
- Right postLoadMode ->
- main' postLoadMode units dflags argv3 flagWarnings
+ Right postLoadMode -> do
+ reifyGhc $ \session -> debugWrapper $
+ reflectGhc (main' postLoadMode units dflags argv3 flagWarnings) session
+
main' :: PostLoadMode -> [String] -> DynFlags -> [Located String] -> [Warn]
-> Ghc ()
=====================================
ghc/ghc-bin.cabal.in
=====================================
@@ -22,6 +22,11 @@ Flag internal-interpreter
Default: False
Manual: True
+Flag ghc-debug
+ Description: Build with support for ghc-debug.
+ Default: False
+ Manual: True
+
Flag threaded
Description: Link the ghc executable against the threaded RTS
Default: True
@@ -42,6 +47,10 @@ Executable ghc
ghc-boot == @ProjectVersionMunged@,
ghc == @ProjectVersionMunged@
+ if flag(ghc-debug)
+ build-depends: ghc-debug-stub
+ CPP-OPTIONS: -DGHC_DEBUG
+
if os(windows)
Build-Depends: Win32 >= 2.3 && < 2.14
else
=====================================
hadrian/src/Packages.hs
=====================================
@@ -12,7 +12,7 @@ module Packages (
runGhc, semaphoreCompat, stm, templateHaskell, terminfo, text, time, timeout, touchy,
transformers, unlit, unix, win32, xhtml,
lintersCommon, lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace,
- ghcPackages, isGhcPackage,
+ ghcPackages, isGhcPackage, ghc_debug_convention, ghc_debug_stub,
-- * Package information
crossPrefix, programName, nonHsMainPackage, autogenPath, programPath, timeoutPath,
@@ -45,7 +45,9 @@ ghcPackages =
, terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml
, timeout
, lintersCommon
- , lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace ]
+ , lintNotes, lintCodes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace
+ , ghc_debug_convention
+ , ghc_debug_stub ]
-- TODO: Optimise by switching to sets of packages.
isGhcPackage :: Package -> Bool
@@ -132,6 +134,8 @@ unlit = util "unlit"
unix = lib "unix"
win32 = lib "Win32"
xhtml = lib "xhtml"
+ghc_debug_convention = lib "ghc-debug-convention" `setPath` "ghc-debug/convention"
+ghc_debug_stub = lib "ghc-debug-stub" `setPath` "ghc-debug/stub"
lintersCommon = lib "linters-common" `setPath` "linters/linters-common"
lintNotes = linter "lint-notes"
=====================================
hadrian/src/Settings/Default.hs
=====================================
@@ -159,6 +159,8 @@ stage1Packages = do
, unlit
, xhtml
, if winTarget then win32 else unix
+ , ghc_debug_convention
+ , ghc_debug_stub
]
, when (not cross)
[ haddock
=====================================
hadrian/src/Settings/Packages.hs
=====================================
@@ -99,6 +99,7 @@ packageArgs = do
, builder (Cabal Flags) ? mconcat
[ andM [expr ghcWithInterpreter, notStage0] `cabalFlag` "internal-interpreter"
+ , notStage0 `cabalFlag` "ghc-debug"
, ifM stage0
-- We build a threaded stage 1 if the bootstrapping compiler
-- supports it.
=====================================
instructions.md
=====================================
@@ -0,0 +1,45 @@
+# Building GHC
+
+* Add the following to _build/hadrian.settings
+
+```
+stage1.*.ghc.hs.opts += -finfo-table-map -fdistinct-constructor-tables
+```
+
+* Build GHC as normal
+
+```
+./hadrian/build -j8
+```
+
+* The result is a ghc-debug enabled compiler
+
+# Building a debugger
+
+* Use the compiler you just built to build ghc-debug
+
+```
+cd ghc-debug
+cabal update
+cabal new-build debugger -w ../_build/stage1/bin/ghc
+```
+
+# Running the debugger
+
+Modify `test/Test.hs` to implement the debugging thing you want to do. Perhaps
+start with `p30`, which is a program to generate a profile.
+
+
+* Start the process you want to debug
+```
+GHC_DEBUG_SOCKET=/tmp/ghc-debug build-cabal
+```
+
+* Start the debugger
+```
+cabal new-run debugger -w ...
+```
+
+* Open a ticket about the memory issue you find.
+
+
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9a09777fb4ac59711865c86673175d23c9c2d391
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9a09777fb4ac59711865c86673175d23c9c2d391
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240124/59910c0f/attachment-0001.html>
More information about the ghc-commits
mailing list