diff --git a/pykd/dbgexcept.cpp b/pykd/dbgexcept.cpp index a022644..d8c8b3c 100644 --- a/pykd/dbgexcept.cpp +++ b/pykd/dbgexcept.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "dbgexcept.h" -//#include "diawrapper.h" +#include "dbgengine.h" namespace pykd { @@ -17,4 +17,35 @@ python::handle<> exceptPyType::pyExceptType; python::handle<> exceptPyType::pyExceptType; /////////////////////////////////////////////////////////////////////////////////// + +void printException() +{ + // ошибка в скрипте + PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; + + PyErr_Fetch( &errtype, &errvalue, &traceback ); + + PyErr_NormalizeException( &errtype, &errvalue, &traceback ); + + python::object tracebackModule = python::import("traceback"); + + std::wstringstream sstr; + + python::object lst = + python::object( tracebackModule.attr("format_exception" ) )( + python::handle<>( errtype ), + python::handle<>( python::allow_null( errvalue ) ), + python::handle<>( python::allow_null( traceback ) ) ); + + sstr << std::endl << std::endl; + + for ( long i = 0; i < python::len(lst); ++i ) + sstr << std::wstring( python::extract(lst[i]) ) << std::endl; + + eprintln( sstr.str() ); +} + + +/////////////////////////////////////////////////////////////////////////////////// + }; // end namespace pykd diff --git a/pykd/dbgexcept.h b/pykd/dbgexcept.h index 62ebb2f..397c3e8 100644 --- a/pykd/dbgexcept.h +++ b/pykd/dbgexcept.h @@ -226,5 +226,9 @@ private: ///////////////////////////////////////////////////////////////////////////////// +void printException(); + +///////////////////////////////////////////////////////////////////////////////// + }; // namespace pykd diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 233b532..e481f95 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -208,9 +208,6 @@ py( PDEBUG_CLIENT4 client, PCSTR args ) global["globalEventHandler"] = EventHandlerPtr( new EventHandlerImpl() ); - // импортируем модуль обработки исключений ( нужен для вывода traceback а ) - python::object tracebackModule = python::import("traceback"); - // разбор параметров typedef boost::escaped_list_separator char_separator_t; typedef boost::tokenizer< char_separator_t > char_tokenizer_t; @@ -262,27 +259,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args ) } catch( boost::python::error_already_set const & ) { - // ошибка в скрипте - PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; - - PyErr_Fetch( &errtype, &errvalue, &traceback ); - - PyErr_NormalizeException( &errtype, &errvalue, &traceback ); - - std::wstringstream sstr; - - python::object lst = - python::object( tracebackModule.attr("format_exception" ) )( - python::handle<>( errtype ), - python::handle<>( python::allow_null( errvalue ) ), - python::handle<>( python::allow_null( traceback ) ) ); - - sstr << std::endl << std::endl; - - for ( long i = 0; i < python::len(lst); ++i ) - sstr << std::wstring( python::extract(lst[i]) ) << std::endl; - - eprintln( sstr.str() ); + printException(); } } catch(...) diff --git a/pykd/eventhandler.cpp b/pykd/eventhandler.cpp index ae6d55d..9c7af3c 100644 --- a/pykd/eventhandler.cpp +++ b/pykd/eventhandler.cpp @@ -50,6 +50,7 @@ DEBUG_CALLBACK_RESULT EventHandlerImpl::OnBreakpoint( ULONG bpId ) return DEBUG_CALLBACK_RESULT(retVal); } catch (const python::error_already_set &) { + printException(); } return DebugCallbackBreak; diff --git a/pykd/eventhandler.h b/pykd/eventhandler.h index 13f6230..990e396 100644 --- a/pykd/eventhandler.h +++ b/pykd/eventhandler.h @@ -6,6 +6,7 @@ #include "dbgengine.h" #include "bpoint.h" +#include "dbgexcept.h" namespace pykd { @@ -62,7 +63,7 @@ private: return pythonHandler(arg1); } catch (const python::error_already_set &) { - //onHandlerException(); + printException(); } } return DebugCallbackNoChange; @@ -77,7 +78,7 @@ private: return pythonHandler(arg1,arg2); } catch (const python::error_already_set &) { - //onHandlerException(); + printException(); } } return DebugCallbackNoChange; @@ -91,12 +92,13 @@ private: return pythonHandler(); } catch (const python::error_already_set &) { - //onHandlerException(); + printException(); } } return DebugCallbackNoChange; } + }; typedef boost::shared_ptr EventHandlerPtr; diff --git a/pykd/pykdver.h b/pykd/pykdver.h index 123c98e..6cf2226 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -2,7 +2,7 @@ #define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_SUBVERSION 0 -#define PYKD_VERSION_BUILDNO 4 +#define PYKD_VERSION_BUILDNO 6 #define __VER_STR2__(x) #x