dispatch: add ability to specify a custom pdb module as a debugger
authorSean Farley <sean.michael.farley@gmail.com>
Thu, 25 Jul 2013 22:28:34 -0500
changeset 19640 472fa3b782b1
parent 19639 09573ad59f7b
child 19641 5528c31c629c
dispatch: add ability to specify a custom pdb module as a debugger This adds the ability to specify a config option, ui.debugger, to a custom pdb module, such as ipdb, and have mercurial use that as its debugger. As long as the value of ui.debugger is a loadable module with the set_trace and post_mortem functions, then dispatch will be able to use the custom module. Debugging _parseconfig is still available in the case of an error since it will be caught with a default the value of pdb.post_mortem.
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sat Jul 13 16:33:07 2013 -0500
+++ b/mercurial/dispatch.py	Thu Jul 25 22:28:34 2013 -0500
@@ -88,6 +88,13 @@
 
     try:
         try:
+            debugger = 'pdb'
+            debugtrace = {
+                'pdb' : pdb.set_trace
+            }
+            debugmortem = {
+                'pdb' : pdb.post_mortem
+            }
 
             # read --config before doing anything else
             # (e.g. to change trust settings for reading .hg/hgrc)
@@ -99,11 +106,29 @@
                 for cfg in cfgs:
                     req.repo.ui.setconfig(*cfg)
 
+            debugger = ui.config("ui", "debugger")
+            if not debugger:
+                debugger = 'pdb'
+
+            try:
+                debugmod = __import__(debugger)
+            except ImportError:
+                debugmod = pdb
+
+            debugtrace[debugger] = debugmod.set_trace
+            debugmortem[debugger] = debugmod.post_mortem
+
             # enter the debugger before command execution
             if '--debugger' in req.args:
                 ui.warn(_("entering debugger - "
                         "type c to continue starting hg or h for help\n"))
-                pdb.set_trace()
+
+                if (debugger != 'pdb' and
+                    debugtrace[debugger] == debugtrace['pdb']):
+                    ui.warn(_("%s debugger specified "
+                              "but its module was not found\n") % debugger)
+
+                debugtrace[debugger]()
             try:
                 return _dispatch(req)
             finally:
@@ -112,7 +137,7 @@
             # enter the debugger when we hit an exception
             if '--debugger' in req.args:
                 traceback.print_exc()
-                pdb.post_mortem(sys.exc_info()[2])
+                debugmortem[debugger](sys.exc_info()[2])
             ui.traceback()
             raise