[Git][ghc/ghc][wip/ghc-with-debug] Add support for ghc-debug to ghc executable
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Thu Mar 9 11:28:24 UTC 2023
Matthew Pickering pushed to branch wip/ghc-with-debug at Glasgow Haskell Compiler / GHC
Commits:
325c124e by Matthew Pickering at 2023-03-09T11:28:14+00: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
=====================================
@@ -113,3 +113,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
=====================================
@@ -32,6 +32,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
@@ -99,6 +100,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:
@@ -111,6 +116,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
@@ -159,8 +171,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
=====================================
@@ -11,7 +11,7 @@ module Packages (
runGhc, stm, templateHaskell, terminfo, text, time, timeout, touchy,
transformers, unlit, unix, win32, xhtml,
lintersCommon, lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace,
- ghcPackages, isGhcPackage,
+ ghcPackages, isGhcPackage, ghc_debug_convention, ghc_debug_stub,
-- * Package information
crossPrefix, programName, nonHsMainPackage, autogenPath, programPath, timeoutPath,
@@ -43,7 +43,9 @@ ghcPackages =
, terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml
, timeout
, lintersCommon
- , lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace ]
+ , lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace
+ , ghc_debug_convention
+ , ghc_debug_stub ]
-- TODO: Optimise by switching to sets of packages.
isGhcPackage :: Package -> Bool
@@ -122,6 +124,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
=====================================
@@ -146,6 +146,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
=====================================
@@ -89,6 +89,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/325c124eb817b157476b305265a0f8361df92d3d
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/325c124eb817b157476b305265a0f8361df92d3d
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/20230309/dbd016f1/attachment-0001.html>
More information about the ghc-commits
mailing list