[Lldb-commits] [lldb] r125207 - in /lldb/trunk: include/lldb/Symbol/UnwindPlan.h source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Greg Clayton gclayton at apple.com
Wed Feb 9 11:06:17 PST 2011


Author: gclayton
Date: Wed Feb  9 13:06:17 2011
New Revision: 125207

URL: http://llvm.org/viewvc/llvm-project?rev=125207&view=rev
Log:
Added the DWARF unique type map such that we only create a type once in the
module's AST context. Prior to this fix, with gcc binaries, we end up with
a full class definition for any used classes in each compile unit due to the
one definition rule. This would result in us making N copies of class T, where
N is the number of compile units that use class T, in the module AST. When
an expression would then try and use any types that were duplicated, it would
quickly confuse clang and make expression evaluation fail due to all of the
duplicate types that got copied over. This is now fixed by making a map of
types in the DWARF that maps type names to a collection of types + declaration
(file + line number) + DIE. Then later when we find a type we look in this
module map and find any already cached types that we can just use.

8935777


Modified:
    lldb/trunk/include/lldb/Symbol/UnwindPlan.h
    lldb/trunk/source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Modified: lldb/trunk/include/lldb/Symbol/UnwindPlan.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/UnwindPlan.h?rev=125207&r1=125206&r2=125207&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/UnwindPlan.h (original)
+++ lldb/trunk/include/lldb/Symbol/UnwindPlan.h Wed Feb  9 13:06:17 2011
@@ -205,15 +205,19 @@
 public:
 
     UnwindPlan () : 
-        m_register_kind(-1), 
-        m_row_list(), 
-        m_plan_valid_address_range(), 
-        m_source_name()
-    { 
-        m_plan_valid_address_range.SetByteSize (0);
+        m_row_list (), 
+        m_plan_valid_address_range (), 
+        m_register_kind (UINT32_MAX), 
+        m_source_name ()
+    {
     }
 
-    void Dump (Stream& s, Thread* thread) const;
+    ~UnwindPlan ()
+	{
+	}
+
+    void 
+    Dump (Stream& s, Thread* thread) const;
 
     void 
     AppendRow (const Row& row);

Modified: lldb/trunk/source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp?rev=125207&r1=125206&r2=125207&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/UnwindAssemblyProfiler-x86.cpp Wed Feb  9 13:06:17 2011
@@ -519,7 +519,6 @@
 bool 
 AssemblyParse_x86::get_non_call_site_unwind_plan (UnwindPlan &unwind_plan)
 {
-    UnwindPlan up;
     UnwindPlan::Row row;
     int non_prologue_insn_count = 0;
     m_cur_insn = m_func_bounds.GetBaseAddress ();

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=125207&r1=125206&r2=125207&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Feb  9 13:06:17 2011
@@ -179,8 +179,8 @@
     m_namespace_index(),
     m_indexed (false),
     m_is_external_ast_source (false),
-    m_ranges()//,
-    //m_unique_ast_type_map ()
+    m_ranges(),
+    m_unique_ast_type_map ()
 {
 }
 
@@ -3169,134 +3169,130 @@
                         }
                     }
 
