[Lldb-commits] [lldb] r107459 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Symbol/ClangASTContext.cpp tools/debugserver/source/MacOSX/MachProcess.cpp

Greg Clayton gclayton at apple.com
Thu Jul 1 18:29:14 PDT 2010


Author: gclayton
Date: Thu Jul  1 20:29:13 2010
New Revision: 107459

URL: http://llvm.org/viewvc/llvm-project?rev=107459&view=rev
Log:
More leaks detection:
- fixed 3 posix spawn attributes leaks 
- fixed us always leaking CXXBaseSpecifier objects when we create class 
  base classes. Clang apparently copies the base classes we pass in.

Fixed some code formatting in ClangASTContext.cpp.


Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Jul  1 20:29:13 2010
@@ -33,12 +33,8 @@
     //------------------------------------------------------------------
     // Constructors and Destructors
     //------------------------------------------------------------------
-//  ClangASTContext(Module *module);
-
     ClangASTContext(const char *target_triple);
 
-//  ClangASTContext(const ConstString &target_triple);
-
     ~ClangASTContext();
 
     clang::ASTContext *
@@ -131,40 +127,35 @@
     //------------------------------------------------------------------
 
     void *
-    CreateRecordType (
-        const char *name,
-        int kind,
-        clang::DeclContext *decl_ctx);
+    CreateRecordType (const char *name,
+                      int kind,
+                      clang::DeclContext *decl_ctx);
 
     bool
-    AddFieldToRecordType (
-        void * record_qual_type,
-        const char *name,
-        void * field_type,
-        int access,
-        uint32_t bitfield_bit_size);
-
+    AddFieldToRecordType (void * record_qual_type,
+                          const char *name,
+                          void * field_type,
+                          int access,
+                          uint32_t bitfield_bit_size);
+    
     bool
-    FieldIsBitfield (
-        clang::FieldDecl* field,
-        uint32_t& bitfield_bit_size);
+    FieldIsBitfield (clang::FieldDecl* field,
+                     uint32_t& bitfield_bit_size);
 
     static bool
-    FieldIsBitfield (
-        clang::ASTContext *ast_context,
-        clang::FieldDecl* field,
-        uint32_t& bitfield_bit_size);
+    FieldIsBitfield (clang::ASTContext *ast_context,
+                     clang::FieldDecl* field,
+                     uint32_t& bitfield_bit_size);
 
     static bool
     RecordHasFields (const clang::RecordDecl *record_decl);
 
     void
-    SetDefaultAccessForRecordFields (
-        void * clang_qual_type,
-        int default_accessibility,
-        int *assigned_accessibilities,
-        size_t num_assigned_accessibilities);
-
+    SetDefaultAccessForRecordFields (void * clang_qual_type,
+                                     int default_accessibility,
+                                     int *assigned_accessibilities,
+                                     size_t num_assigned_accessibilities);
+    
     //------------------------------------------------------------------
     // Aggregate Types
     //------------------------------------------------------------------
@@ -172,37 +163,34 @@
     IsAggregateType (void * clang_type);
 
     static uint32_t
-    GetNumChildren (
-        void * clang_type,
-        bool omit_empty_base_classes);
-
-    void *
-    GetChildClangTypeAtIndex (
-        const char *parent_name,
-        void * parent_clang_type,
-        uint32_t idx,
-        bool transparent_pointers,
-        bool omit_empty_base_classes,
-        std::string& child_name,
-        uint32_t &child_byte_size,
-        int32_t &child_byte_offset,
-        uint32_t &child_bitfield_bit_size,
-        uint32_t &child_bitfield_bit_offset);
+    GetNumChildren (void * clang_type,
+                    bool omit_empty_base_classes);
 
+    void *
+    GetChildClangTypeAtIndex (const char *parent_name,
+                              void * parent_clang_type,
+                              uint32_t idx,
+                              bool transparent_pointers,
+                              bool omit_empty_base_classes,
+                              std::string& child_name,
+                              uint32_t &child_byte_size,
+                              int32_t &child_byte_offset,
+                              uint32_t &child_bitfield_bit_size,
+                              uint32_t &child_bitfield_bit_offset);
+    
     static void *
