imp: rename ghcdebug build flag to debug, and enable stack traces with it

Builds made with ghc 9.10+ and the 'debug' build flag, will show
(some kind of, partial) stack traces when the program ends with an
error. (And also will have ghc-debug support enabled.)

The stack traces will probably improve in due course.
This commit is contained in:
Simon Michael 2024-10-19 18:47:03 -10:00
parent b6a5687a38
commit 7325b75d5b
15 changed files with 54 additions and 37 deletions

View File

@ -556,14 +556,14 @@ INSTALLING:
$STACK install --local-bin-path bin/old
for e in hledger hledger-ui hledger-web ; do mv bin/old/$e bin/old/$e-{{ VER }}; echo "bin/old/$e-{{ VER }}"; done
# install hledger with ghc-debug support as bin/hledger*-dbg
# install hledger with stack traces and ghc-debug support enabled, as bin/hledger*-dbg
@installasdbg *STACKARGS:
$STACK install --local-bin-path bin --flag '*:ghcdebug' {{ STACKARGS }} hledger
$STACK install --local-bin-path bin --flag '*:debug' {{ STACKARGS }} hledger
for e in hledger ; do mv bin/$e bin/$e-dbg; echo "bin/$e-dbg"; done
# install all hledger executables with ghc-debug support as bin/hledger*-dbg
# install all hledger executables with stack traces and ghc-debug support enabled, as bin/hledger*-dbg
@installallasdbg *STACKARGS:
$STACK install --local-bin-path bin --flag '*:ghcdebug' {{ STACKARGS }}
$STACK install --local-bin-path bin --flag '*:debug' {{ STACKARGS }}
for e in hledger hledger-ui hledger-web ; do mv bin/$e bin/$e-dbg; echo "bin/$e-dbg"; done
# # make must be GNU Make 4.3+

View File

@ -184,7 +184,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.List hiding (uncons)
-- import Debug.Breakpoint
import Debug.Trace (trace, traceIO, traceShowId)
#ifdef GHCDEBUG
#ifdef DEBUG
import GHC.Debug.Stub (pause, withGhcDebug)
#endif
import Safe (readDef)
@ -224,7 +224,7 @@ debugLevel = case dropWhile (/="--debug") progArgs of
_ -> 0
-- | Whether ghc-debug support is included in this build, and if so, how it will behave.
-- When hledger is built with the ghcdebug cabal build flag (normally disabled),
-- When hledger is built with the @debug@ cabal flag (off by default),
-- it can listen (on unix ?) for connections from ghc-debug clients like ghc-debug-brick,
-- for pausing/resuming the program and inspecting memory usage and profile information.
--
@ -244,7 +244,7 @@ data GhcDebugMode =
-- | Is the hledger-lib package built with ghc-debug support ?
ghcDebugSupportedInLib :: Bool
ghcDebugSupportedInLib =
#ifdef GHCDEBUG
#ifdef DEBUG
True
#else
False
@ -265,7 +265,7 @@ ghcDebugMode =
-- | When ghc-debug support has been built into the program and enabled at runtime with --debug=-N,
-- this calls ghc-debug's withGhcDebug; otherwise it's a no-op.
withGhcDebug' =
#ifdef GHCDEBUG
#ifdef DEBUG
if ghcDebugMode > GDDisabled then withGhcDebug else id
#else
id
@ -274,7 +274,7 @@ withGhcDebug' =
-- | When ghc-debug support has been built into the program, this calls ghc-debug's pause, otherwise it's a no-op.
ghcDebugPause' :: IO ()
ghcDebugPause' =
#ifdef GHCDEBUG
#ifdef DEBUG
pause
#else
return ()

View File

@ -96,7 +96,7 @@ ghc-options:
- -Wno-unused-do-bind
flags:
ghcdebug:
debug:
description: Build with support for attaching a ghc-debug client
default: false
manual: true
@ -105,8 +105,8 @@ when:
- condition: (!(os(windows)))
dependencies:
- pager >=0.1.1.0
- condition: (flag(ghcdebug))
cpp-options: -DGHCDEBUG
- condition: (flag(debug))
cpp-options: -DDEBUG
dependencies:
- ghc-debug-stub >=0.6.0.0 && <0.7

View File

@ -67,10 +67,15 @@ hledgerUiMain = withGhcDebug' $ withProgName "hledger-ui.log" $ do -- force Hle
#if MIN_VERSION_base(4,20,0)
-- Control ghc 9.10+'s stack traces.
-- Strangely only hledger-ui has been showing them (when command line processing fails),
-- even though hledger and hledger-web process it in just the same way.
-- Disable them here.
-- CostCentreBacktrace - collect cost-centre stack backtraces (only available when built with profiling)
-- HasCallStackBacktrace - collect HasCallStack backtraces
-- ExecutionBacktrace - collect backtraces from native execution stack unwinding
-- IPEBacktrace - collect backtraces from Info Table Provenance Entries
#ifdef DEBUG
setBacktraceMechanismState HasCallStackBacktrace True
#else
setBacktraceMechanismState HasCallStackBacktrace False
#endif
#endif
traceLogAtIO 1 "\n\n\n\n==== hledger-ui start"

View File

@ -33,7 +33,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef GHCDEBUG
#ifdef DEBUG
True
#else
False

View File

@ -37,7 +37,7 @@ flags:
description: Build with support for multithreaded execution
default: true
manual: false
ghcdebug:
debug:
description: Build with support for attaching a ghc-debug client
default: false
manual: true
@ -56,8 +56,8 @@ dependencies:
- base >=4.14 && <4.21
when:
- condition: (flag(ghcdebug))
cpp-options: -DGHCDEBUG
- condition: (flag(debug))
cpp-options: -DDEBUG
dependencies:
- ghc-debug-stub >=0.6.0.0 && <0.7

