2012-12-19 00:28:04 +08:00
|
|
|
"""Exception event test"""
|
2012-01-24 06:00:00 +08:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
import target
|
|
|
|
import pykd
|
2012-12-19 00:28:04 +08:00
|
|
|
import testutils
|
2012-01-24 06:00:00 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
class ExceptionHandler(pykd.eventHandler):
|
2012-01-24 06:00:00 +08:00
|
|
|
"""Track load/unload module implementation"""
|
2012-01-25 17:13:19 +08:00
|
|
|
def __init__(self):
|
2012-12-19 00:28:04 +08:00
|
|
|
pykd.eventHandler.__init__(self)
|
|
|
|
self.accessViolationOccured = False
|
2012-01-24 06:00:00 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
def onException(self, exceptInfo):
|
|
|
|
"""Exception handler"""
|
|
|
|
self.accessViolationOccured = exceptInfo.ExceptionCode == 0xC0000005
|
2012-01-24 06:00:00 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
if self.accessViolationOccured:
|
|
|
|
self.param0 = exceptInfo.Parameters[0]
|
|
|
|
self.param1 = exceptInfo.Parameters[1]
|
|
|
|
return pykd.eventResult.Break
|
2012-01-24 06:00:00 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
return pykd.eventResult.NoChange
|
2012-01-24 06:00:00 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
class EhExceptionTest(unittest.TestCase):
|
|
|
|
"""Exception event test"""
|
2012-01-25 01:26:08 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
def testException(self):
|
|
|
|
"""Start new process and track exceptions"""
|
|
|
|
_locProcessId = pykd.startProcess( target.appPath + " -testAccessViolation" )
|
|
|
|
with testutils.ContextCallIt( testutils.KillProcess(_locProcessId) ) as killStartedProcess :
|
|
|
|
exceptionHandler = ExceptionHandler()
|
2012-01-25 04:40:07 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
while not exceptionHandler.accessViolationOccured:
|
|
|
|
pykd.go()
|
2012-01-25 01:26:08 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
self.assertEqual( pykd.lastEvent(), pykd.eventType.Exception )
|
2012-01-25 01:26:08 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
self.assertTrue( exceptionHandler.accessViolationOccured )
|
|
|
|
self.assertEqual( exceptionHandler.param0, 1 ) # write
|
|
|
|
self.assertEqual( exceptionHandler.param1, 6 ) # addr
|
2012-01-25 17:13:19 +08:00
|
|
|
|
2012-12-19 00:28:04 +08:00
|
|
|
exceptInfo = pykd.lastException()
|
|
|
|
self.assertEqual( exceptInfo.ExceptionCode, 0xC0000005 )
|
|
|
|
self.assertEqual( exceptionHandler.param0, exceptInfo.Parameters[0] )
|
|
|
|
self.assertEqual( exceptionHandler.param1, exceptInfo.Parameters[1] )
|