1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""A module for the run command.""" 6 7import cr 8 9 10class DebugCommand(cr.Command): 11 """The implementation of the debug command. 12 13 This is much like the run command except it launches the program under 14 a debugger instead. 15 """ 16 17 def __init__(self): 18 super(DebugCommand, self).__init__() 19 self.help = 'Debug a binary' 20 21 def AddArguments(self, subparsers): 22 parser = super(DebugCommand, self).AddArguments(subparsers) 23 cr.Builder.AddArguments(self, parser) 24 cr.Installer.AddArguments(self, parser) 25 cr.Debugger.AddArguments(self, parser) 26 cr.Target.AddArguments(self, parser) 27 self.ConsumeArgs(parser, 'the binary') 28 return parser 29 30 def Run(self): 31 targets = cr.Target.GetTargets() 32 if not cr.Debugger.ShouldInvoke(): 33 cr.Debugger.Attach(targets, cr.context.remains) 34 elif cr.Installer.Skipping(): 35 cr.Debugger.Restart(targets, cr.context.remains) 36 else: 37 cr.Builder.Build(targets, []) 38 cr.Debugger.Kill(targets, []) 39 cr.Installer.Reinstall(targets, []) 40 cr.Debugger.Invoke(targets, cr.context.remains) 41