-    GetChildClangTypeAtIndex (
-        clang::ASTContext *ast_context,
-        const char *parent_name,
-        void * parent_clang_type,
-        uint32_t idx,
-        bool transparent_pointers,
-        bool omit_empty_base_classes,
-        std::string& child_name,
-        uint32_t &child_byte_size,
-        int32_t &child_byte_offset,
-        uint32_t &child_bitfield_bit_size,
-        uint32_t &child_bitfield_bit_offset);
-
+    GetChildClangTypeAtIndex (clang::ASTContext *ast_context,
+                              const char *parent_name,
+                              void * parent_clang_type,
+                              uint32_t idx,
+                              bool transparent_pointers,
+                              bool omit_empty_base_classes,
+                              std::string& child_name,
+                              uint32_t &child_byte_size,
+                              int32_t &child_byte_offset,
+                              uint32_t &child_bitfield_bit_size,
+                              uint32_t &child_bitfield_bit_offset);
+    
     // Lookup a child given a name. This function will match base class names
     // and member member names in "clang_type" only, not descendants.
     static uint32_t
@@ -228,26 +216,27 @@
     //------------------------------------------------------------------
 
     bool
-    SetTagTypeKind (
-        void * tag_qual_type,
-        int kind);
+    SetTagTypeKind (void * tag_qual_type,
+                    int kind);
 
     //------------------------------------------------------------------
     // C++ Base Classes
     //------------------------------------------------------------------
 
     clang::CXXBaseSpecifier *
-    CreateBaseClassSpecifier (
-        void * base_class_type,
-        int access,
-        bool is_virtual,
-        bool base_of_class);
+    CreateBaseClassSpecifier (void * base_class_type,
+                              int access,
+                              bool is_virtual,
+                              bool base_of_class);
+    
+    static void
+    DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, 
+                               unsigned num_base_classes);
 
     bool
-    SetBaseClassesForClassType (
-        void * class_clang_type,
-        clang::CXXBaseSpecifier const * const *base_classes,
-        unsigned num_base_classes);
+    SetBaseClassesForClassType (void * class_clang_type,
+                                clang::CXXBaseSpecifier const * const *base_classes,
+                                unsigned num_base_classes);
 
     //------------------------------------------------------------------
     // DeclContext Functions
@@ -261,51 +250,45 @@
     //------------------------------------------------------------------
 
     clang::NamespaceDecl *
-    GetUniqueNamespaceDeclaration (
-        const char *name,
-        const Declaration &decl,
-        clang::DeclContext *decl_ctx);
+    GetUniqueNamespaceDeclaration (const char *name,
+                                   const Declaration &decl,
+                                   clang::DeclContext *decl_ctx);
 
     //------------------------------------------------------------------
     // Function Types
     //------------------------------------------------------------------
 
     clang::FunctionDecl *
-    CreateFunctionDeclaration (
-        const char *name,
-        void * function_Type,
-        int storage,
-        bool is_inline);
-
+    CreateFunctionDeclaration (const char *name,
+                               void * function_Type,
+                               int storage,
+                               bool is_inline);
+    
     void *
-    CreateFunctionType (
-        void * result_type,
-        void **args,
-        unsigned num_args,
-        bool isVariadic,
-        unsigned TypeQuals);
-
+    CreateFunctionType (void * result_type,
+                        void **args,
+                        unsigned num_args,
+                        bool isVariadic,
+                        unsigned TypeQuals);
+    
     clang::ParmVarDecl *
-    CreateParmeterDeclaration (
-        const char *name,
-        void * return_type,
-        int storage);
+    CreateParmeterDeclaration (const char *name,
+                               void * return_type,
+                               int storage);
 
     void
-    SetFunctionParameters (
-        clang::FunctionDecl *function_decl,
-        clang::ParmVarDecl **params,
-        unsigned num_params);
+    SetFunctionParameters (clang::FunctionDecl *function_decl,
+                           clang::ParmVarDecl **params,
+                           unsigned num_params);
 
     //------------------------------------------------------------------
     // Array Types
     //------------------------------------------------------------------
 
     void *
-    CreateArrayType (
-        void * element_type,
-        size_t element_count,
-        uint32_t bit_stride);
+    CreateArrayType (void * element_type,
+                     size_t element_count,
+                     uint32_t bit_stride);
 
     //------------------------------------------------------------------
     // Tag Declarations
@@ -323,14 +306,13 @@
     CreateEnumerationType (const Declaration &decl, const char *name);
 
     bool
-    AddEnumerationValueToEnumerationType (
-        void * enum_qual_type,
-        void * enumerator_qual_type,
-        const Declaration &decl,
-        const char *name,
-        int64_t enum_value,
-        uint32_t enum_value_bit_size);
-
+    AddEnumerationValueToEnumerationType (void * enum_qual_type,
+                                          void * enumerator_qual_type,
+                                          const Declaration &decl,
+                                          const char *name,
+                                          int64_t enum_value,
+                                          uint32_t enum_value_bit_size);
+    
     //------------------------------------------------------------------
     // Pointers & References
     //------------------------------------------------------------------
@@ -375,10 +357,9 @@
     // Typedefs
     //------------------------------------------------------------------
     void *
