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 11 12class DebuggerControllerBase(object, metaclass=abc.ABCMeta): 13 def __init__(self, context, step_collection): 14 self.context = context 15 self.step_collection = step_collection 16 17 @abc.abstractclassmethod 18 def _run_debugger_custom(self): 19 """Specify your own implementation of run_debugger_custom in your own 20 controller. 21 """ 22 pass 23 24 def run_debugger(self, debugger): 25 """Responsible for correctly launching and tearing down the debugger.""" 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