-//                    UniqueDWARFASTType unique_ast_entry;
-//                    if (decl.IsValid())
-//                    {
-//                        if (m_unique_ast_type_map.Find (type_name_const_str,
-//                                                        die,
-//                                                        decl,
-//                                                        unique_ast_entry))
-//                        {
-//                            // We have already parsed this type or from another 
-//                            // compile unit. GCC loves to use the "one definition
-//                            // rule" which can result in multiple definitions
-//                            // of the same class over and over in each compile
-//                            // unit.
-//                            type_sp = unique_ast_entry.m_type_sp;
-//                        }
-//                    }
-//                    
-//                    if (type_sp)
-//                    {
-//                        m_die_to_type[die] = type_sp.get();
-//
-//                    }
-//                    else
+                    UniqueDWARFASTType unique_ast_entry;
+                    if (decl.IsValid())
                     {
-                        DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
-
-                        int tag_decl_kind = -1;
-                        AccessType default_accessibility = eAccessNone;
-                        if (tag == DW_TAG_structure_type)
-                        {
-                            tag_decl_kind = clang::TTK_Struct;
-                            default_accessibility = eAccessPublic;
-                        }
-                        else if (tag == DW_TAG_union_type)
-                        {
-                            tag_decl_kind = clang::TTK_Union;
-                            default_accessibility = eAccessPublic;
-                        }
-                        else if (tag == DW_TAG_class_type)
-                        {
-                            tag_decl_kind = clang::TTK_Class;
-                            default_accessibility = eAccessPrivate;
-                        }
-
-
-                        if (is_forward_declaration)
-                        {
-                            // We have a forward declaration to a type and we need
-                            // to try and find a full declaration. We look in the
-                            // current type index just in case we have a forward
-                            // declaration followed by an actual declarations in the
-                            // DWARF. If this fails, we need to look elsewhere...
-                        
-                            type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
-
-                            if (!type_sp && m_debug_map_symfile)
-                            {
-                                // We weren't able to find a full declaration in
-                                // this DWARF, see if we have a declaration anywhere    
-                                // else...
-                                type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
-                            }
-
+                        if (m_unique_ast_type_map.Find (type_name_const_str,
+                                                        die,
+                                                        decl,
+                                                        unique_ast_entry))
+                        {
+                            // We have already parsed this type or from another 
+                            // compile unit. GCC loves to use the "one definition
+                            // rule" which can result in multiple definitions
+                            // of the same class over and over in each compile
+                            // unit.
+                            type_sp = unique_ast_entry.m_type_sp;
                             if (type_sp)
                             {
-                                // We found a real definition for this type elsewhere
-                                // so lets use it and cache the fact that we found
-                                // a complete type for this die
                                 m_die_to_type[die] = type_sp.get();
                                 return type_sp;
                             }
                         }
-                        assert (tag_decl_kind != -1);
-                        bool clang_type_was_created = false;
-                        clang_type = m_forward_decl_die_to_clang_type.lookup (die);
-                        if (clang_type == NULL)
-                        {
-                            clang_type_was_created = true;
-                            clang_type = ast.CreateRecordType (type_name_cstr, 
-                                                               tag_decl_kind, 
-                                                               GetClangDeclContextForDIE (dwarf_cu, die), 
-                                                               class_language);
-                        }
+                    }
+                    
+                    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
 
-                        // Store a forward declaration to this class type in case any 
-                        // parameters in any class methods need it for the clang 
-                        // types for function prototypes. 
-                        m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
-                        type_sp.reset (new Type (die->GetOffset(), 
-                                                 this, 
-                                                 type_name_const_str, 
-                                                 byte_size, 
-                                                 NULL, 
-                                                 LLDB_INVALID_UID, 
-                                                 Type::eEncodingIsUID, 
-                                                 &decl, 
-                                                 clang_type, 
-                                                 Type::eResolveStateForward));
+                    int tag_decl_kind = -1;
+                    AccessType default_accessibility = eAccessNone;
+                    if (tag == DW_TAG_structure_type)
+                    {
+                        tag_decl_kind = clang::TTK_Struct;
+                        default_accessibility = eAccessPublic;
+                    }
+                    else if (tag == DW_TAG_union_type)
+                    {
+                        tag_decl_kind = clang::TTK_Union;
+                        default_accessibility = eAccessPublic;
+                    }
+                    else if (tag == DW_TAG_class_type)
+                    {
+                        tag_decl_kind = clang::TTK_Class;
+                        default_accessibility = eAccessPrivate;
+                    }
 
-                        m_die_to_type[die] = type_sp.get();
 
-                        // Add our type to the unique type map so we don't
-                        // 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_die = die;
-//                        unique_ast_entry.m_declaration = decl;
-//                        m_unique_ast_type_map.Insert (type_name_const_str, 
-//                                                      unique_ast_entry);
-                        
-                        if (die->HasChildren() == false && is_forward_declaration == false)
+                    if (is_forward_declaration)
+                    {
+                        // We have a forward declaration to a type and we need
+                        // to try and find a full declaration. We look in the
+                        // current type index just in case we have a forward
+                        // declaration followed by an actual declarations in the
+                        // DWARF. If this fails, we need to look elsewhere...
+                    
+                        type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
+
+                        if (!type_sp && m_debug_map_symfile)
+                        {
+                            // We weren't able to find a full declaration in
+                            // this DWARF, see if we have a declaration anywhere    
+                            // else...
+                            type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
+                        }
+
+                        if (type_sp)
                         {
-                            // No children for this struct/union/class, lets finish it
-                            ast.StartTagDeclarationDefinition (clang_type);
-                            ast.CompleteTagDeclarationDefinition (clang_type);
-                        }
-                        else if (clang_type_was_created)
-                        {
-                            // Leave this as a forward declaration until we need
-                            // to know the details of the type. lldb_private::Type
-                            // will automatically call the SymbolFile virtual function
-                            // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
-                            // When the definition needs to be defined.
-                            m_forward_decl_die_to_clang_type[die] = clang_type;
-                            m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
-                            ClangASTContext::SetHasExternalStorage (clang_type, true);
+                            // We found a real definition for this type elsewhere
+                            // so lets use it and cache the fact that we found
+                            // a complete type for this die
+                            m_die_to_type[die] = type_sp.get();
+                            return type_sp;
                         }
                     }
+                    assert (tag_decl_kind != -1);
+                    bool clang_type_was_created = false;
+                    clang_type = m_forward_decl_die_to_clang_type.lookup (die);
+                    if (clang_type == NULL)
+                    {
+                        clang_type_was_created = true;
+                        clang_type = ast.CreateRecordType (type_name_cstr, 
+                                                           tag_decl_kind, 
+                                                           GetClangDeclContextForDIE (dwarf_cu, die), 
+                                                           class_language);
+                    }
+
+                    // Store a forward declaration to this class type in case any 
+                    // parameters in any class methods need it for the clang 
+                    // types for function prototypes. 
+                    m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
+                    type_sp.reset (new Type (die->GetOffset(), 
+                                             this, 
+                                             type_name_const_str, 
+                                             byte_size, 
+                                             NULL, 
+                                             LLDB_INVALID_UID, 
+                                             Type::eEncodingIsUID, 
+                                             &decl, 
+                                             clang_type, 
+                                             Type::eResolveStateForward));
+
+
+                    // Add our type to the unique type map so we don't
+                    // 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_die = die;
+                    unique_ast_entry.m_declaration = decl;
+                    m_unique_ast_type_map.Insert (type_name_const_str, 
+                                                  unique_ast_entry);
+                    
+                    if (die->HasChildren() == false && is_forward_declaration == false)
+                    {
+                        // No children for this struct/union/class, lets finish it
+                        ast.StartTagDeclarationDefinition (clang_type);
+                        ast.CompleteTagDeclarationDefinition (clang_type);
+                    }
+                    else if (clang_type_was_created)
+                    {
+                        // Leave this as a forward declaration until we need
+                        // to know the details of the type. lldb_private::Type
+                        // will automatically call the SymbolFile virtual function
+                        // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
+                        // When the definition needs to be defined.
+                        m_forward_decl_die_to_clang_type[die] = clang_type;
+                        m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
+                        ClangASTContext::SetHasExternalStorage (clang_type, true);
+                    }
                 }
                 break;
 
