[Lldb-commits] [lldb] a5f03b4 - [lldb] Support "dereferencing" std::optional in `frame var` (#107077)

via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 3 04:22:34 PDT 2024


Author: Pavel Labath
Date: 2024-09-03T13:22:31+02:00
New Revision: a5f03b4adcd147aeecc0e0d029660c12fb4d2951

URL: https://github.com/llvm/llvm-project/commit/a5f03b4adcd147aeecc0e0d029660c12fb4d2951
DIFF: https://github.com/llvm/llvm-project/commit/a5f03b4adcd147aeecc0e0d029660c12fb4d2951.diff

LOG: [lldb] Support "dereferencing" std::optional in `frame var` (#107077)

Added: 
    

Modified: 
    lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py
    lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp b/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
index 23756de7f1e66e..a8a7c16de5e867 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
@@ -37,6 +37,8 @@ class GenericOptionalFrontend : public SyntheticChildrenFrontEnd {
   GenericOptionalFrontend(ValueObject &valobj, StdLib stdlib);
 
   size_t GetIndexOfChildWithName(ConstString name) override {
+    if (name == "$$dereference$$")
+      return 0;
     return formatters::ExtractIndexFromString(name.GetCString());
   }
 

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py
index f6507294bfb2ac..7dc656a7ae225c 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py
@@ -79,6 +79,18 @@ def cleanup():
             ],
         )
 
+        self.expect_var_path("*number_engaged", value="42")
+        self.expect_var_path("*x", children=[ValueCheck(name="x", value="42")])
+        self.expect_var_path("x->x", value="42")
+
+        # The error message could use some improvement, but at least we can
+        # check we don't crash.
+        self.expect(
+            "frame variable *number_not_engaged",
+            error=True,
+            substrs=["not a pointer or reference type"],
+        )
+
     @add_test_categories(["libc++"])
     ## Clang 7.0 is the oldest Clang that can reliably parse newer libc++ versions
     ## with -std=c++17.

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp
index 8f30df4626636c..18a95b9cc246c6 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp
@@ -12,6 +12,10 @@
 #define HAVE_OPTIONAL 0
 #endif
 
+struct X {
+  int x;
+};
+
 int main() {
   bool has_optional = HAVE_OPTIONAL;
 
@@ -25,6 +29,7 @@ int main() {
 
   optional_int number_not_engaged;
   optional_int number_engaged = 42;
+  std::optional<X> x = X{42};
 
   printf("%d\n", *number_engaged);
 


        


More information about the lldb-commits mailing list