Bug 1107968 - Add --debug-command to mach; r=ahal

People often seek to learn how mach commands work. A common way to do
this is to launch a debugger and step through the code as it is
executing. But this requires someone to first find and modify the mach
command. This involves overhead.

This patch adds a global --debug-command argument to mach. When present,
we launch an interactive debugger right before command dispatch. This
allows people to easily enter a debugger to see what mach commands are
doing, hopefully lowering the barrier to understanding and contributing.

--HG--
extra : rebase_source : 5ebfa7f5fd89f96dac5f7cb035ab520c63b32e55
extra : amend_source : c53c988763c328020b49aa5c6245df685b6f30bc
This commit is contained in:
Gregory Szorc 2014-12-05 10:19:49 -08:00
parent 1c250a0fa4
commit 6bcfb690b5

View File

@ -445,6 +445,10 @@ To see more help for a specific command, run:
fn = getattr(instance, handler.method)
if args.debug_command:
import pdb
pdb.set_trace()
try:
result = fn(**vars(args.command_args))
@ -603,6 +607,8 @@ To see more help for a specific command, run:
global_group.add_argument('-h', '--help', dest='help',
action='store_true', default=False,
help='Show this help message.')
global_group.add_argument('--debug-command', action='store_true',
help='Start a Python debugger when command is dispatched.')
for args, kwargs in self.global_arguments:
global_group.add_argument(*args, **kwargs)