Skip to content

[lldb] Support "dereferencing" std::optional in frame var #107077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea would be nice to bubble a nicer error up somehow. Looks like ValueObject currently just drops any error set by the dereferenced ValueObject (we don't set one in the formatter currently anyway). But not urgent

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#define HAVE_OPTIONAL 0
#endif

struct X {
int x;
};

int main() {
bool has_optional = HAVE_OPTIONAL;

Expand All @@ -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);

Expand Down
Loading