summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2015-05-19 01:23:47 -0500
committerAustin Seipp <austin@well-typed.com>2015-05-19 01:25:23 -0500
commitb03f074fd51adfb9bc4f5275294712ee62741aed (patch)
tree7fb04ed2a1865bf68b4dac9608c5e69ac2135ef2 /ghc
parent578d2bad19b3e03fac4da1e5be4b22b73cef0a44 (diff)
downloadhaskell-b03f074fd51adfb9bc4f5275294712ee62741aed.tar.gz
ghci: Allow :back and :forward to take counts
These behave like the count arguments of the gdb `up` and `down` commands, allowing the user to quickly jump around in history. Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D853
Diffstat (limited to 'ghc')
-rw-r--r--ghc/InteractiveUI.hs46
1 files changed, 28 insertions, 18 deletions
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 70e4df1122..0adc0cd521 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -268,14 +268,14 @@ defFullHelpText =
" -- Commands for debugging:\n" ++
"\n" ++
" :abandon at a breakpoint, abandon current computation\n" ++
- " :back go back in the history (after :trace)\n" ++
+ " :back [<n>] go back in the history N steps (after :trace)\n" ++
" :break [<mod>] <l> [<col>] set a breakpoint at the specified location\n" ++
" :break <name> set a breakpoint on the specified function\n" ++
" :continue resume after a breakpoint\n" ++
" :delete <number> delete the specified breakpoint\n" ++
" :delete * delete all breakpoints\n" ++
" :force <expr> print <expr>, forcing unevaluated parts\n" ++
- " :forward go forward in the history (after :back)\n" ++
+ " :forward [<n>] go forward in the history N step s(after :back)\n" ++
" :history [<n>] after :trace, show the execution history\n" ++
" :list show the source code around current breakpoint\n" ++
" :list <identifier> show the source code for <identifier>\n" ++
@@ -2747,24 +2747,34 @@ bold c | do_bold = text start_bold <> c <> text end_bold
| otherwise = c
backCmd :: String -> GHCi ()
-backCmd = noArgs $ withSandboxOnly ":back" $ do
- (names, _, pan) <- GHC.back
- printForUser $ ptext (sLit "Logged breakpoint at") <+> ppr pan
- printTypeOfNames names
- -- run the command set with ":set stop <cmd>"
- st <- getGHCiState
- enqueueCommands [stop st]
+backCmd arg
+ | null arg = back 1
+ | all isDigit arg = back (read arg)
+ | otherwise = liftIO $ putStrLn "Syntax: :back [num]"
+ where
+ back num = withSandboxOnly ":back" $ do
+ (names, _, pan) <- GHC.back num
+ printForUser $ ptext (sLit "Logged breakpoint at") <+> ppr pan
+ printTypeOfNames names
+ -- run the command set with ":set stop <cmd>"
+ st <- getGHCiState
+ enqueueCommands [stop st]
forwardCmd :: String -> GHCi ()
-forwardCmd = noArgs $ withSandboxOnly ":forward" $ do
- (names, ix, pan) <- GHC.forward
- printForUser $ (if (ix == 0)
- then ptext (sLit "Stopped at")
- else ptext (sLit "Logged breakpoint at")) <+> ppr pan
- printTypeOfNames names
- -- run the command set with ":set stop <cmd>"
- st <- getGHCiState
- enqueueCommands [stop st]
+forwardCmd arg
+ | null arg = forward 1
+ | all isDigit arg = forward (read arg)
+ | otherwise = liftIO $ putStrLn "Syntax: :back [num]"
+ where
+ forward num = withSandboxOnly ":forward" $ do
+ (names, ix, pan) <- GHC.forward num
+ printForUser $ (if (ix == 0)
+ then ptext (sLit "Stopped at")
+ else ptext (sLit "Logged breakpoint at")) <+> ppr pan
+ printTypeOfNames names
+ -- run the command set with ":set stop <cmd>"
+ st <- getGHCiState
+ enqueueCommands [stop st]
-- handle the "break" command
breakCmd :: String -> GHCi ()