From 7c3612f47db2deda55fca88459998e562ff97de4 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 27 Jun 2009 23:38:17 +0000 Subject: [PATCH] * Manage CompilationUnits in a BObjectList instead of a DoublyLinkedList for nicer access. * A CompilationUnit does now know its debug info entry. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31282 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/dwarf/CompilationUnit.cpp | 10 ++++++- src/apps/debugger/dwarf/CompilationUnit.h | 8 +++-- src/apps/debugger/dwarf/DwarfFile.cpp | 33 +++++++++++++++------ src/apps/debugger/dwarf/DwarfFile.h | 6 +++- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/apps/debugger/dwarf/CompilationUnit.cpp b/src/apps/debugger/dwarf/CompilationUnit.cpp index cc432665cd..a7e1ef60ae 100644 --- a/src/apps/debugger/dwarf/CompilationUnit.cpp +++ b/src/apps/debugger/dwarf/CompilationUnit.cpp @@ -14,7 +14,8 @@ CompilationUnit::CompilationUnit(dwarf_off_t headerOffset, fContentOffset(contentOffset), fTotalSize(totalSize), fAbbreviationOffset(abbreviationOffset), - fAbbreviationTable(NULL) + fAbbreviationTable(NULL), + fUnitEntry(NULL) { } @@ -45,6 +46,13 @@ CompilationUnit::AddDebugInfoEntry(DebugInfoEntry* entry, dwarf_off_t offset) } +void +CompilationUnit::SetUnitEntry(DIECompileUnitBase* entry) +{ + fUnitEntry = entry; +} + + int CompilationUnit::CountEntries() const { diff --git a/src/apps/debugger/dwarf/CompilationUnit.h b/src/apps/debugger/dwarf/CompilationUnit.h index 0d9c568927..d206507094 100644 --- a/src/apps/debugger/dwarf/CompilationUnit.h +++ b/src/apps/debugger/dwarf/CompilationUnit.h @@ -5,7 +5,7 @@ #ifndef COMPILATION_UNIT_H #define COMPILATION_UNIT_H -#include +#include #include "Array.h" #include "DwarfTypes.h" @@ -13,9 +13,10 @@ class AbbreviationTable; class DebugInfoEntry; +class DIECompileUnitBase; -class CompilationUnit : public DoublyLinkedListLinkImpl { +class CompilationUnit { public: CompilationUnit(dwarf_off_t headerOffset, dwarf_off_t contentOffset, @@ -39,6 +40,8 @@ public: void SetAbbreviationTable( AbbreviationTable* abbreviationTable); + DIECompileUnitBase* UnitEntry() const { return fUnitEntry; } + void SetUnitEntry(DIECompileUnitBase* entry); status_t AddDebugInfoEntry(DebugInfoEntry* entry, dwarf_off_t offset); @@ -53,6 +56,7 @@ private: dwarf_off_t fTotalSize; dwarf_off_t fAbbreviationOffset; AbbreviationTable* fAbbreviationTable; + DIECompileUnitBase* fUnitEntry; Array fEntries; Array fEntryOffsets; }; diff --git a/src/apps/debugger/dwarf/DwarfFile.cpp b/src/apps/debugger/dwarf/DwarfFile.cpp index da7229b496..09c72652ce 100644 --- a/src/apps/debugger/dwarf/DwarfFile.cpp +++ b/src/apps/debugger/dwarf/DwarfFile.cpp @@ -25,6 +25,7 @@ DwarfFile::DwarfFile() fDebugInfoSection(NULL), fDebugAbbrevSection(NULL), fDebugStringSection(NULL), + fCompilationUnits(20, true), fCurrentCompilationUnit(NULL), fFinished(false), fFinishError(B_OK) @@ -34,9 +35,6 @@ DwarfFile::DwarfFile() DwarfFile::~DwarfFile() { - while (CompilationUnit* unit = fCompilationUnits.RemoveHead()) - delete unit; - while (AbbreviationTable* table = fAbbreviationTables.RemoveHead()) delete table; @@ -133,10 +131,10 @@ DwarfFile::Load(const char* fileName) unitHeaderOffset, unitContentOffset, unitLength + (unitLengthOffset - unitHeaderOffset), abbrevOffset); - if (unit == NULL) + if (unit == NULL || !fCompilationUnits.AddItem(unit)) { + delete unit; return B_NO_MEMORY; - - fCompilationUnits.Add(unit); + } // parse the debug info for the unit fCurrentCompilationUnit = unit; @@ -159,8 +157,8 @@ DwarfFile::FinishLoading() if (fFinishError != B_OK) return fFinishError; - for (CompilationUnitList::Iterator it = fCompilationUnits.GetIterator(); - CompilationUnit* unit = it.Next();) { + for (int32 i = 0; CompilationUnit* unit = fCompilationUnits.ItemAt(i); + i++) { fCurrentCompilationUnit = unit; status_t error = _FinishCompilationUnit(unit); if (error != B_OK) @@ -172,6 +170,20 @@ DwarfFile::FinishLoading() } +int32 +DwarfFile::CountCompilationUnits() const +{ + return fCompilationUnits.CountItems(); +} + + +CompilationUnit* +DwarfFile::CompilationUnitAt(int32 index) const +{ + return fCompilationUnits.ItemAt(index); +} + + status_t DwarfFile::_ParseCompilationUnit(CompilationUnit* unit) { @@ -194,12 +206,15 @@ DwarfFile::_ParseCompilationUnit(CompilationUnit* unit) if (error != B_OK) return error; - if (dynamic_cast(entry) == NULL) { + DIECompileUnitBase* unitEntry = dynamic_cast(entry); + if (unitEntry == NULL) { fprintf(stderr, "No compilation unit entry in .debug_info " "section.\n"); return B_BAD_DATA; } + unit->SetUnitEntry(unitEntry); + printf("remaining bytes in unit: %lld\n", dataReader.BytesRemaining()); if (dataReader.HasData()) { printf(" "); diff --git a/src/apps/debugger/dwarf/DwarfFile.h b/src/apps/debugger/dwarf/DwarfFile.h index 161bce3eec..c8030954c7 100644 --- a/src/apps/debugger/dwarf/DwarfFile.h +++ b/src/apps/debugger/dwarf/DwarfFile.h @@ -5,6 +5,7 @@ #ifndef DWARF_FILE_H #define DWARF_FILE_H +#include #include #include "DebugInfoEntries.h" @@ -28,9 +29,12 @@ public: const char* Name() const { return fName; } + int32 CountCompilationUnits() const; + CompilationUnit* CompilationUnitAt(int32 index) const; + private: typedef DoublyLinkedList AbbreviationTableList; - typedef DoublyLinkedList CompilationUnitList; + typedef BObjectList CompilationUnitList; private: status_t _ParseCompilationUnit(CompilationUnit* unit);