[Lldb-commits] [lldb] r361463 - Simplify `GetName`+`AppendTypeName` by `DWARFDIE`

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Thu May 23 01:00:50 PDT 2019


Author: jankratochvil
Date: Thu May 23 01:00:49 2019
New Revision: 361463

URL: http://llvm.org/viewvc/llvm-project?rev=361463&view=rev
Log:
Simplify `GetName`+`AppendTypeName` by `DWARFDIE`

In D61502#1503247 @clayborg suggested that DWARFUnit *+dw_offset_t can be now
replaced by DWARFDIE.

It is moved from DWARFDebugInfoEntry to DWARFDIE as noted by @clayborg.

I have also removed return type as (1) it was wrong in one case and (2) no
existing caller used the return type. I also refactored the deep nesting noted
by @JDevlieghere.

Differential Revision: https://reviews.llvm.org/D62211

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp?rev=361463&r1=361462&r2=361463&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp Thu May 23 01:00:49 2019
@@ -182,6 +182,130 @@ const char *DWARFDIE::GetQualifiedName(s
     return nullptr;
 }
 
+// GetName
+//
+// Get value of the DW_AT_name attribute and place that value into the supplied
+// stream object. If the DIE is a NULL object "NULL" is placed into the stream,
+// and if no DW_AT_name attribute exists for the DIE then nothing is printed.
+void DWARFDIE::GetName(Stream &s) const {
+  if (!IsValid())
+    return;
+  if (GetDIE()->IsNULL()) {
+    s.PutCString("NULL");
+    return;
+  }
+  const char *name = GetDIE()->GetAttributeValueAsString(GetCU(), DW_AT_name, nullptr, true);
+  if (!name)
+    return;
+  s.PutCString(name);
+}
+
+// AppendTypeName
+//
+// Follows the type name definition down through all needed tags to end up with
+// a fully qualified type name and dump the results to the supplied stream.
+// This is used to show the name of types given a type identifier.
+void DWARFDIE::AppendTypeName(Stream &s) const {
+  if (!IsValid())
+    return;
+  if (GetDIE()->IsNULL()) {
+    s.PutCString("NULL");
+    return;
+  }
+  if (const char *name = GetPubname()) {
+    s.PutCString(name);
+    return;
+  }
+  switch (Tag()) {
+  case DW_TAG_array_type:
+    break; // print out a "[]" after printing the full type of the element
+           // below
+  case DW_TAG_base_type:
+    s.PutCString("base ");
+    break;
+  case DW_TAG_class_type:
+    s.PutCString("class ");
+    break;
+  case DW_TAG_const_type:
+    s.PutCString("const ");
+    break;
+  case DW_TAG_enumeration_type:
+    s.PutCString("enum ");
+    break;
+  case DW_TAG_file_type:
+    s.PutCString("file ");
+    break;
+  case DW_TAG_interface_type:
+    s.PutCString("interface ");
+    break;
+  case DW_TAG_packed_type:
+    s.PutCString("packed ");
+    break;
+  case DW_TAG_pointer_type:
+    break; // print out a '*' after printing the full type below
+  case DW_TAG_ptr_to_member_type:
+    break; // print out a '*' after printing the full type below
+  case DW_TAG_reference_type:
+    break; // print out a '&' after printing the full type below
+  case DW_TAG_restrict_type:
+    s.PutCString("restrict ");
+    break;
+  case DW_TAG_set_type:
+    s.PutCString("set ");
+    break;
+  case DW_TAG_shared_type:
+    s.PutCString("shared ");
+    break;
+  case DW_TAG_string_type:
+    s.PutCString("string ");
+    break;
+  case DW_TAG_structure_type:
+    s.PutCString("struct ");
+    break;
+  case DW_TAG_subrange_type:
+    s.PutCString("subrange ");
+    break;
+  case DW_TAG_subroutine_type:
+    s.PutCString("function ");
+    break;
+  case DW_TAG_thrown_type:
+    s.PutCString("thrown ");
+    break;
+  case DW_TAG_union_type:
+    s.PutCString("union ");
+    break;
+  case DW_TAG_unspecified_type:
+    s.PutCString("unspecified ");
+    break;
+  case DW_TAG_volatile_type:
+    s.PutCString("volatile ");
+    break;
+  default:
+    return;
+  }
+
+  // Follow the DW_AT_type if possible
+  if (DWARFDIE next_die = GetAttributeValueAsReferenceDIE(DW_AT_type))
+    next_die.AppendTypeName(s);
+
+  switch (Tag()) {
+  case DW_TAG_array_type:
+    s.PutCString("[]");
+    break;
+  case DW_TAG_pointer_type:
+    s.PutChar('*');
+    break;
+  case DW_TAG_ptr_to_member_type:
+    s.PutChar('*');
+    break;
+  case DW_TAG_reference_type:
+    s.PutChar('&');
+    break;
+  default:
+    break;
+  }
+}
+
 lldb_private::Type *DWARFDIE::ResolveType() const {
   if (IsValid())
     return GetDWARF()->ResolveType(*this, true);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h?rev=361463&r1=361462&r2=361463&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDIE.h Thu May 23 01:00:49 2019
@@ -34,6 +34,11 @@ public:
 
   const char *GetQualifiedName(std::string &storage) const;
 
+  using DWARFBaseDIE::GetName;
+  void GetName(lldb_private::Stream &s) const;
+
+  void AppendTypeName(lldb_private::Stream &s) const;
+
   lldb_private::Type *ResolveType() const;
 
   // Resolve a type by UID using this DIE's DWARF file

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=361463&r1=361462&r2=361463&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Thu May 23 01:00:49 2019
@@ -693,13 +693,13 @@ void DWARFDebugInfoEntry::DumpAttribute(
     DWARFDIE abstract_die = form_value.Reference();
     form_value.Dump(s);
     //  *ostrm_ptr << HEX32 << abstract_die.GetOffset() << " ( ";
-    GetName(abstract_die.GetCU(), abstract_die.GetOffset(), s);
+    abstract_die.GetName(s);
   } break;
 
   case DW_AT_type: {
     DWARFDIE type_die = form_value.Reference();
     s.PutCString(" ( ");
-    AppendTypeName(type_die.GetCU(), type_die.GetOffset(), s);
+    type_die.AppendTypeName(s);
     s.PutCString(" )");
   } break;
 
@@ -1038,166 +1038,6 @@ const char *DWARFDebugInfoEntry::GetPubn
   return name;
 }
 
