From 6b56c0d739b0d580f3ab98457b2b60ef4b0458f9 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 21 Jul 2009 00:43:42 +0000 Subject: [PATCH] _CreateCompoundType(): Insert the type into the hash table before resolving data members. Otherwise we could run into infinite recursion. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31663 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../debugger/debug_info/DwarfInterfaceFactory.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/apps/debugger/debug_info/DwarfInterfaceFactory.cpp b/src/apps/debugger/debug_info/DwarfInterfaceFactory.cpp index 3d82a090aa..4918a5e24e 100644 --- a/src/apps/debugger/debug_info/DwarfInterfaceFactory.cpp +++ b/src/apps/debugger/debug_info/DwarfInterfaceFactory.cpp @@ -621,7 +621,10 @@ DwarfInterfaceFactory::_CreateType(DIEType* typeEntry, DwarfType*& _type) if (error != B_OK) return error; - fTypes->Insert(type); + // Insert the type into the hash table. Recheck, as the type may already + // have been inserted (e.g. in the compound type case). + if (fTypes->Lookup(typeEntry) == NULL) + fTypes->Insert(type); // try to get the type's size uint64 size; @@ -641,6 +644,7 @@ DwarfInterfaceFactory::_CreateTypeInternal(DIEType* typeEntry, { BString name; DwarfUtils::GetFullyQualifiedDIEName(typeEntry, name); +// TODO: The DIE may not have a name (e.g. pointer and reference types don't). switch (typeEntry->Tag()) { case DW_TAG_class_type: @@ -722,6 +726,11 @@ DwarfInterfaceFactory::_CreateCompoundType(const BString& name, return B_NO_MEMORY; Reference typeReference(type, true); + // Already add the type at this pointer to the hash table, since otherwise + // we could run into an infinite recursion when trying to create the types + // for the data members. + fTypes->Insert(type); + // find the abstract origin or specification that defines the data members if (typeEntry->DataMembers().IsEmpty()) { if (DIECompoundType* abstractOrigin = dynamic_cast( @@ -757,8 +766,10 @@ DwarfInterfaceFactory::_CreateCompoundType(const BString& name, DwarfDataMember* member = new(std::nothrow) DwarfDataMember(memberEntry, memberName, memberType); Reference memberReference(member, true); - if (member == NULL || !type->AddDataMember(member)) + if (member == NULL || !type->AddDataMember(member)) { + fTypes->Remove(type); return B_NO_MEMORY; + } } _type = typeReference.Detach();