Taught :breakpoint add to guess the module name if not given
authorPepe Iborra <mnislaih@gmail.com>
Fri, 16 Feb 2007 19:38:10 +0000 (19:38 +0000)
committerPepe Iborra <mnislaih@gmail.com>
Fri, 16 Feb 2007 19:38:10 +0000 (19:38 +0000)
Now the user can say

> :break add 13

at the ghci prompt and the debugger will use the first top level module as the target for the breakpoint

compiler/ghci/Debugger.hs
compiler/ghci/InteractiveUI.hs

index 6248e0c..62633d2 100644 (file)
@@ -330,18 +330,26 @@ bkptOptions cmd = do
       io$ putStrLn msg
 
     bkptOptions' s ("add":cmds) bt 
+      | [line]         <- cmds
+      , [(lineNum,[])] <- reads line
+      = do (toplevel,_) <- io$ GHC.getContext s
+           case toplevel of
+             (m:_) -> handleAdd (\mod->addBkptByLine mod lineNum) m
+             [] -> throwDyn $ CmdLineError $ "No module loaded in debugging mode"
+
       | [mod_name,line]<- cmds
       , [(lineNum,[])] <- reads line
-      =  handleAdd mod_name $ (\mod->addBkptByLine mod lineNum)
+      = io(GHC.findModule s (GHC.mkModuleName mod_name) Nothing) >>=
+         handleAdd (\mod->addBkptByLine mod lineNum)
 
       | [mod_name,line,col] <- cmds
-      = handleAdd mod_name $ (\mod->addBkptByCoord mod (read line, read col))
+      = io(GHC.findModule s (GHC.mkModuleName mod_name) Nothing) >>=
+         handleAdd (\mod->addBkptByCoord mod (read line, read col))
 
       | otherwise = throwDyn $ CmdLineError $ 
                        "syntax: :breakpoint add Module line [col]"
        where 
-         handleAdd mod_name f = do
-           mod         <- io$ GHC.findModule s (GHC.mkModuleName mod_name) Nothing
+         handleAdd f mod = 
            either 
              (handleBkptEx s mod)
              (\(newTable, site) -> do
@@ -373,31 +381,28 @@ bkptOptions cmd = do
       = handleDel mod $ delBkptByCoord mod (lineNum, colNum)
         
       | otherwise = throwDyn $ CmdLineError $ 
-             "syntax: :breakpoint del (breakpoint # | Module line [col])"
+             "syntax: :breakpoint del (breakpoint # | [Module] line [col])"
 
        where delMsg = "Breakpoint deleted"
              handleDel mod f = either (handleBkptEx s mod)
                                       (\newtable-> setBkptTable newtable >> io (putStrLn delMsg))
                                       (f bt)
                                       
-
     bkptOptions' _ _ _ = throwDyn $ CmdLineError $ 
                          "syntax: :breakpoint (list|continue|stop|add|del)"
 
 -- Error messages
 --    handleBkptEx :: Session -> Module -> Debugger.BkptException -> a
-    handleBkptEx s m NotHandled  = io$
-                                   findModSummary m                  >>= \mod_summary ->
-                                   isModuleInterpreted s mod_summary >>= \it -> 
-       if it
+    handleBkptEx s m NotHandled  = io$ do
+       isInterpreted <- findModSummary m >>= isModuleInterpreted s
+       if isInterpreted
         then error$ "Module " ++ showSDoc (ppr m) ++  " was not loaded under debugging mode.\n" 
                  ++ "Enable debugging mode with -fdebugging (and reload your module)"
         else error$ "Module " ++ showSDoc (ppr m) ++  " was loaded in compiled (.o) mode.\n" 
                  ++ "You must load a module in interpreted mode and with -fdebugging on to debug it."
-                     where findModSummary m = getModuleGraph s >>= \mod_graph ->  
-                               case [ modsum | modsum <- mod_graph
-                                             , ms_mod modsum == m ] of
-                                 [modsum] -> return modsum
+         where findModSummary m = do 
+                 mod_graph <- getModuleGraph s 
+                 return$ head [ modsum | modsum <- mod_graph, ms_mod modsum == m]
     handleBkptEx _ _ e = error (show e)
 
 -------------------------
index 573aaa0..b5af439 100644 (file)
@@ -215,7 +215,7 @@ helpText =
  "\n" ++
  " Options for ':breakpoint':\n" ++
  "   list                                     list the current breakpoints\n" ++
- "   add Module line [col]                    add a new breakpoint\n" ++
+ "   add [Module] line [col]                    add a new breakpoint\n" ++
  "   del (breakpoint# | Module line [col])    delete a breakpoint\n" ++
  "   continue                                 continue execution\n"  ++
  "   stop                   Stop a computation and return to the top level\n" ++