Hannes Siebenhandl pushed to branch wip/fendor/backtraces-decoders at Glasgow Haskell Compiler / GHC
Commits:
-
7324479a
by fendor at 2025-07-18T15:56:55+02:00
5 changed files:
- libraries/ghc-internal/src/GHC/Internal/Exception/Backtrace.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
Changes:
| ... | ... | @@ -11,9 +11,9 @@ import GHC.Internal.IORef |
| 11 | 11 | import GHC.Internal.IO.Unsafe (unsafePerformIO)
|
| 12 | 12 | import GHC.Internal.Exception.Context
|
| 13 | 13 | import GHC.Internal.Ptr
|
| 14 | +import GHC.Internal.Data.Maybe (fromMaybe)
|
|
| 14 | 15 | import GHC.Internal.Stack.Types as GHC.Stack (CallStack)
|
| 15 | 16 | import qualified GHC.Internal.Stack as HCS
|
| 16 | -import qualified GHC.Internal.ExecutionStack as ExecStack
|
|
| 17 | 17 | import qualified GHC.Internal.ExecutionStack.Internal as ExecStack
|
| 18 | 18 | import qualified GHC.Internal.Stack.CloneStack as CloneStack
|
| 19 | 19 | import qualified GHC.Internal.Stack.CCS as CCS
|
| ... | ... | @@ -91,8 +91,8 @@ data Backtraces = |
| 91 | 91 | Backtraces {
|
| 92 | 92 | btrCostCentre :: Maybe (Ptr CCS.CostCentreStack),
|
| 93 | 93 | btrHasCallStack :: Maybe HCS.CallStack,
|
| 94 | - btrExecutionStack :: Maybe [ExecStack.Location],
|
|
| 95 | - btrIpe :: Maybe [CloneStack.StackEntry]
|
|
| 94 | + btrExecutionStack :: Maybe ExecStack.StackTrace,
|
|
| 95 | + btrIpe :: Maybe CloneStack.StackSnapshot
|
|
| 96 | 96 | }
|
| 97 | 97 | |
| 98 | 98 | -- | Render a set of backtraces to a human-readable string.
|
| ... | ... | @@ -109,8 +109,10 @@ displayBacktraces bts = concat |
| 109 | 109 | |
| 110 | 110 | -- The unsafePerformIO here is safe as we don't currently unload cost-centres.
|
| 111 | 111 | displayCc = unlines . map (indent 2) . unsafePerformIO . CCS.ccsToStrings
|
| 112 | - displayExec = unlines . map (indent 2 . flip ExecStack.showLocation "")
|
|
| 113 | - displayIpe = unlines . map (indent 2 . CloneStack.prettyStackEntry)
|
|
| 112 | + displayExec = unlines . map (indent 2 . flip ExecStack.showLocation "") . fromMaybe [] . ExecStack.stackFrames
|
|
| 113 | + -- The unsafePerformIO here is safe as 'StackSnapshot' makes sure neither the stack frames nor
|
|
| 114 | + -- references closures can be garbage collected.
|
|
| 115 | + displayIpe = unlines . map (indent 2 . CloneStack.prettyStackEntry) . unsafePerformIO . CloneStack.decode
|
|
| 114 | 116 | displayHsc = unlines . map (indent 2 . prettyCallSite) . HCS.getCallStack
|
| 115 | 117 | where prettyCallSite (f, loc) = f ++ ", called at " ++ HCS.prettySrcLoc loc
|
| 116 | 118 | |
| ... | ... | @@ -140,12 +142,11 @@ collectBacktraces' enabled = HCS.withFrozenCallStack $ do |
| 140 | 142 | Just `fmap` CCS.getCurrentCCS ()
|
| 141 | 143 | |
| 142 | 144 | exec <- collect ExecutionBacktrace $ do
|
| 143 | - ExecStack.getStackTrace
|
|
| 145 | + ExecStack.collectStackTrace
|
|
| 144 | 146 | |
| 145 | 147 | ipe <- collect IPEBacktrace $ do
|
| 146 | 148 | stack <- CloneStack.cloneMyStack
|
| 147 | - stackEntries <- CloneStack.decode stack
|
|
| 148 | - return (Just stackEntries)
|
|
| 149 | + return (Just stack)
|
|
| 149 | 150 | |
| 150 | 151 | hcs <- collect HasCallStackBacktrace $ do
|
| 151 | 152 | return (Just ?callStack)
|
| ... | ... | @@ -323,7 +323,7 @@ module Control.Exception.Backtrace where |
| 323 | 323 | type BacktraceMechanism :: *
|
| 324 | 324 | data BacktraceMechanism = CostCentreBacktrace | HasCallStackBacktrace | ExecutionBacktrace | IPEBacktrace
|
| 325 | 325 | type Backtraces :: *
|
| 326 | - data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe [GHC.Internal.ExecutionStack.Internal.Location], btrIpe :: GHC.Internal.Maybe.Maybe [GHC.Internal.Stack.CloneStack.StackEntry]}
|
|
| 326 | + data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe GHC.Internal.ExecutionStack.Internal.StackTrace, btrIpe :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.CloneStack.StackSnapshot}
|
|
| 327 | 327 | collectBacktraces :: (?callStack::GHC.Internal.Stack.Types.CallStack) => GHC.Internal.Types.IO Backtraces
|
| 328 | 328 | displayBacktraces :: Backtraces -> GHC.Internal.Base.String
|
| 329 | 329 | getBacktraceMechanismState :: BacktraceMechanism -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -323,7 +323,7 @@ module Control.Exception.Backtrace where |
| 323 | 323 | type BacktraceMechanism :: *
|
| 324 | 324 | data BacktraceMechanism = CostCentreBacktrace | HasCallStackBacktrace | ExecutionBacktrace | IPEBacktrace
|
| 325 | 325 | type Backtraces :: *
|
| 326 | - data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe [GHC.Internal.ExecutionStack.Internal.Location], btrIpe :: GHC.Internal.Maybe.Maybe [GHC.Internal.Stack.CloneStack.StackEntry]}
|
|
| 326 | + data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe GHC.Internal.ExecutionStack.Internal.StackTrace, btrIpe :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.CloneStack.StackSnapshot}
|
|
| 327 | 327 | collectBacktraces :: (?callStack::GHC.Internal.Stack.Types.CallStack) => GHC.Internal.Types.IO Backtraces
|
| 328 | 328 | displayBacktraces :: Backtraces -> GHC.Internal.Base.String
|
| 329 | 329 | getBacktraceMechanismState :: BacktraceMechanism -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -323,7 +323,7 @@ module Control.Exception.Backtrace where |
| 323 | 323 | type BacktraceMechanism :: *
|
| 324 | 324 | data BacktraceMechanism = CostCentreBacktrace | HasCallStackBacktrace | ExecutionBacktrace | IPEBacktrace
|
| 325 | 325 | type Backtraces :: *
|
| 326 | - data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe [GHC.Internal.ExecutionStack.Internal.Location], btrIpe :: GHC.Internal.Maybe.Maybe [GHC.Internal.Stack.CloneStack.StackEntry]}
|
|
| 326 | + data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe GHC.Internal.ExecutionStack.Internal.StackTrace, btrIpe :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.CloneStack.StackSnapshot}
|
|
| 327 | 327 | collectBacktraces :: (?callStack::GHC.Internal.Stack.Types.CallStack) => GHC.Internal.Types.IO Backtraces
|
| 328 | 328 | displayBacktraces :: Backtraces -> GHC.Internal.Base.String
|
| 329 | 329 | getBacktraceMechanismState :: BacktraceMechanism -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -323,7 +323,7 @@ module Control.Exception.Backtrace where |
| 323 | 323 | type BacktraceMechanism :: *
|
| 324 | 324 | data BacktraceMechanism = CostCentreBacktrace | HasCallStackBacktrace | ExecutionBacktrace | IPEBacktrace
|
| 325 | 325 | type Backtraces :: *
|
| 326 | - data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe [GHC.Internal.ExecutionStack.Internal.Location], btrIpe :: GHC.Internal.Maybe.Maybe [GHC.Internal.Stack.CloneStack.StackEntry]}
|
|
| 326 | + data Backtraces = Backtraces {btrCostCentre :: GHC.Internal.Maybe.Maybe (GHC.Internal.Ptr.Ptr GHC.Internal.Stack.CCS.CostCentreStack), btrHasCallStack :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.Types.CallStack, btrExecutionStack :: GHC.Internal.Maybe.Maybe GHC.Internal.ExecutionStack.Internal.StackTrace, btrIpe :: GHC.Internal.Maybe.Maybe GHC.Internal.Stack.CloneStack.StackSnapshot}
|
|
| 327 | 327 | collectBacktraces :: (?callStack::GHC.Internal.Stack.Types.CallStack) => GHC.Internal.Types.IO Backtraces
|
| 328 | 328 | displayBacktraces :: Backtraces -> GHC.Internal.Base.String
|
| 329 | 329 | getBacktraceMechanismState :: BacktraceMechanism -> GHC.Internal.Types.IO GHC.Internal.Types.Bool
|