68 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"""Commmand sets the path for all following commands to 'declared_file'.8"""9 10import os11from pathlib import PurePath12 13from dex.command.CommandBase import CommandBase, StepExpectInfo14 15 16class DexDeclareAddress(CommandBase):17 def __init__(self, addr_name, expression, **kwargs):18 if not isinstance(addr_name, str):19 raise TypeError("invalid argument type")20 21 self.addr_name = addr_name22 self.expression = expression23 self.on_line = kwargs.pop("on_line")24 self.hit_count = kwargs.pop("hit_count", 0)25 26 self.address_resolutions = None27 28 super(DexDeclareAddress, self).__init__()29 30 @staticmethod31 def get_name():32 return __class__.__name__33 34 def get_watches(self):35 return [36 StepExpectInfo(37 self.expression, self.path, 0, range(self.on_line, self.on_line + 1)38 )39 ]40 41 def get_address_name(self):42 return self.addr_name43 44 def eval(self, step_collection):45 self.address_resolutions[self.get_address_name()] = None46 for step in step_collection.steps:47 loc = step.current_location48 49 if (50 loc.path51 and self.path52 and PurePath(loc.path) == PurePath(self.path)53 and loc.lineno == self.on_line54 ):55 if self.hit_count > 0:56 self.hit_count -= 157 continue58 try:59 watch = step.program_state.frames[0].watches[self.expression]60 except KeyError:61 continue62 try:63 hex_val = int(watch.value, 16)64 except ValueError:65 hex_val = None66 self.address_resolutions[self.get_address_name()] = hex_val67 break68