[Lldb-commits] [lldb] r360669 - DWARF/NFC: Centralize DIERef conversions

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue May 14 05:44:40 PDT 2019


Author: labath
Date: Tue May 14 05:44:40 2019
New Revision: 360669

URL: http://llvm.org/viewvc/llvm-project?rev=360669&view=rev
Log:
DWARF/NFC: Centralize DIERef conversions

apple and manual indexing code were creating a DIERef in a bunch of
places. Though the code itself is not much, it is also easy to simplify
by factoring out the DIERef creation. In HashedNameToDIE I create a
conversion operator from DIEInfo to DIERef, and in ManualDWARFIndex I
just create the DIERef in a global variable up-front.

This also reduces the diff in follow-up patches which change how DIERefs
are constructed.

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp?rev=360669&r1=360668&r2=360669&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp Tue May 14 05:44:40 2019
@@ -13,8 +13,7 @@ void DWARFMappedHash::ExtractDIEArray(co
                                       DIEArray &die_offsets) {
   const size_t count = die_info_array.size();
   for (size_t i = 0; i < count; ++i)
-    die_offsets.emplace_back(die_info_array[i].cu_offset,
-                             die_info_array[i].offset);
+    die_offsets.emplace_back(die_info_array[i]);
 }
 
 void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array,
@@ -33,8 +32,7 @@ void DWARFMappedHash::ExtractDIEArray(co
               tag == DW_TAG_structure_type || tag == DW_TAG_class_type;
       }
       if (tag_matches)
-        die_offsets.emplace_back(die_info_array[i].cu_offset,
-                                 die_info_array[i].offset);
+        die_offsets.emplace_back(die_info_array[i]);
     }
   }
 }
@@ -58,8 +56,7 @@ void DWARFMappedHash::ExtractDIEArray(co
               tag == DW_TAG_structure_type || tag == DW_TAG_class_type;
       }
       if (tag_matches)
-        die_offsets.emplace_back(die_info_array[i].cu_offset,
-                                 die_info_array[i].offset);
+        die_offsets.emplace_back(die_info_array[i]);
     }
   }
 }
@@ -77,8 +74,7 @@ void DWARFMappedHash::ExtractClassOrStru
           // We found the one true definition for this class, so only return
           // that
           die_offsets.clear();
-          die_offsets.emplace_back(die_info_array[i].cu_offset,
-                                   die_info_array[i].offset);
+          die_offsets.emplace_back(die_info_array[i]);
           return;
         } else {
           // Put the one true definition as the first entry so it matches first
@@ -86,8 +82,7 @@ void DWARFMappedHash::ExtractClassOrStru
                               die_info_array[i].offset);
         }
       } else {
-        die_offsets.emplace_back(die_info_array[i].cu_offset,
-                                 die_info_array[i].offset);
+        die_offsets.emplace_back(die_info_array[i]);
       }
     }
   }
@@ -99,8 +94,7 @@ void DWARFMappedHash::ExtractTypesFromDI
   const size_t count = die_info_array.size();
   for (size_t i = 0; i < count; ++i) {
     if ((die_info_array[i].type_flags & type_flag_mask) == type_flag_value)
-      die_offsets.emplace_back(die_info_array[i].cu_offset,
-                               die_info_array[i].offset);
+      die_offsets.emplace_back(die_info_array[i]);
   }
 }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=360669&r1=360668&r2=360669&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Tue May 14 05:44:40 2019
@@ -56,6 +56,8 @@ public:
 
     DIEInfo();
     DIEInfo(dw_offset_t c, dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h);
+
+    explicit operator DIERef() const { return {cu_offset, offset}; }
   };
 
   struct Atom {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp?rev=360669&r1=360668&r2=360669&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp Tue May 14 05:44:40 2019
@@ -245,6 +245,7 @@ void ManualDWARFIndex::IndexUnitImpl(
       }
     }
 