@@ -3380,8 +3376,6 @@
                                                  &decl, 
                                                  clang_type, 
                                                  Type::eResolveStateForward));
-                        
-                        m_die_to_type[die] = type_sp.get();
 
 #if LEAVE_ENUMS_FORWARD_DECLARED
                         // Leave this as a forward declaration until we need
@@ -3652,9 +3646,7 @@
                                              Type::eEncodingIsUID, 
                                              &decl, 
                                              clang_type, 
-                                             Type::eResolveStateFull));
-                    
-                    m_die_to_type[die] = type_sp.get();
+                                             Type::eResolveStateFull));                    
                     assert(type_sp.get());
                 }
                 break;
@@ -3749,7 +3741,6 @@
                                                      clang_type, 
                                                      Type::eResolveStateFull));
                             type_sp->SetEncodingType (element_type);
-                            m_die_to_type[die] = type_sp.get();
                         }
                     }
                 }
@@ -3802,7 +3793,6 @@
                                                  NULL, 
                                                  clang_type, 
                                                  Type::eResolveStateForward));
-                        m_die_to_type[die] = type_sp.get();
                     }
                                             
                     break;
@@ -3841,13 +3831,11 @@
 //                  type_sp->SetUserDefinedType(udt_sp);
 //              }
 
-                if (type_sp.unique())
-                {
-                    // We are ready to put this type into the uniqued list up at the module level
-                    type_list->Insert (type_sp);
+                //printf ("Adding type to map: 0x%8.8x for %s\n", die->GetOffset(), type_sp->GetName().GetCString());
+                // We are ready to put this type into the uniqued list up at the module level
+                type_list->Insert (type_sp);
 
-                    m_die_to_type[die] = type_sp.get();
-                }
+                m_die_to_type[die] = type_sp.get();
             }
         }
         else if (type_ptr != DIE_IS_BEING_PARSED)

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=125207&r1=125206&r2=125207&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Feb  9 13:06:17 2011
@@ -32,7 +32,7 @@
 // Project includes
 #include "DWARFDefines.h"
 #include "NameToDIE.h"
-//#include "UniqueDWARFASTType.h"
+#include "UniqueDWARFASTType.h"
 
 
 //----------------------------------------------------------------------
@@ -351,7 +351,7 @@
          m_is_external_ast_source:1;
 
     std::auto_ptr<DWARFDebugRanges>     m_ranges;
-//    UniqueDWARFASTTypeMap m_unique_ast_type_map;
+    UniqueDWARFASTTypeMap m_unique_ast_type_map;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *> DIEToDeclContextMap;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr;
     typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> DIEToVariableSP;





More information about the lldb-commits mailing list