-    CreateTypedefType (
-        const char *name,
-        void * clang_type,
-        clang::DeclContext *decl_ctx);
+    CreateTypedefType (const char *name,
+                       void * clang_type,
+                       clang::DeclContext *decl_ctx);
 
     //------------------------------------------------------------------
     // Type names
@@ -390,11 +371,20 @@
     IsFloatingPointType (void * clang_type, uint32_t &count, bool &is_complex);
 
     //static bool
-    //ConvertFloatValueToString (clang::ASTContext *ast_context, void * clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str);
-
+    //ConvertFloatValueToString (clang::ASTContext *ast_context, 
+    //                           void * clang_type, 
+    //                           const uint8_t* bytes, 
+    //                           size_t byte_size, 
+    //                           int apint_byte_order, 
+    //                           std::string &float_str);
+    
     static size_t
-    ConvertStringToFloatValue (clang::ASTContext *ast_context, void * clang_type, const char *s, uint8_t *dst, size_t dst_size);
-
+    ConvertStringToFloatValue (clang::ASTContext *ast_context, 
+                               void * clang_type, 
+                               const char *s, 
+                               uint8_t *dst, 
+                               size_t dst_size);
+    
 protected:
     //------------------------------------------------------------------
     // Classes that inherit from ClangASTContext can see and modify these

Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp?rev=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp Thu Jul  1 20:29:13 2010
@@ -1802,6 +1802,8 @@
         if (err.Fail() || log)
             err.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp);
     }
+    
+    ::posix_spawnattr_destroy (&attr);
 
     // We have seen some cases where posix_spawnp was returning a valid
     // looking pid even when an error was returned, so clear it out

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Jul  1 20:29:13 2010
@@ -1869,6 +1869,9 @@
                                              (char * const*)inferior_envp),
                              eErrorTypePOSIX);
 
+
+            ::posix_spawnattr_destroy (&attr);
+
             if (file_actions_err.Success())
                 ::posix_spawn_file_actions_destroy (&file_actions);
 

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=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Jul  1 20:29:13 2010
@@ -2885,6 +2885,10 @@
                         {
                             type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, base_classes.data(), base_classes.size());
                         }
+                        
+                        // Clang will copy each CXXBaseSpecifier in "base_classes"
+                        // so we have to free them all.
+                        ClangASTContext::DeleteBaseClassSpecifiers (base_classes.data(), base_classes.size());
                     }
                     type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
                 }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jul  1 20:29:13 2010
@@ -201,38 +201,7 @@
 //    }
 }
 
-//----------------------------------------------------------------------
-// ClangASTContext constructor
-//----------------------------------------------------------------------
-//ClangASTContext::ClangASTContext(Module *module) :
-//  m_target_triple(),
-//  m_ast_context_ap(),
-//  m_language_options_ap(),
-//  m_source_manager_ap(),
-//  m_target_info_ap(),
-//  m_identifier_table_ap(),
-//  m_selector_table_ap(),
-//  m_builtins_ap()
-//{
-//  if (module)
-//  {
-//      ObjectFile * objfile = module->GetObjectFile();
-//      if (objfile)
-//          objfile->GetTargetTriple(m_target_triple);
-//  }
-//}
 
-//ClangASTContext::ClangASTContext(const ConstString& target_triple) :
-//  m_target_triple(target_triple),
-//  m_ast_context_ap(),
-//  m_language_options_ap(),
-//  m_source_manager_ap(),
-//  m_target_info_ap(),
-//  m_identifier_table_ap(),
-//  m_selector_table_ap(),
-//  m_builtins_ap()
-//{
-//}
 ClangASTContext::ClangASTContext(const char *target_triple) :
     m_target_triple(),
     m_ast_context_ap(),
@@ -920,6 +889,16 @@
     return NULL;
 }
 
+void
+ClangASTContext::DeleteBaseClassSpecifiers (CXXBaseSpecifier **base_classes, unsigned num_base_classes)
+{
+    for (unsigned i=0; i<num_base_classes; ++i)
+    {
+        delete base_classes[i];
+        base_classes[i] = NULL;
+    }
+}
+
 bool
 ClangASTContext::SetBaseClassesForClassType (void *class_clang_type, CXXBaseSpecifier const * const *base_classes, unsigned num_base_classes)
 {

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=107459&r1=107458&r2=107459&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Thu Jul  1 20:29:13 2010
@@ -1678,6 +1678,8 @@
             process->SetChildFileDescriptors(master_fd, master_fd, master_fd);
         }
     }
+    
+    ::posix_spawnattr_destroy (&attr);
 
     if (file_actions_valid)
     {





More information about the lldb-commits mailing list