1 """
2 Watchpoint Objects
3 """
4
5 from vtrace import *
6 from vtrace.breakpoints import *
7
9 """
10 The basic "break on access" watchpoint. Extended from
11 Breakpoints and handled almost exactly the same way...
12 """
13 - def __init__(self, addr, expression=None, size=4, perms="rw"):
17
21
25
27 bname = Breakpoint.getName(self)
28 return "%s (%s %d bytes)" % (bname, self.wpperms, self.wpsize)
29
31 trace.requireAttached()
32 if not self.active:
33 if self.address != None:
34 trace.archAddWatchpoint(self.address, size=self.wpsize, perms=self.wpperms)
35 self.active = True
36 return self.active
37
44
45 -class PageWatchpoint(Watchpoint):
46 """
47 A special "watchpoint" that uses memory permissions to
48 watch for accesses to whole memory maps. This *requires* OS
49 help and only works on platforms which support:
50 * platformProtectMemory()
51 * signal/exceptions which denote the fault address on SEGV
52
53 NOTE: These *must* be added page aligned
54 """
55 - def __init__(self, addr, expression=None, size=4, watchread=False):
56 Watchpoint.__init__(self, addr, expression=expression, size=size, perms='rw')
57 self._orig_perms = None
58 self._new_perms = e_mem.MM_READ
59 if watchread:
60 self._new_perms = e_mem.MM_NONE
61
62 - def resolvedaddr(self, trace, addr):
63 self._orig_perms = trace.getMemoryMap(addr)[2]
64
65 - def notify(self, event, trace):
66 pw = trace.getMeta('pagewatch')
67 pc = trace.getProgramCounter()
68 vaddr,vperm = trace.platformGetMemFault()
69 pw.append((pc, vaddr, vperm))
70
71 self.fastbreak = trace.getMeta('pagerun')
72
74 bname = Breakpoint.getName(self)
75 return "%s (%s %d bytes)" % (bname, e_mem.reprPerms(self._new_perms), self.wpsize)
76
77 - def activate(self, trace):
78
79 if not self.active:
80 trace.protectMemory(self.address, self.wpsize, self._new_perms)
81 self.active = True
82 return self.active
83
84 - def deactivate(self, trace):
85
86 if self.active:
87 trace.protectMemory(self.address, self.wpsize, self._orig_perms)
88 self.active = False
89 return self.active
90