-
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 1 commit
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 |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
| """ | ||
| 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"]) |
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
| #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 |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
| """ | ||
| 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"]) |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
| 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 |
30 changes: 30 additions & 0 deletions
30
...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,30 @@ | ||
| """ | ||
| 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'"]) | ||
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
| #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; | ||
|
|
||
| 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 |
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
| """ | ||
| 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") |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
| 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 | ||
| } |
6 changes: 6 additions & 0 deletions
6
lldb/test/API/commands/frame/var-dil/basics/SharedPtr/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,6 @@ | ||
| CXX_SOURCES := main.cpp | ||
| CXXFLAGS_EXTRAS := -std=c++14 | ||
|
|
||
| USE_LIBCPP := 1 | ||
|
|
||
| include Makefile.rules |
36 changes: 36 additions & 0 deletions
36
lldb/test/API/commands/frame/var-dil/basics/SharedPtr/TestFrameVarDILSharedPtr.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,36 @@ | ||
| """ | ||
| Make sure 'frame var' using DIL parser/evaluator works for shared/weak pointers. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
| class TestFrameVarDILSharedPtr(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("ptr_node.__ptr_", | ||
| type="std::shared_ptr<NodeS>::element_type *") | ||
| self.expect_var_path("ptr_node.__ptr_->value", value="1") | ||
| self.expect_var_path("ptr_node.__ptr_->next.__ptr_->value", value="2") | ||
|
|
||
| self.expect_var_path("ptr_int.__ptr_", | ||
| type="std::shared_ptr<int>::element_type *") | ||
| self.expect_var_path("*ptr_int.__ptr_", value="1") | ||
| self.expect_var_path("ptr_int_weak.__ptr_", | ||
| type="std::weak_ptr<int>::element_type *") | ||
| self.expect_var_path("*ptr_int_weak.__ptr_", value="1") |
29 changes: 29 additions & 0 deletions
29
lldb/test/API/commands/frame/var-dil/basics/SharedPtr/TestFrameVarDILSharedPtrDeref.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,29 @@ | ||
| """ | ||
| Make sure 'frame var' using DIL parser/evaluator works for shared pointer deref. | ||
| """ | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test import lldbutil | ||
|
|
||
| import os | ||
| import shutil | ||
| import time | ||
|
|
||
| class TestFrameVarDILSharedPtrDeref(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("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") |
26 changes: 26 additions & 0 deletions
26
lldb/test/API/commands/frame/var-dil/basics/SharedPtr/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> | ||
|
|
||
| int | ||
| main(int argc, char **argv) | ||
| { | ||
|
|
||
| struct NodeS { | ||
| std::shared_ptr<NodeS> next; | ||
| int value; | ||
| }; | ||
| auto ptr_node = std::shared_ptr<NodeS>(new NodeS{nullptr, 2}); | ||
| ptr_node = std::shared_ptr<NodeS>(new NodeS{std::move(ptr_node), 1}); | ||
|
|
||
| std::shared_ptr<char> ptr_null; | ||
| auto ptr_int = std::make_shared<int>(1); | ||
| auto ptr_float = std::make_shared<float>(1.1f); | ||
|
|
||
| std::weak_ptr<int> ptr_int_weak = ptr_int; | ||
|
|
||
| std::shared_ptr<void> ptr_void = ptr_int; | ||
|
|
||
| // TestSharedPtr | ||
| // TestSharedPtrDeref | ||
| // TestSharedPtrCompare | ||
| 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.