mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.3.x] added : onException event handler
git-svn-id: https://pykd.svn.codeplex.com/svn@84645 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
3eb38e0cca
commit
ead4054ccc
@ -177,4 +177,36 @@ std::wstring printSystemVersion( kdlib::SystemInfo& sysInfo )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
python::list getExceptionInfoParameters( kdlib::ExceptionInfo& exceptionInfo )
|
||||
{
|
||||
python::list lst;
|
||||
for ( unsigned long i = 0; i < exceptionInfo.parameterCount; ++i )
|
||||
lst.append( exceptionInfo.parameters[i] );
|
||||
return lst;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::wstring printExceptionInfo( kdlib::ExceptionInfo& exceptionInfo )
|
||||
{
|
||||
std::wstringstream sstream;
|
||||
|
||||
sstream << L"FirstChance= " << (exceptionInfo.firstChance ? "True" : "False") << std::endl;
|
||||
|
||||
sstream << L"ExceptionCode= 0x" << std::hex << exceptionInfo.exceptionCode << std::endl;
|
||||
sstream << L"ExceptionFlags= 0x" << std::hex << exceptionInfo.exceptionFlags << std::endl;
|
||||
sstream << L"ExceptionRecord= 0x" << std::hex << exceptionInfo.exceptionRecord << std::endl;
|
||||
sstream << L"ExceptionAddress= 0x" << std::hex << exceptionInfo.exceptionAddress << std::endl;
|
||||
|
||||
for (ULONG i = 0; i < exceptionInfo.parameterCount; ++i)
|
||||
{
|
||||
sstream << L"Param[" << std::dec << i << L"]= 0x";
|
||||
sstream << std::hex << exceptionInfo.parameters[i] << std::endl;
|
||||
}
|
||||
|
||||
return sstream.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} //end namespace pykd
|
||||
|
@ -29,6 +29,10 @@ kdlib::SystemInfo getSystemVersion();
|
||||
|
||||
std::wstring printSystemVersion( kdlib::SystemInfo& sysInfo );
|
||||
|
||||
python::list getExceptionInfoParameters( kdlib::ExceptionInfo& exceptionInfo );
|
||||
|
||||
std::wstring printExceptionInfo( kdlib::ExceptionInfo& exceptionInfo );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} //end namespace pykd
|
@ -198,4 +198,56 @@ void EventHandler::onExecutionStatusChange( kdlib::ExecutionStatus executionStat
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
kdlib::DebugCallbackResult EventHandler::onException( const kdlib::ExceptionInfo &exceptionInfo )
|
||||
{
|
||||
kdlib::DebugCallbackResult result = kdlib::DebugCallbackNoChange;
|
||||
|
||||
PyEval_RestoreThread( m_pystate );
|
||||
|
||||
try {
|
||||
|
||||
do {
|
||||
|
||||
python::override pythonHandler = get_override( "onException" );
|
||||
if ( !pythonHandler )
|
||||
{
|
||||
result = kdlib::EventHandler::onException( exceptionInfo );
|
||||
break;
|
||||
}
|
||||
|
||||
python::object resObj = pythonHandler( exceptionInfo );
|
||||
|
||||
if ( resObj.is_none() )
|
||||
{
|
||||
result = kdlib::DebugCallbackNoChange;
|
||||
break;
|
||||
}
|
||||
|
||||
int retVal = python::extract<int>( resObj );
|
||||
|
||||
if ( retVal >= kdlib::DebugCallbackMax )
|
||||
{
|
||||
result = kdlib::DebugCallbackBreak;
|
||||
break;
|
||||
}
|
||||
|
||||
result = kdlib::DebugCallbackResult(retVal);
|
||||
|
||||
} while( FALSE );
|
||||
|
||||
}
|
||||
catch (const python::error_already_set &)
|
||||
{
|
||||
printException();
|
||||
result = kdlib::DebugCallbackBreak;
|
||||
}
|
||||
|
||||
m_pystate = PyEval_SaveThread();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
} // end namespace pykd
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
|
||||
virtual kdlib::DebugCallbackResult onBreakpoint( kdlib::BREAKPOINT_ID bpId );
|
||||
virtual void onExecutionStatusChange( kdlib::ExecutionStatus executionStatus );
|
||||
virtual kdlib::DebugCallbackResult onException( const kdlib::ExceptionInfo &exceptionInfo );
|
||||
|
||||
private:
|
||||
|
||||
|
@ -574,7 +574,7 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
// .def("__getitem__", &ScopeVars::getVarByIndex )
|
||||
// .def("__getitem__", &ScopeVars::getVarByName );
|
||||
|
||||
python::class_< kdlib::SystemInfo>(
|
||||
python::class_<kdlib::SystemInfo>(
|
||||
"systemVersion", "Operation system version", python::no_init)
|
||||
//.def_readonly( "platformId", &SystemVersion::platformId,
|
||||
// "Platform ID: VER_PLATFORM_WIN32_NT for NT-based Windows")
|
||||
@ -594,23 +594,22 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return object as a string");
|
||||
|
||||
|
||||
// python::class_< ExceptionInfo, ExceptionInfoPtr, boost::noncopyable >(
|
||||
// "exceptionInfo", "Exception information", python::no_init )
|
||||
// .def_readonly( "FirstChance", &ExceptionInfo::FirstChance,
|
||||
// "Specifies whether this exception has been previously encountered")
|
||||
// .def_readonly( "ExceptionCode", &ExceptionInfo::ExceptionCode,
|
||||
// "The reason the exception occurred")
|
||||
// .def_readonly( "ExceptionFlags", &ExceptionInfo::ExceptionFlags,
|
||||
// "The exception flags")
|
||||
// .def_readonly( "ExceptionRecord", &ExceptionInfo::ExceptionRecord,
|
||||
// "A pointer to an associated EXCEPTION_RECORD structure")
|
||||
// .def_readonly( "ExceptionAddress", &ExceptionInfo::ExceptionAddress,
|
||||
// "The address where the exception occurred")
|
||||
// .add_property( "Parameters", &ExceptionInfo::getParameters,
|
||||
// "An array of additional arguments that describe the exception")
|
||||
// .def( "__str__", &ExceptionInfo::print,
|
||||
// "Return object as a string");
|
||||
|
||||
python::class_<kdlib::ExceptionInfo>(
|
||||
"exceptionInfo", "Exception information", python::no_init )
|
||||
.def_readonly( "firstChance", &kdlib::ExceptionInfo::firstChance,
|
||||
"Specifies whether this exception has been previously encountered")
|
||||
.def_readonly( "exceptionCode", &kdlib::ExceptionInfo::exceptionCode,
|
||||
"The reason the exception occurred")
|
||||
.def_readonly( "exceptionFlags", &kdlib::ExceptionInfo::exceptionFlags,
|
||||
"The exception flags")
|
||||
.def_readonly( "exceptionRecord", &kdlib::ExceptionInfo::exceptionRecord,
|
||||
"A pointer to an associated EXCEPTION_RECORD structure")
|
||||
.def_readonly( "exceptionAddress", &kdlib::ExceptionInfo::exceptionAddress,
|
||||
"The address where the exception occurred")
|
||||
.add_property( "parameters", &getExceptionInfoParameters,
|
||||
"An array of additional arguments that describe the exception")
|
||||
.def( "__str__", &printExceptionInfo,
|
||||
"Return object as a string");
|
||||
|
||||
// python::enum_<EVENT_TYPE>("eventType", "Type of debug event")
|
||||
// .value("Breakpoint", EventTypeBreakpoint)
|
||||
|
Loading…
Reference in New Issue
Block a user