From patchwork Wed Aug 28 16:50:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 2, RESEND] dispatch: add ability to specify a custom pdb module as a debugger From: Sean Farley X-Patchwork-Id: 2281 Message-Id: To: mercurial-devel@selenic.com Date: Wed, 28 Aug 2013 11:50:56 -0500 # HG changeset patch # User Sean Farley # Date 1374809314 18000 # Thu Jul 25 22:28:34 2013 -0500 # Node ID cb899a6cf389c7ebbae15b24559a8b96b1fcc92b # Parent 7e3647631c5c68ee5a543853d9877716e7707875 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 @@ -86,10 +86,17 @@ except ValueError: pass # happens if called in a thread 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) cfgs = _parseconfig(req.ui, _earlygetopt(['--config'], req.args)) @@ -97,24 +104,42 @@ # 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: + 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: 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