+    DIERef ref(cu_offset, die.GetOffset());
     switch (tag) {
     case DW_TAG_inlined_subroutine:
     case DW_TAG_subprogram:
@@ -258,38 +259,30 @@ void ManualDWARFIndex::IndexUnitImpl(
             ConstString objc_fullname_no_category_name(
                 objc_method.GetFullNameWithoutCategory(true));
             ConstString objc_class_name_no_category(objc_method.GetClassName());
-            set.function_fullnames.Insert(ConstString(name),
-                                          DIERef(cu_offset, die.GetOffset()));
+            set.function_fullnames.Insert(ConstString(name), ref);
             if (objc_class_name_with_category)
-              set.objc_class_selectors.Insert(
-                  objc_class_name_with_category,
-                  DIERef(cu_offset, die.GetOffset()));
+              set.objc_class_selectors.Insert(objc_class_name_with_category,
+                                              ref);
             if (objc_class_name_no_category &&
                 objc_class_name_no_category != objc_class_name_with_category)
-              set.objc_class_selectors.Insert(
-                  objc_class_name_no_category,
-                  DIERef(cu_offset, die.GetOffset()));
+              set.objc_class_selectors.Insert(objc_class_name_no_category, ref);
             if (objc_selector_name)
-              set.function_selectors.Insert(objc_selector_name,
-                                            DIERef(cu_offset, die.GetOffset()));
+              set.function_selectors.Insert(objc_selector_name, ref);
             if (objc_fullname_no_category_name)
               set.function_fullnames.Insert(objc_fullname_no_category_name,
-                                            DIERef(cu_offset, die.GetOffset()));
+                                            ref);
           }
           // If we have a mangled name, then the DW_AT_name attribute is
           // usually the method name without the class or any parameters
           bool is_method = DWARFDIE(&unit, &die).IsMethod();
 
           if (is_method)
-            set.function_methods.Insert(ConstString(name),
-                                        DIERef(cu_offset, die.GetOffset()));
+            set.function_methods.Insert(ConstString(name), ref);
           else
-            set.function_basenames.Insert(ConstString(name),
-                                          DIERef(cu_offset, die.GetOffset()));
+            set.function_basenames.Insert(ConstString(name), ref);
 
           if (!is_method && !mangled_cstr && !objc_method.IsValid(true))
-            set.function_fullnames.Insert(ConstString(name),
-                                          DIERef(cu_offset, die.GetOffset()));
+            set.function_fullnames.Insert(ConstString(name), ref);
         }
         if (mangled_cstr) {
           // Make sure our mangled name isn't the same string table entry as
@@ -299,8 +292,7 @@ void ManualDWARFIndex::IndexUnitImpl(
           if (name && name != mangled_cstr &&
               ((mangled_cstr[0] == '_') ||
                (::strcmp(name, mangled_cstr) != 0))) {
-            set.function_fullnames.Insert(ConstString(mangled_cstr),
-                                          DIERef(cu_offset, die.GetOffset()));
+            set.function_fullnames.Insert(ConstString(mangled_cstr), ref);
           }
         }
       }
@@ -318,22 +310,19 @@ void ManualDWARFIndex::IndexUnitImpl(
     case DW_TAG_union_type:
     case DW_TAG_unspecified_type:
       if (name && !is_declaration)
-        set.types.Insert(ConstString(name), DIERef(cu_offset, die.GetOffset()));
+        set.types.Insert(ConstString(name), ref);
       if (mangled_cstr && !is_declaration)
-        set.types.Insert(ConstString(mangled_cstr),
-                         DIERef(cu_offset, die.GetOffset()));
+        set.types.Insert(ConstString(mangled_cstr), ref);
       break;
 
     case DW_TAG_namespace:
       if (name)
-        set.namespaces.Insert(ConstString(name),
-                              DIERef(cu_offset, die.GetOffset()));
+        set.namespaces.Insert(ConstString(name), ref);
       break;
 
     case DW_TAG_variable:
       if (name && has_location_or_const_value && is_global_or_static_variable) {
-        set.globals.Insert(ConstString(name),
-                           DIERef(cu_offset, die.GetOffset()));
+        set.globals.Insert(ConstString(name), ref);
         // 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 mangled name
@@ -345,8 +334,7 @@ void ManualDWARFIndex::IndexUnitImpl(
         // entries
         if (mangled_cstr && name != mangled_cstr &&
             ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) {
-          set.globals.Insert(ConstString(mangled_cstr),
-                             DIERef(cu_offset, die.GetOffset()));
+          set.globals.Insert(ConstString(mangled_cstr), ref);
         }
       }
       break;




More information about the lldb-commits mailing list