[PATCH 2 of 2] dispatch: add ability to specify a custom pdb module as a debugger
Sean Farley
sean.michael.farley at gmail.com
Sat Jul 13 17:16:56 CDT 2013
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1373752000 18000
# Sat Jul 13 16:46:40 2013 -0500
# Node ID 42113a6e12bc864e044bacb57407a68a97d7f1da
# Parent 15a903bca551318cd0c3f42484374a8b8acd08e5
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.
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -97,24 +97,49 @@
# copy configs that were passed on the cmdline (--config) to
# the repo ui
for cfg in cfgs:
req.repo.ui.setconfig(*cfg)
+ debugger = ui.config("ui", "debugger")
+ if not debugger:
+ debugger = 'pdb'
+
+ try:
+ ipdb = __import__(debugger)
+ except ImportError:
+ ipdb = pdb
+
+ debugtrace = {
+ 'pdb' : pdb.set_trace,
+ debugger : ipdb.set_trace,
+ }
+
+ debugmortem = {
+ 'pdb' : pdb.post_mortem,
+ debugger : ipdb.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:
ui.flush()
except: # re-raises
# 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
# Global exception handling, alphabetically
# Mercurial-specific first, followed by built-in and library exceptions
More information about the Mercurial-devel
mailing list