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 8from ctypes import * 9from enum import * 10from functools import partial 11 12from .utils import * 13 14 15class BreakpointTypes(IntEnum): 16 DEBUG_BREAKPOINT_CODE = 0 17 DEBUG_BREAKPOINT_DATA = 1 18 DEBUG_BREAKPOINT_TIME = 2 19 DEBUG_BREAKPOINT_INLINE = 3 20 21 22class BreakpointFlags(IntFlag): 23 DEBUG_BREAKPOINT_GO_ONLY = 0x00000001 24 DEBUG_BREAKPOINT_DEFERRED = 0x00000002 25 DEBUG_BREAKPOINT_ENABLED = 0x00000004 26 DEBUG_BREAKPOINT_ADDER_ONLY = 0x00000008 27 DEBUG_BREAKPOINT_ONE_SHOT = 0x00000010 28 29 30DebugBreakpoint2IID = IID( 31 0x1B278D20, 32 0x79F2, 33 0x426E, 34 IID_Data4_Type(0xA3, 0xF9, 0xC1, 0xDD, 0xF3, 0x75, 0xD4, 0x8E), 35) 36 37 38class DebugBreakpoint2(Structure): 39 pass 40 41 42class DebugBreakpoint2Vtbl(Structure): 43 wrp = partial(WINFUNCTYPE, c_long, POINTER(DebugBreakpoint2)) 44 idb_setoffset = wrp(c_ulonglong) 45 idb_setflags = wrp(c_ulong) 46 _fields_ = [ 47 ("QueryInterface", c_void_p), 48 ("AddRef", c_void_p), 49 ("Release", c_void_p), 50 ("GetId", c_void_p), 51 ("GetType", c_void_p), 52 ("GetAdder", c_void_p), 53 ("GetFlags", c_void_p), 54 ("AddFlags", c_void_p), 55 ("RemoveFlags", c_void_p), 56 ("SetFlags", idb_setflags), 57 ("GetOffset", c_void_p), 58 ("SetOffset", idb_setoffset), 59 ("GetDataParameters", c_void_p), 60 ("SetDataParameters", c_void_p), 61 ("GetPassCount", c_void_p), 62 ("SetPassCount", c_void_p), 63 ("GetCurrentPassCount", c_void_p), 64 ("GetMatchThreadId", c_void_p), 65 ("SetMatchThreadId", c_void_p), 66 ("GetCommand", c_void_p), 67 ("SetCommand", c_void_p), 68 ("GetOffsetExpression", c_void_p), 69 ("SetOffsetExpression", c_void_p), 70 ("GetParameters", c_void_p), 71 ("GetCommandWide", c_void_p), 72 ("SetCommandWide", c_void_p), 73 ("GetOffsetExpressionWide", c_void_p), 74 ("SetOffsetExpressionWide", c_void_p), 75 ] 76 77 78DebugBreakpoint2._fields_ = [("lpVtbl", POINTER(DebugBreakpoint2Vtbl))] 79 80 81class Breakpoint(object): 82 def __init__(self, breakpoint): 83 self.breakpoint = breakpoint.contents 84 self.vt = self.breakpoint.lpVtbl.contents 85 86 def SetFlags(self, flags): 87 res = self.vt.SetFlags(self.breakpoint, flags) 88 aborter(res, "Breakpoint SetFlags") 89 90 def SetOffset(self, offs): 91 res = self.vt.SetOffset(self.breakpoint, offs) 92 aborter(res, "Breakpoint SetOffset") 93 94 def RemoveFlags(self, flags): 95 res = self.vt.RemoveFlags(self.breakpoint, flags) 96 aborter(res, "Breakpoint RemoveFlags") 97 98 def die(self): 99 self.breakpoint = None 100 self.vt = None 101