[Lldb-commits] [lldb] r125208 - in /lldb/branches/apple/calcite/lldb: include/lldb/Symbol/Declaration.h lldb.xcodeproj/project.pbxproj source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h source/Symbol/Declaration.cpp

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


Author: gclayton
Date: Wed Feb  9 13:06:31 2011
New Revision: 125208

URL: http://llvm.org/viewvc/llvm-project?rev=125208&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/branches/apple/calcite/lldb/include/lldb/Symbol/Declaration.h
    lldb/branches/apple/calcite/lldb/lldb.xcodeproj/project.pbxproj
    lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/branches/apple/calcite/lldb/source/Symbol/Declaration.cpp

Modified: lldb/branches/apple/calcite/lldb/include/lldb/Symbol/Declaration.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/include/lldb/Symbol/Declaration.h?rev=125208&r1=125207&r2=125208&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/include/lldb/Symbol/Declaration.h (original)
+++ lldb/branches/apple/calcite/lldb/include/lldb/Symbol/Declaration.h Wed Feb  9 13:06:31 2011
@@ -199,6 +199,10 @@
                         ///< zero indicates no column information is available.
 };
 
+    
+bool
+operator == (const Declaration &lhs, const Declaration &rhs);
+
 } // namespace lldb_private
 
 #endif  // liblldb_Declaration_h_

Modified: lldb/branches/apple/calcite/lldb/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/lldb.xcodeproj/project.pbxproj?rev=125208&r1=125207&r2=125208&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/branches/apple/calcite/lldb/lldb.xcodeproj/project.pbxproj Wed Feb  9 13:06:31 2011
@@ -67,6 +67,8 @@
 		26680336116005EF008E1FE4 /* SBBreakpointLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AF16CC7114086A1007A7B3F /* SBBreakpointLocation.cpp */; };
 		26680337116005F1008E1FE4 /* SBBreakpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AF16A9C11402D5B007A7B3F /* SBBreakpoint.cpp */; };
 		2668035C11601108008E1FE4 /* LLDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26680207115FD0ED008E1FE4 /* LLDB.framework */; };
