52 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 8import os9from itertools import chain10 11 12def in_source_file(source_files, step_info):13 if not step_info.current_frame:14 return False15 if not step_info.current_location.path:16 return False17 if not os.path.exists(step_info.current_location.path):18 return False19 return any(20 os.path.samefile(step_info.current_location.path, f) for f in source_files21 )22 23 24def have_hit_line(watch, loc):25 if hasattr(watch, "on_line"):26 return watch.on_line == loc.lineno27 elif hasattr(watch, "_from_line"):28 return watch._from_line <= loc.lineno and watch._to_line >= loc.lineno29 elif watch.lineno == loc.lineno:30 return True31 return False32 33 34def update_step_watches(step_info, watches, commands):35 watch_cmds = ["DexUnreachable", "DexExpectStepOrder"]36 towatch = chain.from_iterable(commands[x] for x in watch_cmds if x in commands)37 try:38 # Iterate over all watches of the types named in watch_cmds39 for watch in towatch:40 loc = step_info.current_location41 if (42 loc.path is not None43 and os.path.exists(loc.path)44 and os.path.samefile(watch.path, loc.path)45 and have_hit_line(watch, loc)46 ):47 result = watch.eval(step_info)48 step_info.watches.update(result)49 break50 except KeyError:51 pass52