[Lldb-commits] [lldb] r143676 - /lldb/trunk/source/Expression/ClangUserExpression.cpp

Sean Callanan scallanan at apple.com
Thu Nov 3 19:09:33 PDT 2011


Author: spyffe
Date: Thu Nov  3 21:09:33 2011
New Revision: 143676

URL: http://llvm.org/viewvc/llvm-project?rev=143676&view=rev
Log:
Occasionally LLDB runs into contexts where the
target is stopped in a C++ or Objective-C method
but the "self" pointer's valid range actually
doesn't cover the current location.  Before, that
was confusing Clang to the point where it crashed;
now, we sanity-check and fall back to pretending
we're in a C function if "self" or "this" isn't
available.

Modified:
    lldb/trunk/source/Expression/ClangUserExpression.cpp

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=143676&r1=143675&r2=143676&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Thu Nov  3 21:09:33 2011
@@ -82,7 +82,7 @@
 }
 
 void
-ClangUserExpression::ScanContext(ExecutionContext &exe_ctx)
+ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Error &err)
 {
     m_target = exe_ctx.GetTargetPtr();
     
@@ -109,6 +109,28 @@
     {
         if (method_decl->isInstance())
         {
+            VariableList *vars = frame->GetVariableList(false);
+            
+            const char *thisErrorString = "Stopped in a C++ method, but 'this' isn't available; pretending we are in a generic context";
+            
+            if (!vars)
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorString(thisErrorString);
+                return;
+            }
+            
+            lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
+            
+            if (!this_var ||
+                !this_var->IsInScope(frame) || 
+                !this_var->LocationIsValidForFrame (frame))
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorString(thisErrorString);
+                return;
+            }
+            
             m_cplusplus = true;
             m_needs_object_ptr = true;
             
@@ -125,9 +147,31 @@
         }
     }
     else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_context))
-    {
+    {        
         if (method_decl->isInstanceMethod())
         {
+            VariableList *vars = frame->GetVariableList(false);
+            
+            const char *selfErrorString = "Stopped in an Objective-C method, but 'self' isn't available; pretending we are in a generic context";
+            
+            if (!vars)
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorString(selfErrorString);
+                return;
+            }
+            
+            lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
+            
+            if (!self_var || 
+                !self_var->IsInScope(frame) || 
+                !self_var->LocationIsValidForFrame (frame))
+            {
+                err.SetErrorToGenericError();
+                err.SetErrorString(selfErrorString);
+                return;
+            }
+            
             m_objectivec = true;
             m_needs_object_ptr = true;
         }
@@ -182,7 +226,14 @@
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
-    ScanContext(exe_ctx);
+    Error err;
+    
+    ScanContext(exe_ctx, err);
+    
+    if (!err.Success())
+    {
+        error_stream.Printf("warning: %s\n", err.AsCString());
+    }
     
     StreamString m_transformed_stream;
     





More information about the lldb-commits mailing list