[Lldb-commits] [lldb] r163014 - in /lldb/trunk: include/lldb/Symbol/ClangASTContext.h source/Core/ValueObject.cpp source/Symbol/ClangASTContext.cpp

Greg Clayton gclayton at apple.com
Fri Aug 31 11:56:25 PDT 2012


Author: gclayton
Date: Fri Aug 31 13:56:24 2012
New Revision: 163014

URL: http://llvm.org/viewvc/llvm-project?rev=163014&view=rev
Log:
<rdar://problem/12202862>

Added a fix for incorrect dynamic typing. Before when asking if a C++ class could be dynamic, we would answer yes for incomplete C++ classes. This turned out to have issues where if a class was not virtual, yet had its first ivar be an instance of a virtual class, we would incorrectly say that a class was virtual and we would downcast it to be a pointer to the first ivar. We now ask the class to complete itself prior to answering the question. We need to test the effects on memory of this change prior to submission. It is the safest and best fix, but it does have a potential downside of higher memory consumption.


Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=163014&r1=163013&r2=163014&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Aug 31 13:56:24 2012
@@ -868,9 +868,9 @@
     static bool
     IsPossibleDynamicType (clang::ASTContext *ast, 
                            lldb::clang_type_t clang_type, 
-                           lldb::clang_type_t *dynamic_pointee_type = NULL,
-                           bool cplusplus = true,
-                           bool objc = true);
+                           lldb::clang_type_t *dynamic_pointee_type, // Can pass NULL
+                           bool check_cplusplus,
+                           bool check_objc);
 
     static bool
     IsCStringType (lldb::clang_type_t clang_type, uint32_t &length);

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=163014&r1=163013&r2=163014&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri Aug 31 13:56:24 2012
@@ -1784,7 +1784,7 @@
     if (process)
         return process->IsPossibleDynamicValue(*this);
     else
-        return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
+        return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
 }
 
 ValueObjectSP

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=163014&r1=163013&r2=163014&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Aug 31 13:56:24 2012
@@ -5522,10 +5522,18 @@
                 break;
                 
             case clang::Type::Typedef:
-                return ClangASTContext::IsPossibleDynamicType (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), dynamic_pointee_type);
+                return ClangASTContext::IsPossibleDynamicType (ast,
+                                                               cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
+                                                               dynamic_pointee_type,
+                                                               check_cplusplus,
+                                                               check_objc);
             
             case clang::Type::Elaborated:
-                return ClangASTContext::IsPossibleDynamicType (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), dynamic_pointee_type);
+                return ClangASTContext::IsPossibleDynamicType (ast,
+                                                               cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
+                                                               dynamic_pointee_type,
+                                                               check_cplusplus,
+                                                               check_objc);
             
             default:
                 break;
@@ -5590,23 +5598,19 @@
                         CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl();
                         if (cxx_record_decl)
                         {
-                            // Do NOT complete the type here like we used to do
-                            // otherwise EVERY "class *" variable we have will try
-                            // to fully complete itself and this will take a lot of
-                            // time, memory and slow down debugging. If we have a complete
-                            // type, then answer the question definitively, else we
-                            // just say that a C++ class can possibly be dynamic...
-                            if (cxx_record_decl->isCompleteDefinition())
+                            bool is_complete = cxx_record_decl->isCompleteDefinition();
+                            if (!is_complete)
+                                is_complete = ClangASTContext::GetCompleteType (ast, clang_type);
+
+                            if (is_complete)
                             {
                                 success = cxx_record_decl->isDynamicClass();
                             }
                             else
                             {
-                                // We failed to get the complete type, so we have to 
-                                // treat this as a void * which we might possibly be
-                                // able to complete
-                                success = true;
+                                success = false;
                             }
+
                             if (success)
                             {
                                 if (dynamic_pointee_type)





More information about the lldb-commits mailing list