From eef5cf7596a3214d2e787c1707328832a56642b2 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Fri, 14 Sep 2012 17:17:44 +0000 Subject: [PATCH] [0.2.x] ~getName now return undecorated name git-svn-id: https://pykd.svn.codeplex.com/svn@79579 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dia/diawrapper.cpp | 77 ++++++++++++++++++++++++++--------------- pykd/dia/diawrapper.h | 10 +++--- pykd/symengine.h | 1 - 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/pykd/dia/diawrapper.cpp b/pykd/dia/diawrapper.cpp index e8ffbef..2265376 100644 --- a/pykd/dia/diawrapper.cpp +++ b/pykd/dia/diawrapper.cpp @@ -40,10 +40,54 @@ DiaRegToRegRelativeI386::DiaRegToRegRelativeI386() const std::string DiaException::descPrefix("pyDia: "); -std::string DiaException::makeFullDesc(const std::string &desc, HRESULT hres) +std::string DiaException::makeFullDesc(const std::string &desc, HRESULT hres, IDiaSymbol *symbol /*= NULL*/) { std::stringstream sstream; sstream << descPrefix << desc << " failed" << std::endl; + if (symbol) + { + BSTR bstrName = NULL; + HRESULT locRes = symbol->get_undecoratedName(&bstrName); + if (S_OK == locRes && bstrName) + { + autoBstr freeBstr(bstrName); + sstream << "Symbol name: \"" << autoBstr::asStr(bstrName) << "\""; + } + else + { + locRes = symbol->get_name(&bstrName); + if (S_OK == locRes && bstrName) + { + autoBstr freeBstr(bstrName); + sstream << "Symbol name: " << autoBstr::asStr(bstrName); + } + else + { + sstream << "Symbol: "; + } + } + + DWORD dwValue; + locRes = symbol->get_relativeVirtualAddress(&dwValue); + if (S_OK == locRes) + { + sstream << ", RVA= 0x" << std::hex << dwValue; + } + + locRes = symbol->get_symTag(&dwValue); + if (S_OK == locRes) + { + sstream << ", tag= " << std::dec << dwValue; + } + + locRes = symbol->get_locationType(&dwValue); + if (S_OK == locRes) + { + sstream << ", location: " << std::dec << dwValue; + } + + sstream << std::endl; + } sstream << "Return value is 0x" << std::hex << hres; PCHAR errMessage = NULL; @@ -392,32 +436,11 @@ static const boost::regex stdcallMatch("^_(\\w+)@.+$"); std::string DiaSymbol::getName() { - autoBstr retValue( callSymbol(get_name) ); - - boost::cmatch matchResult; - - std::string retStr = retValue.asStr(); - - if ( boost::regex_match( retStr.c_str(), matchResult, stdcallMatch ) ) - { - retStr= std::string( matchResult[1].first, matchResult[1].second ); - } - else if (IMAGE_FILE_MACHINE_I386 == m_machineType) - { - DWORD symTag; - HRESULT hres = m_symbol->get_symTag(&symTag); - if (S_OK == hres && SymTagPublicSymbol == symTag) - retStr.erase( retStr.begin() ); - } - - return retStr; -} - -/////////////////////////////////////////////////////////////////////////////// - -std::string DiaSymbol::getUndecoratedName() -{ - autoBstr retValue( callSymbol(get_undecoratedName) ); + BSTR bstrName = NULL; + HRESULT hres = m_symbol->get_undecoratedName(&bstrName); + if (S_OK != hres) + bstrName = callSymbol(get_name); + autoBstr retValue( bstrName ); return retValue.asStr(); } diff --git a/pykd/dia/diawrapper.h b/pykd/dia/diawrapper.h index a42053e..906a37d 100644 --- a/pykd/dia/diawrapper.h +++ b/pykd/dia/diawrapper.h @@ -25,8 +25,8 @@ typedef std::map DiaRegToRegRelativeBase; class DiaException : public SymbolException { public: - DiaException(const std::string &desc, HRESULT hres) - : SymbolException( makeFullDesc(desc, hres) ) + DiaException(const std::string &desc, HRESULT hres, IDiaSymbol *symbol = NULL) + : SymbolException( makeFullDesc(desc, hres, symbol) ) , m_hres(hres) { } @@ -44,7 +44,7 @@ private: static const std::string descPrefix; - static std::string makeFullDesc(const std::string &desc, HRESULT hres); + static std::string makeFullDesc(const std::string &desc, HRESULT hres, IDiaSymbol *symbol = NULL); HRESULT m_hres; }; @@ -71,8 +71,6 @@ public: std::string getName(); - std::string getUndecoratedName(); - SymbolPtr getType(); SymbolPtr getIndexType(); @@ -208,7 +206,7 @@ protected: TRet retValue; HRESULT hres = (m_symbol->*method)(&retValue); if (S_OK != hres) - throw DiaException(std::string("Call IDiaSymbol::") + methodName, hres); + throw DiaException(std::string("Call IDiaSymbol::") + methodName, hres, m_symbol); return retValue; } diff --git a/pykd/symengine.h b/pykd/symengine.h index 385453d..996a06c 100644 --- a/pykd/symengine.h +++ b/pykd/symengine.h @@ -143,7 +143,6 @@ public: virtual ULONG getSymTag() = 0; virtual SymbolPtr getType() = 0; virtual ULONG getUdtKind() = 0; - virtual std::string getUndecoratedName() = 0; virtual ULONGLONG getVa() = 0; virtual void getValue( BaseTypeVariant &vtValue) = 0; virtual ULONG getVirtualBaseDispIndex() = 0;