[Lldb-commits] [lldb] r127708 - in /lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF: SymbolFileDWARF.cpp UniqueDWARFASTType.cpp UniqueDWARFASTType.h

Greg Clayton gclayton at apple.com
Tue Mar 15 15:42:13 PDT 2011


Author: gclayton
Date: Tue Mar 15 17:42:13 2011
New Revision: 127708

URL: http://llvm.org/viewvc/llvm-project?rev=127708&view=rev
Log:
Fixed an issue where types might not be uniqued correctly.

9133491


Modified:
    lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
    lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h

Modified: lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=127708&r1=127707&r2=127708&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Mar 15 17:42:13 2011
@@ -2985,6 +2985,7 @@
             ConstString type_name_const_str;
             Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
             size_t byte_size = 0;
+            bool byte_size_valid = false;
             Declaration decl;
 
             Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
@@ -3027,7 +3028,7 @@
                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
                                     type_name_const_str.SetCString(type_name_cstr);
                                     break;
-                                case DW_AT_byte_size:   byte_size = form_value.Unsigned();  break;
+                                case DW_AT_byte_size:   byte_size = form_value.Unsigned();  byte_size_valid = true; break;
                                 case DW_AT_encoding:    encoding = form_value.Unsigned(); break;
                                 case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
                                 default:
@@ -3149,6 +3150,7 @@
 
                                 case DW_AT_byte_size:   
                                     byte_size = form_value.Unsigned(); 
+                                    byte_size_valid = true;
                                     break;
 
                                 case DW_AT_accessibility: 
