diff --git a/pykd/dbgexcept.h b/pykd/dbgexcept.h index f69f803..5868049 100644 --- a/pykd/dbgexcept.h +++ b/pykd/dbgexcept.h @@ -27,6 +27,10 @@ public: baseExceptTypeObject = p; } + std::string print() { + return what(); + } + private: static PyObject *baseExceptTypeObject; }; diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index e9b7030..556119e 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -164,7 +164,8 @@ BOOST_PYTHON_MODULE( pykd ) dbgExceptionClass .def( python::init( python::args("desc"), "constructor" ) ) .def( "desc", &DbgException::getDesc, - "Get exception description" ); + "Get exception description" ) + .def( "__str__", &DbgException::print); DbgException::setTypeObject( dbgExceptionClass.ptr() ); // DIA exceptions diff --git a/pykd/diawrapper.cpp b/pykd/diawrapper.cpp index e2eaf62..b93aa7f 100644 --- a/pykd/diawrapper.cpp +++ b/pykd/diawrapper.cpp @@ -14,13 +14,14 @@ namespace pyDia { //////////////////////////////////////////////////////////////////////////////// PyObject *Exception::diaExceptTypeObject = NULL; +const std::string Exception::descPrefix("pyDia: "); //////////////////////////////////////////////////////////////////////////////// std::string Exception::makeFullDesc(const std::string &desc, HRESULT hres) { std::strstream res; - res << "pyDia: " << desc << " failed" << std::endl; + res << descPrefix << desc << " failed" << std::endl; res << "Return value is 0x" << std::hex << hres; PCHAR errMessage = NULL; @@ -153,8 +154,11 @@ python::object Symbol::getChildByName(const std::string &_name) if (FAILED(hres)) throw Exception("Get count of children", hres); + if (!count) + throw Exception(_name + " not found as children"); + if (count != 1) - throw Exception("Query unique child", S_FALSE); + throw Exception(_name + " is not unique"); CComPtr< IDiaSymbol > child; hres = symbols->Item(0, &child); @@ -210,7 +214,7 @@ python::object Symbol::getChildByIndex(ULONG _index) throw Exception("Get count of children", hres); if (LONG(_index) >= count) - throw Exception("Check child index", S_FALSE); + throw Exception("Attempt to access non-existing element: index overflow"); CComPtr< IDiaSymbol > child; hres = symbols->Item(_index, &child); diff --git a/pykd/diawrapper.h b/pykd/diawrapper.h index aac544f..36c73c8 100644 --- a/pykd/diawrapper.h +++ b/pykd/diawrapper.h @@ -15,6 +15,12 @@ public: { } + Exception(const std::string &desc) + : DbgException(descPrefix + desc) + , m_hres(S_FALSE) + { + } + HRESULT getRes() const { return m_hres; } @@ -27,6 +33,8 @@ public: private: + static const std::string descPrefix; + static PyObject *diaExceptTypeObject; static std::string makeFullDesc(const std::string &desc, HRESULT hres); @@ -67,7 +75,7 @@ protected: void throwIfNull(const char *desc) { if (!m_symbol) - throw Exception(desc, S_FALSE); + throw Exception(std::string(desc) + " failed, object not preinitialized"); } Symbol(__inout CComPtr< IDiaSymbol > &_symbol) {