diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index a8484f1..0f175d7 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -71,6 +71,7 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "typedVar", &loadTypedVar ); boost::python::def( "typedVarList", &loadTypedVarList ); boost::python::def( "containingRecord", &containingRecord ); + boost::python::def( "sizeof", &sizeofType ); boost::python::def( "loadModule", &loadModule ); boost::python::def( "findSymbol", &findSymbolForAddress ); boost::python::def( "getOffset", &findAddressForSymbol ); @@ -104,7 +105,8 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "getImplicitThread", &getImplicitThread ); boost::python::def( "setImplicitThread", &setImplicitThread ); boost::python::class_( "typedVarClass" ) - .def("getAddress", &typedVarClass::getAddress ); + .def("getAddress", &typedVarClass::getAddress ) + .def("sizeof", &typedVarClass::size ); boost::python::class_( "dbgModuleClass" ) .def("begin", &dbgModuleClass::getBegin ) .def("end", &dbgModuleClass::getEnd ) diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index 209e949..e779826 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -94,8 +94,13 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6 hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); if ( FAILED( hres ) ) throw DbgException( "IDebugSymbol::GetTypeId failed" ); + + ULONG typeSize; + hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &typeSize ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetTypeSize failed" ); - typedVarClass temp( address ); + typedVarClass temp( address, typeSize ); boost::python::object var( temp ); for ( ULONG i = 0; ; ++i ) @@ -201,6 +206,44 @@ containingRecord( ULONG64 address, const std::string &moduleName, const std::str /////////////////////////////////////////////////////////////////////////////////// +ULONG +sizeofType( const std::string &moduleName, const std::string &typeName ) +{ + HRESULT hres; + ULONG typeSize = ~0; + + try { + + ULONG64 moduleBase; + + hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); + + ULONG typeId; + hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetTypeId failed" ); + + hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &typeSize ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetTypeSize failed" ); + } + + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return typeSize; +} + +/////////////////////////////////////////////////////////////////////////////////// + boost::python::object loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName ) { diff --git a/pykd/dbgtype.h b/pykd/dbgtype.h index 359898c..e5b332d 100644 --- a/pykd/dbgtype.h +++ b/pykd/dbgtype.h @@ -14,8 +14,9 @@ public: typedVarClass() {} - typedVarClass( ULONG64 addr ) : - m_addr( addr ) + typedVarClass( ULONG64 addr, ULONG size ) : + m_addr( addr ), + m_size( size ) {} ULONG64 @@ -23,9 +24,16 @@ public: return m_addr; } + ULONG + size() const { + return m_size; + } + private: ULONG64 m_addr; + + ULONG m_size; }; @@ -40,5 +48,8 @@ loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::str boost::python::object containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName ); +ULONG +sizeofType( const std::string &moduleName, const std::string &typeName ); + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file