This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a85b9d16387: Support expressions in the context of a 
reference (authored by emrekultursay, committed by labath).

Changed prior to commit:
  https://reviews.llvm.org/D128126?vs=438454&id=438659#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128126/new/

https://reviews.llvm.org/D128126

Files:
  lldb/source/Expression/UserExpression.cpp
  lldb/test/API/commands/expression/context-object/TestContextObject.py
  lldb/test/API/commands/expression/context-object/main.cpp

Index: lldb/test/API/commands/expression/context-object/main.cpp
===================================================================
--- lldb/test/API/commands/expression/context-object/main.cpp
+++ lldb/test/API/commands/expression/context-object/main.cpp
@@ -31,6 +31,9 @@
   cpp_namespace::CppStruct cpp_struct = cpp_namespace::GetCppStruct();
   cpp_struct.function();
 
+  cpp_namespace::CppStruct &cpp_struct_ref = cpp_struct;
+  cpp_struct_ref.function();
+
   int field = 4444;
 
   cpp_namespace::CppUnion cpp_union;
Index: lldb/test/API/commands/expression/context-object/TestContextObject.py
===================================================================
--- lldb/test/API/commands/expression/context-object/TestContextObject.py
+++ lldb/test/API/commands/expression/context-object/TestContextObject.py
@@ -16,34 +16,34 @@
         frame = thread.GetFrameAtIndex(0)
 
         #
-        # Test C++ struct variable
+        # Test C++ struct variable and reference-to-struct variable
         #
-
-        obj_val = frame.FindVariable("cpp_struct")
-        self.assertTrue(obj_val.IsValid())
-
-        # Test an empty expression evaluation
-        value = obj_val.EvaluateExpression("")
-        self.assertFalse(value.IsValid())
-        self.assertFalse(value.GetError().Success())
-
-        # Test retrieveing of a field (not a local with the same name)
-        value = obj_val.EvaluateExpression("field")
-        self.assertTrue(value.IsValid())
-        self.assertSuccess(value.GetError())
-        self.assertEqual(value.GetValueAsSigned(), 1111)
-
-        # Test functions evaluation
-        value = obj_val.EvaluateExpression("function()")
-        self.assertTrue(value.IsValid())
-        self.assertSuccess(value.GetError())
-        self.assertEqual(value.GetValueAsSigned(), 2222)
-
-        # Test that we retrieve the right global
-        value = obj_val.EvaluateExpression("global.field")
-        self.assertTrue(value.IsValid())
-        self.assertSuccess(value.GetError())
-        self.assertEqual(value.GetValueAsSigned(), 1111)
+        for obj in "cpp_struct", "cpp_struct_ref":
+            obj_val = frame.FindVariable(obj)
+            self.assertTrue(obj_val.IsValid())
+
+            # Test an empty expression evaluation
+            value = obj_val.EvaluateExpression("")
+            self.assertFalse(value.IsValid())
+            self.assertFalse(value.GetError().Success())
+
+            # Test retrieveing of a field (not a local with the same name)
+            value = obj_val.EvaluateExpression("field")
+            self.assertTrue(value.IsValid())
+            self.assertSuccess(value.GetError())
+            self.assertEqual(value.GetValueAsSigned(), 1111)
+
+            # Test functions evaluation
+            value = obj_val.EvaluateExpression("function()")
+            self.assertTrue(value.IsValid())
+            self.assertSuccess(value.GetError())
+            self.assertEqual(value.GetValueAsSigned(), 2222)
+
+            # Test that we retrieve the right global
+            value = obj_val.EvaluateExpression("global.field")
+            self.assertTrue(value.IsValid())
+            self.assertSuccess(value.GetError())
+            self.assertEqual(value.GetValueAsSigned(), 1111)
 
         #
         # Test C++ union variable
Index: lldb/source/Expression/UserExpression.cpp
===================================================================
--- lldb/source/Expression/UserExpression.cpp
+++ lldb/source/Expression/UserExpression.cpp
@@ -145,8 +145,9 @@
   Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step));
 
   if (ctx_obj) {
-    static unsigned const ctx_type_mask =
-        lldb::TypeFlags::eTypeIsClass | lldb::TypeFlags::eTypeIsStructUnion;
+    static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
+                                          lldb::TypeFlags::eTypeIsStructUnion |
+                                          lldb::TypeFlags::eTypeIsReference;
     if (!(ctx_obj->GetTypeInfo() & ctx_type_mask)) {
       LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of "
                     "an invalid type, can't run expressions.");
@@ -155,6 +156,21 @@
     }
   }
 
+  if (ctx_obj && ctx_obj->GetTypeInfo() & lldb::TypeFlags::eTypeIsReference) {
+    Status error;
+    lldb::ValueObjectSP deref_ctx_sp = ctx_obj->Dereference(error);
+    if (!error.Success()) {
+      LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of "
+                    "a reference type that can't be dereferenced, can't run "
+                    "expressions.");
+      error.SetErrorString(
+          "passed context object of an reference type cannot be deferenced");
+      return lldb::eExpressionSetupError;
+    }
+
+    ctx_obj = deref_ctx_sp.get();
+  }
+
   lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy();
   lldb::LanguageType language = options.GetLanguage();
   const ResultType desired_type = options.DoesCoerceToId()
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to