8
class callCounter(object):
9
def __init__(self,func):
13
self.count = self.count+1
17
return pykd.eventResult.Break
20
return pykd.eventResult.Proceed
23
class BreakpointTest( unittest.TestCase ):
26
pykd.startProcess( target.appPath + " breakhandlertest" )
27
self.targetModule = pykd.module( target.moduleName )
28
self.targetModule.reload()
32
self.taregtModule = None
33
pykd.killAllProcesses()
35
def testNoBreakpoint(self):
36
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
39
bp = pykd.setBp( self.targetModule.CdeclFunc )
40
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
42
def testRemoveBp(self):
43
bp = pykd.setBp( self.targetModule.CdeclFunc )
45
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
47
def testDeleteBp(self):
48
bp = pykd.setBp( self.targetModule.CdeclFunc )
50
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
52
def testRemoveByIndex(self):
53
bp1 = pykd.setBp( self.targetModule.CdeclFunc )
56
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
58
def testRemoveAllBp(self):
59
bp1 = pykd.setBp( self.targetModule.CdeclFunc )
60
bp2 = pykd.setBp( self.targetModule.CdeclFunc + 1)
61
bp3 = pykd.setBp( self.targetModule.CdeclFunc + 2 )
62
self.assertEqual( 3, pykd.getNumberBreakpoints() )
64
self.assertEqual( 0, pykd.getNumberBreakpoints() )
65
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
67
def testBreakCallback(self):
68
breakCount = callCounter(stopOnBreak)
69
bp = pykd.setBp( self.targetModule.CdeclFunc, breakCount )
70
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
71
self.assertEqual( 1, breakCount.count )
73
def testNoBreakCallback(self):
75
breakCount = callCounter(continueOnBreak)
76
bp = pykd.setBp( self.targetModule.CdeclFunc, breakCount )
77
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
78
self.assertEqual( 1, breakCount.count )
80
def testBreakpointHandler(self):
82
class BreakpointHandler( pykd.eventHandler ):
85
super(BreakpointHandler, self).__init__()
88
def onBreakpoint( self, bpid_):
89
self.count = self.count + 1
92
handler = BreakpointHandler()
93
bp = pykd.setBp( self.targetModule.CdeclFunc )
94
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
95
self.assertEqual( 1, handler.count )
97
def testBreakpointClass(self):
99
class MyBreakpoint(pykd.breakpoint):
100
def __init__(self,offset):
101
super(MyBreakpoint, self).__init__(offset)
105
self.count = self.count + 1
108
bp = MyBreakpoint( self.targetModule.typedVar("CdeclFunc").getDebugStart() )
109
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
110
self.assertEqual( 1, bp.count )
113
def testBreakpointCondition1(self):
115
def makebpcallback(n):
118
if pykd.getParam("b") > n:
119
return pykd.eventResult.Break
120
return pykd.eventResult.Proceed
123
bp = pykd.setBp( self.targetModule.typedVar("CdeclFunc").getDebugStart(), makebpcallback(1) )
124
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
127
def testBreakpointCondition2(self):
129
def makebpcallback(n):
132
if pykd.getParam("b") > n:
133
return pykd.eventResult.Break
134
return pykd.eventResult.Proceed
137
bp = pykd.setBp(self.targetModule.typedVar("CdeclFunc").getDebugStart(), makebpcallback(100) )
138
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
141
def testBreakpointEnum(self):
143
b1 = pykd.setBp( self.targetModule.CdeclFunc)
144
b2 = pykd.setBp( self.targetModule.CdeclFunc + 1)
145
b3 = pykd.setBp( self.targetModule.CdeclFunc + 2)
147
self.assertEqual(3, pykd.getNumberBreakpoints());
148
bpLst = [pykd.getBp(i) for i in range(3)]
149
self.assertEqual(3, len(bpLst))
150
for bp in bpLst: bp.remove()
152
self.assertEqual(0, pykd.getNumberBreakpoints());
154
def testBreakpointChangeHandler(self):
156
class BreakpointChangeHandler( pykd.eventHandler ):
159
pykd.eventHandler.__init__(self)
162
def onChangeBreakpoints(self):
165
handler = BreakpointChangeHandler()
166
bp = pykd.setBp(self.targetModule.CdeclFunc)
168
self.assertEqual(0, pykd.getNumberBreakpoints())
169
self.assertEqual(4, handler.count)
171
def testLambdaBpContinue(self):
172
bp1 = pykd.setBp(self.targetModule.CdeclFunc, lambda : None )
173
bp2 = pykd.setBp(self.targetModule.CdeclFunc, lambda : False )
174
bp3 = pykd.setBp(self.targetModule.CdeclFunc, lambda : 0 )
175
self.assertEqual( pykd.executionStatus.NoDebuggee, pykd.go() )
177
def testLambdaBpBreak(self):
178
bp2 = pykd.setBp(self.targetModule.CdeclFunc, lambda : True )
179
self.assertEqual( pykd.executionStatus.Break, pykd.go() )
181
def testBpCommand(self):
182
pykd.dbgCommand("bp 0x100")
183
self.assertEqual(1, pykd.getNumberBreakpoints())
185
self.assertEqual(0x100, bp.getOffset())
187
def testDoubleRemove(self):
188
bp = pykd.setBp( self.targetModule.CdeclFunc )
190
self.assertRaises( pykd.DbgException, bp.remove )
192
def testDetach(self):
193
bp = pykd.setBp( self.targetModule.CdeclFunc ).detach()
194
self.assertEqual(1, pykd.getNumberBreakpoints())
195
self.assertRaises(pykd.DbgException, bp.detach )
197
self.assertEqual(1, pykd.getNumberBreakpoints())