59 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~ ~ ~~ ~ ~~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-exception7"""Base class for all DExTer commands, where a command is a specific Python8function that can be embedded into a comment in the source code under test9which will then be executed by DExTer during debugging.10"""11 12import abc13from collections import namedtuple14from typing import List15 16StepExpectInfo = namedtuple("StepExpectInfo", "expression, path, frame_idx, line_range")17 18 19class CommandBase(object, metaclass=abc.ABCMeta):20 def __init__(self):21 self.path = None22 self.lineno = None23 self.raw_text = ""24 25 def get_label_args(self):26 return list()27 28 def has_labels(self):29 return False30 31 @abc.abstractstaticmethod32 def get_name():33 """This abstract method is usually implemented in subclasses as:34 return __class__.__name__35 """36 37 def get_watches(self) -> List[str]:38 return []39 40 @abc.abstractmethod41 def eval(self):42 """Evaluate the command.43 44 This will be called when constructing a Heuristic object to determine45 the debug score.46 47 Returns:48 The logic for handling the result of CommandBase.eval() must be49 defined in Heuristic.__init__() so a consitent return type between50 commands is not enforced.51 """52 53 @staticmethod54 def get_subcommands() -> dict:55 """Returns a dictionary of subcommands in the form {name: command} or56 None if no subcommands are required.57 """58 return None59