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