View File

@ -55,7 +55,15 @@ hledgerWebMain = withGhcDebug' $ do
#if MIN_VERSION_base(4,20,0)
-- Control ghc 9.10+'s stack traces.
-- CostCentreBacktrace - collect cost-centre stack backtraces (only available when built with profiling)
-- HasCallStackBacktrace - collect HasCallStack backtraces
-- ExecutionBacktrace - collect backtraces from native execution stack unwinding
-- IPEBacktrace - collect backtraces from Info Table Provenance Entries
#ifdef DEBUG
setBacktraceMechanismState HasCallStackBacktrace True
#else
setBacktraceMechanismState HasCallStackBacktrace False
#endif
#endif
-- try to encourage user's $PAGER to properly display ANSI (in command line help)

View File

@ -43,7 +43,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef GHCDEBUG
#ifdef DEBUG
True
#else
False

View File

@ -59,7 +59,7 @@ flags:
description: Build with support for multithreaded execution.
default: true
manual: false
ghcdebug:
debug:
description: Build with support for attaching a ghc-debug client
default: false
manual: true
@ -80,8 +80,8 @@ when:
# 'ghc-options: -O0' is not needed. Use the --disable-optimization configure flag.
- condition: flag(dev)
ghc-options: -O0
- condition: (flag(ghcdebug))
cpp-options: -DGHCDEBUG
- condition: (flag(debug))
cpp-options: -DDEBUG
dependencies:
- ghc-debug-stub >=0.6.0.0 && <0.7

View File

@ -196,11 +196,15 @@ main = withGhcDebug' $ do
#if MIN_VERSION_base(4,20,0)
-- Control ghc 9.10+'s stack traces.
-- CostCentreBacktrace - collect cost-centre stack backtraces (only available when built with profiling)
-- HasCallStackBacktrace - collect HasCallStack backtraces
-- ExecutionBacktrace - collect backtraces from native execution stack unwinding
-- IPEBacktrace - collect backtraces from Info Table Provenance Entries
#ifdef DEBUG
setBacktraceMechanismState HasCallStackBacktrace True
#else
setBacktraceMechanismState HasCallStackBacktrace False
-- CostCentreBacktrace - collect cost-centre stack backtraces (only available when built with profiling)
-- HasCallStackBacktrace - collect HasCallStack backtraces
-- ExecutionBacktrace - collect backtraces from native execution stack unwinding
-- IPEBacktrace - collect backtraces from Info Table Provenance Entries
#endif
#endif
-- 0. let's go!

View File

@ -134,7 +134,7 @@ prognameandversion :: String
prognameandversion =
versionStringWith
$$tGitInfoCwdTry
#ifdef GHCDEBUG
#ifdef DEBUG
True
#else
False

View File

@ -39,7 +39,7 @@ packagemajorversion :: PackageVersion
packagemajorversion = intercalate "." $ take 2 $ splitAtElement '.' packageversion
-- | Given possible git state info from the build directory (or a git error, which is ignored),
-- and the ghcdebug build flag, executable name and package version for the package being built,
-- and the debug build flag, executable name and package version for the package being built,
-- make the best version string we can. Here is the logic:
--
-- * Program name, OS and architecture are always shown.
@ -50,7 +50,7 @@ packagemajorversion = intercalate "." $ take 2 $ splitAtElement '.' packageversi
-- * (TODO, requires adding --match support to githash:
-- If there are tags matching THISPKG-[0-9]*, the latest one is used to calculate patch level
-- (number of commits since tag), and if non-zero, it and the branch name are shown.)
-- * If the ghcdebug build flag was enabled for the package being built, and for hledger-lib (both are needed),
-- * If the debug build flag was enabled for the package being built, and for hledger-lib (both are needed),
-- "ghc-debug support" is shown.
--
-- Some example outputs:
@ -64,7 +64,7 @@ packagemajorversion = intercalate "." $ take 2 $ splitAtElement '.' packageversi
--
-- The GitInfo if any, fetched by template haskell, is passed down from
-- a top-level module, reducing wasteful recompilation.
-- The status of the ghcdebug build flag is also passed down, since it is
-- The status of the debug build flag is also passed down, since it is
-- specific to each hledger package.
--
-- This is used indirectly by at least hledger, hledger-ui, and hledger-web,

View File

@ -99,8 +99,8 @@ flags:
description: Build with support for multithreaded execution
default: true
manual: false
ghcdebug:
description: Build with support for attaching a ghc-debug client
debug:
description: Build with GHC 9.10+'s stack traces enabled, and with support for attaching a ghc-debug client
default: false
manual: true
@ -155,8 +155,8 @@ when:
- condition: (!(os(windows))) && (flag(terminfo))
dependencies:
- terminfo
- condition: (flag(ghcdebug))
cpp-options: -DGHCDEBUG
- condition: (flag(debug))
cpp-options: -DDEBUG
dependencies:
- ghc-debug-stub >=0.6.0.0 && <0.7

View File

@ -34,7 +34,7 @@ extra-deps:
# to silence a warning
- wizards-1.0.3@rev:3
# for dev builds when the ghcdebug flag is enabled:
# for dev builds when the debug flag is enabled:
- ghc-debug-convention-0.6.0.0
- ghc-debug-stub-0.6.0.0

View File

@ -9,7 +9,7 @@ packages:
- hledger-web
extra-deps:
# needed only for dev builds when the ghcdebug flag is enabled:
# needed only for dev builds when the debug flag is enabled:
- ghc-debug-convention-0.6.0.0
- ghc-debug-stub-0.6.0.0