From 310d1e9c7de61789820fd8cb60657825e030a865 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Thu, 10 Jan 2013 12:28:24 +0000 Subject: [PATCH] [0.2.x] ~fix: size of basic type ptr git-svn-id: https://pykd.svn.codeplex.com/svn@82228 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/customtypes.h | 26 ++++++++++----------- pykd/typeinfo.cpp | 57 ++++++++++++++++++++++++++-------------------- pykd/typeinfo.h | 10 ++++---- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/pykd/customtypes.h b/pykd/customtypes.h index ab3efe8..1d8d43b 100644 --- a/pykd/customtypes.h +++ b/pykd/customtypes.h @@ -21,19 +21,19 @@ public: m_ptrSize = pointerSize ? pointerSize : ptrSize(); } - TypeInfoPtr getUInt1B() { return TypeInfo::getBaseTypeInfo( "UInt1B" ); } - TypeInfoPtr getUInt2B() { return TypeInfo::getBaseTypeInfo( "UInt2B" ); } - TypeInfoPtr getUInt4B() { return TypeInfo::getBaseTypeInfo( "UInt4B" ); } - TypeInfoPtr getUInt8B() { return TypeInfo::getBaseTypeInfo( "UInt8B" ); } - TypeInfoPtr getInt1B() { return TypeInfo::getBaseTypeInfo( "Int1B" ); } - TypeInfoPtr getInt2B() { return TypeInfo::getBaseTypeInfo( "Int2B" ); } - TypeInfoPtr getInt4B() { return TypeInfo::getBaseTypeInfo( "Int4B" ); } - TypeInfoPtr getInt8B() { return TypeInfo::getBaseTypeInfo( "Int8B" ); } - TypeInfoPtr getLong() { return TypeInfo::getBaseTypeInfo( "Long" ); } - TypeInfoPtr getULong() { return TypeInfo::getBaseTypeInfo( "ULong" ); } - TypeInfoPtr getBool() { return TypeInfo::getBaseTypeInfo( "Bool" ); } - TypeInfoPtr getChar() { return TypeInfo::getBaseTypeInfo( "Char" ); } - TypeInfoPtr getWChar() { return TypeInfo::getBaseTypeInfo( "WChar" ); } + TypeInfoPtr getUInt1B() { return TypeInfo::getBaseTypeInfo( "UInt1B", m_ptrSize ); } + TypeInfoPtr getUInt2B() { return TypeInfo::getBaseTypeInfo( "UInt2B", m_ptrSize ); } + TypeInfoPtr getUInt4B() { return TypeInfo::getBaseTypeInfo( "UInt4B", m_ptrSize ); } + TypeInfoPtr getUInt8B() { return TypeInfo::getBaseTypeInfo( "UInt8B", m_ptrSize ); } + TypeInfoPtr getInt1B() { return TypeInfo::getBaseTypeInfo( "Int1B", m_ptrSize ); } + TypeInfoPtr getInt2B() { return TypeInfo::getBaseTypeInfo( "Int2B", m_ptrSize ); } + TypeInfoPtr getInt4B() { return TypeInfo::getBaseTypeInfo( "Int4B", m_ptrSize ); } + TypeInfoPtr getInt8B() { return TypeInfo::getBaseTypeInfo( "Int8B", m_ptrSize ); } + TypeInfoPtr getLong() { return TypeInfo::getBaseTypeInfo( "Long", m_ptrSize ); } + TypeInfoPtr getULong() { return TypeInfo::getBaseTypeInfo( "ULong", m_ptrSize ); } + TypeInfoPtr getBool() { return TypeInfo::getBaseTypeInfo( "Bool", m_ptrSize ); } + TypeInfoPtr getChar() { return TypeInfo::getBaseTypeInfo( "Char", m_ptrSize ); } + TypeInfoPtr getWChar() { return TypeInfo::getBaseTypeInfo( "WChar", m_ptrSize ); } TypeInfoPtr getVoidPtr() { return TypeInfoPtr( new PointerTypeInfo(m_ptrSize) ); diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 370e617..df6f253 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -46,7 +46,7 @@ TypeInfoPtr TypeInfo::getTypeInfoByName( const std::string &typeName ) std::string symName; if ( TypeInfo::isBaseType( typeName ) ) - return TypeInfo::getBaseTypeInfo( typeName ); + return TypeInfo::getBaseTypeInfo( typeName, pykd::ptrSize() ); splitSymName( typeName, moduleName, symName ); @@ -63,7 +63,7 @@ ULONG64 TypeInfo::getSymbolSize( const std::string &fullName ) std::string symName; if ( TypeInfo::isBaseType( fullName ) ) - return TypeInfo::getBaseTypeInfo( fullName )->getSize(); + return TypeInfo::getBaseTypeInfo( fullName, pykd::ptrSize() )->getSize(); splitSymName( fullName, moduleName, symName ); @@ -124,6 +124,13 @@ ULONG64 TypeInfo::getOffset( const std::string &fullName ) ///////////////////////////////////////////////////////////////////////////////////// +inline ULONG getTypePointerSize( SymbolPtr &typeSym ) +{ + return (typeSym->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; +} + +///////////////////////////////////////////////////////////////////////////////////// + TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &typeSym ) { ULONG symTag = typeSym->getSymTag(); @@ -185,7 +192,7 @@ TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &typeSym ) } if ( ptr ) - ptr->m_ptrSize = (typeSym->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; + ptr->m_ptrSize = getTypePointerSize(typeSym); return ptr; } @@ -208,7 +215,7 @@ TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &symScope, const std::string &symN if ( pos == std::string::npos ) { - TypeInfoPtr basePtr = getBaseTypeInfo( symName ); + TypeInfoPtr basePtr = getBaseTypeInfo( symName, getTypePointerSize(symScope) ); if ( basePtr != 0 ) return basePtr; @@ -252,56 +259,56 @@ TypeInfo::isBaseType( const std::string &symName ) } TypeInfoPtr -TypeInfo::getBaseTypeInfo( const std::string &symName ) +TypeInfo::getBaseTypeInfo( const std::string &symName, ULONG pointerSize ) { boost::cmatch baseMatchResult; if ( boost::regex_match( symName.c_str(), baseMatchResult, baseMatch ) ) { if ( baseMatchResult[1].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Char") ); + return TypeInfoPtr( new TypeInfoWrapper("Char", pointerSize) ); if ( baseMatchResult[2].matched ) - return TypeInfoPtr( new TypeInfoWrapper("WChar") ); + return TypeInfoPtr( new TypeInfoWrapper("WChar", pointerSize) ); if ( baseMatchResult[3].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Int1B") ); + return TypeInfoPtr( new TypeInfoWrapper("Int1B", pointerSize) ); if ( baseMatchResult[4].matched ) - return TypeInfoPtr( new TypeInfoWrapper("UInt1B") ); + return TypeInfoPtr( new TypeInfoWrapper("UInt1B", pointerSize) ); if ( baseMatchResult[5].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Int2B") ); + return TypeInfoPtr( new TypeInfoWrapper("Int2B", pointerSize) ); if ( baseMatchResult[6].matched ) - return TypeInfoPtr( new TypeInfoWrapper("UInt2B") ); + return TypeInfoPtr( new TypeInfoWrapper("UInt2B", pointerSize) ); if ( baseMatchResult[7].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Int4B") ); + return TypeInfoPtr( new TypeInfoWrapper("Int4B", pointerSize) ); if ( baseMatchResult[8].matched ) - return TypeInfoPtr( new TypeInfoWrapper("UInt4B") ); + return TypeInfoPtr( new TypeInfoWrapper("UInt4B", pointerSize) ); if ( baseMatchResult[9].matched ) - return TypeInfoPtr( new TypeInfoWrapper<__int64>("Int8B") ); + return TypeInfoPtr( new TypeInfoWrapper<__int64>("Int8B", pointerSize) ); if ( baseMatchResult[10].matched ) - return TypeInfoPtr( new TypeInfoWrapper("UInt8B") ); + return TypeInfoPtr( new TypeInfoWrapper("UInt8B", pointerSize) ); if ( baseMatchResult[11].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Long") ); + return TypeInfoPtr( new TypeInfoWrapper("Long", pointerSize) ); if ( baseMatchResult[12].matched ) - return TypeInfoPtr( new TypeInfoWrapper("ULong") ); + return TypeInfoPtr( new TypeInfoWrapper("ULong", pointerSize) ); if ( baseMatchResult[13].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Float") ); + return TypeInfoPtr( new TypeInfoWrapper("Float", pointerSize) ); if ( baseMatchResult[14].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Bool") ); + return TypeInfoPtr( new TypeInfoWrapper("Bool", pointerSize) ); if ( baseMatchResult[15].matched ) - return TypeInfoPtr( new TypeInfoWrapper("Double") ); + return TypeInfoPtr( new TypeInfoWrapper("Double", pointerSize) ); } return TypeInfoPtr(); @@ -319,7 +326,7 @@ TypeInfo::getBaseTypeInfo( SymbolPtr &symbol ) std::stringstream sstr; sstr << symName << symbol->getSize() << "B"; - return getBaseTypeInfo( sstr.str() ); + return getBaseTypeInfo( sstr.str(), getTypePointerSize(symbol) ); } if ( symName == "Float" && symbol->getSize() == 8 ) @@ -327,7 +334,7 @@ TypeInfo::getBaseTypeInfo( SymbolPtr &symbol ) symName = "Double"; } - return getBaseTypeInfo( symName ); + return getBaseTypeInfo( symName, getTypePointerSize(symbol) ); } ///////////////////////////////////////////////////////////////////////////////////// @@ -401,7 +408,7 @@ PointerTypeInfo::PointerTypeInfo( SymbolPtr &symScope, const std::string &symNam { m_derefType.swap( TypeInfoPtr() ); } - m_size = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; + m_size = getTypePointerSize(symScope); } ///////////////////////////////////////////////////////////////////////////////////// @@ -531,7 +538,7 @@ static const boost::regex symbolMatch("^([\\*]*)([^\\(\\)\\*\\[\\]]*)([\\(\\)\\* TypeInfoPtr TypeInfo::getComplexType( SymbolPtr &symScope, const std::string &symName ) { - ULONG ptrSize = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; + ULONG ptrSize = getTypePointerSize(symScope); boost::cmatch matchResult; @@ -540,7 +547,7 @@ TypeInfoPtr TypeInfo::getComplexType( SymbolPtr &symScope, const std::string &sy std::string innerSymName = std::string( matchResult[2].first, matchResult[2].second ); - TypeInfoPtr basePtr = getBaseTypeInfo( innerSymName ); + TypeInfoPtr basePtr = getBaseTypeInfo( innerSymName, getTypePointerSize(symScope) ); if ( basePtr != 0 ) { return getRecurciveComplexType( basePtr, std::string( matchResult[3].first, matchResult[3].second ), ptrSize ); diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index 6888212..21a695f 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -41,7 +41,7 @@ public: TypeInfoPtr getTypeInfo( SymbolPtr &symbol ); static - TypeInfoPtr getBaseTypeInfo( const std::string &name ); + TypeInfoPtr getBaseTypeInfo( const std::string &name, ULONG pointerSize ); static TypeInfoPtr getBaseTypeInfo( SymbolPtr &symbol ); @@ -248,9 +248,11 @@ template class TypeInfoWrapper : public TypeInfo { public: - TypeInfoWrapper( const std::string &name ) : - m_name(name) - {} + TypeInfoWrapper( const std::string &name, ULONG pointerSize ) + : m_name(name) + { + m_ptrSize = pointerSize; + } private: