diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 9949acf..932cc45 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -10,7 +10,8 @@ TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &typeSym ) { ULONG tag = typeSym->getSymTag(); - switch( typeSym->getSymTag() ) + const ULONG symTag = typeSym->getSymTag(); + switch( symTag ) { case SymTagBaseType: return getBaseTypeInfo( typeSym ); @@ -219,7 +220,14 @@ BitFieldTypeInfo::BitFieldTypeInfo( pyDia::SymbolPtr &symbol ) PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symbol ) { - m_derefType = TypeInfo::getTypeInfo( symbol->getType() ); + try + { + m_derefType = TypeInfo::getTypeInfo( symbol->getType() ); + } + catch (const SymbolException &) + { + m_derefType.swap( TypeInfoPtr() ); + } m_size = (ULONG)symbol->getSize(); } @@ -227,7 +235,14 @@ PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symbol ) PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ) { - m_derefType = TypeInfo::getTypeInfo( symScope, symName ); + try + { + m_derefType = TypeInfo::getTypeInfo( symScope, symName ); + } + catch (const SymbolException &) + { + m_derefType.swap( TypeInfoPtr() ); + } m_size = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; } diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index 72a3b1e..4f465ff 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -285,10 +285,14 @@ public: } virtual TypeInfoPtr deref() { + if (!m_derefType) + throw TypeException("", "this pointer can not be dereferenced"); return m_derefType; } TypeInfoPtr getDerefType() { + if (!m_derefType) + throw TypeException("", "this pointer can not be dereferenced"); return m_derefType; } diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 015342b..6375f35 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -168,3 +168,13 @@ class TypedVarTest( unittest.TestCase ): tv = target.module.typedVar( "g_unNamedStruct" ) self.assertEqual( 4, tv.m_fieldNestedStruct ) self.assertEqual( 5, tv.m_fieldOfUnNamed ) + + def testPointerToFunction( self ): + tv1 = target.module.typedVar( "g_unTypedPtrToFunction" ) + self.assertEqual( target.module.offset("EnumWindowsProc2"), tv1 ) + + tv2 = target.module.typedVar( "g_unTypedPtrToFunction" ) + self.assertEqual( tv1, tv2 ) + + self.assertRaises( pykd.TypeException, tv1.deref ) + self.assertRaises( pykd.TypeException, tv2.deref ) diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index 7373968..d7b76ba 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -214,6 +214,8 @@ struct StructWithNested { StructWithNested g_structWithNested; StructWithNested::Nested g_structNested; +WNDENUMPROC g_ptrToFunction; +void *g_unTypedPtrToFunction; #pragma pack( pop ) //////////////////////////////////////////////////////////////////////////////// @@ -276,6 +278,7 @@ void FuncWithName0() std::cout << g_classChild.m_enumField; std::cout << g_unNamedStruct.m_fieldNestedStruct; std::cout << g_structNested.m_nestedFiled; + std::cout << g_unTypedPtrToFunction; } //////////////////////////////////////////////////////////////////////////////// @@ -295,6 +298,7 @@ void FuncWithName1(int a) std::cout << g_string; std::cout << g_unNamedStruct.m_fieldOfUnNamed; std::cout << g_structWithNested.m_field; + std::cout << g_ptrToFunction; } //////////////////////////////////////////////////////////////////////////////// @@ -392,6 +396,9 @@ int _tmain(int argc, _TCHAR* argv[]) g_structWithNested.m_field = 34; g_structNested.m_nestedFiled = 46; + g_ptrToFunction = &EnumWindowsProc2; + g_unTypedPtrToFunction = &EnumWindowsProc2; + // Let test scripts to execute __debugbreak();