diff --git a/test/scripts/ehexcepttest.py b/test/scripts/ehexcepttest.py index fc9af07..e5af138 100644 --- a/test/scripts/ehexcepttest.py +++ b/test/scripts/ehexcepttest.py @@ -26,7 +26,7 @@ class BreakExceptionHandler(pykd.eventHandler): """Breakpoint handler""" self.wasBreakpoint = True self.wasBreakpointIds.append( bpId ) - return pykd.DEBUG_STATUS_NO_CHANGE + return pykd.DEBUG_STATUS_BREAK def onException(self, exceptParams): """Exception handler""" @@ -41,7 +41,7 @@ class BreakExceptionHandler(pykd.eventHandler): elif exceptParams["Code"] == pykd.EXCEPTION_BREAKPOINT: self.bpCount += 1 - return pykd.DEBUG_STATUS_BREAK if self.wasSecondChance else pykd.DEBUG_STATUS_NO_CHANGE + return pykd.DEBUG_STATUS_BREAK class EhExceptionBreakpointTest(unittest.TestCase): """Unit tests of exceptions end breakpoint handling""" @@ -55,33 +55,51 @@ class EhExceptionBreakpointTest(unittest.TestCase): bpIdSoftware = testClient.setBp( targetMod.offset("changeValueForAccessTesting") ) - bpIdHwExecute = testClient.setBp( targetMod.offset("readValueForAccessTesting"), - 1, - pykd.DEBUG_BREAK_EXECUTE ) + allBp = testClient.getAllBp() + self.assertEqual( 1, len( allBp ) ) + self.assertTrue( bpIdSoftware in allBp ) - bpIdHwWrite = testClient.setBp( targetMod.offset("g_valueForAccessTesting1"), - 1, - pykd.DEBUG_BREAK_WRITE ) - - bpIdHwRead = testClient.setBp( targetMod.offset("g_valueForAccessTesting2"), - 1, - pykd.DEBUG_BREAK_READ ) - - self.assertEqual( 4, len( testClient.getAllBp() ) ) + hwBpIsNotSet = True +# kd> ba e 1 +# ^ Unable to set breakpoint error +# The system resets thread contexts after the process +# breakpoint so hardware breakpoints cannot be set. +# Go to the executable's entry point and set it then. breakExceptionHandler = BreakExceptionHandler( testClient ) while not breakExceptionHandler.wasSecondChance: testClient.go() + if hwBpIsNotSet: + hwBpIsNotSet = False + bpIdHwExecute = testClient.setBp( targetMod.offset("readValueForAccessTesting"), + 1, pykd.DEBUG_BREAK_EXECUTE ) + + bpIdHwWrite = testClient.setBp( targetMod.offset("g_valueForAccessTesting1"), + 1, pykd.DEBUG_BREAK_WRITE ) + + bpIdHwRead = testClient.setBp( targetMod.offset("g_valueForAccessTesting2"), + 1, pykd.DEBUG_BREAK_READ ) + + allBp = testClient.getAllBp() + self.assertEqual( 4, len( allBp ) ) + self.assertTrue( bpIdSoftware in allBp ) + self.assertTrue( bpIdHwExecute in allBp ) + self.assertTrue( bpIdHwWrite in allBp ) + self.assertTrue( bpIdHwRead in allBp ) - self.assertTrue( breakExceptionHandler.wasBreakpoint ) self.assertEqual( [2, 3], breakExceptionHandler.firstChanceAccessAddresses ) - self.assertEqual( 2, breakExceptionHandler.bpCount ) # main and doExeptions + self.assertEqual( 3, breakExceptionHandler.bpCount ) # main and 2 in doExeptions self.assertEqual( [3, ], breakExceptionHandler.secondChanceAccessAddresses ) + self.assertTrue( breakExceptionHandler.wasBreakpoint ) + self.assertTrue( bpIdSoftware in breakExceptionHandler.wasBreakpointIds ) + self.assertTrue( bpIdHwExecute in breakExceptionHandler.wasBreakpointIds ) + self.assertTrue( bpIdHwWrite in breakExceptionHandler.wasBreakpointIds ) + self.assertTrue( bpIdHwRead in breakExceptionHandler.wasBreakpointIds ) testClient.removeBp(bpIdHwRead) self.assertEqual( 3, len( testClient.getAllBp() ) ) diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index 04e7721..dac3f17 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -367,6 +367,8 @@ void readValueForAccessTesting() int doExeptions() { + __debugbreak(); + changeValueForAccessTesting(); readValueForAccessTesting();