Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -44,7 +44,6 @@ DWARFDebugInfoEntry** function_die, DWARFDebugInfoEntry** block_die); - void AddCompileUnit(DWARFCompileUnitSP& cu); size_t GetNumCompileUnits(); bool ContainsCompileUnit (const DWARFCompileUnit *cu) const; DWARFCompileUnit* GetCompileUnitAtIndex(uint32_t idx); @@ -77,6 +76,7 @@ SymbolFileDWARF* m_dwarf2Data; typedef std::vector CompileUnitColl; CompileUnitColl m_compile_units; + std::map m_die_to_index_map; std::unique_ptr m_cu_aranges_ap; // A quick address to compile unit table private: Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -34,7 +34,8 @@ DWARFDebugInfo::DWARFDebugInfo() : m_dwarf2Data(NULL), m_compile_units(), - m_cu_aranges_ap () + m_die_to_index_map(), + m_cu_aranges_ap() { } @@ -46,6 +47,7 @@ { m_dwarf2Data = dwarf2Data; m_compile_units.clear(); + m_die_to_index_map.clear(); } @@ -174,6 +176,7 @@ break; m_compile_units.push_back(cu_sp); + m_die_to_index_map[cu_sp->GetOffset()] = m_compile_units.size() - 1; offset = cu_sp->GetNextCompileUnitOffset(); } @@ -249,26 +252,21 @@ DWARFCompileUnitSP DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset) { - DWARFCompileUnitSP cu_sp; if (die_offset != DW_INVALID_OFFSET) { ParseCompileUnitHeadersIfNeeded(); - CompileUnitColl::const_iterator end_pos = m_compile_units.end(); - CompileUnitColl::const_iterator pos; + auto pos = m_die_to_index_map.upper_bound(die_offset); + if (pos == m_die_to_index_map.begin()) + return DWARFCompileUnitSP(); + --pos; - for (pos = m_compile_units.begin(); pos != end_pos; ++pos) - { - 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) - { - cu_sp = *pos; - break; - } - } + DWARFCompileUnitSP& cu_sp = m_compile_units[pos->second]; + assert(cu_sp->GetOffset() <= die_offset && "m_die_to_index_map contains invalid data"); + if (die_offset < cu_sp->GetNextCompileUnitOffset()) + return cu_sp; } - return cu_sp; + return DWARFCompileUnitSP(); } //---------------------------------------------------------------------- @@ -320,30 +318,9 @@ return cu_sp->GetDIEPtrContainingOffset(die_offset); return NULL; // Not found in any compile units - } //---------------------------------------------------------------------- -// AddCompileUnit -//---------------------------------------------------------------------- -void -DWARFDebugInfo::AddCompileUnit(DWARFCompileUnitSP& cu) -{ - m_compile_units.push_back(cu); -} - -/* -void -DWARFDebugInfo::AddDIE(DWARFDebugInfoEntry& die) -{ - m_die_array.push_back(die); -} -*/ - - - - -//---------------------------------------------------------------------- // Parse // // Parses the .debug_info section and uses the .debug_abbrev section