-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LLDB] Update DIL to handle smart pointers; add more tests. #143786
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
837e8dd
[LLDB] Update DIL to handle smart pointers; add more tests.
cmtice dde59df
Remove tests that depend on internals of smart ptr implementation.
cmtice 7dc28d7
Fix clang-format issues with tests.
cmtice 5144a91
Add fake smart pointer test.
cmtice cb2a8ae
Fix clang-format issues.
cmtice e823fd7
Fix another clang-format issue.
cmtice e3a8867
Address reviewer comments:
cmtice fe835ba
Fix clang-format issues.
cmtice 4f9e0fe
Move DIL tests for shared & unique pointers into existing dataformatt…
cmtice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
lldb/test/API/commands/frame/var-dil/basics/BitField/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
43 changes: 43 additions & 0 deletions
43
lldb/test/API/commands/frame/var-dil/basics/BitField/TestFrameVarDILBitField.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """ | ||
| Make sure 'frame var' using DIL parser/evaluator works for bit fields. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
|
|
||
| class TestFrameVarDILBitField(TestBase): | ||
| # If your test case doesn't stress debug info, then | ||
| # set this to true. That way it won't be run once for | ||
| # each debug info format. | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_frame_var(self): | ||
| self.build() | ||
| lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.runCmd("settings set target.experimental.use-DIL true") | ||
| self.expect_var_path("bf.a", value="1023") | ||
| self.expect_var_path("bf.b", value="9") | ||
| self.expect_var_path("bf.c", value="false") | ||
| self.expect_var_path("bf.d", value="true") | ||
|
|
||
| self.expect_var_path("abf.a", value="1023") | ||
| self.expect_var_path("abf.b", value="'\\x0f'") | ||
| self.expect_var_path("abf.c", value="3") | ||
|
|
||
| # Perform an operation to ensure we actually read the value. | ||
| # Address-of is not allowed for bit-fields. | ||
| self.expect( | ||
| "frame variable '&bf.a'", | ||
| error=True, | ||
| substrs=["'bf.a' doesn't have a valid address"], | ||
| ) |
42 changes: 42 additions & 0 deletions
42
lldb/test/API/commands/frame/var-dil/basics/BitField/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include <cstdint> | ||
|
|
||
| int main(int argc, char **argv) { | ||
| enum BitFieldEnum : uint32_t { kZero, kOne }; | ||
|
|
||
| struct BitFieldStruct { | ||
| uint16_t a : 10; | ||
| uint32_t b : 4; | ||
| bool c : 1; | ||
| bool d : 1; | ||
| int32_t e : 32; | ||
| uint32_t f : 32; | ||
| uint32_t g : 31; | ||
| uint64_t h : 31; | ||
| uint64_t i : 33; | ||
| BitFieldEnum j : 10; | ||
| }; | ||
|
|
||
| BitFieldStruct bf; | ||
| bf.a = 0b1111111111; | ||
| bf.b = 0b1001; | ||
| bf.c = 0b0; | ||
| bf.d = 0b1; | ||
| bf.e = 0b1; | ||
| bf.f = 0b1; | ||
| bf.g = 0b1; | ||
| bf.h = 0b1; | ||
| bf.i = 0b1; | ||
| bf.j = BitFieldEnum::kOne; | ||
|
|
||
| struct AlignedBitFieldStruct { | ||
| uint16_t a : 10; | ||
| uint8_t b : 4; | ||
| unsigned char : 0; | ||
| uint16_t c : 2; | ||
| }; | ||
|
|
||
| uint32_t data = ~0; | ||
| AlignedBitFieldStruct abf = (AlignedBitFieldStruct &)data; | ||
|
|
||
| return 0; // Set a breakpoint here | ||
| } |
3 changes: 3 additions & 0 deletions
3
lldb/test/API/commands/frame/var-dil/basics/Indirection/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
46 changes: 46 additions & 0 deletions
46
lldb/test/API/commands/frame/var-dil/basics/Indirection/TestFrameVarDILIndirection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| Make sure 'frame var' using DIL parser/evaluator works for indirection. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
|
|
||
| class TestFrameVarDILIndirection(TestBase): | ||
| # If your test case doesn't stress debug info, then | ||
| # set this to true. That way it won't be run once for | ||
| # each debug info format. | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_frame_var(self): | ||
| self.build() | ||
| lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.runCmd("settings set target.experimental.use-DIL true") | ||
| self.expect_var_path("*p", value="1") | ||
| self.expect_var_path("p", type="int *") | ||
| self.expect_var_path("*my_p", value="1") | ||
| self.expect_var_path("my_p", type="myp") | ||
| self.expect_var_path("*my_pr", type="int *") | ||
| self.expect_var_path("my_pr", type="mypr") | ||
|
|
||
| self.expect( | ||
| "frame variable '*1'", | ||
| error=True, | ||
| substrs=["Unexpected token: <'1' (numeric_constant)>"], | ||
| ) | ||
| self.expect( | ||
| "frame variable '*val'", | ||
| error=True, | ||
| substrs=[ | ||
| "dereference failed: not a pointer, reference or array type: (int) val" | ||
| ], | ||
| ) |
12 changes: 12 additions & 0 deletions
12
lldb/test/API/commands/frame/var-dil/basics/Indirection/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| int main(int argc, char **argv) { | ||
| int val = 1; | ||
| int *p = &val; | ||
|
|
||
| typedef int *myp; | ||
| myp my_p = &val; | ||
|
|
||
| typedef int *&mypr; | ||
| mypr my_pr = p; | ||
|
|
||
| return 0; // Set a breakpoint here | ||
| } |
3 changes: 3 additions & 0 deletions
3
lldb/test/API/commands/frame/var-dil/basics/PointerDereference/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
48 changes: 48 additions & 0 deletions
48
...API/commands/frame/var-dil/basics/PointerDereference/TestFrameVarDILPointerDereference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """ | ||
| Test DIL pointer dereferencing. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
|
|
||
| class TestFrameVarDILPointerDereference(TestBase): | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_frame_var(self): | ||
| self.build() | ||
| lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.runCmd("settings set target.experimental.use-DIL true") | ||
| self.expect_var_path("*p_int0", value="0") | ||
| self.expect_var_path("*cp_int5", value="5") | ||
| self.expect_var_path("&pp_void0[2]", type="void **") | ||
| self.expect_var_path("**pp_int0", value="0") | ||
| self.expect_var_path("&**pp_int0", type="int *") | ||
| self.expect( | ||
| "frame variable '&p_void[0]'", | ||
| error=True, | ||
| substrs=["subscript of pointer to incomplete type 'void'"], | ||
| ) | ||
|
|
||
| # Verify some of the returned values. | ||
| pp_void0_2_got = self.expect_var_path("&pp_void0[2]", type="void **") | ||
| # Initialized in C++ code to point to the same value | ||
| pp_void0_2_exp = self.expect_var_path("pp_void0_2", type="void **") | ||
| self.assertEqual( | ||
| pp_void0_2_got.GetValueAsAddress(), pp_void0_2_exp.GetValueAsAddress() | ||
| ) | ||
| pp_int0_2stars_got = self.expect_var_path("&**pp_int0", type="int *") | ||
| pp_int0_2stars_exp = self.expect_var_path("pp_int0_2stars", type="int *") | ||
| self.assertEqual( | ||
| pp_int0_2stars_got.GetValueAsAddress(), | ||
| pp_int0_2stars_exp.GetValueAsAddress(), | ||
| ) | ||
34 changes: 34 additions & 0 deletions
34
lldb/test/API/commands/frame/var-dil/basics/PointerDereference/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include <cstddef> | ||
|
|
||
| int main(int argc, char **argv) { | ||
| int *p_null = nullptr; | ||
| const char *p_char1 = "hello"; | ||
|
|
||
| typedef const char *my_char_ptr; | ||
| my_char_ptr my_p_char1 = p_char1; | ||
|
|
||
| int offset = 5; | ||
| int array[10]; | ||
| array[0] = 0; | ||
| array[offset] = offset; | ||
|
|
||
| int (&array_ref)[10] = array; | ||
|
|
||
| int *p_int0 = &array[0]; | ||
| int **pp_int0 = &p_int0; | ||
| const int *cp_int0 = &array[0]; | ||
| const int *cp_int5 = &array[offset]; | ||
|
|
||
| typedef int *td_int_ptr_t; | ||
| td_int_ptr_t td_int_ptr0 = &array[0]; | ||
|
|
||
| void *p_void = (void *)p_char1; | ||
| void **pp_void0 = &p_void; | ||
| void **pp_void1 = pp_void0 + 1; | ||
|
|
||
| void **pp_void0_2 = &pp_void0[2]; | ||
| int *pp_int0_2stars = &**pp_int0; | ||
| std::nullptr_t std_nullptr_t = nullptr; | ||
|
|
||
| return 0; // Set a breakpoint here | ||
| } |
3 changes: 3 additions & 0 deletions
3
lldb/test/API/commands/frame/var-dil/basics/QualifiedId/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
31 changes: 31 additions & 0 deletions
31
lldb/test/API/commands/frame/var-dil/basics/QualifiedId/TestFrameVarDILQualifiedId.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| Make sure 'frame var' using DIL parser/evaluator works for namespaces. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
|
|
||
| class TestFrameVarDILQualifiedId(TestBase): | ||
| # If your test case doesn't stress debug info, then | ||
| # set this to true. That way it won't be run once for | ||
| # each debug info format. | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_frame_var(self): | ||
| self.build() | ||
| lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.runCmd("settings set target.experimental.use-DIL true") | ||
| self.expect_var_path("::ns::i", value="1") | ||
| self.expect_var_path("ns::i", value="1") | ||
| self.expect_var_path("::ns::ns::i", value="2") | ||
| self.expect_var_path("ns::ns::i", value="2") |
16 changes: 16 additions & 0 deletions
16
lldb/test/API/commands/frame/var-dil/basics/QualifiedId/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| namespace ns { | ||
|
|
||
| int i = 1; | ||
|
|
||
| namespace ns { | ||
|
|
||
| int i = 2; | ||
|
|
||
| } // namespace ns | ||
|
|
||
| } // namespace ns | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
|
||
| return 0; // Set a breakpoint here | ||
| } |
3 changes: 3 additions & 0 deletions
3
lldb/test/API/commands/frame/var-dil/basics/SyntheticDereference/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CXX_SOURCES := main.cpp | ||
|
|
||
| include Makefile.rules |
34 changes: 34 additions & 0 deletions
34
...commands/frame/var-dil/basics/SyntheticDereference/TestFrameVarDILSyntheticDereference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """ | ||
| Test code for dereferencing synthetic wrapped pointers. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
|
|
||
| class DILSyntheticDereferenceTestCase(TestBase): | ||
| # If your test case doesn't stress debug info, then | ||
| # set this to true. That way it won't be run once for | ||
| # each debug info format. | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_frame_var(self): | ||
| self.build() | ||
| lldbutil.run_to_source_breakpoint( | ||
| self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp") | ||
| ) | ||
|
|
||
| self.runCmd("settings set target.experimental.use-DIL true") | ||
| self.runCmd("script from wrapPtrSynthProvider import *") | ||
| self.runCmd("type synth add -l wrapPtrSynthProvider wrap_ptr") | ||
|
|
||
| self.expect_var_path("ptr_node->value", value="1") | ||
| self.expect_var_path("ptr_node->next->value", value="2") | ||
| self.expect_var_path("(*ptr_node).value", value="1") | ||
| self.expect_var_path("(*(*ptr_node).next).value", value="2") | ||
|
|
||
| self.expect_var_path("ptr_node.ptr", type="NodeS *") | ||
| self.expect_var_path("ptr_node.ptr->value", value="1") | ||
| self.expect_var_path("ptr_node.ptr->next.ptr->value", value="2") |
26 changes: 26 additions & 0 deletions
26
lldb/test/API/commands/frame/var-dil/basics/SyntheticDereference/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include <memory> | ||
|
|
||
| struct NodeS; | ||
|
|
||
| // Class to wrap pointers. | ||
| class wrap_ptr { | ||
| public: | ||
| NodeS *ptr; | ||
|
|
||
| wrap_ptr(NodeS *n_ptr) : ptr(n_ptr) {} | ||
| }; | ||
|
|
||
| struct NodeS { | ||
| wrap_ptr next; | ||
| int value; | ||
|
|
||
| NodeS(NodeS *n_ptr, int val) : next(wrap_ptr(n_ptr)), value(val) {} | ||
| }; | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
|
||
| // Make a short linked list of fake smart pointers. | ||
| auto ptr_node = wrap_ptr(new NodeS(new NodeS(nullptr, 2), 1)); | ||
|
|
||
| return 0; // Set a breakpoint here | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since the goal here is to explicitly check handling pointer arithmetic, you may want to add additional checks for the values you get this way.
expect_var_pathreturns the SBValue it has located, so you could do something like: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.
Thanks for the suggestion! Done.