From e042b11803aab7d13af27100800afe60966582e4 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 17 Jul 2013 18:14:09 -0400 Subject: [PATCH] Debugger: implement support for section-global references. - Add DwarfFile::_GetContainingCompilationUnit() to request a binary search for the compilation unit containing the passed in global offset. - DwarfFile::_ResolveReference(): handle global references by first attempting to find a containing compilation unit, and then seeing if we can find an entry for the corresponding relative offset within it. --- src/apps/debugger/dwarf/DwarfFile.cpp | 30 ++++++++++++++++++++++++++- src/apps/debugger/dwarf/DwarfFile.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/apps/debugger/dwarf/DwarfFile.cpp b/src/apps/debugger/dwarf/DwarfFile.cpp index b771c6b07c..d0d889d4cc 100644 --- a/src/apps/debugger/dwarf/DwarfFile.cpp +++ b/src/apps/debugger/dwarf/DwarfFile.cpp @@ -2576,7 +2576,14 @@ DwarfFile::_ResolveReference(BaseUnit* unit, uint64 offset, break; case dwarf_reference_type_global: { - WARNING("DwarfFile: Unhandled global reference\n"); + CompilationUnit* unit = _GetContainingCompilationUnit(offset); + if (unit == NULL) + break; + + offset -= unit->HeaderOffset(); + DebugInfoEntry* entry = unit->EntryForOffset(offset); + if (entry != NULL) + return entry; break; } case dwarf_reference_type_signature: @@ -2782,3 +2789,24 @@ DwarfFile::_GetTypeUnit(uint64 signature) const return fTypeUnits.Lookup(signature); } + +CompilationUnit* +DwarfFile::_GetContainingCompilationUnit(off_t refAddr) const +{ + if (fCompilationUnits.IsEmpty()) + return NULL; + + // binary search + int lower = 0; + int upper = fCompilationUnits.CountItems() - 1; + while (lower < upper) { + int mid = (lower + upper + 1) / 2; + if (fCompilationUnits.ItemAt(mid)->HeaderOffset() > refAddr) + upper = mid - 1; + else + lower = mid; + } + + CompilationUnit* unit = fCompilationUnits.ItemAt(lower); + return unit->ContainsAbsoluteOffset(refAddr) ? unit : NULL; +} diff --git a/src/apps/debugger/dwarf/DwarfFile.h b/src/apps/debugger/dwarf/DwarfFile.h index cf0d650474..17dee900c8 100644 --- a/src/apps/debugger/dwarf/DwarfFile.h +++ b/src/apps/debugger/dwarf/DwarfFile.h @@ -177,6 +177,8 @@ private: BString& _infoPath) const; TypeUnitTableEntry* _GetTypeUnit(uint64 signature) const; + CompilationUnit* _GetContainingCompilationUnit( + off_t refAddr) const; private: friend class DwarfFile::ExpressionEvaluationContext;