diff --git a/pykd/dbgclient.cpp b/pykd/dbgclient.cpp index 6f5fe44..c25584b 100644 --- a/pykd/dbgclient.cpp +++ b/pykd/dbgclient.cpp @@ -437,4 +437,83 @@ void terminateProcess() /////////////////////////////////////////////////////////////////////////////////// +static const boost::regex moduleSymMatch("^(?:([^!]*)!)?([^!]+)$"); + +TypedVarPtr DebugClient::getTypedVarByName( const std::string &varName ) +{ + boost::cmatch matchResult; + + if ( !boost::regex_match( varName.c_str(), matchResult, moduleSymMatch ) ) + { + std::stringstream sstr; + sstr << "invalid symbol name: " << varName; + throw SymbolException( sstr.str() ); + } + + std::string symName = std::string( matchResult[2].first, matchResult[2].second ); + + if ( matchResult[1].matched ) + { + Module module = loadModuleByName( std::string( matchResult[1].first, matchResult[1].second ) ); + + return module.getTypedVarByName( symName ); + } + + HRESULT hres; + ULONG64 base; + + hres = m_symbols->GetSymbolModule( ( std::string("!") + symName ).c_str(), &base ); + if ( FAILED( hres ) ) + { + std::stringstream sstr; + sstr << "failed to find module for symbol: " << symName; + throw SymbolException( sstr.str() ); + } + + Module module = loadModuleByOffset( base ); + + return module.getTypedVarByName( symName ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +TypedVarPtr DebugClient::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) +{ + boost::cmatch matchResult; + + if ( !boost::regex_match( typeName.c_str(), matchResult, moduleSymMatch ) ) + { + std::stringstream sstr; + sstr << "invalid symbol name: " << typeName; + throw SymbolException( sstr.str() ); + } + + std::string symName = std::string( matchResult[2].first, matchResult[2].second ); + + if ( matchResult[1].matched ) + { + Module module = loadModuleByName( std::string( matchResult[1].first, matchResult[1].second ) ); + + return module.getTypedVarByTypeName( symName, addr ); + } + + HRESULT hres; + ULONG64 base; + + hres = m_symbols->GetSymbolModule( ( std::string("!") + symName ).c_str(), &base ); + if ( FAILED( hres ) ) + { + std::stringstream sstr; + sstr << "failed to find module for symbol: " << symName; + throw SymbolException( sstr.str() ); + } + + Module module = loadModuleByOffset( base ); + + return module.getTypedVarByTypeName( symName, addr ); + +} + +/////////////////////////////////////////////////////////////////////////////////// + }; // end of namespace pykd diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 3394db7..4877d0a 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -325,15 +325,9 @@ public: void removeBp(BPOINT_ID Id); void removeAllBp(); - TypedVarPtr getTypedVarByName( const std::string &varName ) - { - throw DbgException( "not implemented" ); - } + TypedVarPtr getTypedVarByName( const std::string &varName ); - TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) - { - throw DbgException( "not implemented" ); - } + TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ); TypedVarPtr getTypedVarByTypeInfo( const TypeInfoPtr &typeInfo, ULONG64 addr ) { return TypedVar::getTypedVar( m_client, typeInfo, VarDataMemory::factory(m_dataSpaces, addr) ); @@ -344,9 +338,6 @@ private: python::list loadArray( ULONG64 offset, ULONG count, bool phyAddr ); - //python::list - //loadArray( ULONG64 offset, ULONG count, bool phyAddr ); - BpCallbackMap m_bpCallbacks; SynSymbolsPtr m_symSymbols; // DebugClient is creator