Index: include/lldb/Expression/DWARFExpression.h =================================================================== --- include/lldb/Expression/DWARFExpression.h +++ include/lldb/Expression/DWARFExpression.h @@ -218,7 +218,8 @@ /// The byte length of the location expression. //------------------------------------------------------------------ void CopyOpcodeData(lldb::ModuleSP module_sp, const DataExtractor &data, - lldb::offset_t data_offset, lldb::offset_t data_length); + lldb::offset_t data_file_offset, + lldb::offset_t data_length); void CopyOpcodeData(const void *data, lldb::offset_t data_length, lldb::ByteOrder byte_order, uint8_t addr_byte_size); Index: source/Expression/DWARFExpression.cpp =================================================================== --- source/Expression/DWARFExpression.cpp +++ source/Expression/DWARFExpression.cpp @@ -89,9 +89,9 @@ void DWARFExpression::CopyOpcodeData(lldb::ModuleSP module_sp, const DataExtractor &data, - lldb::offset_t data_offset, + lldb::offset_t data_file_offset, lldb::offset_t data_length) { - const uint8_t *bytes = data.PeekData(data_offset, data_length); + const uint8_t *bytes = data.PeekData(data_file_offset, data_length); if (bytes) { m_module_wp = module_sp; m_data.SetData(DataBufferSP(new DataBufferHeap(bytes, data_length))); Index: source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFAttribute.cpp @@ -51,9 +51,9 @@ const DWARFUnit *cu = CompileUnitAtIndex(i); form_value.SetCompileUnit(cu); form_value.SetForm(FormAtIndex(i)); - lldb::offset_t offset = DIEOffsetAtIndex(i); + lldb::offset_t file_offset = cu->ThisCUUniqToFileOffset(DIEOffsetAtIndex(i)); return form_value.ExtractValue( - cu->GetSymbolFileDWARF()->get_debug_info_data(), &offset); + cu->GetSymbolFileDWARF()->get_debug_info_data(), &file_offset); } uint64_t DWARFAttributes::FormValueAsUnsigned(dw_attr_t attr, Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -11,6 +11,7 @@ #define SymbolFileDWARF_DWARFCompileUnit_h_ #include "DWARFUnit.h" +#include "lldb/Utility/LLDBAssert.h" class DWARFCompileUnit : public DWARFUnit { friend class DWARFUnit; @@ -78,6 +79,14 @@ virtual DWARFCompileUnit &Data() override { return *this; } virtual const DWARFCompileUnit &Data() const override { return *this; } + dw_offset_t GetFileOffset() const; + dw_offset_t MainCU_FileOffsetToUniqOffset(dw_offset_t file) const { + return file; + } + dw_offset_t GetNextCompileUnitFileOffset() const { + return ThisCUUniqToFileOffset(GetNextCompileUnitOffset() - 1) + 1; + } + SymbolFileDWARF *m_dwarf2Data; std::unique_ptr m_dwo_symbol_file; const DWARFAbbreviationDeclarationSet *m_abbrevs; Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -41,7 +41,7 @@ : m_dwarf2Data(dwarf2Data) {} DWARFUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data, - lldb::offset_t *offset_ptr) { + lldb::offset_t *file_offset_ptr) { // std::make_shared would require the ctor to be public. std::shared_ptr cu_sp(new DWARFCompileUnit(dwarf2Data)); // Out of memory? @@ -50,19 +50,19 @@ const DWARFDataExtractor &debug_info = dwarf2Data->get_debug_info_data(); - cu_sp->m_offset = *offset_ptr; + cu_sp->m_offset = *file_offset_ptr; - if (debug_info.ValidOffset(*offset_ptr)) { + if (debug_info.ValidOffset(*file_offset_ptr)) { dw_offset_t abbr_offset; const DWARFDebugAbbrev *abbr = dwarf2Data->DebugAbbrev(); - cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr); + cu_sp->m_length = debug_info.GetDWARFInitialLength(file_offset_ptr); cu_sp->m_is_dwarf64 = debug_info.IsDWARF64(); - cu_sp->m_version = debug_info.GetU16(offset_ptr); - abbr_offset = debug_info.GetDWARFOffset(offset_ptr); - cu_sp->m_addr_size = debug_info.GetU8(offset_ptr); + cu_sp->m_version = debug_info.GetU16(file_offset_ptr); + abbr_offset = debug_info.GetDWARFOffset(file_offset_ptr); + cu_sp->m_addr_size = debug_info.GetU8(file_offset_ptr); bool length_OK = - debug_info.ValidOffset(cu_sp->GetNextCompileUnitOffset() - 1); + debug_info.ValidOffset(cu_sp->GetNextCompileUnitFileOffset() - 1); bool version_OK = SymbolFileDWARF::SupportedVersion(cu_sp->m_version); bool abbr_offset_OK = dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset); @@ -75,7 +75,7 @@ } // reset the offset to where we tried to parse from if anything went wrong - *offset_ptr = cu_sp->m_offset; + *file_offset_ptr = cu_sp->m_offset; } return nullptr; @@ -121,7 +121,7 @@ // Set the offset to that of the first DIE and calculate the start of the // next compilation unit header. - lldb::offset_t offset = GetFirstDIEOffset(); + lldb::offset_t file_offset = ThisCUUniqToFileOffset(GetFirstDIEOffset()); lldb::offset_t next_cu_offset = GetNextCompileUnitOffset(); DWARFDebugInfoEntry die; @@ -149,8 +149,9 @@ 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)) { + while (ThisCUFileOffsetToUniq_nocheck(file_offset) < next_cu_offset && + die.FastExtract(debug_info_data, this, fixed_form_sizes, &file_offset)) + { // if (log) // log->Printf("0x%8.8x: %*.*s%s%s", // die.GetOffset(), @@ -219,11 +220,11 @@ // Give a little bit of info if we encounter corrupt DWARF (our offset // should always terminate at or before the start of the next compilation // unit header). - if (offset > next_cu_offset) { + if (ThisCUFileOffsetToUniq_nocheck(file_offset) > next_cu_offset) { m_dwarf2Data->GetObjectFile()->GetModule()->ReportWarning( "DWARF compile unit extends beyond its bounds cu 0x%8.8x at " - "0x%8.8" PRIx64 "\n", - GetOffset(), offset); + "0x%8.8" PRIx32 "\n", + GetOffset(), ThisCUFileOffsetToUniq(file_offset)); } // Since std::vector objects will double their size, we really need to @@ -625,6 +626,10 @@ } } +dw_offset_t DWARFCompileUnit::GetFileOffset() const { + return GetOffset(); +} + TypeSystem *DWARFCompileUnit::GetTypeSystem() { if (m_dwarf2Data) return m_dwarf2Data->GetTypeSystemForLanguage(GetLanguageType()); Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -25,6 +25,7 @@ #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/TypeSystem.h" +#include "lldb/Utility/LLDBAssert.h" using namespace lldb_private; @@ -35,7 +36,7 @@ dw_offset_t cu_offset = m_cu->GetOffset(); if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET) cu_offset = m_cu->GetBaseObjOffset(); - return DIERef(cu_offset, m_die->GetOffset()); + return DIERef(cu_offset, m_die->GetOffset(m_cu)); } dw_tag_t DWARFDIE::Tag() const { @@ -159,11 +160,11 @@ DWARFDebugInfoEntry *block_die = nullptr; if (m_die->LookupAddress(file_addr, dwarf, cu, &function_die, &block_die)) { if (block_die && block_die != function_die) { - if (cu->ContainsDIEOffset(block_die->GetOffset())) + if (cu->ContainsDIEOffset(block_die->GetOffset(cu))) return DWARFDIE(cu, block_die); else return DWARFDIE(dwarf->DebugInfo()->GetCompileUnit( - DIERef(cu->GetOffset(), block_die->GetOffset())), + DIERef(cu->GetOffset(), block_die->GetOffset(cu))), block_die); } } @@ -323,16 +324,17 @@ } dw_offset_t DWARFDIE::GetOffset() const { - if (IsValid()) - return m_die->GetOffset(); - else + if (IsValid()) { + lldbassert(m_cu); + return m_die->GetOffset(m_cu); + } else return DW_INVALID_OFFSET; } dw_offset_t DWARFDIE::GetCompileUnitRelativeOffset() const { - if (IsValid()) - return m_die->GetOffset() - m_cu->GetOffset(); - else + if (IsValid()) { + return m_die->GetOffset(m_cu) - m_cu->GetOffset(); + } else return DW_INVALID_OFFSET; } Index: source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h +++ source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h @@ -30,7 +30,8 @@ void Clear() { m_aranges.Clear(); } - bool Extract(const lldb_private::DWARFDataExtractor &debug_aranges_data); + bool Extract(const lldb_private::DWARFDataExtractor &debug_aranges_data, + dw_offset_t dwz_offset); bool Generate(SymbolFileDWARF *dwarf2Data); Index: source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp @@ -48,7 +48,8 @@ //---------------------------------------------------------------------- // Extract //---------------------------------------------------------------------- -bool DWARFDebugAranges::Extract(const DWARFDataExtractor &debug_aranges_data) { +bool DWARFDebugAranges::Extract( + const DWARFDataExtractor &debug_aranges_data, dw_offset_t dwz_offset) { if (debug_aranges_data.ValidOffset(0)) { lldb::offset_t offset = 0; @@ -57,7 +58,9 @@ while (set.Extract(debug_aranges_data, &offset)) { const uint32_t num_descriptors = set.NumDescriptors(); if (num_descriptors > 0) { - const dw_offset_t cu_offset = set.GetCompileUnitDIEOffset(); + const dw_offset_t cu_file_offset = set.GetCompileUnitDIEOffset(); + + const dw_offset_t cu_offset = cu_file_offset + dwz_offset; for (uint32_t i = 0; i < num_descriptors; ++i) { const DWARFDebugArangeSet::Descriptor &descriptor = Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -29,7 +29,7 @@ typedef dw_offset_t (*Callback)(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, DWARFDebugInfoEntry *die, - const dw_offset_t next_offset, + const dw_offset_t next_file_offset, const uint32_t depth, void *userData); DWARFDebugInfo(); Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -57,7 +57,8 @@ "DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from " ".debug_aranges", m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str()); - m_cu_aranges_ap->Extract(debug_aranges_data); + dw_offset_t dwz_offset = 0; + m_cu_aranges_ap->Extract(debug_aranges_data, dwz_offset); } // Make a list of all CUs represented by the arange data in the file. @@ -97,12 +98,12 @@ void DWARFDebugInfo::ParseCompileUnitHeadersIfNeeded() { if (m_compile_units.empty()) { if (m_dwarf2Data != NULL) { - lldb::offset_t offset = 0; + lldb::offset_t file_offset = 0; DWARFUnitSP cu_sp; - while ((cu_sp = DWARFCompileUnit::Extract(m_dwarf2Data, &offset))) { + while ((cu_sp = DWARFCompileUnit::Extract(m_dwarf2Data, &file_offset))) { m_compile_units.push_back(cu_sp); - offset = cu_sp->GetNextCompileUnitOffset(); + file_offset = cu_sp->GetNextCompileUnitFileOffset(); } } } @@ -243,29 +244,33 @@ void DWARFDebugInfo::Parse(SymbolFileDWARF *dwarf2Data, Callback callback, void *userData) { if (dwarf2Data) { - lldb::offset_t offset = 0; + lldb::offset_t file_offset = 0; uint32_t depth = 0; DWARFDebugInfoEntry die; DWARFUnitSP cu; - while ((cu = DWARFCompileUnit::Extract(dwarf2Data, &offset))) { - const dw_offset_t next_cu_offset = cu->GetNextCompileUnitOffset(); + while ((cu = DWARFCompileUnit::Extract(dwarf2Data, &file_offset))) { + const dw_offset_t next_cu_file_offset = + cu->GetNextCompileUnitFileOffset(); 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.get(), NULL, offset, depth, userData); + // and get the file_offset that we are to continue to parse from + file_offset = + callback(dwarf2Data, cu.get(), NULL, file_offset, depth, userData); // Make sure we are within our compile unit - if (offset < next_cu_offset) { - // We are in our compile unit, parse starting at the offset + if (file_offset < next_cu_file_offset) { + // We are in our compile unit, parse starting at the file_offset // we were told to parse bool done = false; - while (!done && die.Extract(dwarf2Data, cu.get(), &offset)) { + while (!done && die.Extract(dwarf2Data, cu.get(), &file_offset)) { // Call the callback function with DIE pointer that falls within the // compile unit - offset = - callback(dwarf2Data, cu.get(), &die, offset, depth, userData); + file_offset = callback( + dwarf2Data, cu.get(), &die, file_offset, depth, userData); + + // Missing DWZ support: DW_TAG_imported_unit if (die.IsNULL()) { if (depth) @@ -277,24 +282,24 @@ } } - // Make sure the offset returned is valid, and if not stop parsing. + // Make sure the file_offset returned is valid, and if not stop parsing. // Returning DW_INVALID_OFFSET from this callback is a good way to end // all parsing - if (!dwarf2Data->get_debug_info_data().ValidOffset(offset)) + if (!dwarf2Data->get_debug_info_data().ValidOffset(file_offset)) break; // Make sure we start on a proper - offset = next_cu_offset; + file_offset = next_cu_file_offset; } } } typedef struct DumpInfo { DumpInfo(Stream *init_strm, uint32_t off, uint32_t depth) - : strm(init_strm), die_offset(off), recurse_depth(depth), + : strm(init_strm), die_file_offset(off), recurse_depth(depth), found_depth(UINT32_MAX), found_die(false), ancestors() {} Stream *strm; - const uint32_t die_offset; + const uint32_t die_file_offset; const uint32_t recurse_depth; uint32_t found_depth; bool found_die; @@ -315,7 +320,7 @@ //---------------------------------------------------------------------- static dw_offset_t DumpCallback(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, DWARFDebugInfoEntry *die, - const dw_offset_t next_offset, + const dw_offset_t next_file_offset, const uint32_t curr_depth, void *userData) { DumpInfo *dumpInfo = (DumpInfo *)userData; Stream *s = dumpInfo->strm; @@ -324,13 +329,13 @@ if (die) { // Are we dumping everything? - if (dumpInfo->die_offset == DW_INVALID_OFFSET) { + if (dumpInfo->die_file_offset == DW_INVALID_OFFSET) { // Yes we are dumping everything. Obey our recurse level though if (curr_depth < dumpInfo->recurse_depth) die->Dump(dwarf2Data, cu, *s, 0); } else { // We are dumping a specific DIE entry by offset - if (dumpInfo->die_offset == die->GetOffset()) { + if (dumpInfo->die_file_offset == die->GetFileOffset()) { // We found the DIE we were looking for, dump it! if (show_parents) { s->SetIndentLevel(0); @@ -365,7 +370,7 @@ if (dumpInfo->recurse_depth == UINT32_MAX || curr_depth <= dumpInfo->found_depth + dumpInfo->recurse_depth) die->Dump(dwarf2Data, cu, *s, 0); - } else if (dumpInfo->die_offset > die->GetOffset()) { + } else if (dumpInfo->die_file_offset > die->GetFileOffset()) { if (show_parents) dumpInfo->ancestors.back() = *die; } @@ -394,7 +399,7 @@ s->SetIndentLevel(0); // See if we are dumping everything? - if (dumpInfo->die_offset == DW_INVALID_OFFSET) { + if (dumpInfo->die_file_offset == DW_INVALID_OFFSET) { // We are dumping everything if (cu) { cu->Dump(s); @@ -411,15 +416,17 @@ // We are dumping only a single DIE possibly with it's children and // we must find it's compile unit before we can dump it properly - if (cu && dumpInfo->die_offset < cu->GetFirstDIEOffset()) { + if (cu && dumpInfo->die_file_offset + < cu->ThisCUUniqToFileOffset(cu->GetFirstDIEOffset())) { // Not found, maybe the DIE offset provided wasn't correct? // *ostrm_ptr << "DIE at offset " << HEX32 << dumpInfo->die_offset << " // was not found." << endl; return DW_INVALID_OFFSET; } else { // See if the DIE is in this compile unit? - if (cu && dumpInfo->die_offset < cu->GetNextCompileUnitOffset()) { - return next_offset; + if (cu && dumpInfo->die_file_offset + < cu->GetNextCompileUnitFileOffset()) { + return next_file_offset; // // We found our compile unit that contains our DIE, just skip to // dumping the requested DIE... // return dumpInfo->die_offset; @@ -436,7 +443,7 @@ } // Just return the current offset to parse the next CU or DIE entry - return next_offset; + return next_file_offset; } //---------------------------------------------------------------------- Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -56,7 +56,7 @@ typedef offset_collection::const_iterator offset_collection_const_iterator; DWARFDebugInfoEntry() - : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0), + : m_file_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0), m_empty_children(false), m_abbr_idx(0), m_has_children(false), m_tag(0) {} @@ -71,10 +71,10 @@ bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data, const DWARFUnit *cu, const DWARFFormValue::FixedFormSizes &fixed_form_sizes, - lldb::offset_t *offset_ptr); + lldb::offset_t *file_offset_ptr); bool Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - lldb::offset_t *offset_ptr); + lldb::offset_t *file_offset_ptr); bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, @@ -173,7 +173,7 @@ static void DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const lldb_private::DWARFDataExtractor &debug_info_data, - lldb::offset_t *offset_ptr, lldb_private::Stream &s, + lldb::offset_t *file_offset_ptr, lldb_private::Stream &s, dw_attr_t attr, dw_form_t form); // This one dumps the comp unit name, objfile name and die offset for this die // so the stream S. @@ -191,13 +191,15 @@ const DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - lldb::offset_t &offset) const; + lldb::offset_t &file_offset) const; dw_tag_t Tag() const { return m_tag; } bool IsNULL() const { return m_abbr_idx == 0; } - dw_offset_t GetOffset() const { return m_offset; } + dw_offset_t GetFileOffset() const { return m_file_offset; } + + dw_offset_t GetOffset(const DWARFUnit *cu) const; bool HasChildren() const { return m_has_children; } @@ -277,7 +279,7 @@ protected: dw_offset_t - m_offset; // Offset within the .debug_info of the start of this entry + m_file_offset; // Offset within the .debug_info of the start of this entry uint32_t m_parent_idx; // How many to subtract from "this" to get the parent. // If zero this die has no parent uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling. Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -36,12 +36,12 @@ bool DWARFDebugInfoEntry::FastExtract( const DWARFDataExtractor &debug_info_data, const DWARFUnit *cu, const DWARFFormValue::FixedFormSizes &fixed_form_sizes, - lldb::offset_t *offset_ptr) { - m_offset = *offset_ptr; + lldb::offset_t *file_offset_ptr) { + m_file_offset = *file_offset_ptr; m_parent_idx = 0; m_sibling_idx = 0; m_empty_children = false; - const uint64_t abbr_idx = debug_info_data.GetULEB128(offset_ptr); + const uint64_t abbr_idx = debug_info_data.GetULEB128(file_offset_ptr); assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE)); m_abbr_idx = abbr_idx; @@ -49,7 +49,7 @@ // specified! if (m_abbr_idx) { - lldb::offset_t offset = *offset_ptr; + lldb::offset_t file_offset = *file_offset_ptr; const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx); @@ -58,9 +58,9 @@ cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError( "{0x%8.8x}: invalid abbreviation code %u, please file a bug and " "attach the file at the start of this error message", - m_offset, (unsigned)abbr_idx); + m_file_offset, (unsigned)abbr_idx); // WE can't parse anymore if the DWARF is borked... - *offset_ptr = UINT32_MAX; + *file_offset_ptr = UINT32_MAX; return false; } m_tag = abbrevDecl->Tag(); @@ -74,7 +74,7 @@ const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form); if (fixed_skip_size) - offset += fixed_skip_size; + file_offset += fixed_skip_size; else { bool form_is_indirect = false; do { @@ -85,21 +85,21 @@ // inlined in the .debug_info case DW_FORM_exprloc: case DW_FORM_block: - form_size = debug_info_data.GetULEB128(&offset); + form_size = debug_info_data.GetULEB128(&file_offset); break; case DW_FORM_block1: - form_size = debug_info_data.GetU8_unchecked(&offset); + form_size = debug_info_data.GetU8_unchecked(&file_offset); break; case DW_FORM_block2: - form_size = debug_info_data.GetU16_unchecked(&offset); + form_size = debug_info_data.GetU16_unchecked(&file_offset); break; case DW_FORM_block4: - form_size = debug_info_data.GetU32_unchecked(&offset); + form_size = debug_info_data.GetU32_unchecked(&file_offset); break; // Inlined NULL terminated C-strings case DW_FORM_string: - debug_info_data.GetCStr(&offset); + debug_info_data.GetCStr(&file_offset); break; // Compile unit address sized values @@ -150,32 +150,32 @@ case DW_FORM_ref_udata: case DW_FORM_GNU_addr_index: case DW_FORM_GNU_str_index: - debug_info_data.Skip_LEB128(&offset); + debug_info_data.Skip_LEB128(&file_offset); break; case DW_FORM_indirect: form_is_indirect = true; - form = debug_info_data.GetULEB128(&offset); + form = debug_info_data.GetULEB128(&file_offset); break; case DW_FORM_strp: case DW_FORM_sec_offset: if (cu->IsDWARF64()) - debug_info_data.GetU64(&offset); + debug_info_data.GetU64(&file_offset); else - debug_info_data.GetU32(&offset); + debug_info_data.GetU32(&file_offset); break; default: - *offset_ptr = m_offset; + *file_offset_ptr = m_file_offset; return false; } - offset += form_size; + file_offset += form_size; } while (form_is_indirect); } } - *offset_ptr = offset; + *file_offset_ptr = file_offset; return true; } else { m_tag = 0; @@ -195,19 +195,20 @@ //---------------------------------------------------------------------- bool DWARFDebugInfoEntry::Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - lldb::offset_t *offset_ptr) { + lldb::offset_t *file_offset_ptr) { const DWARFDataExtractor &debug_info_data = dwarf2Data->get_debug_info_data(); // const DWARFDataExtractor& debug_str_data = // dwarf2Data->get_debug_str_data(); const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset(); - lldb::offset_t offset = *offset_ptr; - // if (offset >= cu_end_offset) + lldb::offset_t file_offset = *file_offset_ptr; + // if (cu->ThisCUFileOffsetToUniq(file_offset) >= cu_end_offset) // Log::Status("DIE at offset 0x%8.8x is beyond the end of the current // compile unit (0x%8.8x)", m_offset, cu_end_offset); - if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset)) { - m_offset = offset; + if ((cu->ThisCUFileOffsetToUniq(file_offset) < cu_end_offset) + && debug_info_data.ValidOffset(file_offset)) { + m_file_offset = file_offset; - const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset); + const uint64_t abbr_idx = debug_info_data.GetULEB128(&file_offset); assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE)); m_abbr_idx = abbr_idx; if (abbr_idx) { @@ -233,7 +234,7 @@ if (isCompileUnitTag && ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) { DWARFFormValue form_value(cu, form); - if (form_value.ExtractValue(debug_info_data, &offset)) { + if (form_value.ExtractValue(debug_info_data, &file_offset)) { if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc) const_cast(cu)->SetBaseAddress( form_value.Address()); @@ -249,21 +250,21 @@ // inlined in the .debug_info case DW_FORM_exprloc: case DW_FORM_block: - form_size = debug_info_data.GetULEB128(&offset); + form_size = debug_info_data.GetULEB128(&file_offset); break; case DW_FORM_block1: - form_size = debug_info_data.GetU8(&offset); + form_size = debug_info_data.GetU8(&file_offset); break; case DW_FORM_block2: - form_size = debug_info_data.GetU16(&offset); + form_size = debug_info_data.GetU16(&file_offset); break; case DW_FORM_block4: - form_size = debug_info_data.GetU32(&offset); + form_size = debug_info_data.GetU32(&file_offset); break; // Inlined NULL terminated C-strings case DW_FORM_string: - debug_info_data.GetCStr(&offset); + debug_info_data.GetCStr(&file_offset); break; // Compile unit address sized values @@ -314,38 +315,38 @@ case DW_FORM_ref_udata: case DW_FORM_GNU_addr_index: case DW_FORM_GNU_str_index: - debug_info_data.Skip_LEB128(&offset); + debug_info_data.Skip_LEB128(&file_offset); break; case DW_FORM_indirect: - form = debug_info_data.GetULEB128(&offset); + form = debug_info_data.GetULEB128(&file_offset); form_is_indirect = true; break; case DW_FORM_strp: case DW_FORM_sec_offset: if (cu->IsDWARF64()) - debug_info_data.GetU64(&offset); + debug_info_data.GetU64(&file_offset); else - debug_info_data.GetU32(&offset); + debug_info_data.GetU32(&file_offset); break; default: - *offset_ptr = offset; + *file_offset_ptr = file_offset; return false; } - offset += form_size; + file_offset += form_size; } while (form_is_indirect); } } - *offset_ptr = offset; + *file_offset_ptr = file_offset; return true; } } else { m_tag = 0; m_has_children = false; - *offset_ptr = offset; + *file_offset_ptr = file_offset; return true; // NULL debug tag entry } } @@ -397,9 +398,9 @@ std::vector die_refs; bool set_frame_base_loclist_addr = false; - lldb::offset_t offset; + lldb::offset_t file_offset; const DWARFAbbreviationDeclaration *abbrevDecl = - GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + GetAbbreviationDeclarationPtr(dwarf2Data, cu, file_offset); lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule(); @@ -407,7 +408,7 @@ const DWARFDataExtractor &debug_info_data = dwarf2Data->get_debug_info_data(); - if (!debug_info_data.ValidOffset(offset)) + if (!debug_info_data.ValidOffset(file_offset)) return false; const uint32_t numAttributes = abbrevDecl->NumAttributes(); @@ -419,7 +420,7 @@ for (i = 0; i < numAttributes; ++i) { abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form); DWARFFormValue form_value(cu, form); - if (form_value.ExtractValue(debug_info_data, &offset)) { + if (form_value.ExtractValue(debug_info_data, &file_offset)) { switch (attr) { case DW_AT_low_pc: lo_pc = form_value.Address(); @@ -460,7 +461,7 @@ "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug " "and attach the file at the start of this error message", - m_offset, form_value.Unsigned()); + m_file_offset, form_value.Unsigned()); } } break; @@ -589,12 +590,12 @@ const DWARFUnit *cu, Stream &s, uint32_t recurse_depth) const { const DWARFDataExtractor &debug_info_data = dwarf2Data->get_debug_info_data(); - lldb::offset_t offset = m_offset; + lldb::offset_t file_offset = m_file_offset; - if (debug_info_data.ValidOffset(offset)) { - dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset); + if (debug_info_data.ValidOffset(file_offset)) { + dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&file_offset); - s.Printf("\n0x%8.8x: ", m_offset); + s.Printf("\n0x%8.8x: ", m_file_offset); s.Indent(); if (abbrCode != m_abbr_idx) { s.Printf("error: DWARF has been modified\n"); @@ -614,7 +615,7 @@ for (i = 0; i < numAttributes; ++i) { abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form); - DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, + DumpAttribute(dwarf2Data, cu, debug_info_data, &file_offset, s, attr, form); } @@ -651,7 +652,8 @@ obj_file->GetFileSpec().GetFilename().AsCString(""); const char *die_name = GetName(dwarf2Data, cu); s.Printf("0x%8.8x/0x%8.8x: %-30s (from %s in %s)", cu->GetOffset(), - GetOffset(), die_name ? die_name : "", cu_name ? cu_name : "", + GetFileOffset(), die_name ? die_name : "", + cu_name ? cu_name : "", obj_file_name ? obj_file_name : ""); } @@ -664,7 +666,7 @@ //---------------------------------------------------------------------- void DWARFDebugInfoEntry::DumpAttribute( SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr, + const DWARFDataExtractor &debug_info_data, lldb::offset_t *file_offset_ptr, Stream &s, dw_attr_t attr, dw_form_t form) { bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm); @@ -677,7 +679,7 @@ DWARFFormValue form_value(cu, form); - if (!form_value.ExtractValue(debug_info_data, offset_ptr)) + if (!form_value.ExtractValue(debug_info_data, file_offset_ptr)) return; if (show_form) { @@ -710,9 +712,9 @@ const uint8_t *blockData = form_value.BlockData(); if (blockData) { // Location description is inlined in data in the form value - DWARFDataExtractor locationData(debug_info_data, - (*offset_ptr) - form_value.Unsigned(), - form_value.Unsigned()); + DWARFDataExtractor locationData( + debug_info_data, (*file_offset_ptr) - form_value.Unsigned(), + form_value.Unsigned()); DWARFExpression::PrintDWARFExpression( s, locationData, DWARFUnit::GetAddressByteSize(cu), 4, false); } else { @@ -768,7 +770,7 @@ DWARFAttributes &attributes, uint32_t curr_depth) const { SymbolFileDWARF *dwarf2Data = nullptr; const DWARFAbbreviationDeclaration *abbrevDecl = nullptr; - lldb::offset_t offset = 0; + lldb::offset_t file_offset = 0; if (cu) { if (m_tag != DW_TAG_compile_unit) { SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile(); @@ -778,7 +780,7 @@ } dwarf2Data = cu->GetSymbolFileDWARF(); - abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, file_offset); } if (abbrevDecl) { @@ -810,13 +812,14 @@ } LLVM_FALLTHROUGH; default: - attributes.Append(cu, offset, attr, form); + attributes.Append( + cu, cu->ThisCUFileOffsetToUniq(file_offset), attr, form); break; } if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) { DWARFFormValue form_value(cu, form); - if (form_value.ExtractValue(debug_info_data, &offset)) { + if (form_value.ExtractValue(debug_info_data, &file_offset)) { dw_offset_t die_offset = form_value.Reference(); DWARFDIE spec_die = const_cast(cu)->GetDIE(die_offset); @@ -826,9 +829,9 @@ } else { const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form); if (fixed_skip_size) - offset += fixed_skip_size; + file_offset += fixed_skip_size; else - DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu); + DWARFFormValue::SkipValue(form, debug_info_data, &file_offset, cu); } } } else { @@ -856,9 +859,9 @@ attr, form_value, end_attr_offset_ptr, check_specification_or_abstract_origin); - lldb::offset_t offset; + lldb::offset_t file_offset; const DWARFAbbreviationDeclaration *abbrevDecl = - GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + GetAbbreviationDeclarationPtr(dwarf2Data, cu, file_offset); if (abbrevDecl) { uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr); @@ -870,14 +873,14 @@ uint32_t idx = 0; while (idx < attr_idx) DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), - debug_info_data, &offset, cu); + debug_info_data, &file_offset, cu); - const dw_offset_t attr_offset = offset; + const dw_offset_t attr_offset = file_offset; form_value.SetCompileUnit(cu); form_value.SetForm(abbrevDecl->GetFormByIndex(idx)); - if (form_value.ExtractValue(debug_info_data, &offset)) { + if (form_value.ExtractValue(debug_info_data, &file_offset)) { if (end_attr_offset_ptr) - *end_attr_offset_ptr = offset; + *end_attr_offset_ptr = file_offset; return attr_offset; } } @@ -1199,8 +1202,8 @@ } DWARFDebugInfoEntry die; - lldb::offset_t offset = die_offset; - if (die.Extract(dwarf2Data, cu, &offset)) { + lldb::offset_t file_offset = cu->ThisCUUniqToFileOffset(die_offset); + if (die.Extract(dwarf2Data, cu, &file_offset)) { if (die.IsNULL()) { s.PutCString("NULL"); return true; @@ -1211,7 +1214,7 @@ else { bool result = true; const DWARFAbbreviationDeclaration *abbrevDecl = - die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset); + die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, file_offset); if (abbrevDecl == NULL) return false; @@ -1359,7 +1362,7 @@ LLDB_INVALID_ADDRESS)) { // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - // 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY - debug_aranges->AppendRange(GetOffset(), lo_pc, hi_pc); + debug_aranges->AppendRange(GetOffset(cu), lo_pc, hi_pc); } } @@ -1773,9 +1776,9 @@ const DWARFAbbreviationDeclaration * DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr( SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, - lldb::offset_t &offset) const { + lldb::offset_t &file_offset) const { if (dwarf2Data) { - offset = GetOffset(); + file_offset = GetFileOffset(); const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations(); if (abbrev_set) { @@ -1786,7 +1789,7 @@ // the DWARF data was mmap'ed, the backing file might have been modified // which is bad news. const uint64_t abbrev_code = - dwarf2Data->get_debug_info_data().GetULEB128(&offset); + dwarf2Data->get_debug_info_data().GetULEB128(&file_offset); if (abbrev_decl->Code() == abbrev_code) return abbrev_decl; @@ -1794,17 +1797,18 @@ dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected( "0x%8.8x: the DWARF debug information has been modified (abbrev " "code was %u, and is now %u)", - GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code); + GetFileOffset(), (uint32_t)abbrev_decl->Code(), + (uint32_t)abbrev_code); } } } - offset = DW_INVALID_OFFSET; + file_offset = DW_INVALID_OFFSET; return NULL; } bool DWARFDebugInfoEntry::OffsetLessThan(const DWARFDebugInfoEntry &a, const DWARFDebugInfoEntry &b) { - return a.GetOffset() < b.GetOffset(); + return a.GetFileOffset() < b.GetFileOffset(); } void DWARFDebugInfoEntry::DumpDIECollection( @@ -1818,10 +1822,14 @@ const DWARFDebugInfoEntry *p = die_ref.GetParent(); const DWARFDebugInfoEntry *s = die_ref.GetSibling(); const DWARFDebugInfoEntry *c = die_ref.GetFirstChild(); - strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetOffset(), - p ? p->GetOffset() : 0, s ? s->GetOffset() : 0, - c ? c->GetOffset() : 0, die_ref.Tag(), + strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetFileOffset(), + p ? p->GetFileOffset() : 0, s ? s->GetFileOffset() : 0, + c ? c->GetFileOffset() : 0, die_ref.Tag(), DW_TAG_value_to_name(die_ref.Tag()), die_ref.HasChildren() ? " *" : ""); } } + +dw_offset_t DWARFDebugInfoEntry::GetOffset(const DWARFUnit *cu) const { + return cu->ThisCUFileOffsetToUniq(m_file_offset); +} Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFFormValue.h +++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.h @@ -63,8 +63,9 @@ const ValueType &Value() const { return m_value; } void Dump(lldb_private::Stream &s) const; bool ExtractValue(const lldb_private::DWARFDataExtractor &data, - lldb::offset_t *offset_ptr); + lldb::offset_t *file_offset_ptr); const uint8_t *BlockData() const; + uint64_t ReferenceInFile() const; uint64_t Reference() const; uint64_t Reference(dw_offset_t offset) const; bool Boolean() const { return m_value.value.uval != 0; } @@ -76,10 +77,10 @@ dw_addr_t Address() const; bool IsValid() const { return m_form != 0; } bool SkipValue(const lldb_private::DWARFDataExtractor &debug_info_data, - lldb::offset_t *offset_ptr) const; + lldb::offset_t *file_offset_ptr) const; static bool SkipValue(const dw_form_t form, const lldb_private::DWARFDataExtractor &debug_info_data, - lldb::offset_t *offset_ptr, const DWARFUnit *cu); + lldb::offset_t *file_offset_ptr, const DWARFUnit *cu); static bool IsBlockForm(const dw_form_t form); static bool IsDataForm(const dw_form_t form); static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size, Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp @@ -164,7 +164,7 @@ } bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data, - lldb::offset_t *offset_ptr) { + lldb::offset_t *file_offset_ptr) { bool indirect = false; bool is_block = false; m_value.data = NULL; @@ -177,54 +177,54 @@ case DW_FORM_addr: assert(m_cu); m_value.value.uval = data.GetMaxU64( - offset_ptr, DWARFUnit::GetAddressByteSize(m_cu)); + file_offset_ptr, DWARFUnit::GetAddressByteSize(m_cu)); break; case DW_FORM_block2: - m_value.value.uval = data.GetU16(offset_ptr); + m_value.value.uval = data.GetU16(file_offset_ptr); is_block = true; break; case DW_FORM_block4: - m_value.value.uval = data.GetU32(offset_ptr); + m_value.value.uval = data.GetU32(file_offset_ptr); is_block = true; break; case DW_FORM_data2: - m_value.value.uval = data.GetU16(offset_ptr); + m_value.value.uval = data.GetU16(file_offset_ptr); break; case DW_FORM_data4: - m_value.value.uval = data.GetU32(offset_ptr); + m_value.value.uval = data.GetU32(file_offset_ptr); break; case DW_FORM_data8: - m_value.value.uval = data.GetU64(offset_ptr); + m_value.value.uval = data.GetU64(file_offset_ptr); break; case DW_FORM_string: - m_value.value.cstr = data.GetCStr(offset_ptr); + m_value.value.cstr = data.GetCStr(file_offset_ptr); break; case DW_FORM_exprloc: case DW_FORM_block: - m_value.value.uval = data.GetULEB128(offset_ptr); + m_value.value.uval = data.GetULEB128(file_offset_ptr); is_block = true; break; case DW_FORM_block1: - m_value.value.uval = data.GetU8(offset_ptr); + m_value.value.uval = data.GetU8(file_offset_ptr); is_block = true; break; case DW_FORM_data1: - m_value.value.uval = data.GetU8(offset_ptr); + m_value.value.uval = data.GetU8(file_offset_ptr); break; case DW_FORM_flag: - m_value.value.uval = data.GetU8(offset_ptr); + m_value.value.uval = data.GetU8(file_offset_ptr); break; case DW_FORM_sdata: - m_value.value.sval = data.GetSLEB128(offset_ptr); + m_value.value.sval = data.GetSLEB128(file_offset_ptr); break; case DW_FORM_strp: assert(m_cu); m_value.value.uval = - data.GetMaxU64(offset_ptr, DWARFUnit::IsDWARF64(m_cu) ? 8 : 4); + data.GetMaxU64(file_offset_ptr, DWARFUnit::IsDWARF64(m_cu) ? 8 : 4); break; // case DW_FORM_APPLE_db_str: case DW_FORM_udata: - m_value.value.uval = data.GetULEB128(offset_ptr); + m_value.value.uval = data.GetULEB128(file_offset_ptr); break; case DW_FORM_ref_addr: assert(m_cu); @@ -233,44 +233,44 @@ ref_addr_size = m_cu->GetAddressByteSize(); else ref_addr_size = m_cu->IsDWARF64() ? 8 : 4; - m_value.value.uval = data.GetMaxU64(offset_ptr, ref_addr_size); + m_value.value.uval = data.GetMaxU64(file_offset_ptr, ref_addr_size); break; case DW_FORM_ref1: - m_value.value.uval = data.GetU8(offset_ptr); + m_value.value.uval = data.GetU8(file_offset_ptr); break; case DW_FORM_ref2: - m_value.value.uval = data.GetU16(offset_ptr); + m_value.value.uval = data.GetU16(file_offset_ptr); break; case DW_FORM_ref4: - m_value.value.uval = data.GetU32(offset_ptr); + m_value.value.uval = data.GetU32(file_offset_ptr); break; case DW_FORM_ref8: - m_value.value.uval = data.GetU64(offset_ptr); + m_value.value.uval = data.GetU64(file_offset_ptr); break; case DW_FORM_ref_udata: - m_value.value.uval = data.GetULEB128(offset_ptr); + m_value.value.uval = data.GetULEB128(file_offset_ptr); break; case DW_FORM_indirect: - m_form = data.GetULEB128(offset_ptr); + m_form = data.GetULEB128(file_offset_ptr); indirect = true; break; case DW_FORM_sec_offset: assert(m_cu); m_value.value.uval = - data.GetMaxU64(offset_ptr, DWARFUnit::IsDWARF64(m_cu) ? 8 : 4); + data.GetMaxU64(file_offset_ptr, DWARFUnit::IsDWARF64(m_cu) ? 8 : 4); break; case DW_FORM_flag_present: m_value.value.uval = 1; break; case DW_FORM_ref_sig8: - m_value.value.uval = data.GetU64(offset_ptr); + m_value.value.uval = data.GetU64(file_offset_ptr); break; case DW_FORM_GNU_str_index: - m_value.value.uval = data.GetULEB128(offset_ptr); + m_value.value.uval = data.GetULEB128(file_offset_ptr); break; case DW_FORM_GNU_addr_index: - m_value.value.uval = data.GetULEB128(offset_ptr); + m_value.value.uval = data.GetULEB128(file_offset_ptr); break; default: return false; @@ -279,9 +279,9 @@ } while (indirect); if (is_block) { - m_value.data = data.PeekData(*offset_ptr, m_value.value.uval); + m_value.data = data.PeekData(*file_offset_ptr, m_value.value.uval); if (m_value.data != NULL) { - *offset_ptr += m_value.value.uval; + *file_offset_ptr += m_value.value.uval; } } @@ -289,13 +289,14 @@ } bool DWARFFormValue::SkipValue(const DWARFDataExtractor &debug_info_data, - lldb::offset_t *offset_ptr) const { - return DWARFFormValue::SkipValue(m_form, debug_info_data, offset_ptr, m_cu); + lldb::offset_t *file_offset_ptr) const { + return DWARFFormValue::SkipValue( + m_form, debug_info_data, file_offset_ptr, m_cu); } bool DWARFFormValue::SkipValue(dw_form_t form, const DWARFDataExtractor &debug_info_data, - lldb::offset_t *offset_ptr, + lldb::offset_t *file_offset_ptr, const DWARFUnit *cu) { uint8_t ref_addr_size; switch (form) { @@ -303,34 +304,34 @@ // inlined in the .debug_info case DW_FORM_exprloc: case DW_FORM_block: { - dw_uleb128_t size = debug_info_data.GetULEB128(offset_ptr); - *offset_ptr += size; + dw_uleb128_t size = debug_info_data.GetULEB128(file_offset_ptr); + *file_offset_ptr += size; } return true; case DW_FORM_block1: { - dw_uleb128_t size = debug_info_data.GetU8(offset_ptr); - *offset_ptr += size; + dw_uleb128_t size = debug_info_data.GetU8(file_offset_ptr); + *file_offset_ptr += size; } return true; case DW_FORM_block2: { - dw_uleb128_t size = debug_info_data.GetU16(offset_ptr); - *offset_ptr += size; + dw_uleb128_t size = debug_info_data.GetU16(file_offset_ptr); + *file_offset_ptr += size; } return true; case DW_FORM_block4: { - dw_uleb128_t size = debug_info_data.GetU32(offset_ptr); - *offset_ptr += size; + dw_uleb128_t size = debug_info_data.GetU32(file_offset_ptr); + *file_offset_ptr += size; } return true; // Inlined NULL terminated C-strings case DW_FORM_string: - debug_info_data.GetCStr(offset_ptr); + debug_info_data.GetCStr(file_offset_ptr); return true; // Compile unit address sized values case DW_FORM_addr: - *offset_ptr += DWARFUnit::GetAddressByteSize(cu); + *file_offset_ptr += DWARFUnit::GetAddressByteSize(cu); return true; case DW_FORM_ref_addr: @@ -341,7 +342,7 @@ ref_addr_size = cu->GetAddressByteSize(); else ref_addr_size = cu->IsDWARF64() ? 8 : 4; - *offset_ptr += ref_addr_size; + *file_offset_ptr += ref_addr_size; return true; // 0 bytes values (implied from DW_FORM) @@ -352,33 +353,33 @@ case DW_FORM_data1: case DW_FORM_flag: case DW_FORM_ref1: - *offset_ptr += 1; + *file_offset_ptr += 1; return true; // 2 byte values case DW_FORM_data2: case DW_FORM_ref2: - *offset_ptr += 2; + *file_offset_ptr += 2; return true; // 32 bit for DWARF 32, 64 for DWARF 64 case DW_FORM_sec_offset: case DW_FORM_strp: assert(cu); - *offset_ptr += (cu->IsDWARF64() ? 8 : 4); + *file_offset_ptr += (cu->IsDWARF64() ? 8 : 4); return true; // 4 byte values case DW_FORM_data4: case DW_FORM_ref4: - *offset_ptr += 4; + *file_offset_ptr += 4; return true; // 8 byte values case DW_FORM_data8: case DW_FORM_ref8: case DW_FORM_ref_sig8: - *offset_ptr += 8; + *file_offset_ptr += 8; return true; // signed or unsigned LEB 128 values @@ -387,13 +388,13 @@ case DW_FORM_ref_udata: case DW_FORM_GNU_addr_index: case DW_FORM_GNU_str_index: - debug_info_data.Skip_LEB128(offset_ptr); + debug_info_data.Skip_LEB128(file_offset_ptr); return true; case DW_FORM_indirect: { - dw_form_t indirect_form = debug_info_data.GetULEB128(offset_ptr); - return DWARFFormValue::SkipValue(indirect_form, debug_info_data, offset_ptr, - cu); + dw_form_t indirect_form = debug_info_data.GetULEB128(file_offset_ptr); + return DWARFFormValue::SkipValue(indirect_form, debug_info_data, + file_offset_ptr, cu); } default: @@ -567,8 +568,8 @@ return symbol_file->get_debug_addr_data().GetMaxU64(&offset, index_size); } -uint64_t DWARFFormValue::Reference() const { - uint64_t die_offset = m_value.value.uval; +uint64_t DWARFFormValue::ReferenceInFile() const { + uint64_t die_file_offset = m_value.value.uval; switch (m_form) { case DW_FORM_ref1: case DW_FORM_ref2: @@ -577,14 +578,19 @@ case DW_FORM_ref_udata: assert(m_cu); // CU must be valid for DW_FORM_ref forms that are compile // unit relative or we will get this wrong - die_offset += m_cu->GetOffset(); + die_file_offset += m_cu->GetFileOffset(); break; default: break; } - return die_offset; + return die_file_offset; +} + +uint64_t DWARFFormValue::Reference() const { + uint64_t file = ReferenceInFile(); + return m_cu->FileOffsetToUniqOffset(file); } uint64_t DWARFFormValue::Reference(dw_offset_t base_offset) const { Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -13,6 +13,7 @@ #include "DWARFDIE.h" #include "DWARFDebugInfoEntry.h" #include "lldb/lldb-enumerations.h" +#include "lldb/Utility/LLDBAssert.h" class DWARFUnit; class DWARFCompileUnit; @@ -133,6 +134,23 @@ dw_offset_t GetBaseObjOffset() const; + dw_offset_t GetFileOffset() const; + + dw_offset_t ThisCUFileOffsetToUniq_nocheck(dw_offset_t file) const { + return file + (GetOffset() - GetFileOffset()); + } + dw_offset_t ThisCUFileOffsetToUniq(dw_offset_t file) const { + dw_offset_t uniq = ThisCUFileOffsetToUniq_nocheck(file); + lldbassert(ContainsDIEOffset(uniq)); + return uniq; + } + dw_offset_t FileOffsetToUniqOffset(dw_offset_t file) const; + dw_offset_t ThisCUUniqToFileOffset(dw_offset_t uniq) const; + bool ContainsFileOffset(dw_offset_t file) const { + return ContainsDIEOffset(ThisCUFileOffsetToUniq_nocheck(file)); + } + dw_offset_t GetNextCompileUnitFileOffset() const; + protected: virtual DWARFCompileUnit &Data() = 0; virtual const DWARFCompileUnit &Data() const = 0; Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -128,9 +128,9 @@ //---------------------------------------------------------------------- // Compare function DWARFDebugAranges::Range structures //---------------------------------------------------------------------- -static bool CompareDIEOffset(const DWARFDebugInfoEntry &die, - const dw_offset_t die_offset) { - return die.GetOffset() < die_offset; +static bool CompareDIEFileOffset(const DWARFDebugInfoEntry &die, + const dw_offset_t die_file_offset) { + return die.GetFileOffset() < die_file_offset; } //---------------------------------------------------------------------- @@ -149,11 +149,13 @@ if (ContainsDIEOffset(die_offset)) { ExtractDIEsIfNeeded(false); + dw_offset_t die_file_offset = ThisCUUniqToFileOffset(die_offset); DWARFDebugInfoEntry::iterator end = Data().m_die_array.end(); DWARFDebugInfoEntry::iterator pos = lower_bound( - Data().m_die_array.begin(), end, die_offset, CompareDIEOffset); + Data().m_die_array.begin(), end, die_file_offset, + CompareDIEFileOffset); if (pos != end) { - if (die_offset == (*pos).GetOffset()) + if (die_file_offset == (*pos).GetFileOffset()) return DWARFDIE(this, &(*pos)); } } else { @@ -273,6 +275,25 @@ return Data().m_base_obj_offset; } +dw_offset_t DWARFUnit::GetFileOffset() const { + return Data().GetFileOffset(); +} + +dw_offset_t DWARFUnit::FileOffsetToUniqOffset(dw_offset_t file) const { + return static_cast(this) + ->MainCU_FileOffsetToUniqOffset(file); +} + +dw_offset_t DWARFUnit::ThisCUUniqToFileOffset(dw_offset_t uniq) const { + lldbassert(Data().m_length == 0 || ContainsDIEOffset(uniq)); + return uniq - (GetOffset() - GetFileOffset()); +} + +dw_offset_t DWARFUnit::GetNextCompileUnitFileOffset() const { + lldbassert(&Data() == this); + return Data().GetNextCompileUnitFileOffset(); +} + const DWARFDebugInfoEntry *DWARFUnit::GetCompileUnitDIEPtrOnly() { return Data().GetCompileUnitDIEPtrOnly(); } @@ -485,20 +506,20 @@ objc_method.GetFullNameWithoutCategory(true)); ConstString objc_class_name_no_category(objc_method.GetClassName()); func_fullnames.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (objc_class_name_with_category) objc_class_selectors.Insert(objc_class_name_with_category, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); 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, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (objc_selector_name) func_selectors.Insert(objc_selector_name, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (objc_fullname_no_category_name) func_fullnames.Insert(objc_fullname_no_category_name, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } // If we have a mangled name, then the DW_AT_name attribute // is usually the method name without the class or any parameters @@ -522,14 +543,14 @@ if (is_method) func_methods.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); else func_basenames.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (!is_method && !mangled_cstr && !objc_method.IsValid(true)) func_fullnames.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry @@ -541,11 +562,11 @@ (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled(ConstString(mangled_cstr), true); func_fullnames.Insert(mangled.GetMangledName(), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) func_fullnames.Insert(demangled, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } } } @@ -555,7 +576,7 @@ if (has_address) { if (name) func_basenames.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry // as our name. If it starts with '_', then it is ok, else compare @@ -566,15 +587,15 @@ (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled(ConstString(mangled_cstr), true); func_fullnames.Insert(mangled.GetMangledName(), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) func_fullnames.Insert(demangled, - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } } else func_fullnames.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } break; @@ -590,21 +611,23 @@ case DW_TAG_union_type: case DW_TAG_unspecified_type: if (name && !is_declaration) - types.Insert(ConstString(name), DIERef(cu_offset, die.GetOffset())); + types.Insert(ConstString(name), + DIERef(cu_offset, die.GetOffset(dwarf_cu))); if (mangled_cstr && !is_declaration) types.Insert(ConstString(mangled_cstr), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); break; case DW_TAG_namespace: if (name) namespaces.Insert(ConstString(name), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); break; case DW_TAG_variable: if (name && has_location_or_const_value && is_global_or_static_variable) { - globals.Insert(ConstString(name), DIERef(cu_offset, die.GetOffset())); + globals.Insert(ConstString(name), + DIERef(cu_offset, die.GetOffset(dwarf_cu))); // 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 @@ -618,10 +641,11 @@ ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { Mangled mangled(ConstString(mangled_cstr), true); globals.Insert(mangled.GetMangledName(), - DIERef(cu_offset, die.GetOffset())); + DIERef(cu_offset, die.GetOffset(dwarf_cu))); ConstString demangled = mangled.GetDemangledName(cu_language); if (demangled) - globals.Insert(demangled, DIERef(cu_offset, die.GetOffset())); + globals.Insert(demangled, + DIERef(cu_offset, die.GetOffset(dwarf_cu))); } } break; Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3810,7 +3810,8 @@ DWARFFormValue::GetFixedFormSizesForAddressSize( attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); - uint32_t data_offset = attributes.DIEOffsetAtIndex(i); + uint32_t data_file_offset = die.GetCU() + ->ThisCUUniqToFileOffset(attributes.DIEOffsetAtIndex(i)); uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); if (data_length == 0) { @@ -3823,8 +3824,8 @@ const_value = form_value; } } else - location.CopyOpcodeData(module, debug_info_data, data_offset, - data_length); + location.CopyOpcodeData(module, debug_info_data, + data_file_offset, data_length); } else { // Retrieve the value as a string expression. if (form_value.Form() == DW_FORM_strp) { @@ -3833,11 +3834,12 @@ attributes.CompileUnitAtIndex(i) ->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); - uint32_t data_offset = attributes.DIEOffsetAtIndex(i); + uint32_t data_file_offset = die.GetCU() + ->ThisCUUniqToFileOffset(attributes.DIEOffsetAtIndex(i)); uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form()); - location.CopyOpcodeData(module, debug_info_data, data_offset, - data_length); + location.CopyOpcodeData(module, debug_info_data, + data_file_offset, data_length); } else { const char *str = form_value.AsCString(); uint32_t string_offset =