Skip to content

Commit a5f03b4

Browse files
authored
[lldb] Support "dereferencing" std::optional in frame var (#107077)
1 parent 5e19e31 commit a5f03b4

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class GenericOptionalFrontend : public SyntheticChildrenFrontEnd {
3737
GenericOptionalFrontend(ValueObject &valobj, StdLib stdlib);
3838

3939
size_t GetIndexOfChildWithName(ConstString name) override {
40+
if (name == "$$dereference$$")
41+
return 0;
4042
return formatters::ExtractIndexFromString(name.GetCString());
4143
}
4244

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ def cleanup():
7979
],
8080
)
8181

82+
self.expect_var_path("*number_engaged", value="42")
83+
self.expect_var_path("*x", children=[ValueCheck(name="x", value="42")])
84+
self.expect_var_path("x->x", value="42")
85+
86+
# The error message could use some improvement, but at least we can
87+
# check we don't crash.
88+
self.expect(
89+
"frame variable *number_not_engaged",
90+
error=True,
91+
substrs=["not a pointer or reference type"],
92+
)
93+
8294
@add_test_categories(["libc++"])
8395
## Clang 7.0 is the oldest Clang that can reliably parse newer libc++ versions
8496
## with -std=c++17.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#define HAVE_OPTIONAL 0
1313
#endif
1414

15+
struct X {
16+
int x;
17+
};
18+
1519
int main() {
1620
bool has_optional = HAVE_OPTIONAL;
1721

@@ -25,6 +29,7 @@ int main() {
2529

2630
optional_int number_not_engaged;
2731
optional_int number_engaged = 42;
32+
std::optional<X> x = X{42};
2833

2934
printf("%d\n", *number_engaged);
3035

0 commit comments

Comments
 (0)