# HG changeset patch # User Sean Farley # Date 2013-07-26 03:28:34 # Node ID 472fa3b782b1d33d12738c288beac6f7a78e0514 # Parent 09573ad59f7b946d07e88940ab0afea69f1d4683 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. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -88,6 +88,13 @@ def _runcatch(req): 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 @@ def _runcatch(req): 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 @@ def _runcatch(req): # 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