-
Notifications
You must be signed in to change notification settings - Fork 16k
[lldb][Expression] Make __lldb_expr function qualifiers match source context #177922
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import lldb | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
|
|
||
| class TestCase(TestBase): | ||
| def test(self): | ||
| self.build() | ||
| (_, process, _, _) = lldbutil.run_to_source_breakpoint( | ||
| self, "Break: const_method begin", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.expect_expr("bar()", result_value="2", result_type="int") | ||
| self.expect( | ||
| "expression m_const_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member", | ||
| "with const-qualified type", | ||
| ], | ||
| ) | ||
| self.expect( | ||
| "expression m_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member within const member function" | ||
| ], | ||
| ) | ||
| self.expect_expr("((Foo*)this)->bar()", result_type="double", result_value="5") | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, | ||
| process, | ||
| "Break: const_method no-this lambda", | ||
| lldb.SBFileSpec("main.cpp"), | ||
| ) | ||
|
|
||
| self.expect( | ||
| "expression x = 7.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member within const member function" | ||
| ], | ||
| ) | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, | ||
| process, | ||
| "Break: const_method mutable no-this lambda", | ||
| lldb.SBFileSpec("main.cpp"), | ||
| ) | ||
|
|
||
| self.expect_expr("x = 7.0; x", result_value="7") | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, process, "Break: const_method lambda", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| # FIXME: mutating this capture should be disallowed in a non-mutable lambda. | ||
| self.expect_expr("y = 8.0") | ||
| self.expect_expr("bar()", result_value="2", result_type="int") | ||
| self.expect( | ||
| "expression m_const_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member", | ||
| "with const-qualified type", | ||
| ], | ||
| ) | ||
| self.expect( | ||
| "expression m_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member within const member function" | ||
| ], | ||
| ) | ||
| self.expect_expr("m_mem", result_value="-2") | ||
| self.expect_expr("((Foo*)this)->bar()", result_type="double", result_value="5") | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, | ||
| process, | ||
| "Break: const_method mutable lambda", | ||
| lldb.SBFileSpec("main.cpp"), | ||
| ) | ||
|
|
||
| self.expect_expr("y = 9.0") | ||
| self.expect_expr("bar()", result_value="2", result_type="int") | ||
| self.expect( | ||
| "expression m_const_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member", | ||
| "with const-qualified type", | ||
| ], | ||
| ) | ||
| self.expect( | ||
| "expression m_mem = 2.0", | ||
| error=True, | ||
| substrs=[ | ||
| "cannot assign to non-static data member within const member function" | ||
| ], | ||
| ) | ||
| self.expect_expr("m_mem", result_value="-2") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include <cassert> | ||
| #include <cstdio> | ||
|
|
||
| struct Foo { | ||
| double bar() { return 5.0; } | ||
|
|
||
| int bar() const { return 2; } | ||
|
|
||
| int const_method() const { | ||
| auto x = bar(); | ||
| assert(x == 2); | ||
| std::puts("Break: const_method begin"); | ||
|
|
||
| [x] { | ||
| std::puts("Keep on multiple lines..."); | ||
| std::puts("Break: const_method no-this lambda"); | ||
| }(); | ||
|
|
||
| [x]() mutable { | ||
| std::puts("Keep on multiple lines..."); | ||
| std::puts("Break: const_method mutable no-this lambda"); | ||
| }(); | ||
|
|
||
| [this, y = x] { | ||
| auto x = bar() + y; | ||
| std::puts("Break: const_method lambda"); | ||
| }(); | ||
|
|
||
| [this, y = x]() mutable { | ||
| auto x = bar() + y; | ||
| std::puts("Break: const_method mutable lambda"); | ||
| }(); | ||
|
|
||
| return 120; | ||
| } | ||
|
|
||
| float m_mem = -2.0; | ||
| const float m_const_mem = -3.0; | ||
| }; | ||
|
|
||
| int main() { | ||
| const Foo f; | ||
| f.bar(); | ||
|
|
||
| Foo f2; | ||
| f2.bar(); | ||
|
|
||
| return Foo{}.const_method(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import lldb | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
|
|
||
| class TestCase(TestBase): | ||
| def test(self): | ||
| self.build() | ||
| (_, process, _, _) = lldbutil.run_to_source_breakpoint( | ||
| self, "Break here: const", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.expect_expr("bar()", result_type="double", result_value="5") | ||
| self.expect_expr("const_volatile_method()") | ||
| self.expect_expr("const_method()") | ||
| self.expect( | ||
| "expression volatile_method()", | ||
| error=True, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why can this not be expect_expr?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| substrs=["has type 'const Foo'", "but function is not marked const"], | ||
| ) | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, process, "Break here: volatile", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.expect_expr( | ||
| "bar()", result_type="const char *", result_summary='"volatile_bar"' | ||
| ) | ||
| self.expect_expr("const_volatile_method()") | ||
| self.expect( | ||
| "expression const_method()", | ||
| error=True, | ||
| substrs=["has type 'volatile Foo'", "but function is not marked volatile"], | ||
| ) | ||
| self.expect_expr("volatile_method()") | ||
|
|
||
| lldbutil.continue_to_source_breakpoint( | ||
| self, process, "Break here: const volatile", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.expect_expr("bar()", result_type="int", result_value="2") | ||
| self.expect_expr("other_cv_method()") | ||
|
|
||
| self.expect( | ||
| "expression const_method()", | ||
| error=True, | ||
| substrs=[ | ||
| "has type 'const volatile Foo'", | ||
| "but function is not marked const or volatile", | ||
| ], | ||
| ) | ||
| self.expect( | ||
| "expression volatile_method()", | ||
| error=True, | ||
| substrs=[ | ||
| "has type 'const volatile Foo'", | ||
| "but function is not marked const or volatile", | ||
| ], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include <cassert> | ||
| #include <cstdio> | ||
|
|
||
| struct Foo { | ||
| double bar() const { return 5.0; } | ||
| const char *bar() volatile { return "volatile_bar"; } | ||
| int bar() volatile const { return 2; } | ||
|
|
||
| int volatile_method() volatile { | ||
| std::puts("Break here: volatile"); | ||
| return 0; | ||
| } | ||
| int const_method() const { | ||
| std::puts("Break here: const"); | ||
| return 0; | ||
| } | ||
| int other_cv_method() const volatile { return 20; } | ||
|
|
||
| int const_volatile_method() const volatile { | ||
| auto x = bar(); | ||
| assert(x == 2); | ||
| other_cv_method(); | ||
|
|
||
| std::puts("Break here: const volatile"); | ||
|
|
||
| return 120; | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| const Foo f; | ||
| f.bar(); | ||
| f.const_method(); | ||
|
|
||
| volatile Foo f2; | ||
| f2.bar(); | ||
| f2.volatile_method(); | ||
|
|
||
| const volatile Foo f3; | ||
| f3.bar(); | ||
|
|
||
| return Foo{}.const_volatile_method(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: I was always puzzled why we use Printf format strings here. It would seem that << operations would be more readable and we could avoid the c_str() conversions that recompute the length of the strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea we could definitely do that. Probably best as a separate clean-up?