diff options
author | Jim Ingham <jingham@apple.com> | 2018-07-13 19:28:32 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2018-07-13 19:28:32 +0000 |
commit | 393fe62e3373c04ac9a2ab391335dfe6e08949e7 (patch) | |
tree | 5e74973e4fd8a341872bac637782c4996c264416 /lldb/packages/Python/lldbsuite | |
parent | 0925c1fdffe79874e0f628024202e97354a49319 (diff) | |
download | bcm5719-llvm-393fe62e3373c04ac9a2ab391335dfe6e08949e7.tar.gz bcm5719-llvm-393fe62e3373c04ac9a2ab391335dfe6e08949e7.zip |
Fix the libcxx set, multiset, vector and bitset formatters to work on references.
The synthetic child providers for these classes had a type expression that matched
pointers & references to the type, but the Front End only worked on the actual object.
I fixed this by adding a way for the Synthetic Child FrontEnd provider to request dereference,
and then had these formatters use that mode.
<rdar://problem/40849836>
Differential Revision: https://reviews.llvm.org/D49279
llvm-svn: 337035
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
8 files changed, 202 insertions, 120 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py index 73a1b4e16bf..6e1a9d8710c 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/TestDataFormatterLibcxxBitset.py @@ -35,7 +35,7 @@ class TestDataFormatterLibcxxBitset(TestBase): "variable: %s, index: %d"%(name, size)) @add_test_categories(["libc++"]) - def test(self): + def test_value(self): """Test that std::bitset is displayed correctly""" self.build() lldbutil.run_to_source_breakpoint(self, '// break here', @@ -44,3 +44,18 @@ class TestDataFormatterLibcxxBitset(TestBase): self.check("empty", 0) self.check("small", 13) self.check("large", 200) + + def test_ptr_and_ref(self): + """Test that ref and ptr to std::bitset is displayed correctly""" + self.build() + (_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, + 'Check ref and ptr', + lldb.SBFileSpec("main.cpp", False)) + + self.check("ref", 13) + self.check("ptr", 13) + + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check("ref", 200) + self.check("ptr", 200) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp index a80f97b8015..2a1532adb4b 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/bitset/main.cpp @@ -1,4 +1,5 @@ #include <bitset> +#include <stdio.h> template<std::size_t N> void fill(std::bitset<N> &b) { @@ -10,11 +11,19 @@ void fill(std::bitset<N> &b) { } } +template<std::size_t N> +void by_ref_and_ptr(std::bitset<N> &ref, std::bitset<N> *ptr) { + // Check ref and ptr + return; +} + int main() { std::bitset<0> empty; std::bitset<13> small; fill(small); std::bitset<200> large; fill(large); - return 0; // break here + by_ref_and_ptr(small, &small); // break here + by_ref_and_ptr(large, &large); + return 0; } diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py index 9ebbf160787..72a886ff128 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py @@ -27,22 +27,31 @@ class LibcxxMultiSetDataFormatterTestCase(TestBase): self.assertTrue(var.IsValid()) return var.GetType().GetCanonicalType().GetName() + def check_ii(self, var_name): + """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr. + We use this to make sure we get the same values for ii when we look at the object + directly, and when we look at a reference to the object. """ + self.expect( + "frame variable " + var_name, + substrs=["size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + self.expect("frame variable " + var_name + "[2]", substrs=[" = 2"]) + self.expect( + "p " + var_name, + substrs=[ + "size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + @add_test_categories(["libc++"]) def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - bkpt = self.target().FindBreakpointByID( - lldbutil.run_break_set_by_source_regexp( - self, "Set break point at this line.")) - - self.runCmd("run", RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", lldb.SBFileSpec("main.cpp", False)) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. @@ -63,7 +72,7 @@ class LibcxxMultiSetDataFormatterTestCase(TestBase): "Type: " + ii_type) self.expect("frame variable ii", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ii", substrs=[ @@ -74,38 +83,26 @@ class LibcxxMultiSetDataFormatterTestCase(TestBase): "[3] = 3", "[4] = 4", "[5] = 5"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) - self.expect( - "frame variable ii", - substrs=[ - "size=7", - "[2] = 2", - "[3] = 3", - "[6] = 6"]) - self.expect( - "p ii", - substrs=[ - "size=7", - "[2] = 2", - "[3] = 3", - "[6] = 6"]) - self.expect("frame variable ii[2]", substrs=[" = 2"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) + + self.check_ii("ii") + + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable ii", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable ii", substrs=["size=0", "{}"]) ss_type = self.getVariableType("ss") self.assertTrue(ss_type.startswith(self.namespace + "::multiset"), "Type: " + ss_type) self.expect("frame variable ss", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=[ "size=2", '[0] = "a"', '[1] = "a very long string is right here"']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=[ @@ -123,7 +120,7 @@ class LibcxxMultiSetDataFormatterTestCase(TestBase): '[0] = "a"', '[1] = "a very long string is right here"']) self.expect("frame variable ss[2]", substrs=[' = "b"']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=[ @@ -131,3 +128,18 @@ class LibcxxMultiSetDataFormatterTestCase(TestBase): '[0] = "a"', '[1] = "a very long string is right here"', '[2] = "c"']) + + @add_test_categories(["libc++"]) + def test_ref_and_ptr(self): + """Test that the data formatters work on ref and ptr.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref and ptr.", + lldb.SBFileSpec("main.cpp", False)) + # The reference should print just like the value: + self.check_ii("ref") + + self.expect("frame variable ptr", + substrs=["ptr =", "size=7"]) + self.expect("expr ptr", + substrs=["size=7"]) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp index c315dcb9b40..dd3d8be4ae9 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp @@ -16,6 +16,12 @@ int thefoo_rw(int arg = 1) return g_the_foo; } +void by_ref_and_ptr(intset &ref, intset *ptr) +{ + // Stop here to check by ref and ptr + return; +} + int main() { intset ii; @@ -31,7 +37,9 @@ int main() ii.insert(6); thefoo_rw(1); // Set break point at this line. - + + by_ref_and_ptr(ii, &ii); + ii.clear(); thefoo_rw(1); // Set break point at this line. diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py index 64e718bb940..a6f1a3d2f43 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py @@ -27,21 +27,31 @@ class LibcxxSetDataFormatterTestCase(TestBase): self.assertTrue(var.IsValid()) return var.GetType().GetCanonicalType().GetName() + def check_ii(self, var_name): + """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr. + We use this to make sure we get the same values for ii when we look at the object + directly, and when we look at a reference to the object. """ + self.expect( + "frame variable " + var_name, + substrs=["size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + self.expect("frame variable " + var_name + "[2]", substrs=[" = 2"]) + self.expect( + "p " + var_name, + substrs=[ + "size=7", + "[2] = 2", + "[3] = 3", + "[6] = 6"]) + @add_test_categories(["libc++"]) def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - - bkpt = self.target().FindBreakpointByID( - lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")) - - self.runCmd("run", RUN_SUCCEEDED) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Set break point at this line.", lldb.SBFileSpec("main.cpp", False)) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. @@ -62,7 +72,7 @@ class LibcxxSetDataFormatterTestCase(TestBase): "Type: " + ii_type) self.expect("frame variable ii", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ii", substrs=["size=6", @@ -72,24 +82,12 @@ class LibcxxSetDataFormatterTestCase(TestBase): "[3] = 3", "[4] = 4", "[5] = 5"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) - self.expect( - "frame variable ii", - substrs=["size=7", - "[2] = 2", - "[3] = 3", - "[6] = 6"]) - self.expect("frame variable ii[2]", substrs=[" = 2"]) - self.expect( - "p ii", - substrs=[ - "size=7", - "[2] = 2", - "[3] = 3", - "[6] = 6"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) + self.check_ii("ii") + + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable ii", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable ii", substrs=["size=0", "{}"]) ss_type = self.getVariableType("ss") @@ -97,13 +95,13 @@ class LibcxxSetDataFormatterTestCase(TestBase): "Type: " + ss_type) self.expect("frame variable ss", substrs=["size=0", "{}"]) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=["size=2", '[0] = "a"', '[1] = "a very long string is right here"']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=["size=4", @@ -119,10 +117,26 @@ class LibcxxSetDataFormatterTestCase(TestBase): '[0] = "a"', '[1] = "a very long string is right here"']) self.expect("frame variable ss[2]", substrs=[' = "b"']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect( "frame variable ss", substrs=["size=3", '[0] = "a"', '[1] = "a very long string is right here"', '[2] = "c"']) + + @add_test_categories(["libc++"]) + def test_ref_and_ptr(self): + """Test that the data formatters work on ref and ptr.""" + self.build() + (self.target, process, _, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref and ptr.", + lldb.SBFileSpec("main.cpp", False)) + # The reference should print just like the value: + self.check_ii("ref") + + self.expect("frame variable ptr", + substrs=["ptr =", "size=7"]) + self.expect("expr ptr", + substrs=["size=7"]) + diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp index 29efcc61e65..df39e9746c0 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp @@ -16,6 +16,12 @@ int thefoo_rw(int arg = 1) return g_the_foo; } +void by_ref_and_ptr(intset &ref, intset *ptr) +{ + // Stop here to check by ref and ptr + return; +} + int main() { intset ii; @@ -31,7 +37,9 @@ int main() ii.insert(6); thefoo_rw(1); // Set break point at this line. - + + by_ref_and_ptr(ii, &ii); + ii.clear(); thefoo_rw(1); // Set break point at this line. diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py index 203f9c0ae5d..8c52d812d9e 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/TestDataFormatterLibcxxVector.py @@ -20,21 +20,45 @@ class LibcxxVectorDataFormatterTestCase(TestBase): @add_test_categories(["libc++"]) @skipIf(debug_info="gmodules", bugnumber="https://bugs.llvm.org/show_bug.cgi?id=36048") - def test_with_run_command(self): - """Test that that file and class static variables display correctly.""" - self.build() - self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) - bkpt = self.target().FindBreakpointByID( - lldbutil.run_break_set_by_source_regexp( - self, "break here")) + def check_numbers(self, var_name): + self.expect("frame variable " + var_name, + substrs=[var_name + ' = size=7', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) - self.runCmd("run", RUN_SUCCEEDED) + self.expect("p " + var_name, + substrs=['$', 'size=7', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', - 'stop reason = breakpoint']) + # check access-by-index + self.expect("frame variable " + var_name + "[0]", + substrs=['1']) + self.expect("frame variable " + var_name + "[1]", + substrs=['12']) + self.expect("frame variable " + var_name + "[2]", + substrs=['123']) + self.expect("frame variable " + var_name + "[3]", + substrs=['1234']) + + def test_with_run_command(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.cpp", False)) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. @@ -54,7 +78,7 @@ class LibcxxVectorDataFormatterTestCase(TestBase): self.expect("frame variable numbers", substrs=['numbers = size=0']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) # first value added self.expect("frame variable numbers", @@ -63,7 +87,7 @@ class LibcxxVectorDataFormatterTestCase(TestBase): '}']) # add some more data - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable numbers", substrs=['numbers = size=4', @@ -96,47 +120,17 @@ class LibcxxVectorDataFormatterTestCase(TestBase): self.runCmd("type summary delete int_vect") # add some more data - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) - self.expect("frame variable numbers", - substrs=['numbers = size=7', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '[4] = 12345', - '[5] = 123456', - '[6] = 1234567', - '}']) - - self.expect("p numbers", - substrs=['$', 'size=7', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '[4] = 12345', - '[5] = 123456', - '[6] = 1234567', - '}']) - - # check access-by-index - self.expect("frame variable numbers[0]", - substrs=['1']) - self.expect("frame variable numbers[1]", - substrs=['12']) - self.expect("frame variable numbers[2]", - substrs=['123']) - self.expect("frame variable numbers[3]", - substrs=['1234']) + self.check_numbers("numbers") # clear out the vector and see that we do the right thing once again - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable numbers", substrs=['numbers = size=0']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) # first value added self.expect("frame variable numbers", @@ -170,7 +164,7 @@ class LibcxxVectorDataFormatterTestCase(TestBase): 'is', 'smart']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable strings", substrs=['vector has 4 items']) @@ -181,7 +175,22 @@ class LibcxxVectorDataFormatterTestCase(TestBase): self.expect("frame variable strings[1]", substrs=['is']) - lldbutil.continue_to_breakpoint(self.process(), bkpt) + lldbutil.continue_to_breakpoint(process, bkpt) self.expect("frame variable strings", substrs=['vector has 0 items']) + + def test_ref_and_ptr(self): + """Test that that file and class static variables display correctly.""" + self.build() + (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( + self, "Stop here to check by ref", lldb.SBFileSpec("main.cpp", False)) + + # The reference should display the same was as the value did + self.check_numbers("ref") + + # The pointer should just show the right number of elements: + + self.expect("frame variable ptr", substrs=['ptr =', ' size=7']) + + self.expect("p ptr", substrs=['$', 'size=7']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp index 32dc104784b..0e1dbe4f03e 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/vector/main.cpp @@ -4,6 +4,12 @@ typedef std::vector<int> int_vect; typedef std::vector<std::string> string_vect; +template <class T> +void by_ref_and_ptr(std::vector<T> &ref, std::vector<T> *ptr) { + // Stop here to check by ref + return; +} + int main() { int_vect numbers; @@ -14,6 +20,7 @@ int main() (numbers.push_back(12345)); // break here (numbers.push_back(123456)); (numbers.push_back(1234567)); + by_ref_and_ptr(numbers, &numbers); printf("break here"); numbers.clear(); |