diff --git a/pykd/dbgclient.cpp b/pykd/dbgclient.cpp index f25aa89..c3dfe3f 100644 --- a/pykd/dbgclient.cpp +++ b/pykd/dbgclient.cpp @@ -493,6 +493,20 @@ void DebugClient::splitSymName( const std::string &fullName, std::string &module /////////////////////////////////////////////////////////////////////////////////// +TypeInfoPtr DebugClient::getTypeInfoByName( const std::string &typeName ) +{ + std::string moduleName; + std::string symName; + + splitSymName( typeName, moduleName, symName ); + + Module module = loadModuleByName( moduleName ); + + return module.getTypeByName( symName ); +} + +/////////////////////////////////////////////////////////////////////////////////// + TypedVarPtr DebugClient::getTypedVarByName( const std::string &varName ) { std::string moduleName; diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index cfe5658..a40647e 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -327,6 +327,8 @@ public: void splitSymName( const std::string &fullName, std::string &moduleName, std::string &symbolName ); + TypeInfoPtr getTypeInfoByName( const std::string &typeName ); + TypedVarPtr getTypedVarByName( const std::string &varName ); TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ); diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 5791d56..96cb8a6 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -520,6 +520,7 @@ BOOST_PYTHON_MODULE( pykd ) "Remove all breapoints" ); python::class_, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) + .def("__init__", python::make_constructor(TypeInfo::getTypeInfoByName ) ) .def( "name", &TypeInfo::getName ) .def( "size", &TypeInfo::getSize ) .def( "offset", &TypeInfo::getOffset ) diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index f819da8..c364d36 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -1,11 +1,19 @@ #include "stdafx.h" #include "typeinfo.h" +#include "dbgclient.h" namespace pykd { ///////////////////////////////////////////////////////////////////////////////////// +TypeInfoPtr TypeInfo::getTypeInfoByName( const std::string &typeName ) +{ + return g_dbgClient->getTypeInfoByName( typeName ); +} + +///////////////////////////////////////////////////////////////////////////////////// + TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &typeSym ) { const ULONG symTag = typeSym->getSymTag(); diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index a1e10b4..7603270 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -18,6 +18,9 @@ class TypeInfo : boost::noncopyable, public intBase { public: + static + TypeInfoPtr getTypeInfoByName( const std::string &symName ); + static TypeInfoPtr getTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ); diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 86341e7..15e62a8 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -9,10 +9,11 @@ import pykd class TypeInfoTest( unittest.TestCase ): def testCtor( self ): - """ typeInfo class can not be created direct """ - try: pykd.typeInfo() - except RuntimeError: pass - + self.assertEqual( "structTest", pykd.typeInfo( "structTest" ).name() ) + self.assertEqual( "structTest", pykd.typeInfo( target.moduleName + "!structTest" ).name() ) + self.assertEqual( "structTest", pykd.typeInfo( "g_structTest" ).name() ) + self.assertEqual( "structTest", pykd.typeInfo( target.moduleName + "!g_structTest" ).name() ) + def testCreateByName( self ): """ creating typeInfo by the type name """ self.assertEqual( "structTest", target.module.type( "structTest" ).name() )