Mercurial > hg
comparison mercurial/dispatch.py @ 19640:472fa3b782b1
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.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 22:28:34 -0500 |
parents | 09573ad59f7b |
children | 8f4a226c840c |
comparison
equal
deleted
inserted
replaced
19639:09573ad59f7b | 19640:472fa3b782b1 |
---|---|
86 except ValueError: | 86 except ValueError: |
87 pass # happens if called in a thread | 87 pass # happens if called in a thread |
88 | 88 |
89 try: | 89 try: |
90 try: | 90 try: |
91 debugger = 'pdb' | |
92 debugtrace = { | |
93 'pdb' : pdb.set_trace | |
94 } | |
95 debugmortem = { | |
96 'pdb' : pdb.post_mortem | |
97 } | |
91 | 98 |
92 # read --config before doing anything else | 99 # read --config before doing anything else |
93 # (e.g. to change trust settings for reading .hg/hgrc) | 100 # (e.g. to change trust settings for reading .hg/hgrc) |
94 cfgs = _parseconfig(req.ui, _earlygetopt(['--config'], req.args)) | 101 cfgs = _parseconfig(req.ui, _earlygetopt(['--config'], req.args)) |
95 | 102 |
97 # copy configs that were passed on the cmdline (--config) to | 104 # copy configs that were passed on the cmdline (--config) to |
98 # the repo ui | 105 # the repo ui |
99 for cfg in cfgs: | 106 for cfg in cfgs: |
100 req.repo.ui.setconfig(*cfg) | 107 req.repo.ui.setconfig(*cfg) |
101 | 108 |
109 debugger = ui.config("ui", "debugger") | |
110 if not debugger: | |
111 debugger = 'pdb' | |
112 | |
113 try: | |
114 debugmod = __import__(debugger) | |
115 except ImportError: | |
116 debugmod = pdb | |
117 | |
118 debugtrace[debugger] = debugmod.set_trace | |
119 debugmortem[debugger] = debugmod.post_mortem | |
120 | |
102 # enter the debugger before command execution | 121 # enter the debugger before command execution |
103 if '--debugger' in req.args: | 122 if '--debugger' in req.args: |
104 ui.warn(_("entering debugger - " | 123 ui.warn(_("entering debugger - " |
105 "type c to continue starting hg or h for help\n")) | 124 "type c to continue starting hg or h for help\n")) |
106 pdb.set_trace() | 125 |
126 if (debugger != 'pdb' and | |
127 debugtrace[debugger] == debugtrace['pdb']): | |
128 ui.warn(_("%s debugger specified " | |
129 "but its module was not found\n") % debugger) | |
130 | |
131 debugtrace[debugger]() | |
107 try: | 132 try: |
108 return _dispatch(req) | 133 return _dispatch(req) |
109 finally: | 134 finally: |
110 ui.flush() | 135 ui.flush() |
111 except: # re-raises | 136 except: # re-raises |
112 # enter the debugger when we hit an exception | 137 # enter the debugger when we hit an exception |
113 if '--debugger' in req.args: | 138 if '--debugger' in req.args: |
114 traceback.print_exc() | 139 traceback.print_exc() |
115 pdb.post_mortem(sys.exc_info()[2]) | 140 debugmortem[debugger](sys.exc_info()[2]) |
116 ui.traceback() | 141 ui.traceback() |
117 raise | 142 raise |
118 | 143 |
119 # Global exception handling, alphabetically | 144 # Global exception handling, alphabetically |
120 # Mercurial-specific first, followed by built-in and library exceptions | 145 # Mercurial-specific first, followed by built-in and library exceptions |