@@ -3181,8 +3183,11 @@
                     if (decl.IsValid())
                     {
                         if (GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
+                                                             this,
+                                                             dwarf_cu,
                                                              die,
                                                              decl,
+                                                             byte_size_valid ? byte_size : -1,
                                                              unique_ast_entry))
                         {
                             // We have already parsed this type or from another 
@@ -3279,6 +3284,8 @@
                     // end up creating many copies of the same type over
                     // and over in the ASTContext for our module
                     unique_ast_entry.m_type_sp = type_sp;
+                    unique_ast_entry.m_symfile = this;
+                    unique_ast_entry.m_cu = dwarf_cu;
                     unique_ast_entry.m_die = die;
                     unique_ast_entry.m_declaration = decl;
                     GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, 
@@ -3332,7 +3339,7 @@
                                     type_name_const_str.SetCString(type_name_cstr);
                                     break;
                                 case DW_AT_type:            encoding_uid = form_value.Reference(dwarf_cu); break;
-                                case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break;
+                                case DW_AT_byte_size:       byte_size = form_value.Unsigned(); byte_size_valid = true; break;
                                 case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
                                 case DW_AT_declaration:     is_forward_declaration = form_value.Unsigned() != 0; break;
                                 case DW_AT_allocated:
@@ -3690,7 +3697,7 @@
                                     break;
 
                                 case DW_AT_type:            type_die_offset = form_value.Reference(dwarf_cu); break;
-                                case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break;
+                                case DW_AT_byte_size:       byte_size = form_value.Unsigned(); byte_size_valid = true; break;
                                 case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break;
                                 case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break;
                                 case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;

Modified: lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp?rev=127708&r1=127707&r2=127708&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp (original)
+++ lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp Tue Mar 15 17:42:13 2011
@@ -20,20 +20,64 @@
 bool
 UniqueDWARFASTTypeList::Find 
 (
+    SymbolFileDWARF *symfile,
+    const DWARFCompileUnit *cu,
     const DWARFDebugInfoEntry *die, 
     const lldb_private::Declaration &decl,
+    const int32_t byte_size,
     UniqueDWARFASTType &entry
 ) const
 {
     collection::const_iterator pos, end = m_collection.end();
     for (pos = m_collection.begin(); pos != end; ++pos)
     {
+        // Make sure the tags match
         if (pos->m_die->Tag() == die->Tag())
         {
-            if (pos->m_declaration == decl)
+            // Validate byte sizes of both types only if both are valid.
+            if (pos->m_byte_size < 0 || byte_size < 0 || pos->m_byte_size == byte_size)
             {
-                entry = *pos;
-                return true;
+                // Make sure the file and line match
+                if (pos->m_declaration == decl)
+                {
+                    // The type has the same name, and was defined on the same
+                    // file and line. Now verify all of the parent DIEs match.
+                    const DWARFDebugInfoEntry *parent_arg_die = die->GetParent();
+                    const DWARFDebugInfoEntry *parend_pos_die = pos->m_die->GetParent();
+                    bool match = true;
+                    bool done = false;
+                    while (!done && match && parent_arg_die && parend_pos_die)
+                    {
+                        if (parent_arg_die->Tag() == parend_pos_die->Tag())
+                        {
+                            const dw_tag_t tag = parent_arg_die->Tag();
+                            switch (tag)
+                            {
+                            case DW_TAG_class_type:
+                            case DW_TAG_structure_type:
+                            case DW_TAG_union_type:
+                            case DW_TAG_namespace:
+                                {
+                                    const char *parent_arg_die_name = parent_arg_die->GetName(symfile, cu);
+                                    const char *parent_pos_die_name = parend_pos_die->GetName(pos->m_symfile, pos->m_cu);
+                                    if (strcmp (parent_arg_die_name, parent_pos_die_name))
+                                        match = false;
+                                }
+                                break;
+                            
+                            case DW_TAG_compile_unit:
+                                done = true;
+                                break;
+                            }
+                        }
+                    }
+
+                    if (match)
+                    {
+                        entry = *pos;
+                        return true;
+                    }
+                }
             }
         }
     }

Modified: lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h?rev=127708&r1=127707&r2=127708&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h (original)
+++ lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h Tue Mar 15 17:42:13 2011
@@ -32,24 +32,36 @@
 	//------------------------------------------------------------------
 	UniqueDWARFASTType () :
         m_type_sp (),
+        m_symfile (NULL),
+        m_cu (NULL),
         m_die (NULL),
-        m_declaration ()
+        m_declaration (),
+        m_byte_size (-1) // Set to negative value to make sure we have a valid value
     {
     }
 
 	UniqueDWARFASTType (lldb::TypeSP &type_sp,
+                        SymbolFileDWARF *symfile,
+                        DWARFCompileUnit *cu,
                         DWARFDebugInfoEntry *die,
-                        const lldb_private::Declaration &decl) :
+                        const lldb_private::Declaration &decl,
+                        int32_t byte_size) :
         m_type_sp (type_sp),
+        m_symfile (symfile),
+        m_cu (cu),
         m_die (die),
-        m_declaration (decl)
+        m_declaration (decl),
+        m_byte_size (byte_size)
     {
     }
     
     UniqueDWARFASTType (const UniqueDWARFASTType &rhs) :
         m_type_sp (rhs.m_type_sp),
+        m_symfile (rhs.m_symfile),
+        m_cu (rhs.m_cu),
         m_die (rhs.m_die),
-        m_declaration (rhs.m_declaration)
+        m_declaration (rhs.m_declaration),
+        m_byte_size (rhs.m_byte_size)
     {
     }
 
@@ -63,15 +75,21 @@
         if (this != &rhs)
         {
             m_type_sp = rhs.m_type_sp;
+            m_symfile = rhs.m_symfile;
+            m_cu = rhs.m_cu;
             m_die = rhs.m_die;
             m_declaration = rhs.m_declaration;
+            m_byte_size = rhs.m_byte_size;
         }
         return *this;
     }
 
     lldb::TypeSP m_type_sp;
+    SymbolFileDWARF *m_symfile;
+    const DWARFCompileUnit *m_cu;
     const DWARFDebugInfoEntry *m_die;
-    lldb_private::Declaration m_declaration;    
+    lldb_private::Declaration m_declaration;
+    int32_t m_byte_size;
 };
 
 class UniqueDWARFASTTypeList
@@ -99,8 +117,11 @@
     }
     
     bool
-    Find (const DWARFDebugInfoEntry *die, 
+    Find (SymbolFileDWARF *symfile,
+          const DWARFCompileUnit *cu,
+          const DWARFDebugInfoEntry *die, 
           const lldb_private::Declaration &decl,
+          const int32_t byte_size,
           UniqueDWARFASTType &entry) const;
     
 protected:
@@ -129,15 +150,18 @@
 
     bool
     Find (const lldb_private::ConstString &name, 
+          SymbolFileDWARF *symfile,
+          const DWARFCompileUnit *cu,
           const DWARFDebugInfoEntry *die, 
           const lldb_private::Declaration &decl,
+          const int32_t byte_size,
           UniqueDWARFASTType &entry) const
     {
         const char *unique_name_cstr = name.GetCString();
         collection::const_iterator pos = m_collection.find (unique_name_cstr);
         if (pos != m_collection.end())
         {
-            return pos->second.Find (die, decl, entry);
+            return pos->second.Find (symfile, cu, die, decl, byte_size, entry);
         }
         return false;
     }





More information about the lldb-commits mailing list