Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -22,6 +22,7 @@ DWARFFormValue.cpp DWARFLocationDescription.cpp DWARFLocationList.cpp + HashedNameToDIE.cpp LogChannelDWARF.cpp NameToDIE.cpp SymbolFileDWARF.cpp Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -106,9 +106,6 @@ DWARFDIE GetDIE (dw_offset_t die_offset); - DWARFDIE - GetDIEContainingOffset (dw_offset_t die_offset); - static uint8_t GetAddressByteSize(const DWARFCompileUnit* cu); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -569,46 +569,6 @@ return DWARFDIE(); // Not found } -//---------------------------------------------------------------------- -// GetDIEPtrContainingOffset() -// -// Get the DIE (Debug Information Entry) that contains the specified -// .debug_info offset. -//---------------------------------------------------------------------- -DWARFDIE -DWARFCompileUnit::GetDIEContainingOffset(dw_offset_t die_offset) -{ - if (die_offset != DW_INVALID_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); - if (pos != end) - { - if (die_offset >= (*pos).GetOffset()) - { - DWARFDebugInfoEntry::iterator next = pos + 1; - if (next != end) - { - if (die_offset < (*next).GetOffset()) - return DWARFDIE(this, &(*pos)); - } - } - } - } - else - { - return m_dwarf2Data->DebugInfo()->GetDIEContainingOffset (die_offset); - } - } - return DWARFDIE(); // Not found -} - - - size_t DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& dies, uint32_t depth) const { Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -295,17 +295,6 @@ return DWARFDIE(); // Not found } -DWARFDIE -DWARFDebugInfo::GetDIEContainingOffset (dw_offset_t die_offset) -{ - DWARFCompileUnit *cu = GetCompileUnitContainingDIE(die_offset); - if (cu) - return cu->GetDIEContainingOffset (die_offset); - - return DWARFDIE(); // Not found - -} - //---------------------------------------------------------------------- // Parse // Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -57,23 +57,6 @@ typedef offset_collection::iterator offset_collection_iterator; typedef offset_collection::const_iterator offset_collection_const_iterator; - struct CompareState - { - CompareState() : - die_offset_pairs() - { - assert(sizeof(dw_offset_t)*2 == sizeof(uint64_t)); - } - - bool AddTypePair(dw_offset_t a, dw_offset_t b) - { - uint64_t a_b_offsets = (uint64_t)a << 32 | (uint64_t)b; - // Return true if this type was inserted, false otherwise - return die_offset_pairs.insert(a_b_offsets).second; - } - std::set< uint64_t > die_offset_pairs; - }; - DWARFDebugInfoEntry(): m_offset (DW_INVALID_OFFSET), m_parent_idx (0), @@ -225,22 +208,6 @@ const DWARFAttributes& attributes, std::string &storage) const; -// static int Compare( -// SymbolFileDWARF* dwarf2Data, -// dw_offset_t a_die_offset, -// dw_offset_t b_die_offset, -// CompareState &compare_state, -// bool compare_siblings, -// bool compare_children); -// -// static int Compare( -// SymbolFileDWARF* dwarf2Data, -// DWARFCompileUnit* a_cu, const DWARFDebugInfoEntry* a_die, -// DWARFCompileUnit* b_cu, const DWARFDebugInfoEntry* b_die, -// CompareState &compare_state, -// bool compare_siblings, -// bool compare_children); - static bool OffsetLessThan ( const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h @@ -12,134 +12,36 @@ #include -#include "DWARFDefines.h" -#include "DWARFFormValue.h" - #include "lldb/lldb-defines.h" #include "lldb/Core/dwarf.h" #include "lldb/Core/RegularExpression.h" #include "lldb/Core/MappedHash.h" -struct DWARFMappedHash -{ - struct DIEInfo - { - dw_offset_t offset; // The DIE offset - dw_tag_t tag; - uint32_t type_flags; // Any flags for this DIEInfo - uint32_t qualified_name_hash; // A 32 bit hash of the fully qualified name - - DIEInfo () : - offset (DW_INVALID_OFFSET), - tag (0), - type_flags (0), - qualified_name_hash (0) - { - } - - DIEInfo (dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h) : - offset(o), - tag (t), - type_flags (f), - qualified_name_hash (h) - { - } - - void - Clear() - { - offset = DW_INVALID_OFFSET; - tag = 0; - type_flags = 0; - qualified_name_hash = 0; - } - }; - - typedef std::vector DIEInfoArray; - typedef std::vector DIEArray; - - static void - ExtractDIEArray (const DIEInfoArray &die_info_array, - DIEArray &die_offsets) - { - const size_t count = die_info_array.size(); - for (size_t i=0; i::iterator" would have a name of "iterator" // and a 32 bit hash for "std::vector::iterator" to allow us to not have to pull // in debug info for a type when we know the fully qualified name. }; - + // Bit definitions for the eAtomTypeTypeFlags flags enum TypeFlags { @@ -147,719 +49,172 @@ // @implementation for class eTypeFlagClassIsImplementation = ( 1u << 1 ) }; - - static void - ExtractClassOrStructDIEArray (const DIEInfoArray &die_info_array, - bool return_implementation_only_if_available, - DIEArray &die_offsets) + struct DIEInfo { - const size_t count = die_info_array.size(); - for (size_t i=0; i DIEInfoArray; typedef std::vector AtomArray; - static const char * - GetAtomTypeName (uint16_t atom) - { - switch (atom) - { - case eAtomTypeNULL: return "NULL"; - case eAtomTypeDIEOffset: return "die-offset"; - case eAtomTypeCUOffset: return "cu-offset"; - case eAtomTypeTag: return "die-tag"; - case eAtomTypeNameFlags: return "name-flags"; - case eAtomTypeTypeFlags: return "type-flags"; - case eAtomTypeQualNameHash: return "qualified-name-hash"; - } - return ""; - } - struct Prologue + class Prologue { - // DIE offset base so die offsets in hash_data can be CU relative - dw_offset_t die_base_offset; - AtomArray atoms; - uint32_t atom_mask; - size_t min_hash_data_byte_size; - bool hash_data_has_fixed_byte_size; - - Prologue (dw_offset_t _die_base_offset = 0) : - die_base_offset (_die_base_offset), - atoms(), - atom_mask (0), - min_hash_data_byte_size(0), - hash_data_has_fixed_byte_size(true) - { - // Define an array of DIE offsets by first defining an array, - // and then define the atom type for the array, in this case - // we have an array of DIE offsets - AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); - } - - virtual ~Prologue() - { - } + public: + Prologue (dw_offset_t _die_base_offset = 0); void - ClearAtoms () - { - hash_data_has_fixed_byte_size = true; - min_hash_data_byte_size = 0; - atom_mask = 0; - atoms.clear(); - } + ClearAtoms (); bool - ContainsAtom (AtomType atom_type) const - { - return (atom_mask & (1u << atom_type)) != 0; - } - - virtual void - Clear () - { - die_base_offset = 0; - ClearAtoms (); - } - + ContainsAtom (AtomType atom_type) const; + void - AppendAtom (AtomType type, dw_form_t form) - { - atoms.push_back (Atom(type, form)); - atom_mask |= 1u << type; - switch (form) - { - case DW_FORM_indirect: - case DW_FORM_exprloc: - case DW_FORM_flag_present: - case DW_FORM_ref_sig8: - assert (!"Unhandled atom form"); - break; - - case DW_FORM_string: - case DW_FORM_block: - case DW_FORM_block1: - case DW_FORM_sdata: - case DW_FORM_udata: - case DW_FORM_ref_udata: - case DW_FORM_GNU_addr_index: - case DW_FORM_GNU_str_index: - hash_data_has_fixed_byte_size = false; - // Fall through to the cases below... - case DW_FORM_flag: - case DW_FORM_data1: - case DW_FORM_ref1: - case DW_FORM_sec_offset: - min_hash_data_byte_size += 1; - break; - - case DW_FORM_block2: - hash_data_has_fixed_byte_size = false; - // Fall through to the cases below... - case DW_FORM_data2: - case DW_FORM_ref2: - min_hash_data_byte_size += 2; - break; - - case DW_FORM_block4: - hash_data_has_fixed_byte_size = false; - // Fall through to the cases below... - case DW_FORM_data4: - case DW_FORM_ref4: - case DW_FORM_addr: - case DW_FORM_ref_addr: - case DW_FORM_strp: - min_hash_data_byte_size += 4; - break; - - case DW_FORM_data8: - case DW_FORM_ref8: - min_hash_data_byte_size += 8; - break; - - } - } - -// void -// Dump (std::ostream* ostrm_ptr); - + Clear (); + + void + AppendAtom (AtomType type, dw_form_t form); + lldb::offset_t - Read (const lldb_private::DataExtractor &data, - lldb::offset_t offset) - { - ClearAtoms (); - - die_base_offset = data.GetU32 (&offset); - - const uint32_t atom_count = data.GetU32 (&offset); - if (atom_count == 0x00060003u) - { - // Old format, deal with contents of old pre-release format - while (data.GetU32(&offset)) - /* do nothing */; - - // Hardcode to the only known value for now. - AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); - } - else - { - for (uint32_t i=0; i + class Header : public MappedHash::Header { - Header (dw_offset_t _die_base_offset = 0) - { - } - - virtual - ~Header() - { - } - - virtual size_t - GetByteSize (const HeaderData &header_data) - { - return header_data.GetByteSize(); - } - - // virtual void - // Dump (std::ostream* ostrm_ptr); - // - virtual lldb::offset_t - Read (lldb_private::DataExtractor &data, lldb::offset_t offset) - { - offset = MappedHash::Header::Read (data, offset); - if (offset != UINT32_MAX) - { - offset = header_data.Read (data, offset); - } - return offset; - } - + public: + size_t + GetByteSize (const HeaderData &header_data) override; + + lldb::offset_t + Read (lldb_private::DataExtractor &data, lldb::offset_t offset) override; + bool Read (const lldb_private::DWARFDataExtractor &data, lldb::offset_t *offset_ptr, - DIEInfo &hash_data) const - { - const size_t num_atoms = header_data.atoms.size(); - if (num_atoms == 0) - return false; - - for (size_t i=0; i 0) - strm.PutCString (", "); - - DWARFFormValue form_value (NULL, header_data.atoms[i].form); - switch (header_data.atoms[i].type) - { - case eAtomTypeDIEOffset: // DIE offset, check form for encoding - strm.Printf ("{0x%8.8x}", hash_data.offset); - break; - - case eAtomTypeTag: // DW_TAG value for the DIE - { - const char *tag_cstr = lldb_private::DW_TAG_value_to_name (hash_data.tag); - if (tag_cstr) - strm.PutCString (tag_cstr); - else - strm.Printf ("DW_TAG_(0x%4.4x)", hash_data.tag); - } - break; - - case eAtomTypeTypeFlags: // Flags from enum TypeFlags - strm.Printf ("0x%2.2x", hash_data.type_flags); - if (hash_data.type_flags) - { - strm.PutCString (" ("); - if (hash_data.type_flags & eTypeFlagClassIsImplementation) - strm.PutCString (" implementation"); - strm.PutCString (" )"); - } - break; - - case eAtomTypeQualNameHash: // Flags from enum TypeFlags - strm.Printf ("0x%8.8x", hash_data.qualified_name_hash); - break; - - default: - strm.Printf ("AtomType(0x%x)", header_data.atoms[i].type); - break; - } - } - } + Dump (lldb_private::Stream& strm, const DIEInfo &hash_data) const; }; - + // A class for reading and using a saved hash table from a block of data // in memory class MemoryTable : public MappedHash::MemoryTable { public: - MemoryTable (lldb_private::DWARFDataExtractor &table_data, const lldb_private::DWARFDataExtractor &string_table, - const char *name) : - MappedHash::MemoryTable (table_data), - m_data (table_data), - m_string_table (string_table), - m_name (name) - { - } - - virtual - ~MemoryTable () - { - } - - virtual const char * - GetStringForKeyType (KeyType key) const - { - // The key in the DWARF table is the .debug_str offset for the string - return m_string_table.PeekCStr (key); - } - - virtual bool - ReadHashData (uint32_t hash_data_offset, - HashData &hash_data) const - { - lldb::offset_t offset = hash_data_offset; - offset += 4; // Skip string table offset that contains offset of hash name in .debug_str - const uint32_t count = m_data.GetU32 (&offset); - if (count > 0) - { - hash_data.resize(count); - for (uint32_t i=0; i 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) - { - // We have at least one HashData entry, and we have enough - // data to parse at least "count" HashData entries. - - // First make sure the entire C string matches... - const bool match = strcmp (name, strp_cstr) == 0; - - if (!match && m_header.header_data.HashDataHasFixedByteSize()) - { - // If the string doesn't match and we have fixed size data, - // we can just add the total byte size of all HashData objects - // to the hash data offset and be done... - *hash_data_offset_ptr += min_total_hash_data_size; - } - else - { - // If the string does match, or we don't have fixed size data - // then we need to read the hash data as a stream. If the - // string matches we also append all HashData objects to the - // value array. - for (uint32_t i=0; i 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) - { - const bool match = regex.Execute(strp_cstr); - - if (!match && m_header.header_data.HashDataHasFixedByteSize()) - { - // If the regex doesn't match and we have fixed size data, - // we can just add the total byte size of all HashData objects - // to the hash data offset and be done... - *hash_data_offset_ptr += min_total_hash_data_size; - } - else - { - // If the string does match, or we don't have fixed size data - // then we need to read the hash data as a stream. If the - // string matches we also append all HashData objects to the - // value array. - for (uint32_t i=0; i"; +} + +DWARFMappedHash::DIEInfo::DIEInfo () : + offset (DW_INVALID_OFFSET), + tag (0), + type_flags (0), + qualified_name_hash (0) +{ +} + +DWARFMappedHash::DIEInfo::DIEInfo (dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h) : + offset (o), + tag (t), + type_flags (f), + qualified_name_hash (h) +{ +} + +DWARFMappedHash::Prologue::Prologue (dw_offset_t _die_base_offset) : + die_base_offset (_die_base_offset), + atoms(), + atom_mask (0), + min_hash_data_byte_size(0), + hash_data_has_fixed_byte_size(true) +{ + // Define an array of DIE offsets by first defining an array, + // and then define the atom type for the array, in this case + // we have an array of DIE offsets + AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); +} + +void +DWARFMappedHash::Prologue::ClearAtoms () +{ + hash_data_has_fixed_byte_size = true; + min_hash_data_byte_size = 0; + atom_mask = 0; + atoms.clear(); +} + +bool +DWARFMappedHash::Prologue::ContainsAtom (AtomType atom_type) const +{ + return (atom_mask & (1u << atom_type)) != 0; +} + +void +DWARFMappedHash::Prologue::Clear () +{ + die_base_offset = 0; + ClearAtoms (); +} + +void +DWARFMappedHash::Prologue::AppendAtom (AtomType type, dw_form_t form) +{ + atoms.push_back ({type, form}); + atom_mask |= 1u << type; + switch (form) + { + case DW_FORM_indirect: + case DW_FORM_exprloc: + case DW_FORM_flag_present: + case DW_FORM_ref_sig8: + assert (!"Unhandled atom form"); + break; + + case DW_FORM_string: + case DW_FORM_block: + case DW_FORM_block1: + case DW_FORM_sdata: + case DW_FORM_udata: + case DW_FORM_ref_udata: + case DW_FORM_GNU_addr_index: + case DW_FORM_GNU_str_index: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... + case DW_FORM_flag: + case DW_FORM_data1: + case DW_FORM_ref1: + case DW_FORM_sec_offset: + min_hash_data_byte_size += 1; + break; + + case DW_FORM_block2: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... + case DW_FORM_data2: + case DW_FORM_ref2: + min_hash_data_byte_size += 2; + break; + + case DW_FORM_block4: + hash_data_has_fixed_byte_size = false; + // Fall through to the cases below... + case DW_FORM_data4: + case DW_FORM_ref4: + case DW_FORM_addr: + case DW_FORM_ref_addr: + case DW_FORM_strp: + min_hash_data_byte_size += 4; + break; + + case DW_FORM_data8: + case DW_FORM_ref8: + min_hash_data_byte_size += 8; + break; + + } +} + +lldb::offset_t +DWARFMappedHash::Prologue::Read (const lldb_private::DataExtractor &data, + lldb::offset_t offset) +{ + ClearAtoms (); + + die_base_offset = data.GetU32 (&offset); + + const uint32_t atom_count = data.GetU32 (&offset); + if (atom_count == 0x00060003u) + { + // Old format, deal with contents of old pre-release format + while (data.GetU32(&offset)) + /* do nothing */; + + // Hardcode to the only known value for now. + AppendAtom (eAtomTypeDIEOffset, DW_FORM_data4); + } + else + { + for (uint32_t i=0; i::Read (data, offset); + if (offset != UINT32_MAX) + { + offset = header_data.Read (data, offset); + } + return offset; +} + +bool +DWARFMappedHash::Header::Read (const lldb_private::DWARFDataExtractor &data, + lldb::offset_t *offset_ptr, + DIEInfo &hash_data) const +{ + const size_t num_atoms = header_data.atoms.size(); + if (num_atoms == 0) + return false; + + for (size_t i=0; i 0) + strm.PutCString (", "); + + DWARFFormValue form_value (NULL, header_data.atoms[i].form); + switch (header_data.atoms[i].type) + { + case eAtomTypeDIEOffset: // DIE offset, check form for encoding + strm.Printf ("{0x%8.8x}", hash_data.offset); + break; + + case eAtomTypeTag: // DW_TAG value for the DIE + { + const char *tag_cstr = lldb_private::DW_TAG_value_to_name (hash_data.tag); + if (tag_cstr) + strm.PutCString (tag_cstr); + else + strm.Printf ("DW_TAG_(0x%4.4x)", hash_data.tag); + } + break; + + case eAtomTypeTypeFlags: // Flags from enum TypeFlags + strm.Printf ("0x%2.2x", hash_data.type_flags); + if (hash_data.type_flags) + { + strm.PutCString (" ("); + if (hash_data.type_flags & eTypeFlagClassIsImplementation) + strm.PutCString (" implementation"); + strm.PutCString (" )"); + } + break; + + case eAtomTypeQualNameHash: // Flags from enum TypeFlags + strm.Printf ("0x%8.8x", hash_data.qualified_name_hash); + break; + + default: + strm.Printf ("AtomType(0x%x)", header_data.atoms[i].type); + break; + } + } +} + +DWARFMappedHash::MemoryTable::MemoryTable (lldb_private::DWARFDataExtractor &table_data, + const lldb_private::DWARFDataExtractor &string_table, + const char *name) : + MappedHash::MemoryTable (table_data), + m_data (table_data), + m_string_table (string_table), + m_name (name) +{ +} + +const char * +DWARFMappedHash::MemoryTable::GetStringForKeyType (KeyType key) const +{ + // The key in the DWARF table is the .debug_str offset for the string + return m_string_table.PeekCStr (key); +} + +bool +DWARFMappedHash::MemoryTable::ReadHashData (uint32_t hash_data_offset, HashData &hash_data) const +{ + lldb::offset_t offset = hash_data_offset; + offset += 4; // Skip string table offset that contains offset of hash name in .debug_str + const uint32_t count = m_data.GetU32 (&offset); + if (count > 0) + { + hash_data.resize(count); + for (uint32_t i=0; i 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) + { + // We have at least one HashData entry, and we have enough + // data to parse at least "count" HashData entries. + + // First make sure the entire C string matches... + const bool match = strcmp (name, strp_cstr) == 0; + + if (!match && m_header.header_data.HashDataHasFixedByteSize()) + { + // If the string doesn't match and we have fixed size data, + // we can just add the total byte size of all HashData objects + // to the hash data offset and be done... + *hash_data_offset_ptr += min_total_hash_data_size; + } + else + { + // If the string does match, or we don't have fixed size data + // then we need to read the hash data as a stream. If the + // string matches we also append all HashData objects to the + // value array. + for (uint32_t i=0; i 0 && m_data.ValidOffsetForDataOfSize (*hash_data_offset_ptr, min_total_hash_data_size)) + { + const bool match = regex.Execute(strp_cstr); + + if (!match && m_header.header_data.HashDataHasFixedByteSize()) + { + // If the regex doesn't match and we have fixed size data, + // we can just add the total byte size of all HashData objects + // to the hash data offset and be done... + *hash_data_offset_ptr += min_total_hash_data_size; + } + else + { + // If the string does match, or we don't have fixed size data + // then we need to read the hash data as a stream. If the + // string matches we also append all HashData objects to the + // value array. + for (uint32_t i=0; iGetName().AsCString()); assert (clang_type); - DWARFAttributes attributes; - - DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser(); if (dwarf_ast) return dwarf_ast->CompleteTypeFromDWARF (dwarf_die, type, clang_type); - return false; }