diff options
Diffstat (limited to 'source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp')
-rw-r--r-- | source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp | 230 |
1 files changed, 75 insertions, 155 deletions
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp index 393434800c01..a1b00d1892e9 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -103,57 +103,6 @@ DWARFDebugInfo::GetCompileUnitAranges () return *m_cu_aranges_ap.get(); } - -//---------------------------------------------------------------------- -// LookupAddress -//---------------------------------------------------------------------- -bool -DWARFDebugInfo::LookupAddress -( - const dw_addr_t address, - const dw_offset_t hint_die_offset, - DWARFCompileUnitSP& cu_sp, - DWARFDebugInfoEntry** function_die, - DWARFDebugInfoEntry** block_die -) -{ - - if (hint_die_offset != DW_INVALID_OFFSET) - cu_sp = GetCompileUnit(hint_die_offset); - else - { - DWARFDebugAranges &cu_aranges = GetCompileUnitAranges (); - const dw_offset_t cu_offset = cu_aranges.FindAddress (address); - cu_sp = GetCompileUnit(cu_offset); - } - - if (cu_sp.get()) - { - if (cu_sp->LookupAddress(address, function_die, block_die)) - return true; - cu_sp.reset(); - } - else - { - // The hint_die_offset may have been a pointer to the actual item that - // we are looking for - DWARFDebugInfoEntry* die_ptr = GetDIEPtr(hint_die_offset, &cu_sp); - if (die_ptr) - { - if (cu_sp.get()) - { - if (function_die || block_die) - return die_ptr->LookupAddress(address, m_dwarf2Data, cu_sp.get(), function_die, block_die); - - // We only wanted the compile unit that contained this address - return true; - } - } - } - return false; -} - - void DWARFDebugInfo::ParseCompileUnitHeadersIfNeeded() { @@ -213,19 +162,13 @@ DWARFDebugInfo::ContainsCompileUnit (const DWARFCompileUnit *cu) const return false; } -static int -CompareDWARFCompileUnitSPOffset (const void *key, const void *arrmem) +bool +DWARFDebugInfo::OffsetLessThanCompileUnitOffset (dw_offset_t offset, const DWARFCompileUnitSP& cu_sp) { - const dw_offset_t key_cu_offset = *(dw_offset_t*) key; - const dw_offset_t cu_offset = ((DWARFCompileUnitSP *)arrmem)->get()->GetOffset(); - if (key_cu_offset < cu_offset) - return -1; - if (key_cu_offset > cu_offset) - return 1; - return 0; + return offset < cu_sp->GetOffset(); } -DWARFCompileUnitSP +DWARFCompileUnit * DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr) { DWARFCompileUnitSP cu_sp; @@ -234,41 +177,80 @@ DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr) { ParseCompileUnitHeadersIfNeeded(); - DWARFCompileUnitSP* match = (DWARFCompileUnitSP*)bsearch(&cu_offset, &m_compile_units[0], m_compile_units.size(), sizeof(DWARFCompileUnitSP), CompareDWARFCompileUnitSPOffset); - if (match) + // Watch out for single compile unit executable as they are pretty common + const size_t num_cus = m_compile_units.size(); + if (num_cus == 1) { - cu_sp = *match; - cu_idx = match - &m_compile_units[0]; + if (m_compile_units[0]->GetOffset() == cu_offset) + { + cu_sp = m_compile_units[0]; + cu_idx = 0; + } + } + else if (num_cus) + { + CompileUnitColl::const_iterator end_pos = m_compile_units.end(); + CompileUnitColl::const_iterator begin_pos = m_compile_units.begin(); + CompileUnitColl::const_iterator pos = std::upper_bound(begin_pos, end_pos, cu_offset, OffsetLessThanCompileUnitOffset); + if (pos != begin_pos) + { + --pos; + if ((*pos)->GetOffset() == cu_offset) + { + cu_sp = *pos; + cu_idx = std::distance(begin_pos, pos); + } + } } } if (idx_ptr) *idx_ptr = cu_idx; - return cu_sp; + return cu_sp.get(); } -DWARFCompileUnitSP -DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) +DWARFCompileUnit * +DWARFDebugInfo::GetCompileUnitContainingDIE (const DIERef& die_ref) { + dw_offset_t search_offset = die_ref.die_offset; + bool is_cu_offset = false; + if (m_dwarf2Data->GetID() == 0 && die_ref.cu_offset != DW_INVALID_OFFSET) + { + is_cu_offset = true; + search_offset = die_ref.cu_offset; + } + DWARFCompileUnitSP cu_sp; - if (die_offset != DW_INVALID_OFFSET) + if (search_offset != DW_INVALID_OFFSET) { ParseCompileUnitHeadersIfNeeded(); - CompileUnitColl::const_iterator end_pos = m_compile_units.end(); - CompileUnitColl::const_iterator pos; - - for (pos = m_compile_units.begin(); pos != end_pos; ++pos) + // Watch out for single compile unit executable as they are pretty common + const size_t num_cus = m_compile_units.size(); + if (num_cus == 1) { - dw_offset_t cu_start_offset = (*pos)->GetOffset(); - dw_offset_t cu_end_offset = (*pos)->GetNextCompileUnitOffset(); - if (cu_start_offset <= die_offset && die_offset < cu_end_offset) + if ((is_cu_offset && m_compile_units[0]->GetOffset() == search_offset) || + (!is_cu_offset && m_compile_units[0]->ContainsDIEOffset(search_offset))) { - cu_sp = *pos; - break; + cu_sp = m_compile_units[0]; + } + } + else if (num_cus) + { + CompileUnitColl::const_iterator end_pos = m_compile_units.end(); + CompileUnitColl::const_iterator begin_pos = m_compile_units.begin(); + CompileUnitColl::const_iterator pos = std::upper_bound(begin_pos, end_pos, search_offset, OffsetLessThanCompileUnitOffset); + if (pos != begin_pos) + { + --pos; + if ((is_cu_offset && (*pos)->GetOffset() == search_offset) || + (!is_cu_offset && (*pos)->ContainsDIEOffset(search_offset))) + { + cu_sp = *pos; + } } } } - return cu_sp; + return cu_sp.get(); } //---------------------------------------------------------------------- @@ -276,73 +258,15 @@ DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) // // Get the DIE (Debug Information Entry) with the specified offset. //---------------------------------------------------------------------- -DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtr(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr) -{ - DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset)); - if (cu_sp_ptr) - *cu_sp_ptr = cu_sp; - if (cu_sp.get()) - return cu_sp->GetDIEPtr(die_offset); - return NULL; // Not found in any compile units -} - -DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtrWithCompileUnitHint (dw_offset_t die_offset, DWARFCompileUnit**cu_handle) -{ - assert (cu_handle); - DWARFDebugInfoEntry* die = NULL; - if (*cu_handle) - die = (*cu_handle)->GetDIEPtr(die_offset); - - if (die == NULL) - { - DWARFCompileUnitSP cu_sp (GetCompileUnitContainingDIE(die_offset)); - if (cu_sp.get()) - { - *cu_handle = cu_sp.get(); - die = cu_sp->GetDIEPtr(die_offset); - } - } - if (die == NULL) - *cu_handle = NULL; - return die; -} - - -const DWARFDebugInfoEntry* -DWARFDebugInfo::GetDIEPtrContainingOffset(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr) -{ - DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset)); - if (cu_sp_ptr) - *cu_sp_ptr = cu_sp; - if (cu_sp.get()) - return cu_sp->GetDIEPtrContainingOffset(die_offset); - - return NULL; // Not found in any compile units - -} - -//---------------------------------------------------------------------- -// AddCompileUnit -//---------------------------------------------------------------------- -void -DWARFDebugInfo::AddCompileUnit(DWARFCompileUnitSP& cu) +DWARFDIE +DWARFDebugInfo::GetDIE(const DIERef& die_ref) { - m_compile_units.push_back(cu); + DWARFCompileUnit *cu = GetCompileUnitContainingDIE(die_ref); + if (cu) + return cu->GetDIE (die_ref.die_offset); + return DWARFDIE(); // Not found } -/* -void -DWARFDebugInfo::AddDIE(DWARFDebugInfoEntry& die) -{ - m_die_array.push_back(die); -} -*/ - - - - //---------------------------------------------------------------------- // Parse // @@ -372,7 +296,7 @@ DWARFDebugInfo::Parse(SymbolFileDWARF* dwarf2Data, Callback callback, void* user depth = 0; // Call the callback function with no DIE pointer for the compile unit // and get the offset that we are to continue to parse from - offset = callback(dwarf2Data, cu, NULL, offset, depth, userData); + offset = callback(dwarf2Data, cu.get(), NULL, offset, depth, userData); // Make sure we are within our compile unit if (offset < next_cu_offset) @@ -383,7 +307,7 @@ DWARFDebugInfo::Parse(SymbolFileDWARF* dwarf2Data, Callback callback, void* user while (!done && die.Extract(dwarf2Data, cu.get(), &offset)) { // Call the callback function with DIE pointer that falls within the compile unit - offset = callback(dwarf2Data, cu, &die, offset, depth, userData); + offset = callback(dwarf2Data, cu.get(), &die, offset, depth, userData); if (die.IsNULL()) { @@ -450,7 +374,7 @@ typedef struct DumpInfo static dw_offset_t DumpCallback ( SymbolFileDWARF* dwarf2Data, - DWARFCompileUnitSP& cu_sp, + DWARFCompileUnit* cu, DWARFDebugInfoEntry* die, const dw_offset_t next_offset, const uint32_t curr_depth, @@ -458,9 +382,6 @@ static dw_offset_t DumpCallback ) { DumpInfo* dumpInfo = (DumpInfo*)userData; - - const DWARFCompileUnit* cu = cu_sp.get(); - Stream *s = dumpInfo->strm; bool show_parents = s->GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowAncestors); @@ -676,12 +597,12 @@ DWARFDebugInfo::Dump (Stream *s, const uint32_t die_offset, const uint32_t recur ParseCompileUnitHeadersIfNeeded(); for (pos = m_compile_units.begin(); pos != m_compile_units.end(); ++pos) { - const DWARFCompileUnitSP& cu_sp = *pos; - DumpCallback(m_dwarf2Data, (DWARFCompileUnitSP&)cu_sp, NULL, 0, curr_depth, &dumpInfo); + DWARFCompileUnit *cu = pos->get(); + DumpCallback(m_dwarf2Data, cu, NULL, 0, curr_depth, &dumpInfo); - const DWARFDebugInfoEntry* die = cu_sp->DIE(); + const DWARFDIE die = cu->DIE(); if (die) - die->Dump(m_dwarf2Data, cu_sp.get(), *s, recurse_depth); + die.Dump(s, recurse_depth); } } @@ -707,7 +628,7 @@ typedef struct FindCallbackStringInfoTag static dw_offset_t FindCallbackString ( SymbolFileDWARF* dwarf2Data, - DWARFCompileUnitSP& cu_sp, + DWARFCompileUnit* cu, DWARFDebugInfoEntry* die, const dw_offset_t next_offset, const uint32_t curr_depth, @@ -715,7 +636,6 @@ static dw_offset_t FindCallbackString ) { FindCallbackStringInfo* info = (FindCallbackStringInfo*)userData; - const DWARFCompileUnit* cu = cu_sp.get(); if (die) { |