Merge branch 'addmainunit3-altlink-sharedstmt' into addmainunit3-altlink-sharedstmt...
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jan 2021 23:45:06 +0000 (00:45 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jan 2021 23:45:06 +0000 (00:45 +0100)
lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp
lldb/source/Plugins/SymbolFile/DWARF/DIERef.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

index 7a8ab9c..d2b4d14 100644 (file)
@@ -13,6 +13,19 @@ void llvm::format_provider<DIERef>::format(const DIERef &ref, raw_ostream &OS,
                                            StringRef Style) {
   if (ref.dwo_num())
     OS << format_hex_no_prefix(*ref.dwo_num(), 8) << "/";
-  OS << (ref.section() == DIERef::DebugInfo ? "INFO" : "TYPE");
+  if (ref.main_cu())
+    OS << format_hex_no_prefix(*ref.main_cu(), 8) << "/";
+  OS << (ref.section() == DIERef::Section::DebugInfo ? "INFO" : "TYPE");
+  switch (ref.kind_get()) {
+    case DIERef::Kind::NoneKind:
+    case DIERef::Kind::DwoKind:
+      break;
+    case DIERef::Kind::MainDwzKind:
+      OS << "/DWZ";
+      break;
+    case DIERef::Kind::DwzCommonKind:
+      OS << "/DWZCOMMON";
+      break;
+  }
   OS << "/" << format_hex_no_prefix(ref.die_offset(), 8);
 }
index 72c595d..41e8c06 100644 (file)
 class DIERef {
 public:
   enum Section : uint8_t { DebugInfo, DebugTypes };
+  enum DwzCommon : uint8_t { MainDwz, CommonDwz };
+  enum Kind : uint8_t { NoneKind, MainDwzKind, DwoKind, DwzCommonKind };
 
-  DIERef(llvm::Optional<uint32_t> dwo_num, Section section,
+  DIERef(llvm::Optional<uint32_t> dwo_num, llvm::Optional<uint32_t> main_cu, DwzCommon dwz_common, Section section,
          dw_offset_t die_offset)
-      : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)),
+      : m_data(dwo_num.getValueOr(0) | main_cu.getValueOr(0)), m_data_kind(dwo_num ? DwoKind : (main_cu ? (dwz_common == MainDwz ? MainDwzKind : DwzCommonKind ) : NoneKind)),
         m_section(section), m_die_offset(die_offset) {
     assert(this->dwo_num() == dwo_num && "Dwo number out of range?");
+    assert(this->main_cu() == main_cu && "Main Cu number out of range?");
+    assert(dwz_common == MainDwz || main_cu);
   }
 
   llvm::Optional<uint32_t> dwo_num() const {
-    if (m_dwo_num_valid)
-      return m_dwo_num;
+    if (m_data_kind == DwoKind)
+      return m_data;
     return llvm::None;
   }
 
+  // It indexes DWARFCompileUnit's excl. DWARFTypeUnit's.
+  // It is the index used as parameter of SymbolFileDWARF::GetDWARFUnitIndex.
+  llvm::Optional<uint32_t> main_cu() const {
+    if (m_data_kind == MainDwzKind || m_data_kind == DwzCommonKind )
+      return m_data;
+    return llvm::None;
+  }
+
+  DwzCommon dwz_common() const {
+    assert(m_data_kind == MainDwzKind || m_data_kind == DwzCommonKind );
+    return m_data_kind == MainDwzKind ? MainDwz : CommonDwz;
+  }
+
+  Kind kind_get() const {
+    return Kind(m_data_kind);
+  }
+
   Section section() const { return static_cast<Section>(m_section); }
 
   dw_offset_t die_offset() const { return m_die_offset; }
 
   bool operator<(DIERef other) const {
-    if (m_dwo_num_valid != other.m_dwo_num_valid)
-      return m_dwo_num_valid < other.m_dwo_num_valid;
-    if (m_dwo_num_valid && (m_dwo_num != other.m_dwo_num))
-      return m_dwo_num < other.m_dwo_num;
+    if (m_data_kind != other.m_data_kind)
+      return m_data_kind < other.m_data_kind;
+    if (m_data_kind != NoneKind && (m_data != other.m_data))
+      return m_data < other.m_data;
     if (m_section != other.m_section)
       return m_section < other.m_section;
     return m_die_offset < other.m_die_offset;
   }
 
   bool operator==(DIERef other) const {
-    if (m_dwo_num_valid != other.m_dwo_num_valid ||
-        m_section != other.m_section || m_die_offset != other.m_die_offset)
-      return false;
-    if (m_dwo_num_valid && m_dwo_num != other.m_dwo_num)
-      return false;
-    return true;
+    if (m_data_kind != other.m_data_kind)
+      return m_data_kind == other.m_data_kind;
+    if (m_data_kind != NoneKind && (m_data != other.m_data))
+      return m_data == other.m_data;
+    if (m_section != other.m_section)
+      return m_section == other.m_section;
+    return m_die_offset == other.m_die_offset;
   }
 
 private:
-  uint32_t m_dwo_num : 30;
-  uint32_t m_dwo_num_valid : 1;
+  uint32_t m_data : 29;
+  uint32_t m_data_kind : 2;
   uint32_t m_section : 1;
   dw_offset_t m_die_offset;
 };
