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"""Base class for all DExTer commands, where a command is a specific Python 8function that can be embedded into a comment in the source code under test 9which will then be executed by DExTer during debugging. 10""" 11 12import abc 13from collections import namedtuple 14from typing import List 15 16StepExpectInfo = namedtuple('StepExpectInfo', 'expression, path, frame_idx, line_range') 17 18class CommandBase(object, metaclass=abc.ABCMeta): 19 def __init__(self): 20 self.path = None 21 self.lineno = None 22 self.raw_text = '' 23 24 def get_label_args(self): 25 return list() 26 27 def has_labels(self): 28 return False 29 30 @abc.abstractstaticmethod 31 def get_name(): 32 """This abstract method is usually implemented in subclasses as: 33 return __class__.__name__ 34 """ 35 36 def get_watches(self) -> List[str]: 37 return [] 38 39 @abc.abstractmethod 40 def eval(self): 41 """Evaluate the command. 42 43 This will be called when constructing a Heuristic object to determine 44 the debug score. 45 46 Returns: 47 The logic for handling the result of CommandBase.eval() must be 48 defined in Heuristic.__init__() so a consitent return type between 49 commands is not enforced. 50 """ 51 52 @staticmethod 53 def get_subcommands() -> dict: 54 """Returns a dictionary of subcommands in the form {name: command} or 55 None if no subcommands are required. 56 """ 57 return None 58