[Lldb-commits] [lldb] [lldb] Support "dereferencing" std::optional in `frame var` (PR #107077)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 3 03:21:59 PDT 2024
https://github.com/labath created https://github.com/llvm/llvm-project/pull/107077
None
>From 86b1e913b0756974b82b69f803238974f249b876 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 3 Sep 2024 12:15:17 +0200
Subject: [PATCH] [lldb] Support "dereferencing" std::optional
---
.../Plugins/Language/CPlusPlus/GenericOptional.cpp | 2 ++
.../optional/TestDataFormatterGenericOptional.py | 12 ++++++++++++
.../data-formatter-stl/generic/optional/main.cpp | 5 +++++
3 files changed, 19 insertions(+)
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