Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"entryFile": "hdb/Main.hs",
"entryArgs": ["server", "--port", "12345"],
"entryPoint": "main",
"extraGhcArgs": []
"extraGhcArgs": [],
"cradleFile" : "hie-self-debug.yaml"
},
{
"type": "haskell-debugger",
Expand All @@ -19,7 +20,8 @@
"entryFile": "test/haskell/Main.hs",
"entryPoint": "main",
"entryArgs": ["--pattern", "DAP.Scopes"],
"extraGhcArgs": []
"extraGhcArgs": [],
"cradleFile": "hie-self-debug.yaml"
}
]
}
7 changes: 7 additions & 0 deletions cabal.project.self-debug-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- cabal project file used for self-debug tests.
-- Meant to be just `cabal.project` but separate file to prevent cabal
-- from including `cabal.project.local` as well.
--
-- Referenced by hie-self-debug-test.yaml

import: cabal.project
5 changes: 4 additions & 1 deletion hdb-dap/Development/Debug/Adapter/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ data LaunchArgs
-- or function arguments otherwise.
, extraGhcArgs :: Maybe [String]
-- ^ Additional arguments to pass to the GHC invocation inferred by hie-bios for this project
, cradleFile :: Maybe FilePath
-- ^ specify cradle file rather than let it be inferred from @entryFile@, relative to @projectRoot@.
} deriving stock (Show, Eq, Generic)
deriving anyclass FromJSON

Expand Down Expand Up @@ -115,6 +117,7 @@ initDebugger l servConf supportsRunInTerminal preferInternalInterpreter
, entryPoint = fromMaybe "main" -> entryPoint
, entryArgs = fromMaybe [] -> entryArgs
, extraGhcArgs = fromMaybe [] -> extraGhcArgs
, cradleFile
} = do
syncRequests <- liftIO newEmptyMVar
syncResponses <- liftIO newEmptyMVar
Expand Down Expand Up @@ -144,7 +147,7 @@ initDebugger l servConf supportsRunInTerminal preferInternalInterpreter
WithSeverity msg sev
| sev >= Info -> dapLogger <& renderSessionSetupLog msg
| otherwise -> mempty
let debugRunnerConf = DebugRunnerConf projectRoot entryFile extraGhcArgs
let debugRunnerConf = DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile
liftIO (getDebugRunner servConf hieBiosLogger debugRunnerConf) >>= \case
Left e -> throwError (ErrorMessage (T.pack e), Nothing)
Right (ghcInvocation, debugRunner) -> do
Expand Down
24 changes: 18 additions & 6 deletions hdb-dap/Development/Debug/Session/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

