From 2d1d141a4c677013213a597ad08f77e3a891e65f Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Mon, 26 Mar 2012 06:29:41 +0000
Subject: [PATCH] [0.1.x] added : implemented typedVar class constructors

git-svn-id: https://pykd.svn.codeplex.com/svn@75068 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgclient.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++
 pykd/dbgclient.h   | 13 ++------
 2 files changed, 81 insertions(+), 11 deletions(-)

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