Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -20,7 +20,7 @@ typedef std::shared_ptr DWARFCompileUnitSP; -class DWARFCompileUnit { +class DWARFCompileUnitDecls { public: enum Producer { eProducerInvalid = 0, @@ -29,7 +29,53 @@ eProducerLLVMGCC, eProcucerOther }; +}; + +class DWARFCompileUnitData : public DWARFCompileUnitDecls { +public: + DWARFCompileUnitData(SymbolFileDWARF *dwarf2Data); + + static uint8_t GetDefaultAddressSize(); + + static void SetDefaultAddressSize(uint8_t addr_size); + + SymbolFileDWARF *m_dwarf2Data; + std::unique_ptr m_dwo_symbol_file; + const DWARFAbbreviationDeclarationSet *m_abbrevs; + void *m_user_data = nullptr; + DWARFDebugInfoEntry::collection + m_die_array; // The compile unit debug information entry item + std::unique_ptr m_func_aranges_ap; // A table similar to + // the .debug_aranges + // table, but this one + // points to the exact + // DW_TAG_subprogram + // DIEs + dw_addr_t m_base_addr = 0; + dw_offset_t m_length; + uint16_t m_version; + uint8_t m_addr_size; + Producer m_producer = eProducerInvalid; + uint32_t m_producer_version_major = 0; + uint32_t m_producer_version_minor = 0; + uint32_t m_producer_version_update = 0; + lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown; + bool m_is_dwarf64; + lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate; + dw_addr_t m_addr_base = 0; // Value of DW_AT_addr_base + dw_addr_t m_ranges_base = 0; // Value of DW_AT_ranges_base + // If this is a dwo compile unit this is the offset of the base compile unit + // in the main object file + dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET; + +private: + static uint8_t g_default_addr_size; + + DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnitData); +}; +class DWARFCompileUnit : public DWARFCompileUnitDecls { +public: static DWARFCompileUnitSP Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr); ~DWARFCompileUnit(); @@ -45,31 +91,32 @@ dw_offset_t GetOffset() const { return m_offset; } lldb::user_id_t GetID() const; // Size in bytes of the initial length + compile unit header. - uint32_t Size() const { return m_is_dwarf64 ? 23 : 11; } + uint32_t Size() const { return m_data->m_is_dwarf64 ? 23 : 11; } bool ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); } dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); } dw_offset_t GetNextCompileUnitOffset() const { - return m_offset + (m_is_dwarf64 ? 12 : 4) + m_length; + return m_offset + (m_data->m_is_dwarf64 ? 12 : 4) + m_data->m_length; } // Size of the CU data (without initial length and without header). size_t GetDebugInfoSize() const { - return (m_is_dwarf64 ? 12 : 4) + m_length - Size(); + return (m_data->m_is_dwarf64 ? 12 : 4) + m_data->m_length - Size(); } // Size of the CU data incl. header but without initial length. - uint32_t GetLength() const { return m_length; } - uint16_t GetVersion() const { return m_version; } + uint32_t GetLength() const { return m_data->m_length; } + uint16_t GetVersion() const { return m_data->m_version; } const DWARFAbbreviationDeclarationSet *GetAbbreviations() const { - return m_abbrevs; + return m_data->m_abbrevs; } dw_offset_t GetAbbrevOffset() const; - uint8_t GetAddressByteSize() const { return m_addr_size; } - dw_addr_t GetBaseAddress() const { return m_base_addr; } - dw_addr_t GetAddrBase() const { return m_addr_base; } - dw_addr_t GetRangesBase() const { return m_ranges_base; } - void SetAddrBase(dw_addr_t addr_base, dw_addr_t ranges_base, dw_offset_t base_obj_offset); + uint8_t GetAddressByteSize() const { return m_data->m_addr_size; } + dw_addr_t GetBaseAddress() const { return m_data->m_base_addr; } + dw_addr_t GetAddrBase() const { return m_data->m_addr_base; } + dw_addr_t GetRangesBase() const { return m_data->m_ranges_base; } + void SetAddrBase( + dw_addr_t addr_base, dw_addr_t ranges_base, dw_offset_t base_obj_offset); void ClearDIEs(bool keep_compile_unit_die); void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges); @@ -80,7 +127,7 @@ DWARFFormValue::FixedFormSizes GetFixedFormSizes(); - void SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; } + void SetBaseAddress(dw_addr_t base_addr) { m_data->m_base_addr = base_addr; } DWARFDIE GetCompileUnitDIEOnly() { return DWARFDIE(this, GetCompileUnitDIEPtrOnly()); } @@ -98,14 +145,14 @@ // the first entry, so if our size is 1, then we are adding // the first compile unit child DIE and should reserve // the memory. - if (m_die_array.empty()) - m_die_array.reserve(GetDebugInfoSize() / 24); - m_die_array.push_back(die); + if (m_data->m_die_array.empty()) + m_data->m_die_array.reserve(GetDebugInfoSize() / 24); + m_data->m_die_array.push_back(die); } void AddCompileUnitDIE(DWARFDebugInfoEntry &die); - bool HasDIEsParsed() const { return m_die_array.size() > 1; } + bool HasDIEsParsed() const { return m_data->m_die_array.size() > 1; } DWARFDIE GetDIE(dw_offset_t die_offset); @@ -114,11 +161,7 @@ static bool IsDWARF64(const DWARFCompileUnit *cu); - static uint8_t GetDefaultAddressSize(); - - static void SetDefaultAddressSize(uint8_t addr_size); - - void *GetUserData() const { return m_user_data; } + void *GetUserData() const { return m_data->m_user_data; } void SetUserData(void *d); @@ -135,7 +178,7 @@ const DWARFDebugAranges &GetFunctionAranges(); - SymbolFileDWARF *GetSymbolFileDWARF() const { return m_dwarf2Data; } + SymbolFileDWARF *GetSymbolFileDWARF() const { return m_data->m_dwarf2Data; } Producer GetProducer(); @@ -154,43 +197,12 @@ bool GetIsOptimized(); SymbolFileDWARFDwo *GetDwoSymbolFile() const { - return m_dwo_symbol_file.get(); + return m_data->m_dwo_symbol_file.get(); } - dw_offset_t GetBaseObjOffset() const { return m_base_obj_offset; } + dw_offset_t GetBaseObjOffset() const { return m_data->m_base_obj_offset; } protected: - SymbolFileDWARF *m_dwarf2Data; - std::unique_ptr m_dwo_symbol_file; - const DWARFAbbreviationDeclarationSet *m_abbrevs; - void *m_user_data = nullptr; - DWARFDebugInfoEntry::collection - m_die_array; // The compile unit debug information entry item - std::unique_ptr m_func_aranges_ap; // A table similar to - // the .debug_aranges - // table, but this one - // points to the exact - // DW_TAG_subprogram - // DIEs - dw_addr_t m_base_addr = 0; - // Offset of the initial length field. - dw_offset_t m_offset; - dw_offset_t m_length; - uint16_t m_version; - uint8_t m_addr_size; - Producer m_producer = eProducerInvalid; - uint32_t m_producer_version_major = 0; - uint32_t m_producer_version_minor = 0; - uint32_t m_producer_version_update = 0; - lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown; - bool m_is_dwarf64; - lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate; - dw_addr_t m_addr_base = 0; // Value of DW_AT_addr_base - dw_addr_t m_ranges_base = 0; // Value of DW_AT_ranges_base - // If this is a dwo compile unit this is the offset of the base compile unit - // in the main object file - dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET; - void ParseProducerInfo(); static void @@ -201,21 +213,26 @@ NameToDIE &func_selectors, NameToDIE &objc_class_selectors, NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces); + DWARFCompileUnitData *m_data; + + // Offset of the initial length field. + dw_offset_t m_offset; + private: DWARFCompileUnit(SymbolFileDWARF *dwarf2Data); const DWARFDebugInfoEntry *GetCompileUnitDIEPtrOnly() { ExtractDIEsIfNeeded(true); - if (m_die_array.empty()) + if (m_data->m_die_array.empty()) return NULL; - return &m_die_array[0]; + return &m_data->m_die_array[0]; } const DWARFDebugInfoEntry *DIEPtr() { ExtractDIEsIfNeeded(false); - if (m_die_array.empty()) + if (m_data->m_die_array.empty()) return NULL; - return &m_die_array[0]; + return &m_data->m_die_array[0]; } DISALLOW_COPY_AND_ASSIGN(DWARFCompileUnit); Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -38,9 +38,12 @@ extern int g_verbose; -DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data) +DWARFCompileUnitData::DWARFCompileUnitData(SymbolFileDWARF *dwarf2Data) : m_dwarf2Data(dwarf2Data) {} +DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data) + : m_data(dwarf2Data->NewCompileUnitData()) {} + DWARFCompileUnit::~DWARFCompileUnit() {} DWARFCompileUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data, @@ -49,6 +52,7 @@ // Out of memory? if (cu_sp.get() == NULL) return nullptr; + DWARFCompileUnitData *m_data = cu_sp->m_data; const DWARFDataExtractor &debug_info = dwarf2Data->get_debug_info_data(); @@ -57,22 +61,23 @@ if (debug_info.ValidOffset(*offset_ptr)) { dw_offset_t abbr_offset; const DWARFDebugAbbrev *abbr = dwarf2Data->DebugAbbrev(); - cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr); - cu_sp->m_is_dwarf64 = debug_info.IsDWARF64(); - cu_sp->m_version = debug_info.GetU16(offset_ptr); + m_data->m_length = debug_info.GetDWARFInitialLength(offset_ptr); + m_data->m_is_dwarf64 = debug_info.IsDWARF64(); + m_data->m_version = debug_info.GetU16(offset_ptr); abbr_offset = debug_info.GetDWARFOffset(offset_ptr); - cu_sp->m_addr_size = debug_info.GetU8(offset_ptr); + m_data->m_addr_size = debug_info.GetU8(offset_ptr); bool length_OK = debug_info.ValidOffset(cu_sp->GetNextCompileUnitOffset() - 1); - bool version_OK = SymbolFileDWARF::SupportedVersion(cu_sp->m_version); + bool version_OK = SymbolFileDWARF::SupportedVersion(m_data->m_version); bool abbr_offset_OK = dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset); - bool addr_size_OK = (cu_sp->m_addr_size == 4) || (cu_sp->m_addr_size == 8); + bool addr_size_OK = + (m_data->m_addr_size == 4) || (m_data->m_addr_size == 8); if (length_OK && version_OK && addr_size_OK && abbr_offset_OK && abbr != NULL) { - cu_sp->m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset); + m_data->m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset); return cu_sp; } @@ -84,7 +89,7 @@ } void DWARFCompileUnit::ClearDIEs(bool keep_compile_unit_die) { - if (m_die_array.size() > 1) { + if (m_data->m_die_array.size() > 1) { // std::vectors never get any smaller when resized to a smaller size, // or when clear() or erase() are called, the size will report that it // is smaller, but the memory allocated remains intact (call capacity() @@ -95,13 +100,14 @@ // Save at least the compile unit DIE DWARFDebugInfoEntry::collection tmp_array; - m_die_array.swap(tmp_array); + m_data->m_die_array.swap(tmp_array); if (keep_compile_unit_die) - m_die_array.push_back(tmp_array.front()); + m_data->m_die_array.push_back(tmp_array.front()); } - if (m_dwo_symbol_file) - m_dwo_symbol_file->GetCompileUnit()->ClearDIEs(keep_compile_unit_die); + if (m_data->m_dwo_symbol_file) + m_data->m_dwo_symbol_file->GetCompileUnit() + ->ClearDIEs(keep_compile_unit_die); } //---------------------------------------------------------------------- @@ -111,7 +117,7 @@ // done. //---------------------------------------------------------------------- size_t DWARFCompileUnit::ExtractDIEsIfNeeded(bool cu_die_only) { - const size_t initial_die_array_size = m_die_array.size(); + const size_t initial_die_array_size = m_data->m_die_array.size(); if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1) return 0; // Already parsed @@ -132,10 +138,11 @@ Log *log( LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS)); if (log) { - m_dwarf2Data->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( - log, "DWARFCompileUnit::ExtractDIEsIfNeeded () for compile unit at " - ".debug_info[0x%8.8x]", - GetOffset()); + m_data->m_dwarf2Data->GetObjectFile()->GetModule() + ->LogMessageVerboseBacktrace( + log, "DWARFCompileUnit::ExtractDIEsIfNeeded () " + "for compile unit at .debug_info[0x%8.8x]", + GetOffset()); } } @@ -143,14 +150,14 @@ // We are in our compile unit, parse starting at the offset // we were told to parse const DWARFDataExtractor &debug_info_data = - m_dwarf2Data->get_debug_info_data(); + m_data->m_dwarf2Data->get_debug_info_data(); std::vector die_index_stack; die_index_stack.reserve(32); die_index_stack.push_back(0); bool prev_die_had_children = false; DWARFFormValue::FixedFormSizes fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(), - m_is_dwarf64); + m_data->m_is_dwarf64); while (offset < next_cu_offset && die.FastExtract(debug_info_data, this, fixed_form_sizes, &offset)) { // if (log) @@ -165,9 +172,9 @@ if (initial_die_array_size == 0) AddCompileUnitDIE(die); uint64_t base_addr = die.GetAttributeValueAsAddress( - m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS); + m_data->m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS); if (base_addr == LLDB_INVALID_ADDRESS) - base_addr = die.GetAttributeValueAsAddress(m_dwarf2Data, this, + base_addr = die.GetAttributeValueAsAddress(m_data->m_dwarf2Data, this, DW_AT_entry_pc, 0); SetBaseAddress(base_addr); if (cu_die_only) @@ -180,18 +187,19 @@ // the NULL DIEs from the list (saves up to 25% in C++ code), // we need a way to let the DIE know that it actually doesn't // have children. - if (!m_die_array.empty()) - m_die_array.back().SetEmptyChildren(true); + if (!m_data->m_die_array.empty()) + m_data->m_die_array.back().SetEmptyChildren(true); } } else { - die.SetParentIndex(m_die_array.size() - die_index_stack[depth - 1]); + die.SetParentIndex( + m_data->m_die_array.size() - die_index_stack[depth - 1]); if (die_index_stack.back()) - m_die_array[die_index_stack.back()].SetSiblingIndex( - m_die_array.size() - die_index_stack.back()); + m_data->m_die_array[die_index_stack.back()].SetSiblingIndex( + m_data->m_die_array.size() - die_index_stack.back()); // Only push the DIE if it isn't a NULL DIE - m_die_array.push_back(die); + m_data->m_die_array.push_back(die); } } @@ -207,7 +215,7 @@ prev_die_had_children = false; } else { - die_index_stack.back() = m_die_array.size() - 1; + die_index_stack.back() = m_data->m_die_array.size() - 1; // Normal DIE const bool die_has_children = die.HasChildren(); if (die_has_children) { @@ -222,7 +230,7 @@ // should always terminate at or before the start of the next compilation // unit header). if (offset > next_cu_offset) { - m_dwarf2Data->GetObjectFile()->GetModule()->ReportWarning( + m_data->m_dwarf2Data->GetObjectFile()->GetModule()->ReportWarning( "DWARF compile unit extends beyond its bounds cu 0x%8.8x at " "0x%8.8" PRIx64 "\n", GetOffset(), offset); @@ -233,38 +241,38 @@ // space. So here we copy and swap to make sure we don't have any extra // memory taken up. - if (m_die_array.size() < m_die_array.capacity()) { - DWARFDebugInfoEntry::collection exact_size_die_array(m_die_array.begin(), - m_die_array.end()); - exact_size_die_array.swap(m_die_array); + if (m_data->m_die_array.size() < m_data->m_die_array.capacity()) { + DWARFDebugInfoEntry::collection exact_size_die_array( + m_data->m_die_array.begin(), m_data->m_die_array.end()); + exact_size_die_array.swap(m_data->m_die_array); } Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log && log->GetVerbose()) { StreamString strm; Dump(&strm); - if (m_die_array.empty()) + if (m_data->m_die_array.empty()) strm.Printf("error: no DIE for compile unit"); else - m_die_array[0].Dump(m_dwarf2Data, this, strm, UINT32_MAX); + m_data->m_die_array[0].Dump(m_data->m_dwarf2Data, this, strm, UINT32_MAX); log->PutString(strm.GetString()); } - if (!m_dwo_symbol_file) - return m_die_array.size(); + if (!m_data->m_dwo_symbol_file) + return m_data->m_die_array.size(); - DWARFCompileUnit *dwo_cu = m_dwo_symbol_file->GetCompileUnit(); + DWARFCompileUnit *dwo_cu = m_data->m_dwo_symbol_file->GetCompileUnit(); size_t dwo_die_count = dwo_cu->ExtractDIEsIfNeeded(cu_die_only); - return m_die_array.size() + dwo_die_count - + return m_data->m_die_array.size() + dwo_die_count - 1; // We have 2 CU die, but we want to count it only as one } void DWARFCompileUnit::AddCompileUnitDIE(DWARFDebugInfoEntry &die) { - assert(m_die_array.empty() && "Compile unit DIE already added"); + assert(m_data->m_die_array.empty() && "Compile unit DIE already added"); AddDIE(die); - const DWARFDebugInfoEntry &cu_die = m_die_array.front(); + const DWARFDebugInfoEntry &cu_die = m_data->m_die_array.front(); std::unique_ptr dwo_symbol_file = - m_dwarf2Data->GetDwoSymbolFileForCompileUnit(*this, cu_die); + m_data->m_dwarf2Data->GetDwoSymbolFileForCompileUnit(*this, cu_die); if (!dwo_symbol_file) return; @@ -277,40 +285,42 @@ return; // Can't fetch the compile unit DIE from the dwo file. uint64_t main_dwo_id = cu_die.GetAttributeValueAsUnsigned( - m_dwarf2Data, this, DW_AT_GNU_dwo_id, 0); + m_data->m_dwarf2Data, this, DW_AT_GNU_dwo_id, 0); uint64_t sub_dwo_id = dwo_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_dwo_id, 0); if (main_dwo_id != sub_dwo_id) return; // The 2 dwo ID isn't match. Don't use the dwo file as it belongs to // a differectn compilation. - m_dwo_symbol_file = std::move(dwo_symbol_file); + m_data->m_dwo_symbol_file = std::move(dwo_symbol_file); dw_addr_t addr_base = cu_die.GetAttributeValueAsUnsigned( - m_dwarf2Data, this, DW_AT_GNU_addr_base, 0); + m_data->m_dwarf2Data, this, DW_AT_GNU_addr_base, 0); dw_addr_t ranges_base = cu_die.GetAttributeValueAsUnsigned( - m_dwarf2Data, this, DW_AT_GNU_ranges_base, 0); + m_data->m_dwarf2Data, this, DW_AT_GNU_ranges_base, 0); dwo_cu->SetAddrBase(addr_base, ranges_base, m_offset); } dw_offset_t DWARFCompileUnit::GetAbbrevOffset() const { - return m_abbrevs ? m_abbrevs->GetOffset() : DW_INVALID_OFFSET; + return m_data->m_abbrevs ? m_data->m_abbrevs->GetOffset() : DW_INVALID_OFFSET; } bool DWARFCompileUnit::Verify(Stream *s) const { - const DWARFDataExtractor &debug_info = m_dwarf2Data->get_debug_info_data(); + const DWARFDataExtractor &debug_info = + m_data->m_dwarf2Data->get_debug_info_data(); bool valid_offset = debug_info.ValidOffset(m_offset); bool length_OK = debug_info.ValidOffset(GetNextCompileUnitOffset() - 1); - bool version_OK = SymbolFileDWARF::SupportedVersion(m_version); - bool abbr_offset_OK = - m_dwarf2Data->get_debug_abbrev_data().ValidOffset(GetAbbrevOffset()); - bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8)); + bool version_OK = SymbolFileDWARF::SupportedVersion(m_data->m_version); + bool abbr_offset_OK = m_data->m_dwarf2Data->get_debug_abbrev_data() + .ValidOffset(GetAbbrevOffset()); + bool addr_size_OK = + ((m_data->m_addr_size == 4) || (m_data->m_addr_size == 8)); if (valid_offset && length_OK && version_OK && addr_size_OK && abbr_offset_OK) { return true; } else { s->Printf(" 0x%8.8x: ", m_offset); - DumpDataExtractor(m_dwarf2Data->get_debug_info_data(), s, m_offset, + DumpDataExtractor(m_data->m_dwarf2Data->get_debug_info_data(), s, m_offset, lldb::eFormatHex, 1, Size(), 32, LLDB_INVALID_ADDRESS, 0, 0); s->EOL(); @@ -318,7 +328,7 @@ if (!length_OK) s->Printf(" The length (0x%8.8x) for this compile unit is too " "large for the .debug_info provided.\n", - m_length); + m_data->m_length); if (!version_OK) s->Printf(" The 16 bit compile unit header version is not " "supported.\n"); @@ -328,7 +338,7 @@ GetAbbrevOffset()); if (!addr_size_OK) s->Printf(" The address size is unsupported: 0x%2.2x\n", - m_addr_size); + m_data->m_addr_size); } else s->Printf(" The start offset of the compile unit header in the " ".debug_info is invalid.\n"); @@ -340,16 +350,16 @@ s->Printf("0x%8.8x: Compile Unit: length = 0x%8.8x, version = 0x%4.4x, " "abbr_offset = 0x%8.8x, addr_size = 0x%2.2x (next CU at " "{0x%8.8x})\n", - m_offset, m_length, m_version, GetAbbrevOffset(), m_addr_size, - GetNextCompileUnitOffset()); + m_offset, m_data->m_length, m_data->m_version, GetAbbrevOffset(), + m_data->m_addr_size, GetNextCompileUnitOffset()); } -static uint8_t g_default_addr_size = 4; +uint8_t DWARFCompileUnitData::g_default_addr_size = 4; uint8_t DWARFCompileUnit::GetAddressByteSize(const DWARFCompileUnit *cu) { if (cu) return cu->GetAddressByteSize(); - return DWARFCompileUnit::GetDefaultAddressSize(); + return DWARFCompileUnitData::GetDefaultAddressSize(); } bool DWARFCompileUnit::IsDWARF64(const DWARFCompileUnit *cu) { @@ -358,19 +368,19 @@ return false; } -uint8_t DWARFCompileUnit::GetDefaultAddressSize() { +uint8_t DWARFCompileUnitData::GetDefaultAddressSize() { return g_default_addr_size; } -void DWARFCompileUnit::SetDefaultAddressSize(uint8_t addr_size) { +void DWARFCompileUnitData::SetDefaultAddressSize(uint8_t addr_size) { g_default_addr_size = addr_size; } lldb::user_id_t DWARFCompileUnit::GetID() const { - dw_offset_t local_id = - m_base_obj_offset != DW_INVALID_OFFSET ? m_base_obj_offset : m_offset; - if (m_dwarf2Data) - return DIERef(local_id, local_id).GetUID(m_dwarf2Data); + dw_offset_t local_id = m_data->m_base_obj_offset != DW_INVALID_OFFSET + ? m_data->m_base_obj_offset : m_offset; + if (m_data->m_dwarf2Data) + return DIERef(local_id, local_id).GetUID(m_data->m_dwarf2Data); else return local_id; } @@ -424,7 +434,7 @@ sc.comp_unit = dwarf2Data->GetCompUnitForDWARFCompUnit(this); if (sc.comp_unit) { SymbolFileDWARFDebugMap *debug_map_sym_file = - m_dwarf2Data->GetDebugMapSymfile(); + m_data->m_dwarf2Data->GetDebugMapSymfile(); if (debug_map_sym_file == NULL) { LineTable *line_table = sc.comp_unit->GetLineTable(); @@ -475,33 +485,34 @@ } const DWARFDebugAranges &DWARFCompileUnit::GetFunctionAranges() { - if (m_func_aranges_ap.get() == NULL) { - m_func_aranges_ap.reset(new DWARFDebugAranges()); + if (m_data->m_func_aranges_ap.get() == NULL) { + m_data->m_func_aranges_ap.reset(new DWARFDebugAranges()); Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES)); if (log) { - m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage( + m_data->m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage( log, "DWARFCompileUnit::GetFunctionAranges() for compile unit at " ".debug_info[0x%8.8x]", GetOffset()); } const DWARFDebugInfoEntry *die = DIEPtr(); if (die) - die->BuildFunctionAddressRangeTable(m_dwarf2Data, this, - m_func_aranges_ap.get()); + die->BuildFunctionAddressRangeTable(m_data->m_dwarf2Data, this, + m_data->m_func_aranges_ap.get()); - if (m_dwo_symbol_file) { - DWARFCompileUnit *dwo_cu = m_dwo_symbol_file->GetCompileUnit(); + if (m_data->m_dwo_symbol_file) { + DWARFCompileUnit *dwo_cu = m_data->m_dwo_symbol_file->GetCompileUnit(); const DWARFDebugInfoEntry *dwo_die = dwo_cu->DIEPtr(); if (dwo_die) - dwo_die->BuildFunctionAddressRangeTable(m_dwo_symbol_file.get(), dwo_cu, - m_func_aranges_ap.get()); + dwo_die->BuildFunctionAddressRangeTable( + m_data->m_dwo_symbol_file.get(), dwo_cu, + m_data->m_func_aranges_ap.get()); } const bool minimize = false; - m_func_aranges_ap->Sort(minimize); + m_data->m_func_aranges_ap->Sort(minimize); } - return *m_func_aranges_ap.get(); + return *m_data->m_func_aranges_ap.get(); } DWARFDIE @@ -535,14 +546,14 @@ DWARFDIE DWARFCompileUnit::GetDIE(dw_offset_t die_offset) { if (die_offset != DW_INVALID_OFFSET) { - if (m_dwo_symbol_file) - return m_dwo_symbol_file->GetCompileUnit()->GetDIE(die_offset); + if (m_data->m_dwo_symbol_file) + return m_data->m_dwo_symbol_file->GetCompileUnit()->GetDIE(die_offset); if (ContainsDIEOffset(die_offset)) { ExtractDIEsIfNeeded(false); - DWARFDebugInfoEntry::iterator end = m_die_array.end(); - DWARFDebugInfoEntry::iterator pos = - lower_bound(m_die_array.begin(), end, die_offset, CompareDIEOffset); + DWARFDebugInfoEntry::iterator end = m_data->m_die_array.end(); + DWARFDebugInfoEntry::iterator pos = lower_bound( + m_data->m_die_array.begin(), end, die_offset, CompareDIEOffset); if (pos != end) { if (die_offset == (*pos).GetOffset()) return DWARFDIE(this, &(*pos)); @@ -551,7 +562,7 @@ // Don't specify the compile unit offset as we don't know it because the // DIE belongs to // a different compile unit in the same symbol file. - return m_dwarf2Data->DebugInfo()->GetDIEForDIEOffset(die_offset); + return m_data->m_dwarf2Data->DebugInfo()->GetDIEForDIEOffset(die_offset); } } return DWARFDIE(); // Not found @@ -562,8 +573,8 @@ uint32_t depth) const { size_t old_size = dies.Size(); DWARFDebugInfoEntry::const_iterator pos; - DWARFDebugInfoEntry::const_iterator end = m_die_array.end(); - for (pos = m_die_array.begin(); pos != end; ++pos) { + DWARFDebugInfoEntry::const_iterator end = m_data->m_die_array.end(); + for (pos = m_data->m_die_array.begin(); pos != end; ++pos) { if (pos->Tag() == tag) dies.Append(DWARFDIE(this, &(*pos))); } @@ -585,11 +596,11 @@ // // Indexes to all file level global and static variables // m_global_die_indexes; // -// if (m_die_array.empty()) +// if (m_data->m_die_array.empty()) // return; // -// const DWARFDebugInfoEntry* first_die = &m_die_array[0]; -// const DWARFDebugInfoEntry* end = first_die + m_die_array.size(); +// const DWARFDebugInfoEntry* first_die = &m_data->m_die_array[0]; +// const DWARFDebugInfoEntry* end = first_die + m_data->m_die_array.size(); // if (first_die <= die && die < end) // m_global_die_indexes.push_back (die - first_die); //} @@ -600,14 +611,14 @@ NameToDIE &objc_class_selectors, NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces) { - assert(!m_dwarf2Data->GetBaseCompileUnit() && + assert(!m_data->m_dwarf2Data->GetBaseCompileUnit() && "DWARFCompileUnit associated with .dwo or .dwp " "should not be indexed directly"); Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); if (log) { - m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage( + m_data->m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage( log, "DWARFCompileUnit::Index() for compile unit at .debug_info[0x%8.8x]", GetOffset()); @@ -616,7 +627,7 @@ const LanguageType cu_language = GetLanguageType(); DWARFFormValue::FixedFormSizes fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(), - m_is_dwarf64); + m_data->m_is_dwarf64); IndexPrivate(this, cu_language, fixed_form_sizes, GetOffset(), func_basenames, func_fullnames, func_methods, func_selectors, @@ -639,8 +650,9 @@ NameToDIE &func_selectors, NameToDIE &objc_class_selectors, NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces) { DWARFDebugInfoEntry::const_iterator pos; - DWARFDebugInfoEntry::const_iterator begin = dwarf_cu->m_die_array.begin(); - DWARFDebugInfoEntry::const_iterator end = dwarf_cu->m_die_array.end(); + DWARFDebugInfoEntry::const_iterator begin = + dwarf_cu->m_data->m_die_array.begin(); + DWARFDebugInfoEntry::const_iterator end = dwarf_cu->m_data->m_die_array.end(); for (pos = begin; pos != end; ++pos) { const DWARFDebugInfoEntry &die = *pos; @@ -970,22 +982,22 @@ } void DWARFCompileUnit::ParseProducerInfo() { - m_producer_version_major = UINT32_MAX; - m_producer_version_minor = UINT32_MAX; - m_producer_version_update = UINT32_MAX; + m_data->m_producer_version_major = UINT32_MAX; + m_data->m_producer_version_minor = UINT32_MAX; + m_data->m_producer_version_update = UINT32_MAX; const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); if (die) { const char *producer_cstr = die->GetAttributeValueAsString( - m_dwarf2Data, this, DW_AT_producer, NULL); + m_data->m_dwarf2Data, this, DW_AT_producer, NULL); if (producer_cstr) { RegularExpression llvm_gcc_regex( llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple " "Inc\\. build [0-9]+\\) \\(LLVM build " "[\\.0-9]+\\)$")); if (llvm_gcc_regex.Execute(llvm::StringRef(producer_cstr))) { - m_producer = eProducerLLVMGCC; + m_data->m_producer = eProducerLLVMGCC; } else if (strstr(producer_cstr, "clang")) { static RegularExpression g_clang_version_regex( llvm::StringRef("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)")); @@ -994,46 +1006,46 @@ ®ex_match)) { std::string str; if (regex_match.GetMatchAtIndex(producer_cstr, 1, str)) - m_producer_version_major = + m_data->m_producer_version_major = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10); if (regex_match.GetMatchAtIndex(producer_cstr, 2, str)) - m_producer_version_minor = + m_data->m_producer_version_minor = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10); if (regex_match.GetMatchAtIndex(producer_cstr, 3, str)) - m_producer_version_update = + m_data->m_producer_version_update = StringConvert::ToUInt32(str.c_str(), UINT32_MAX, 10); } - m_producer = eProducerClang; + m_data->m_producer = eProducerClang; } else if (strstr(producer_cstr, "GNU")) - m_producer = eProducerGCC; + m_data->m_producer = eProducerGCC; } } - if (m_producer == eProducerInvalid) - m_producer = eProcucerOther; + if (m_data->m_producer == eProducerInvalid) + m_data->m_producer = eProcucerOther; } DWARFCompileUnit::Producer DWARFCompileUnit::GetProducer() { - if (m_producer == eProducerInvalid) + if (m_data->m_producer == eProducerInvalid) ParseProducerInfo(); - return m_producer; + return m_data->m_producer; } uint32_t DWARFCompileUnit::GetProducerVersionMajor() { - if (m_producer_version_major == 0) + if (m_data->m_producer_version_major == 0) ParseProducerInfo(); - return m_producer_version_major; + return m_data->m_producer_version_major; } uint32_t DWARFCompileUnit::GetProducerVersionMinor() { - if (m_producer_version_minor == 0) + if (m_data->m_producer_version_minor == 0) ParseProducerInfo(); - return m_producer_version_minor; + return m_data->m_producer_version_minor; } uint32_t DWARFCompileUnit::GetProducerVersionUpdate() { - if (m_producer_version_update == 0) + if (m_data->m_producer_version_update == 0) ParseProducerInfo(); - return m_producer_version_update; + return m_data->m_producer_version_update; } LanguageType DWARFCompileUnit::LanguageTypeFromDWARF(uint64_t val) { @@ -1050,30 +1062,31 @@ } LanguageType DWARFCompileUnit::GetLanguageType() { - if (m_language_type != eLanguageTypeUnknown) - return m_language_type; + if (m_data->m_language_type != eLanguageTypeUnknown) + return m_data->m_language_type; const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); if (die) - m_language_type = LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned( - m_dwarf2Data, this, DW_AT_language, 0)); - return m_language_type; + m_data->m_language_type = LanguageTypeFromDWARF( + die->GetAttributeValueAsUnsigned( + m_data->m_dwarf2Data, this, DW_AT_language, 0)); + return m_data->m_language_type; } -bool DWARFCompileUnit::IsDWARF64() const { return m_is_dwarf64; } +bool DWARFCompileUnit::IsDWARF64() const { return m_data->m_is_dwarf64; } bool DWARFCompileUnit::GetIsOptimized() { - if (m_is_optimized == eLazyBoolCalculate) { + if (m_data->m_is_optimized == eLazyBoolCalculate) { const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); if (die) { - m_is_optimized = eLazyBoolNo; - if (die->GetAttributeValueAsUnsigned(m_dwarf2Data, this, + m_data->m_is_optimized = eLazyBoolNo; + if (die->GetAttributeValueAsUnsigned(m_data->m_dwarf2Data, this, DW_AT_APPLE_optimized, 0) == 1) { - m_is_optimized = eLazyBoolYes; + m_data->m_is_optimized = eLazyBoolYes; } } } - if (m_is_optimized == eLazyBoolYes) { + if (m_data->m_is_optimized == eLazyBoolYes) { return true; } else { return false; @@ -1086,26 +1099,26 @@ } TypeSystem *DWARFCompileUnit::GetTypeSystem() { - if (m_dwarf2Data) - return m_dwarf2Data->GetTypeSystemForLanguage(GetLanguageType()); + if (m_data->m_dwarf2Data) + return m_data->m_dwarf2Data->GetTypeSystemForLanguage(GetLanguageType()); else return nullptr; } void DWARFCompileUnit::SetUserData(void *d) { - m_user_data = d; - if (m_dwo_symbol_file) - m_dwo_symbol_file->GetCompileUnit()->SetUserData(d); + m_data->m_user_data = d; + if (m_data->m_dwo_symbol_file) + m_data->m_dwo_symbol_file->GetCompileUnit()->SetUserData(d); } void DWARFCompileUnit::SetAddrBase(dw_addr_t addr_base, dw_addr_t ranges_base, dw_offset_t base_obj_offset) { - m_addr_base = addr_base; - m_ranges_base = ranges_base; - m_base_obj_offset = base_obj_offset; + m_data->m_addr_base = addr_base; + m_data->m_ranges_base = ranges_base; + m_data->m_base_obj_offset = base_obj_offset; } lldb::ByteOrder DWARFCompileUnit::GetByteOrder() const { - return m_dwarf2Data->GetObjectFile()->GetByteOrder(); + return m_data->m_dwarf2Data->GetObjectFile()->GetByteOrder(); } Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -18,6 +18,7 @@ #include #include #include +#include // Other libraries and framework includes #include "llvm/ADT/DenseMap.h" @@ -62,6 +63,7 @@ class SymbolFileDWARFDebugMap; class SymbolFileDWARFDwo; class SymbolFileDWARFDwp; +class DWARFCompileUnitData; #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1) @@ -304,6 +306,8 @@ // the method returns a pointer to the base compile unit. virtual DWARFCompileUnit *GetBaseCompileUnit(); + DWARFCompileUnitData *NewCompileUnitData(); + protected: typedef llvm::DenseMap DIEToTypePtr; @@ -468,6 +472,8 @@ SymbolFileDWARFDwp *GetDwpSymbolFile(); + std::forward_list m_compile_unit_data_list; + lldb::ModuleWP m_debug_map_module_wp; SymbolFileDWARFDebugMap *m_debug_map_symfile; Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -4369,3 +4369,8 @@ }); return m_dwp_symfile.get(); } + +DWARFCompileUnitData *SymbolFileDWARF::NewCompileUnitData() { + m_compile_unit_data_list.emplace_front(this); + return &m_compile_unit_data_list.front(); +}