[Lldb-commits] [lldb] r146465 - in /lldb/trunk: include/lldb/Expression/ClangUserExpression.h source/Expression/ClangUserExpression.cpp

Sean Callanan scallanan at apple.com
Mon Dec 12 17:42:04 PST 2011


Author: spyffe
Date: Mon Dec 12 19:42:04 2011
New Revision: 146465

URL: http://llvm.org/viewvc/llvm-project?rev=146465&view=rev
Log:
I have modified the part of the code that finds and
validates the "self," "this," and "_cmd" pointers
that get passed into expressions.  It used to check
them aggressively for validity before allowing the
expression to run as an object method; now, this
functionality is gated by a bool and off by default.

Now the default is that when LLDB is stopped in a
method of a class, code entered using "expr" will
always masquerade as an instance method.  If for
some reason "self," "this," or "_cmd" is unavailable
it will be reported as NULL.  This may cause the
expression to crash if it relies on those pointers,
but for example getting the addresses of ivars will
now work as the user would expect.

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

Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=146465&r1=146464&r2=146465&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Mon Dec 12 19:42:04 2011
@@ -354,6 +354,7 @@
     
     std::auto_ptr<ASTResultSynthesizer>         m_result_synthesizer;   ///< The result synthesizer, if one is needed.
     
+    bool                                        m_enforce_valid_object; ///< True if the expression parser should enforce the presence of a valid class pointer in order to generate the expression as a method.
     bool                                        m_cplusplus;            ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method).
     bool                                        m_objectivec;           ///< True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was in an Objective-C method).
     bool                                        m_static_method;        ///< True if the expression is compiled as a static (or class) method (currently true if it was parsed when exe_ctx was in an Objective-C class method).

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=146465&r1=146464&r2=146465&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Dec 12 19:42:04 2011
@@ -59,7 +59,8 @@
     m_static_method(false),
     m_target (NULL),
     m_evaluated_statically (false),
-    m_const_result ()
+    m_const_result (),
+    m_enforce_valid_object (false)
 {
     switch (m_language)
     {
@@ -128,26 +129,29 @@
     {
         if (m_allow_cxx && 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))
+            if (m_enforce_valid_object)
             {
-                err.SetErrorToGenericError();
-                err.SetErrorString(thisErrorString);
-                return;
+                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;
@@ -169,26 +173,29 @@
     {        
         if (m_allow_objc)
         {
-            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)
+            if (m_enforce_valid_object)
             {
-                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;
+                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;
@@ -400,8 +407,8 @@
             
             if (!(m_expr_decl_map->GetObjectPointer(object_ptr, object_name, exe_ctx, materialize_error)))
             {
-                error_stream.Printf("Couldn't get required object pointer: %s\n", materialize_error.AsCString());
-                return false;
+                error_stream.Printf("warning: couldn't get required object pointer (substituting NULL): %s\n", materialize_error.AsCString());
+                object_ptr = 0;
             }
             
             if (m_objectivec)
@@ -410,8 +417,8 @@
                 
                 if (!(m_expr_decl_map->GetObjectPointer(cmd_ptr, cmd_name, exe_ctx, materialize_error, true)))
                 {
-                    error_stream.Printf("Couldn't get required object pointer: %s\n", materialize_error.AsCString());
-                    return false;
+                    error_stream.Printf("warning: couldn't get object pointer (substituting NULL): %s\n", materialize_error.AsCString());
+                    cmd_ptr = 0;
                 }
             }
         }





More information about the lldb-commits mailing list