+		266847D413031C98002262D6 /* UniqueDWARFASTType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266847D213031C98002262D6 /* UniqueDWARFASTType.cpp */; };
+		266847D513031C98002262D6 /* UniqueDWARFASTType.h in Headers */ = {isa = PBXBuildFile; fileRef = 266847D313031C98002262D6 /* UniqueDWARFASTType.h */; };
 		266A42D6128E3FFB0090CF7C /* ClangNamespaceDecl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266A42D5128E3FFB0090CF7C /* ClangNamespaceDecl.cpp */; };
 		266A42D8128E40040090CF7C /* ClangNamespaceDecl.h in Headers */ = {isa = PBXBuildFile; fileRef = 266A42D7128E40040090CF7C /* ClangNamespaceDecl.h */; };
 		268F9D53123AA15200B91E9B /* SBSymbolContextList.h in Headers */ = {isa = PBXBuildFile; fileRef = 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -569,6 +571,8 @@
 		2660D9F711922A1300958FBD /* StringExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StringExtractor.h; path = source/Utility/StringExtractor.h; sourceTree = "<group>"; };
 		2660D9FE11922A7F00958FBD /* ThreadPlanStepUntil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadPlanStepUntil.cpp; path = source/Target/ThreadPlanStepUntil.cpp; sourceTree = "<group>"; };
 		26680207115FD0ED008E1FE4 /* LLDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LLDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+		266847D213031C98002262D6 /* UniqueDWARFASTType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UniqueDWARFASTType.cpp; path = ../../../../../../../../../../../private/tmp/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp; sourceTree = "<group>"; };
+		266847D313031C98002262D6 /* UniqueDWARFASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UniqueDWARFASTType.h; path = ../../../../../../../../../../../private/tmp/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.h; sourceTree = "<group>"; };
 		266960591199F4230075C61A /* build-llvm.pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; path = "build-llvm.pl"; sourceTree = "<group>"; };
 		2669605A1199F4230075C61A /* build-swig-wrapper-classes.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "build-swig-wrapper-classes.sh"; sourceTree = "<group>"; };
 		2669605B1199F4230075C61A /* checkpoint-llvm.pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; path = "checkpoint-llvm.pl"; sourceTree = "<group>"; };
@@ -1371,6 +1375,8 @@
 		260C89B210F57C5600BB2B04 /* DWARF */ = {
 			isa = PBXGroup;
 			children = (
+				266847D213031C98002262D6 /* UniqueDWARFASTType.cpp */,
+				266847D313031C98002262D6 /* UniqueDWARFASTType.h */,
 				260C89B310F57C5600BB2B04 /* DWARFAbbreviationDeclaration.cpp */,
 				260C89B410F57C5600BB2B04 /* DWARFAbbreviationDeclaration.h */,
 				260C89B610F57C5600BB2B04 /* DWARFAttribute.h */,
@@ -2315,6 +2321,7 @@
 				B23DD25012EDFAC1000C3894 /* ARMUtils.h in Headers */,
 				B2D3033712EFA5C500F84EB3 /* InstructionUtils.h in Headers */,
 				B287E63F12EFAE2C00C9BEFE /* ARMDefines.h in Headers */,
+				266847D513031C98002262D6 /* UniqueDWARFASTType.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2818,6 +2825,7 @@
 				B296983712C2FB98002D92C3 /* CommandObjectVersion.cpp in Sources */,
 				2621C9CD12EA009300711A30 /* EmulateInstructionARM.cpp in Sources */,
 				2621CA0B12EA107700711A30 /* EmulateInstruction.cpp in Sources */,
+				266847D413031C98002262D6 /* UniqueDWARFASTType.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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=125208&r1=125207&r2=125208&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 Wed Feb  9 13:06:31 2011
@@ -179,7 +179,8 @@
     m_namespace_index(),
     m_indexed (false),
     m_is_external_ast_source (false),
-    m_ranges()
+    m_ranges(),
+    m_unique_ast_type_map ()
 {
 }
 
@@ -3168,6 +3169,28 @@
                         }
                     }
 
+                    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();
+                                return type_sp;
+                            }
+                        }
+                    }
+                    
                     DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
 
                     int tag_decl_kind = -1;
@@ -3242,9 +3265,17 @@
                                              &decl, 
                                              clang_type, 
                                              Type::eResolveStateForward));
-                    
-                    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)
                     {
                         // No children for this struct/union/class, lets finish it
@@ -3262,7 +3293,6 @@
                         m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
                         ClangASTContext::SetHasExternalStorage (clang_type, true);
                     }
-                    
                 }
                 break;
 
@@ -3346,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
@@ -3618,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;
@@ -3715,7 +3741,6 @@
                                                      clang_type, 
                                                      Type::eResolveStateFull));
                             type_sp->SetEncodingType (element_type);
-                            m_die_to_type[die] = type_sp.get();
                         }
                     }
                 }
@@ -3768,7 +3793,6 @@
                                                  NULL, 
                                                  clang_type, 
                                                  Type::eResolveStateForward));
-                        m_die_to_type[die] = type_sp.get();
                     }
                                             
                     break;
@@ -3800,20 +3824,10 @@
                     type_sp->SetSymbolContextScope(symbol_context_scope);
                 }
 
-//              if (udt_sp.get())
-//              {
-//                  if (is_forward_declaration)
-//                      udt_sp->GetFlags().Set(UserDefType::flagIsForwardDefinition);
-//                  type_sp->SetUserDefinedType(udt_sp);
-//              }
+                // We are ready to put this type into the uniqued list up at the module level
+                type_list->Insert (type_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);
-
-                    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/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=125208&r1=125207&r2=125208&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/branches/apple/calcite/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Feb  9 13:06:31 2011
@@ -32,6 +32,7 @@
 // Project includes
 #include "DWARFDefines.h"
 #include "NameToDIE.h"
+#include "UniqueDWARFASTType.h"
 
 
 //----------------------------------------------------------------------
@@ -216,7 +217,7 @@
         flagsGotDebugPubNamesData   = (1 << 7),
         flagsGotDebugPubTypesData   = (1 << 8),
         flagsGotDebugRangesData     = (1 << 9),
-        flagsGotDebugStrData        = (1 << 10),
+        flagsGotDebugStrData        = (1 << 10)
     };
 
     DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF);
@@ -350,7 +351,7 @@
          m_is_external_ast_source:1;
 
     std::auto_ptr<DWARFDebugRanges>     m_ranges;
-
+    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;

Modified: lldb/branches/apple/calcite/lldb/source/Symbol/Declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Symbol/Declaration.cpp?rev=125208&r1=125207&r2=125208&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Symbol/Declaration.cpp (original)
+++ lldb/branches/apple/calcite/lldb/source/Symbol/Declaration.cpp Wed Feb  9 13:06:31 2011
@@ -173,3 +173,14 @@
         return 1;
     return 0;
 }
+
+bool
+lldb_private::operator == (const Declaration &lhs, const Declaration &rhs)
+{
+    if (lhs.GetColumn () == rhs.GetColumn ())
+        if (lhs.GetLine () == rhs.GetLine ())
+            return lhs.GetFile() == rhs.GetFile();
+    return false;
+}
+
+





More information about the lldb-commits mailing list