diff options
Diffstat (limited to 'source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp')
-rw-r--r-- | source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp | 459 |
1 files changed, 305 insertions, 154 deletions
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp index 60933108c97a4..e7cb2b413ad7a 100644 --- a/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ b/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -12,12 +12,13 @@ #include "lldb/Core/Mangled.h" #include "lldb/Core/Module.h" #include "lldb/Core/Stream.h" +#include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" #include "lldb/Host/StringConvert.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/LineTable.h" #include "lldb/Symbol/ObjectFile.h" -#include "lldb/Target/ObjCLanguageRuntime.h" +#include "Plugins/Language/ObjC/ObjCLanguage.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" @@ -27,6 +28,7 @@ #include "LogChannelDWARF.h" #include "NameToDIE.h" #include "SymbolFileDWARF.h" +#include "SymbolFileDWARFDwo.h" #include "SymbolFileDWARFDebugMap.h" using namespace lldb; @@ -52,10 +54,16 @@ DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF* dwarf2Data) : m_producer_version_minor (0), m_producer_version_update (0), m_language_type (eLanguageTypeUnknown), - m_is_dwarf64 (false) + m_is_dwarf64 (false), + m_is_optimized (eLazyBoolCalculate), + m_addr_base (0), + m_base_obj_offset (DW_INVALID_OFFSET) { } +DWARFCompileUnit::~DWARFCompileUnit() +{} + void DWARFCompileUnit::Clear() { @@ -71,6 +79,9 @@ DWARFCompileUnit::Clear() m_producer = eProducerInvalid; m_language_type = eLanguageTypeUnknown; m_is_dwarf64 = false; + m_is_optimized = eLazyBoolCalculate; + m_addr_base = 0; + m_base_obj_offset = DW_INVALID_OFFSET; } bool @@ -128,6 +139,9 @@ DWARFCompileUnit::ClearDIEs(bool keep_compile_unit_die) if (keep_compile_unit_die) m_die_array.push_back(tmp_array.front()); } + + if (m_dwo_symbol_file) + m_dwo_symbol_file->GetCompileUnit()->ClearDIEs(keep_compile_unit_die); } //---------------------------------------------------------------------- @@ -174,7 +188,8 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only) die_index_stack.reserve(32); die_index_stack.push_back(0); bool prev_die_had_children = false; - const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), m_is_dwarf64); + DWARFFormValue::FixedFormSizes fixed_form_sizes = + DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), m_is_dwarf64); while (offset < next_cu_offset && die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset)) { @@ -188,12 +203,12 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only) const bool null_die = die.IsNULL(); if (depth == 0) { - uint64_t base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS); + if (initial_die_array_size == 0) + AddCompileUnitDIE(die); + uint64_t base_addr = die.GetAttributeValueAsAddress(m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS); if (base_addr == LLDB_INVALID_ADDRESS) - base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_entry_pc, 0); + base_addr = die.GetAttributeValueAsAddress(m_dwarf2Data, this, DW_AT_entry_pc, 0); SetBaseAddress (base_addr); - if (initial_die_array_size == 0) - AddDIE (die); if (cu_die_only) return 1; } @@ -283,9 +298,83 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only) verbose_log->PutCString (strm.GetString().c_str()); } - return m_die_array.size(); + if (!m_dwo_symbol_file) + return m_die_array.size(); + + DWARFCompileUnit* dwo_cu = m_dwo_symbol_file->GetCompileUnit(); + size_t dwo_die_count = dwo_cu->ExtractDIEsIfNeeded(cu_die_only); + return m_die_array.size() + dwo_die_count - 1; // We have 2 CU die, but we waht to count it only as one } +void +DWARFCompileUnit::AddCompileUnitDIE(DWARFDebugInfoEntry& die) +{ + assert (m_die_array.empty() && "Compile unit DIE already added"); + AddDIE(die); + + DWARFDebugInfoEntry& cu_die = m_die_array.front(); + + const char* dwo_name = cu_die.GetAttributeValueAsString(m_dwarf2Data, + this, + DW_AT_GNU_dwo_name, + nullptr); + if (!dwo_name) + return; + + FileSpec dwo_file(dwo_name, true); + if (dwo_file.IsRelative()) + { + const char* comp_dir = cu_die.GetAttributeValueAsString(m_dwarf2Data, + this, + DW_AT_comp_dir, + nullptr); + if (!comp_dir) + return; + + dwo_file.SetFile(comp_dir, true); + dwo_file.AppendPathComponent(dwo_name); + } + + if (!dwo_file.Exists()) + return; + + DataBufferSP dwo_file_data_sp; + lldb::offset_t dwo_file_data_offset = 0; + ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin(m_dwarf2Data->GetObjectFile()->GetModule(), + &dwo_file, + 0 /* file_offset */, + dwo_file.GetByteSize(), + dwo_file_data_sp, + dwo_file_data_offset); + if (dwo_obj_file == nullptr) + return; + + std::unique_ptr<SymbolFileDWARFDwo> dwo_symbol_file(new SymbolFileDWARFDwo(dwo_obj_file, this)); + + DWARFCompileUnit* dwo_cu = dwo_symbol_file->GetCompileUnit(); + if (!dwo_cu) + return; // Can't fetch the compile unit from the dwo file. + + DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly(); + if (!dwo_cu_die.IsValid()) + 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); + 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); + + dw_addr_t addr_base = cu_die.GetAttributeValueAsUnsigned(m_dwarf2Data, + this, + DW_AT_GNU_addr_base, + 0); + dwo_cu->SetAddrBase(addr_base, m_offset); +} dw_offset_t DWARFCompileUnit::GetAbbrevOffset() const @@ -373,6 +462,16 @@ DWARFCompileUnit::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 m_dwarf2Data->MakeUserID(local_id); + else + return local_id; +} + void DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, DWARFDebugAranges* debug_aranges) @@ -381,13 +480,15 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, // in order to produce a compile unit level set of address ranges that // is accurate. + size_t num_debug_aranges = debug_aranges->GetNumRanges(); + // First get the compile unit DIE only and check if it has a DW_AT_ranges - const DWARFDebugInfoEntry* die = GetCompileUnitDIEOnly(); + const DWARFDebugInfoEntry* die = GetCompileUnitDIEPtrOnly(); const dw_offset_t cu_offset = GetOffset(); if (die) { - DWARFDebugRanges::RangeList ranges; + DWARFRangeList ranges; const size_t num_ranges = die->GetAttributeAddressRanges(dwarf2Data, this, ranges, false); if (num_ranges > 0) { @@ -397,7 +498,7 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, // this with recent GCC builds. for (size_t i=0; i<num_ranges; ++i) { - const DWARFDebugRanges::RangeList::Entry &range = ranges.GetEntryRef(i); + const DWARFRangeList::Entry &range = ranges.GetEntryRef(i); debug_aranges->AppendRange(cu_offset, range.GetRangeBase(), range.GetRangeEnd()); } @@ -411,11 +512,11 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, // and then throwing them all away to keep memory usage down. const bool clear_dies = ExtractDIEsIfNeeded (false) > 1; - die = DIE(); + die = DIEPtr(); if (die) die->BuildAddressRangeTable(dwarf2Data, this, debug_aranges); - if (debug_aranges->IsEmpty()) + if (debug_aranges->GetNumRanges() == num_debug_aranges) { // We got nothing from the functions, maybe we have a line tables only // situation. Check the line tables and build the arange table from this. @@ -437,7 +538,6 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, { const LineTable::FileAddressRanges::Entry &range = file_ranges.GetEntryRef(idx); debug_aranges->AppendRange(cu_offset, range.GetRangeBase(), range.GetRangeEnd()); - printf ("0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", GetOffset(), range.GetRangeBase(), range.GetRangeEnd()); } } } @@ -446,7 +546,7 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, } } - if (debug_aranges->IsEmpty()) + if (debug_aranges->GetNumRanges() == num_debug_aranges) { // We got nothing from the functions, maybe we have a line tables only // situation. Check the line tables and build the arange table from this. @@ -465,7 +565,6 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data, { const LineTable::FileAddressRanges::Entry &range = file_ranges.GetEntryRef(idx); debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(), range.GetRangeEnd()); - printf ("0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", GetOffset(), range.GetRangeBase(), range.GetRangeEnd()); } } } @@ -493,119 +592,85 @@ DWARFCompileUnit::GetFunctionAranges () "DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]", GetOffset()); } - const DWARFDebugInfoEntry* die = DIE(); + const DWARFDebugInfoEntry* die = DIEPtr(); if (die) die->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get()); + + if (m_dwo_symbol_file) + { + DWARFCompileUnit* dwo_cu = 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()); + } + const bool minimize = false; m_func_aranges_ap->Sort(minimize); } return *m_func_aranges_ap.get(); } -bool -DWARFCompileUnit::LookupAddress -( - const dw_addr_t address, - DWARFDebugInfoEntry** function_die_handle, - DWARFDebugInfoEntry** block_die_handle -) +DWARFDIE +DWARFCompileUnit::LookupAddress (const dw_addr_t address) { - bool success = false; - - if (function_die_handle != NULL && DIE()) + if (DIE()) { - const DWARFDebugAranges &func_aranges = GetFunctionAranges (); // Re-check the aranges auto pointer contents in case it was created above if (!func_aranges.IsEmpty()) - { - *function_die_handle = GetDIEPtr(func_aranges.FindAddress(address)); - if (*function_die_handle != NULL) - { - success = true; - if (block_die_handle != NULL) - { - DWARFDebugInfoEntry* child = (*function_die_handle)->GetFirstChild(); - while (child) - { - if (child->LookupAddress(address, m_dwarf2Data, this, NULL, block_die_handle)) - break; - child = child->GetSibling(); - } - } - } - } + return GetDIE(func_aranges.FindAddress(address)); } - return success; + return DWARFDIE(); } //---------------------------------------------------------------------- // Compare function DWARFDebugAranges::Range structures //---------------------------------------------------------------------- -static bool CompareDIEOffset (const DWARFDebugInfoEntry& die1, const DWARFDebugInfoEntry& die2) +static bool CompareDIEOffset (const DWARFDebugInfoEntry& die, const dw_offset_t die_offset) { - return die1.GetOffset() < die2.GetOffset(); + return die.GetOffset() < die_offset; } //---------------------------------------------------------------------- -// GetDIEPtr() +// GetDIE() // -// Get the DIE (Debug Information Entry) with the specified offset. +// Get the DIE (Debug Information Entry) with the specified offset by +// first checking if the DIE is contained within this compile unit and +// grabbing the DIE from this compile unit. Otherwise we grab the DIE +// from the DWARF file. //---------------------------------------------------------------------- -DWARFDebugInfoEntry* -DWARFCompileUnit::GetDIEPtr(dw_offset_t die_offset) +DWARFDIE +DWARFCompileUnit::GetDIE (dw_offset_t die_offset) { if (die_offset != DW_INVALID_OFFSET) { - ExtractDIEsIfNeeded (false); - DWARFDebugInfoEntry compare_die; - compare_die.SetOffset(die_offset); - DWARFDebugInfoEntry::iterator end = m_die_array.end(); - DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset); - if (pos != end) - { - if (die_offset == (*pos).GetOffset()) - return &(*pos); - } - } - return NULL; // Not found in any compile units -} + if (m_dwo_symbol_file) + return m_dwo_symbol_file->GetCompileUnit()->GetDIE(die_offset); -//---------------------------------------------------------------------- -// GetDIEPtrContainingOffset() -// -// Get the DIE (Debug Information Entry) that contains the specified -// .debug_info offset. -//---------------------------------------------------------------------- -const DWARFDebugInfoEntry* -DWARFCompileUnit::GetDIEPtrContainingOffset(dw_offset_t die_offset) -{ - if (die_offset != DW_INVALID_OFFSET) - { - ExtractDIEsIfNeeded (false); - DWARFDebugInfoEntry compare_die; - compare_die.SetOffset(die_offset); - DWARFDebugInfoEntry::iterator end = m_die_array.end(); - DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset); - if (pos != end) + if (ContainsDIEOffset(die_offset)) { - if (die_offset >= (*pos).GetOffset()) + ExtractDIEsIfNeeded (false); + DWARFDebugInfoEntry::iterator end = m_die_array.end(); + DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, die_offset, CompareDIEOffset); + if (pos != end) { - DWARFDebugInfoEntry::iterator next = pos + 1; - if (next != end) - { - if (die_offset < (*next).GetOffset()) - return &(*pos); - } + if (die_offset == (*pos).GetOffset()) + return DWARFDIE(this, &(*pos)); } } + else + { + // 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()->GetDIE (DIERef(die_offset)); + } } - return NULL; // Not found in any compile units + return DWARFDIE(); // Not found } - - size_t DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& dies, uint32_t depth) const { @@ -615,7 +680,7 @@ DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& die for (pos = m_die_array.begin(); pos != end; ++pos) { if (pos->Tag() == tag) - dies.Append (&(*pos)); + dies.Append (DWARFDIE(this, &(*pos))); } // Return the number of DIEs added to the collection @@ -646,8 +711,7 @@ DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& die void -DWARFCompileUnit::Index (const uint32_t cu_idx, - NameToDIE& func_basenames, +DWARFCompileUnit::Index (NameToDIE& func_basenames, NameToDIE& func_fullnames, NameToDIE& func_methods, NameToDIE& func_selectors, @@ -656,10 +720,6 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, NameToDIE& types, NameToDIE& namespaces) { - const DWARFDataExtractor* debug_str = &m_dwarf2Data->get_debug_str_data(); - - const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), m_is_dwarf64); - Log *log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_LOOKUPS)); if (log) @@ -670,9 +730,57 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, } const LanguageType cu_language = GetLanguageType(); + DWARFFormValue::FixedFormSizes fixed_form_sizes = + DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), m_is_dwarf64); + + IndexPrivate(this, + cu_language, + fixed_form_sizes, + GetOffset(), + func_basenames, + func_fullnames, + func_methods, + func_selectors, + objc_class_selectors, + globals, + types, + namespaces); + + SymbolFileDWARFDwo* dwo_symbol_file = GetDwoSymbolFile(); + if (dwo_symbol_file) + { + IndexPrivate(dwo_symbol_file->GetCompileUnit(), + cu_language, + fixed_form_sizes, + GetOffset(), + func_basenames, + func_fullnames, + func_methods, + func_selectors, + objc_class_selectors, + globals, + types, + namespaces); + } +} + +void +DWARFCompileUnit::IndexPrivate (DWARFCompileUnit* dwarf_cu, + const LanguageType cu_language, + const DWARFFormValue::FixedFormSizes& fixed_form_sizes, + const dw_offset_t cu_offset, + NameToDIE& func_basenames, + NameToDIE& func_fullnames, + NameToDIE& func_methods, + NameToDIE& func_selectors, + NameToDIE& objc_class_selectors, + NameToDIE& globals, + NameToDIE& types, + NameToDIE& namespaces) +{ DWARFDebugInfoEntry::const_iterator pos; - DWARFDebugInfoEntry::const_iterator begin = m_die_array.begin(); - DWARFDebugInfoEntry::const_iterator end = m_die_array.end(); + DWARFDebugInfoEntry::const_iterator begin = dwarf_cu->m_die_array.begin(); + DWARFDebugInfoEntry::const_iterator end = dwarf_cu->m_die_array.end(); for (pos = begin; pos != end; ++pos) { const DWARFDebugInfoEntry &die = *pos; @@ -701,17 +809,17 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, continue; } - DWARFDebugInfoEntry::Attributes attributes; + DWARFAttributes attributes; const char *name = NULL; const char *mangled_cstr = NULL; bool is_declaration = false; //bool is_artificial = false; bool has_address = false; - bool has_location = false; + bool has_location_or_const_value = false; bool is_global_or_static_variable = false; - dw_offset_t specification_die_offset = DW_INVALID_OFFSET; - const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, fixed_form_sizes, attributes); + DWARFFormValue specification_die_form; + const size_t num_attributes = die.GetAttributes(dwarf_cu, fixed_form_sizes, attributes); if (num_attributes > 0) { for (uint32_t i=0; i<num_attributes; ++i) @@ -721,24 +829,24 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, switch (attr) { case DW_AT_name: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - name = form_value.AsCString(debug_str); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + name = form_value.AsCString(); break; case DW_AT_declaration: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) + if (attributes.ExtractFormValueAtIndex(i, form_value)) is_declaration = form_value.Unsigned() != 0; break; // case DW_AT_artificial: -// if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) +// if (attributes.ExtractFormValueAtIndex(i, form_value)) // is_artificial = form_value.Unsigned() != 0; // break; case DW_AT_MIPS_linkage_name: case DW_AT_linkage_name: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - mangled_cstr = form_value.AsCString(debug_str); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + mangled_cstr = form_value.AsCString(); break; case DW_AT_low_pc: @@ -752,7 +860,8 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, break; case DW_AT_location: - has_location = true; + case DW_AT_const_value: + has_location_or_const_value = true; if (tag == DW_TAG_variable) { const DWARFDebugInfoEntry* parent_die = die.GetParent(); @@ -800,8 +909,8 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, break; case DW_AT_specification: - if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value)) - specification_die_offset = form_value.Reference(); + if (attributes.ExtractFormValueAtIndex(i, form_value)) + specification_die_form = form_value; break; } } @@ -814,24 +923,22 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, { if (name) { - // Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the - // simple inlined check outside the call. - ObjCLanguageRuntime::MethodName objc_method(name, true); + ObjCLanguage::MethodName objc_method(name, true); if (objc_method.IsValid(true)) { ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory()); ConstString objc_selector_name (objc_method.GetSelector()); ConstString objc_fullname_no_category_name (objc_method.GetFullNameWithoutCategory(true)); ConstString objc_class_name_no_category (objc_method.GetClassName()); - func_fullnames.Insert (ConstString(name), die.GetOffset()); + func_fullnames.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); if (objc_class_name_with_category) - objc_class_selectors.Insert(objc_class_name_with_category, die.GetOffset()); + objc_class_selectors.Insert(objc_class_name_with_category, DIERef(cu_offset, die.GetOffset())); if (objc_class_name_no_category && objc_class_name_no_category != objc_class_name_with_category) - objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset()); + objc_class_selectors.Insert(objc_class_name_no_category, DIERef(cu_offset, die.GetOffset())); if (objc_selector_name) - func_selectors.Insert (objc_selector_name, die.GetOffset()); + func_selectors.Insert (objc_selector_name, DIERef(cu_offset, die.GetOffset())); if (objc_fullname_no_category_name) - func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset()); + func_fullnames.Insert (objc_fullname_no_category_name, DIERef(cu_offset, die.GetOffset())); } // If we have a mangled name, then the DW_AT_name attribute // is usually the method name without the class or any parameters @@ -846,32 +953,23 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, } else { - if (specification_die_offset != DW_INVALID_OFFSET) + if (specification_die_form.IsValid()) { - const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL); - if (specification_die) - { - parent = specification_die->GetParent(); - if (parent) - { - parent_tag = parent->Tag(); - - if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type) - is_method = true; - } - } + DWARFDIE specification_die = dwarf_cu->GetSymbolFileDWARF()->DebugInfo()->GetDIE (DIERef(specification_die_form)); + if (specification_die.GetParent().IsStructOrClass()) + is_method = true; } } } if (is_method) - func_methods.Insert (ConstString(name), die.GetOffset()); + func_methods.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); else - func_basenames.Insert (ConstString(name), die.GetOffset()); + func_basenames.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); if (!is_method && !mangled_cstr && !objc_method.IsValid(true)) - func_fullnames.Insert (ConstString(name), die.GetOffset()); + func_fullnames.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); } if (mangled_cstr) { @@ -882,10 +980,10 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (name && ::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (ConstString(mangled_cstr), true); - func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset()); + func_fullnames.Insert (mangled.GetMangledName(), DIERef(cu_offset, die.GetOffset())); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) - func_fullnames.Insert (demangled, die.GetOffset()); + func_fullnames.Insert (demangled, DIERef(cu_offset, die.GetOffset())); } } } @@ -895,7 +993,7 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, if (has_address) { if (name) - func_basenames.Insert (ConstString(name), die.GetOffset()); + func_basenames.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry @@ -905,14 +1003,14 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (ConstString(mangled_cstr), true); - func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset()); + func_fullnames.Insert (mangled.GetMangledName(), DIERef(cu_offset, die.GetOffset())); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) - func_fullnames.Insert (demangled, die.GetOffset()); + func_fullnames.Insert (demangled, DIERef(cu_offset, die.GetOffset())); } } else - func_fullnames.Insert (ConstString(name), die.GetOffset()); + func_fullnames.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); } break; @@ -928,19 +1026,19 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, case DW_TAG_unspecified_type: if (name && is_declaration == false) { - types.Insert (ConstString(name), die.GetOffset()); + types.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); } break; case DW_TAG_namespace: if (name) - namespaces.Insert (ConstString(name), die.GetOffset()); + namespaces.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); break; case DW_TAG_variable: - if (name && has_location && is_global_or_static_variable) + if (name && has_location_or_const_value && is_global_or_static_variable) { - globals.Insert (ConstString(name), die.GetOffset()); + globals.Insert (ConstString(name), DIERef(cu_offset, die.GetOffset())); // Be sure to include variables by their mangled and demangled // names if they have any since a variable can have a basename // "i", a mangled named "_ZN12_GLOBAL__N_11iE" and a demangled @@ -953,10 +1051,10 @@ DWARFCompileUnit::Index (const uint32_t cu_idx, if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled (ConstString(mangled_cstr), true); - globals.Insert (mangled.GetMangledName(), die.GetOffset()); + globals.Insert (mangled.GetMangledName(), DIERef(cu_offset, die.GetOffset())); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) - globals.Insert (demangled, die.GetOffset()); + globals.Insert (demangled, DIERef(cu_offset, die.GetOffset())); } } break; @@ -1004,7 +1102,7 @@ DWARFCompileUnit::ParseProducerInfo () m_producer_version_minor = UINT32_MAX; m_producer_version_update = UINT32_MAX; - const DWARFDebugInfoEntry *die = GetCompileUnitDIEOnly(); + const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); if (die) { @@ -1095,10 +1193,9 @@ DWARFCompileUnit::GetLanguageType() if (m_language_type != eLanguageTypeUnknown) return m_language_type; - const DWARFDebugInfoEntry *die = GetCompileUnitDIEOnly(); + const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); if (die) - m_language_type = LanguageTypeFromDWARF( - die->GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, 0)); + m_language_type = LanguageTypeFromDWARF(die->GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, 0)); return m_language_type; } @@ -1108,3 +1205,57 @@ DWARFCompileUnit::IsDWARF64() const return m_is_dwarf64; } +bool +DWARFCompileUnit::GetIsOptimized () +{ + if (m_is_optimized == eLazyBoolCalculate) + { + const DWARFDebugInfoEntry *die = GetCompileUnitDIEPtrOnly(); + if (die) + { + m_is_optimized = eLazyBoolNo; + if (die->GetAttributeValueAsUnsigned (m_dwarf2Data, this, DW_AT_APPLE_optimized, 0) == 1) + { + m_is_optimized = eLazyBoolYes; + } + } + } + if (m_is_optimized == eLazyBoolYes) + { + return true; + } + else + { + return false; + } +} + +DWARFFormValue::FixedFormSizes +DWARFCompileUnit::GetFixedFormSizes () +{ + return DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize(), IsDWARF64()); +} + +TypeSystem * +DWARFCompileUnit::GetTypeSystem () +{ + if (m_dwarf2Data) + return 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); +} + +void +DWARFCompileUnit::SetAddrBase(dw_addr_t addr_base, dw_offset_t base_obj_offset) +{ + m_addr_base = addr_base; + m_base_obj_offset = base_obj_offset; +} |