index 46efc27..7999a49 100644 (file)
@@ -29,7 +29,9 @@ llvm::Optional<DIERef> DWARFBaseDIE::GetDIERef(DWARFUnit *main_unit) const {
   if (m_cu == main_unit)
     main_unit = nullptr;
 
-  return DIERef(m_cu->GetSymbolFileDWARF().GetDwoNum(), m_cu->GetDebugSection(),
+  return DIERef(m_cu->GetSymbolFileDWARF().GetDwoNum(), (!main_unit ? llvm::None : llvm::Optional<uint32_t>(main_unit->GetID())),
+    DIERef::MainDwz,
+  m_cu->GetDebugSection(),
                 m_die->GetOffset());
 }
 
index d857133..52398de 100644 (file)
@@ -53,7 +53,7 @@ DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) {
 
   cu = &cu->GetNonSkeletonUnit();
   if (llvm::Optional<uint64_t> die_offset = entry.getDIEUnitOffset())
-    return DIERef(cu->GetSymbolFileDWARF().GetDwoNum(),
+    return DIERef(cu->GetSymbolFileDWARF().GetDwoNum(), llvm::None, DIERef::MainDwz,
                   DIERef::Section::DebugInfo, cu->GetOffset() + *die_offset);
 
   return llvm::None;
index dabf7fe..3914ae1 100644 (file)
@@ -66,7 +66,7 @@ public:
     DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
 
     explicit operator DIERef() const {
-      return DIERef(llvm::None, DIERef::Section::DebugInfo, die_offset);
+      return DIERef(llvm::None, llvm::None, DIERef::MainDwz, DIERef::Section::DebugInfo, die_offset);
     }
   };
 
index c1b2880..395d169 100644 (file)
@@ -1300,10 +1300,14 @@ user_id_t SymbolFileDWARF::GetUID(DWARFUnit *main_unit, DIERef ref) {
 
   // WARNING: Use ref.dwo_num() as GetDwoNum() may not be valid in 'this'.
   static_assert(sizeof(ref.die_offset()) * 8 == 32, "");
-  lldbassert(!ref.dwo_num().hasValue()||*ref.dwo_num()<=0x3fffffff);
-  user_id_t retval = user_id_t(ref.dwo_num().getValueOr(0)) << 32 |
+  lldbassert(!ref.dwo_num().hasValue()||*ref.dwo_num()<=0x1fffffff);
+  lldbassert(!ref.main_cu().hasValue()||*ref.main_cu()<=0x1fffffff);
+  lldbassert(0 <= ref.kind_get());
+  lldbassert(ref.kind_get() <= 3);
+  user_id_t retval =
+         user_id_t(ref.dwo_num() ? *ref.dwo_num() : (ref.main_cu() ? *ref.main_cu() : 0)) << 32 |
          ref.die_offset() |
-         lldb::user_id_t(ref.dwo_num().hasValue()) << 62 |
+         user_id_t(ref.kind_get()) << 61 |
          lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63;
 
 #ifndef NDEBUG
@@ -1328,7 +1332,7 @@ SymbolFileDWARF::DecodeUIDUnlocked(lldb::user_id_t uid) {
     SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex(
         debug_map->GetOSOIndexFromUserID(uid));
     return DecodedUID{
-        *dwarf, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}};
+        *dwarf, {llvm::None, llvm::None, DIERef::MainDwz, DIERef::Section::DebugInfo, dw_offset_t(uid)}};
   }
   dw_offset_t die_offset = uid;
   if (die_offset == DW_INVALID_OFFSET)
@@ -1337,12 +1341,13 @@ SymbolFileDWARF::DecodeUIDUnlocked(lldb::user_id_t uid) {
   DIERef::Section section =
       uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo;
 
+  DIERef::Kind kind = DIERef::Kind(uid >> 61 & 3);
+
   llvm::Optional<uint32_t> dwo_num;
-  bool dwo_valid = uid >> 62 & 1;
-  if (dwo_valid)
-    dwo_num = uid >> 32 & 0x3fffffff;
+  if (kind == DIERef::Kind::DwoKind)
+    dwo_num = uid >> 32 & 0x1fffffff;
 
-  return DecodedUID{*this, {dwo_num, section, die_offset}};
+  return DecodedUID{*this, {dwo_num, llvm::None, DIERef::MainDwz, section, die_offset}};
 }
 
 llvm::Optional<SymbolFileDWARF::DecodedUID>
@@ -1633,7 +1638,7 @@ lldb::ModuleSP SymbolFileDWARF::GetExternalModule(ConstString name) {
 DWARFDIE
 SymbolFileDWARF::GetDIE(const DIERef &die_ref, DWARFUnit **main_unit_return) {
   if (die_ref.dwo_num()) {
-    SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x3fffffff
+    SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x1fffffff
                                  ? m_dwp_symfile.get()
                                  : this->DebugInfo()
                                        .GetUnitAtIndex(*die_ref.dwo_num())
@@ -1726,6 +1731,7 @@ SymbolFileDWARF::GetDwoSymbolFileForCompileUnit(
   if (dwo_obj_file == nullptr)
     return nullptr;
 
+  lldbassert(dwarf_cu->GetID()<0x1fffffff);
   return std::make_shared<SymbolFileDWARFDwo>(*this, dwo_obj_file,
                                               dwarf_cu->GetID());
 }
@@ -3963,7 +3969,7 @@ const std::shared_ptr<SymbolFileDWARFDwo> &SymbolFileDWARF::GetDwpSymbolFile() {
       if (!dwp_obj_file)
         return;
       m_dwp_symfile =
-          std::make_shared<SymbolFileDWARFDwo>(*this, dwp_obj_file, 0x3fffffff);
+          std::make_shared<SymbolFileDWARFDwo>(*this, dwp_obj_file, 0x1fffffff);
     }
   });
   return m_dwp_symfile;