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 Debugger base class."""
6
7import cr
8
9
10class Debugger(cr.Action, cr.Plugin.Type):
11  """Base class for implementing debuggers.
12
13  Implementations must override the Invoke and Attach methods.
14  """
15
16  SELECTOR_ARG = '--debugger'
17  SELECTOR = 'CR_DEBUGGER'
18  SELECTOR_HELP = 'Sets the debugger to use for debug commands.'
19
20  @classmethod
21  def AddArguments(cls, command, parser):
22    cr.Runner.AddSelectorArg(command, parser)
23
24  @classmethod
25  def ShouldInvoke(cls):
26    """Checks if the debugger is attaching or launching."""
27    return not cr.Runner.Skipping()
28
29  @cr.Plugin.activemethod
30  def Restart(self, targets, arguments):
31    """Ask the debugger to restart.
32
33    Defaults to a Kill Invoke sequence.
34    """
35    self.Kill(targets, [])
36    self.Invoke(targets, arguments)
37
38  @cr.Plugin.activemethod
39  def Kill(self, targets, arguments):
40    """Kill the running debugger."""
41    cr.Runner.Kill(targets, arguments)
42
43  @cr.Plugin.activemethod
44  def Invoke(self, targets, arguments):
45    """Invoke the program within a debugger."""
46    raise NotImplementedError('Must be overridden.')
47
48  @cr.Plugin.activemethod
49  def Attach(self, targets, arguments):
50    """Attach a debugger to a running program."""
51    raise NotImplementedError('Must be overridden.')
52