module Development.Debug.Session.Setup
(
Expand Down Expand Up @@ -75,6 +76,10 @@ data DebugRunnerConf = DebugRunnerConf
{ drcProjectRoot :: FilePath
, drcEntryFile :: FilePath
, drcExtraGhcArgs :: [String]
, drcCradleFile :: Maybe FilePath
-- ^ specified cradle file rather than letting be inferred from
-- @drcEntryFile@, relative to @drcProjectRoot@ if so. @DebugRunnerProvider@s
-- must WARN if this field is @Just@ but they do not use hie cradles.
}

data SessionSetupLog
Expand Down Expand Up @@ -106,11 +111,12 @@ data HieBiosFlags = HieBiosFlags
hieBiosSetup :: LogAction IO (WithSeverity SessionSetupLog)
-> FilePath -- ^ project root
-> FilePath -- ^ entry file
-> Maybe FilePath -- ^ cradle file
-> ExceptT String IO (Either String HieBiosFlags)
hieBiosSetup logger projectRoot entryFile = do
hieBiosSetup logger projectRoot entryFile cradleFile = do

logInfo "Figuring out the right flags to compile the project using hie-bios..."
cradle <- hieBiosCradle logger projectRoot entryFile & ExceptT
cradle <- hieBiosCradle logger projectRoot entryFile cradleFile & ExceptT

-- GHC is found in PATH (by hie-bios as well).
logInfo "Checking GHC version against debugger version..."
Expand All @@ -129,10 +135,16 @@ hieBiosSetup logger projectRoot entryFile = do
hieBiosCradle :: LogAction IO (WithSeverity SessionSetupLog)
-> FilePath -- ^ Project root
-> FilePath -- ^ Entry file relative to root
-> Maybe FilePath -- ^ Cradle file relative to root
-> IO (Either String (HIE.Cradle Void))
hieBiosCradle logger root relTarget = runExceptT $ do
hieBiosCradle logger root relTarget mrelCradle = runExceptT $ do
let target = root </> relTarget
explicitCradle <- HIE.findCradle target & liftIO
explicitCradle <- case mrelCradle of
Nothing -> HIE.findCradle target & liftIO
Just ((root </>) -> cradleFile) -> do
liftIO (doesFileExist cradleFile) >>= \case
True -> return $ Just cradleFile
False -> throwError $ "Specified Cradle file does not exist: " ++ cradleFile
cradle <- maybe (loadImplicitCradle hieBiosLogger target)
(HIE.loadCradle hieBiosLogger) explicitCradle & liftIO
liftLogIO logger <& WithSeverity (LogCradle cradle) Info
Expand Down Expand Up @@ -219,8 +231,8 @@ hieDebugRunner
:: LogAction IO (WithSeverity SessionSetupLog)
-> DebugRunnerConf
-> IO (Either String (GhcInvocation, Debugger.DebugRunner Ghc a))
hieDebugRunner l (DebugRunnerConf projectRoot entryFile extraGhcArgs) = runExceptT $ do
r <- hieBiosSetup l projectRoot entryFile
hieDebugRunner l (DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile) = runExceptT $ do
r <- hieBiosSetup l projectRoot entryFile cradleFile
HieBiosFlags{..} <- case r of
Left e -> throwError e
Right f -> return f
Expand Down
5 changes: 3 additions & 2 deletions hdb/Development/Debug/Interactive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ runIDM :: LogAction IO InteractiveLog
-> FilePath -- ^ entryFile
-> [String] -- ^ entryArgs
-> [String] -- ^ extraGhcArgs
-> Maybe FilePath
-> RunDebuggerSettings
-> InteractiveDM a
-> IO a
runIDM logger entryPoint entryFile entryArgs extraGhcArgs runConf act = do
runIDM logger entryPoint entryFile entryArgs extraGhcArgs cradleFile runConf act = do
projectRoot <- getCurrentDirectory

let hieBiosLogger = contramap ISessionSetupLog logger
hieDebugRunner hieBiosLogger (DebugRunnerConf projectRoot entryFile extraGhcArgs) >>= \case
hieDebugRunner hieBiosLogger (DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile) >>= \case
Left e -> exitWithMsg e
Right (_ghcInvocation, debugRunner)
-> do
Expand Down
1 change: 1 addition & 0 deletions hdb/Development/Debug/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data HdbOptions
, entryFile :: FilePath
, entryArgs :: [String]
, extraGhcArgs :: [String]
, cradleFile :: Maybe FilePath
, verbosity :: Severity
, internalInterpreter :: Bool
, disableIpeBacktraces :: Bool
Expand Down
6 changes: 6 additions & 0 deletions hdb/Development/Debug/Options/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ cliParser = HdbCLI
<> metavar "GHC_ARGS"
<> value []
<> help "Additional flags to pass to the ghc invocation that loads the program for debugging" )
<*> option (Just <$> str)
(long "cradle-file"
<> metavar "HIE_PATH"
<> value Nothing
<> help "Path to .yaml file to use as cradle configuration. Location inferred from ENTRY_POINT otherwise."
)
<*> verbosityParser Warning
<*> internalInterpreterParser
<*> disableIpeBacktracesParser
Expand Down
2 changes: 1 addition & 1 deletion hdb/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ main = do
, externalInterpreterCustomProc = Left stdinStream
, externalInterpreterProg = thisProg
}
runIDM (contramap InteractiveLog l) entryPoint entryFile entryArgs extraGhcArgs
runIDM (contramap InteractiveLog l) entryPoint entryFile entryArgs extraGhcArgs cradleFile
runConf debugInteractive
HdbProxy{port} -> do
setBacktraceMechanismState IPEBacktrace True
Expand Down
6 changes: 6 additions & 0 deletions hie-self-debug-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# HIE cradle used for self-debug tests.
# It has to be at the project root, otherwise HIE will not resolve it properly.
cradle:
cabal:
cabalProject: "cabal.project.self-debug-test"
component: "all"
3 changes: 3 additions & 0 deletions hie-self-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cradle:
cabal:
component: "all"
13 changes: 6 additions & 7 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cradle:
cabal:
component: "all"
# - path: "./haskell-debugger/"
# component: "lib:haskell-debugger"
# - path: "./hdb/"
# component: "exe:hdb"
# - path: "./test/haskell/"
# component: "test:haskell-debugger-test"
- path: "./haskell-debugger/"
component: "lib:haskell-debugger"
- path: "./hdb/"
component: "exe:hdb"
- path: "./test/haskell/"
component: "test:haskell-debugger-test"
3 changes: 3 additions & 0 deletions test/golden/self-debug-cli/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cradle:
cabal:
component: "all"
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
#
# 5) When testing the sdist (just the packaged things), the root doesn't have a hie.yaml.
# Add one temporarily

