From 104b28862d8432f6e7402f9cb24b48b097318eb7 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 19 Jul 2013 21:44:48 -0400 Subject: [PATCH] Debugger: DwarfFile: Fix DWARF4 signature handling. Depending on how the type unit was actually set up hierarchically, we sometimes ended up with the unit set to the wrong actual type object. Instead, we now simply let the unit parse, and then look up the entry by the offset specified in the header after all is said and done. Fixes class/struct objects sometimes winding up resolving to one of their members instead. Some problems still remain with resolving variable values for such types though, needs further investigation. --- src/apps/debugger/dwarf/DebugInfoEntries.cpp | 10 ---------- src/apps/debugger/dwarf/DebugInfoEntries.h | 5 ----- src/apps/debugger/dwarf/DwarfFile.cpp | 8 ++++++++ src/apps/debugger/dwarf/TypeUnit.cpp | 11 ++++++++--- src/apps/debugger/dwarf/TypeUnit.h | 2 ++ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.cpp b/src/apps/debugger/dwarf/DebugInfoEntries.cpp index b4f620a1bc..93ff1dc999 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntries.cpp +++ b/src/apps/debugger/dwarf/DebugInfoEntries.cpp @@ -2549,16 +2549,6 @@ DIETypeUnit::Tag() const } -status_t -DIETypeUnit::AddChild(DebugInfoEntry* child) -{ - if (child->IsType()) - fType = dynamic_cast(child); - - return B_OK; -} - - status_t DIETypeUnit::AddAttribute_language(uint16 attributeName, const AttributeValue& value) diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.h b/src/apps/debugger/dwarf/DebugInfoEntries.h index 6fffdf4176..66b481883c 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntries.h +++ b/src/apps/debugger/dwarf/DebugInfoEntries.h @@ -1614,16 +1614,11 @@ public: uint16 Language() const { return fLanguage; } - virtual status_t AddChild(DebugInfoEntry* child); - virtual status_t AddAttribute_language(uint16 attributeName, const AttributeValue& value); - inline DIEType* GetType() const { return fType; } - private: uint16 fLanguage; - DIEType* fType; }; diff --git a/src/apps/debugger/dwarf/DwarfFile.cpp b/src/apps/debugger/dwarf/DwarfFile.cpp index fd2c8531fa..66b9c41f5e 100644 --- a/src/apps/debugger/dwarf/DwarfFile.cpp +++ b/src/apps/debugger/dwarf/DwarfFile.cpp @@ -1142,6 +1142,13 @@ DwarfFile::_ParseTypeUnit(TypeUnit* unit) } unit->SetUnitEntry(unitEntry); + DebugInfoEntry* typeEntry = unit->EntryForOffset(unit->TypeOffset()); + if (typeEntry == NULL) { + WARNING("No type found for type unit %p at specified offset %" + B_PRId64 ".\n", unit, unit->TypeOffset()); + return B_BAD_DATA; + } + unit->SetTypeEntry(typeEntry); TRACE_DIE_ONLY( TRACE_DIE("remaining bytes in unit: %" B_PRIdOFF "\n", @@ -2591,6 +2598,7 @@ DwarfFile::_ResolveReference(BaseUnit* unit, uint64 offset, } case dwarf_reference_type_signature: { + TRACE_DIE("Resolving signature %#" B_PRIx64 "\n", offset); TypeUnitTableEntry* entry = fTypeUnits.Lookup(offset); if (entry != NULL && entry->unit != NULL) return entry->unit->TypeEntry(); diff --git a/src/apps/debugger/dwarf/TypeUnit.cpp b/src/apps/debugger/dwarf/TypeUnit.cpp index 0a3af5d85a..6dd4113bd6 100644 --- a/src/apps/debugger/dwarf/TypeUnit.cpp +++ b/src/apps/debugger/dwarf/TypeUnit.cpp @@ -16,6 +16,7 @@ TypeUnit::TypeUnit(off_t headerOffset, off_t contentOffset, BaseUnit(headerOffset, contentOffset, totalSize, abbreviationOffset, addressSize, isDwarf64), fUnitEntry(NULL), + fTypeEntry(NULL), fSignature(signature), fTypeOffset(typeOffset) { @@ -37,10 +38,14 @@ TypeUnit::SetUnitEntry(DIETypeUnit* entry) DebugInfoEntry* TypeUnit::TypeEntry() const { - if (fUnitEntry != NULL) - return fUnitEntry->GetType(); + return fTypeEntry; +} - return NULL; + +void +TypeUnit::SetTypeEntry(DebugInfoEntry* entry) +{ + fTypeEntry = entry; } diff --git a/src/apps/debugger/dwarf/TypeUnit.h b/src/apps/debugger/dwarf/TypeUnit.h index 74664e6491..ee3d594f2b 100644 --- a/src/apps/debugger/dwarf/TypeUnit.h +++ b/src/apps/debugger/dwarf/TypeUnit.h @@ -36,11 +36,13 @@ public: void SetUnitEntry(DIETypeUnit* entry); DebugInfoEntry* TypeEntry() const; + void SetTypeEntry(DebugInfoEntry* entry); virtual dwarf_unit_kind Kind() const; private: DIETypeUnit* fUnitEntry; + DebugInfoEntry* fTypeEntry; uint64 fSignature; off_t fTypeOffset; };