[Lldb-commits] [lldb] [lldb] Support "dereferencing" std::optional in `frame var` (PR #107077)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 3 03:22:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Pavel Labath (labath)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/107077.diff
3 Files Affected:
- (modified) lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp (+2)
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py (+12)
- (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp (+5)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/107077
More information about the lldb-commits
mailing list