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"""Commmand sets the path for all following commands to 'declared_file'. 8""" 9 10import os 11from pathlib import PurePath 12 13from dex.command.CommandBase import CommandBase, StepExpectInfo 14 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_name 22 self.expression = expression 23 self.on_line = kwargs.pop("on_line") 24 self.hit_count = kwargs.pop("hit_count", 0) 25 26 self.address_resolutions = None 27 28 super(DexDeclareAddress, self).__init__() 29 30 @staticmethod 31 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_name 43 44 def eval(self, step_collection): 45 self.address_resolutions[self.get_address_name()] = None 46 for step in step_collection.steps: 47 loc = step.current_location 48 49 if ( 50 loc.path 51 and self.path 52 and PurePath(loc.path) == PurePath(self.path) 53 and loc.lineno == self.on_line 54 ): 55 if self.hit_count > 0: 56 self.hit_count -= 1 57 continue 58 try: 59 watch = step.program_state.frames[0].watches[self.expression] 60 except KeyError: 61 continue 62 try: 63 hex_val = int(watch.value, 16) 64 except ValueError: 65 hex_val = None 66 self.address_resolutions[self.get_address_name()] = hex_val 67 break 68