-// GetName
-//
-// Get value of the DW_AT_name attribute for a debug information entry that
-// exists at offset "die_offset" and place that value into the supplied stream
-// object. If the DIE is a NULL object "NULL" is placed into the stream, and if
-// no DW_AT_name attribute exists for the DIE then nothing is printed.
-bool DWARFDebugInfoEntry::GetName(const DWARFUnit *cu,
-                                  const dw_offset_t die_offset, Stream &s) {
-  if (cu == NULL) {
-    s.PutCString("NULL");
-    return false;
-  }
-
-  DWARFDebugInfoEntry die;
-  lldb::offset_t offset = die_offset;
-  if (die.Extract(cu, &offset)) {
-    if (die.IsNULL()) {
-      s.PutCString("NULL");
-      return true;
-    } else {
-      const char *name =
-          die.GetAttributeValueAsString(cu, DW_AT_name, nullptr, true);
-      if (name) {
-        s.PutCString(name);
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-// AppendTypeName
-//
-// Follows the type name definition down through all needed tags to end up with
-// a fully qualified type name and dump the results to the supplied stream.
-// This is used to show the name of types given a type identifier.
-bool DWARFDebugInfoEntry::AppendTypeName(const DWARFUnit *cu,
-                                         const dw_offset_t die_offset,
-                                         Stream &s) {
-  if (cu == NULL) {
-    s.PutCString("NULL");
-    return false;
-  }
-
-  DWARFDebugInfoEntry die;
-  lldb::offset_t offset = die_offset;
-  if (die.Extract(cu, &offset)) {
-    if (die.IsNULL()) {
-      s.PutCString("NULL");
-      return true;
-    } else {
-      const char *name = die.GetPubname(cu);
-      if (name)
-        s.PutCString(name);
-      else {
-        bool result = true;
-        const DWARFAbbreviationDeclaration *abbrevDecl =
-            die.GetAbbreviationDeclarationPtr(cu, offset);
-
-        if (abbrevDecl == NULL)
-          return false;
-
-        switch (abbrevDecl->Tag()) {
-        case DW_TAG_array_type:
-          break; // print out a "[]" after printing the full type of the element
-                 // below
-        case DW_TAG_base_type:
-          s.PutCString("base ");
-          break;
-        case DW_TAG_class_type:
-          s.PutCString("class ");
-          break;
-        case DW_TAG_const_type:
-          s.PutCString("const ");
-          break;
-        case DW_TAG_enumeration_type:
-          s.PutCString("enum ");
-          break;
-        case DW_TAG_file_type:
-          s.PutCString("file ");
-          break;
-        case DW_TAG_interface_type:
-          s.PutCString("interface ");
-          break;
-        case DW_TAG_packed_type:
-          s.PutCString("packed ");
-          break;
-        case DW_TAG_pointer_type:
-          break; // print out a '*' after printing the full type below
-        case DW_TAG_ptr_to_member_type:
-          break; // print out a '*' after printing the full type below
-        case DW_TAG_reference_type:
-          break; // print out a '&' after printing the full type below
-        case DW_TAG_restrict_type:
-          s.PutCString("restrict ");
-          break;
-        case DW_TAG_set_type:
-          s.PutCString("set ");
-          break;
-        case DW_TAG_shared_type:
-          s.PutCString("shared ");
-          break;
-        case DW_TAG_string_type:
-          s.PutCString("string ");
-          break;
-        case DW_TAG_structure_type:
-          s.PutCString("struct ");
-          break;
-        case DW_TAG_subrange_type:
-          s.PutCString("subrange ");
-          break;
-        case DW_TAG_subroutine_type:
-          s.PutCString("function ");
-          break;
-        case DW_TAG_thrown_type:
-          s.PutCString("thrown ");
-          break;
-        case DW_TAG_union_type:
-          s.PutCString("union ");
-          break;
-        case DW_TAG_unspecified_type:
-          s.PutCString("unspecified ");
-          break;
-        case DW_TAG_volatile_type:
-          s.PutCString("volatile ");
-          break;
-        default:
-          return false;
-        }
-
-        // Follow the DW_AT_type if possible
-        DWARFFormValue form_value;
-        if (die.GetAttributeValue(cu, DW_AT_type, form_value)) {
-          DWARFDIE next_die = form_value.Reference();
-          result = AppendTypeName(next_die.GetCU(), next_die.GetOffset(), s);
-        }
-
-        switch (abbrevDecl->Tag()) {
-        case DW_TAG_array_type:
-          s.PutCString("[]");
-          break;
-        case DW_TAG_pointer_type:
-          s.PutChar('*');
-          break;
-        case DW_TAG_ptr_to_member_type:
-          s.PutChar('*');
-          break;
-        case DW_TAG_reference_type:
-          s.PutChar('&');
-          break;
-        default:
-          break;
-        }
-        return result;
-      }
-    }
-  }
-  return false;
-}
-
 // BuildAddressRangeTable
 void DWARFDebugInfoEntry::BuildAddressRangeTable(
     const DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h?rev=361463&r1=361462&r2=361463&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Thu May 23 01:00:49 2019
@@ -126,12 +126,6 @@ public:
 
   const char *GetPubname(const DWARFUnit *cu) const;
 
-  static bool GetName(const DWARFUnit *cu, const dw_offset_t die_offset,
-                      lldb_private::Stream &s);
-
-  static bool AppendTypeName(const DWARFUnit *cu, const dw_offset_t die_offset,
-                             lldb_private::Stream &s);
-
   const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const;
 
   const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes,




More information about the lldb-commits mailing list