1# DExTer : Debugging Experience Tester
2# ~~~~~~   ~         ~~         ~   ~~
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7"""Abstract Base class for controlling debuggers."""
8
9import abc
10
11class DebuggerControllerBase(object, metaclass=abc.ABCMeta):
12    def __init__(self, context, step_collection):
13        self.context = context
14        self.step_collection = step_collection
15
16    @abc.abstractclassmethod
17    def _run_debugger_custom(self):
18        """Specify your own implementation of run_debugger_custom in your own
19        controller.
20        """
21        pass
22
23    def run_debugger(self, debugger):
24        """Responsible for correctly launching and tearing down the debugger.
25        """
26        self.debugger = debugger
27
28        # Fetch command line options, if any.
29        the_cmdline = []
30        commands = self.step_collection.commands
31        if 'DexCommandLine' in commands:
32            cmd_line_objs = commands['DexCommandLine']
33            assert len(cmd_line_objs) == 1
34            cmd_line_obj = cmd_line_objs[0]
35            the_cmdline = cmd_line_obj.the_cmdline
36
37        with self.debugger:
38            if not self.debugger.loading_error:
39                self._run_debugger_custom(the_cmdline)
40
41        # We may need to pickle this debugger controller after running the
42        # debugger. Debuggers are not picklable objects, so set to None.
43        self.debugger = None
44