# Dedicated HIE file for self-debug tests.

yaml_file=hie-self-debug-test.yaml

created_yaml=false
if [ ! -f hie.yaml ]; then
echo 'cradle:\n cabal:\n component: "all"' > hie.yaml
if [ ! -f "$yaml_file" ]; then
printf 'cradle:\n cabal:\n component: "all"\n' > "$yaml_file"
created_yaml=true;
fi

$HDB -v0 hdb/Main.hs < "test/golden/self-debug-cli/self-debug-cli.hdb-stdin" 2>&1 \
$HDB -v0 --cradle-file="$yaml_file" hdb/Main.hs < "test/golden/self-debug-cli/self-debug-cli.hdb-stdin" 2>&1 \
| grep -v "BreakFound" \
| grep -v "] Compiling" \
| sed \
Expand All @@ -34,5 +39,5 @@ $HDB -v0 hdb/Main.hs < "test/golden/self-debug-cli/self-debug-cli.hdb-stdin" 2>&
-e 's|haskell-debugger-view-[0-9.][0-9.]*-inplace|haskell-debugger-view-<VERSION>-inplace|g'

if [ $created_yaml = true ]; then
rm hie.yaml
rm "$yaml_file"
fi
4 changes: 4 additions & 0 deletions test/haskell/Test/DAP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ data LaunchConfig = LaunchConfig
, lcEntryPoint :: Maybe String
, lcEntryArgs :: [String]
, lcExtraGhcArgs :: [String]
, lcCradleFile :: Maybe FilePath
, lcInternalInterpreter :: Maybe Bool
}

Expand All @@ -137,6 +138,7 @@ mkLaunchConfig projectRoot entryFile = LaunchConfig
, lcEntryPoint = Just "main"
, lcEntryArgs = []
, lcExtraGhcArgs = []
, lcCradleFile = Nothing
, lcInternalInterpreter = Nothing
}

Expand All @@ -150,8 +152,10 @@ launchWith LaunchConfig{..} = launch $ object $
[ "entryPoint" .= ep | Just ep <- [lcEntryPoint] ] ++
[ "entryArgs" .= lcEntryArgs ] ++
[ "extraGhcArgs" .= lcExtraGhcArgs ] ++
[ "cradleFile" .= file | Just file <- [lcCradleFile] ] ++
[ "internalInterpreter" .= b | Just b <- [lcInternalInterpreter] ]


-- | Set breakpoints in a particular source file of a project at the given
-- lines.
setLineBreakpoints :: FilePath -- ^ project root
Expand Down
1 change: 1 addition & 0 deletions test/haskell/Test/Integration/Basic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ minimalConfig =
, lcEntryArgs = []
, lcExtraGhcArgs = []
, lcInternalInterpreter = Nothing
, lcCradleFile = Nothing
}
hitBreakpointWith cfg 2
disconnect
Expand Down
6 changes: 4 additions & 2 deletions test/haskell/Test/Integration/SelfDebug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ selfDebugDAPTest = do
doesFileExist (test_dir </> "cabal.project") >>= \exists ->
unless exists $ writeFile (test_dir </> "cabal.project")
"packages: . haskell-debugger-view\nallow-newer: ghc-bignum,containers,time,ghc,base,template-haskell"
doesFileExist (test_dir </> "hie.yaml") >>= \exists ->
unless exists $ writeFile (test_dir </> "hie.yaml")
let hieFileName = "hie-self-debug-test.yaml"
doesFileExist (test_dir </> hieFileName) >>= \exists ->
unless exists $ writeFile (test_dir </> hieFileName)
"cradle:\n cabal:\n component: \"all\""
withTestDAPServerClient server $ do
let cfg = LaunchConfig
Expand All @@ -42,6 +43,7 @@ selfDebugDAPTest = do
, lcEntryPoint = Just "main"
, lcEntryArgs = ["cli", "test/golden/self-debug-cli/Main.hs"]
, lcExtraGhcArgs = []
, lcCradleFile = Just hieFileName
, lcInternalInterpreter = Nothing
}

Expand Down
Loading