forked from OSchip/llvm-project
[formatters] Add a pointer and reference tests for a list and forward_list formatters for libstdcpp and libcxx
This adds extra tests for libstdcpp and libcxx list and forward_list formatters to check whether formatter behaves correctly when applied on pointer and reference values. Reviewed By: wallace Differential Revision: https://reviews.llvm.org/D115137
This commit is contained in:
parent
2ea3c8a50a
commit
6622c14113
|
@ -936,7 +936,7 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
|
|||
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
|
||||
RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$"),
|
||||
SyntheticChildrenSP(new ScriptedSyntheticChildren(
|
||||
stl_synth_flags,
|
||||
stl_deref_flags,
|
||||
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
|
||||
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
|
||||
RegularExpression("^std::(__cxx11::)?forward_list<.+>(( )?&)?$"),
|
||||
|
|
|
@ -84,10 +84,100 @@ class TestDataFormatterGenericForwardList(TestBase):
|
|||
'...'
|
||||
])
|
||||
|
||||
def do_test_ptr_and_ref(self, stdlib_type):
|
||||
"""Test that ref and ptr to std::forward_list is displayed correctly"""
|
||||
self.build(dictionary={stdlib_type: "1"})
|
||||
|
||||
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
|
||||
'Check ref and ptr',
|
||||
lldb.SBFileSpec("main.cpp", False))
|
||||
|
||||
self.expect("frame variable ref",
|
||||
substrs=[
|
||||
'size=0',
|
||||
'{}'])
|
||||
|
||||
self.expect("frame variable *ptr",
|
||||
substrs=[
|
||||
'size=0',
|
||||
'{}'])
|
||||
|
||||
lldbutil.continue_to_breakpoint(process, bkpt)
|
||||
|
||||
self.expect("frame variable ref",
|
||||
substrs=[
|
||||
'{',
|
||||
'[0] = 47',
|
||||
'}'])
|
||||
|
||||
self.expect("frame variable *ptr",
|
||||
substrs=[
|
||||
'{',
|
||||
'[0] = 47',
|
||||
'}'])
|
||||
|
||||
lldbutil.continue_to_breakpoint(process, bkpt)
|
||||
|
||||
self.expect("frame variable ref",
|
||||
substrs=[
|
||||
'size=5',
|
||||
'{',
|
||||
'[0] = 1',
|
||||
'[1] = 22',
|
||||
'[2] = 333',
|
||||
'[3] = 4444',
|
||||
'[4] = 55555',
|
||||
'}'])
|
||||
|
||||
self.expect("frame variable *ptr",
|
||||
substrs=[
|
||||
'size=5',
|
||||
'{',
|
||||
'[0] = 1',
|
||||
'[1] = 22',
|
||||
'[2] = 333',
|
||||
'[3] = 4444',
|
||||
'[4] = 55555',
|
||||
'}'])
|
||||
|
||||
lldbutil.continue_to_breakpoint(process, bkpt)
|
||||
|
||||
self.runCmd(
|
||||
"settings set target.max-children-count 256",
|
||||
check=False)
|
||||
|
||||
self.expect("settings show target.max-children-count", matching=True,
|
||||
substrs=['target.max-children-count (int) = 256'])
|
||||
|
||||
|
||||
self.expect("frame variable ref",matching=True,
|
||||
substrs=[
|
||||
'size=256',
|
||||
'[0] = 999',
|
||||
'[1] = 998',
|
||||
'[2] = 997',
|
||||
])
|
||||
|
||||
self.expect("frame variable *ptr",matching=True,
|
||||
substrs=[
|
||||
'size=256',
|
||||
'[0] = 999',
|
||||
'[1] = 998',
|
||||
'[2] = 997',
|
||||
])
|
||||
|
||||
@add_test_categories(["libstdcxx"])
|
||||
def test_libstdcpp(self):
|
||||
self.do_test(USE_LIBSTDCPP)
|
||||
|
||||
@add_test_categories(["libstdcxx"])
|
||||
def test_ptr_and_ref_libstdcpp(self):
|
||||
self.do_test_ptr_and_ref(USE_LIBSTDCPP)
|
||||
|
||||
@add_test_categories(["libc++"])
|
||||
def test_libcpp(self):
|
||||
self.do_test(USE_LIBCPP)
|
||||
|
||||
@add_test_categories(["libc++"])
|
||||
def test_ptr_and_ref_libcpp(self):
|
||||
self.do_test_ptr_and_ref(USE_LIBCPP)
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
#include <forward_list>
|
||||
|
||||
|
||||
void by_ref_and_ptr(std::forward_list<int> &ref, std::forward_list<int> *ptr) {
|
||||
// Check ref and ptr
|
||||
return;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::forward_list<int> empty{}, one_elt{47},
|
||||
five_elts{1, 22, 333, 4444, 55555}, thousand_elts{};
|
||||
for(int i = 0; i<1000;i++){
|
||||
thousand_elts.push_front(i);
|
||||
}
|
||||
return 0; // break here
|
||||
|
||||
by_ref_and_ptr(empty, &empty); // break here
|
||||
by_ref_and_ptr(one_elt, &one_elt);
|
||||
by_ref_and_ptr(five_elts, &five_elts);
|
||||
by_ref_and_ptr(thousand_elts, &thousand_elts);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -205,11 +205,58 @@ class GenericListDataFormatterTestCase(TestBase):
|
|||
self.assertTrue(
|
||||
self.frame().FindVariable("text_list").MightHaveChildren(),
|
||||
"text_list.MightHaveChildren() says False for non empty!")
|
||||
|
||||
def do_test_ptr_and_ref(self, stdlib_type):
|
||||
"""Test that ref and ptr to std::list is displayed correctly"""
|
||||
self.build(dictionary={stdlib_type: "1"})
|
||||
|
||||
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(self,
|
||||
'Check ref and ptr',
|
||||
lldb.SBFileSpec("main.cpp", False))
|
||||
|
||||
self.expect("frame variable ref",
|
||||
substrs=['size=4',
|
||||
'[0] = ', '1',
|
||||
'[1] = ', '2',
|
||||
'[2] = ', '3',
|
||||
'[3] = ', '4'])
|
||||
|
||||
|
||||
self.expect("frame variable *ptr",
|
||||
substrs=['size=4',
|
||||
'[0] = ', '1',
|
||||
'[1] = ', '2',
|
||||
'[2] = ', '3',
|
||||
'[3] = ', '4'])
|
||||
|
||||
lldbutil.continue_to_breakpoint(process, bkpt)
|
||||
|
||||
self.expect("frame variable ref",
|
||||
substrs=['size=4',
|
||||
'[0]', 'goofy',
|
||||
'[1]', 'is',
|
||||
'[2]', 'smart',
|
||||
'[3]', '!!!'])
|
||||
|
||||
self.expect("frame variable *ptr",
|
||||
substrs=['size=4',
|
||||
'[0]', 'goofy',
|
||||
'[1]', 'is',
|
||||
'[2]', 'smart',
|
||||
'[3]', '!!!'])
|
||||
|
||||
@add_test_categories(["libstdcxx"])
|
||||
def test_with_run_command_libstdcpp(self):
|
||||
self.do_test_with_run_command(USE_LIBSTDCPP)
|
||||
|
||||
@add_test_categories(["libstdcxx"])
|
||||
def test_ptr_and_ref_libstdcpp(self):
|
||||
self.do_test_ptr_and_ref(USE_LIBSTDCPP)
|
||||
|
||||
@add_test_categories(["libc++"])
|
||||
def test_with_run_command_libcpp(self):
|
||||
self.do_test_with_run_command(USE_LIBCPP)
|
||||
self.do_test_with_run_command(USE_LIBCPP)
|
||||
|
||||
@add_test_categories(["libc++"])
|
||||
def test_ptr_and_ref_libcpp(self):
|
||||
self.do_test_ptr_and_ref(USE_LIBCPP)
|
|
@ -4,6 +4,12 @@
|
|||
typedef std::list<int> int_list;
|
||||
typedef std::list<std::string> string_list;
|
||||
|
||||
|
||||
template <typename T> void by_ref_and_ptr(T &ref, T *ptr) {
|
||||
// Check ref and ptr
|
||||
return;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int_list numbers_list;
|
||||
|
@ -21,13 +27,16 @@ int main()
|
|||
numbers_list.push_back(2);
|
||||
numbers_list.push_back(3);
|
||||
numbers_list.push_back(4);
|
||||
|
||||
by_ref_and_ptr(numbers_list, &numbers_list);
|
||||
|
||||
string_list text_list;
|
||||
text_list.push_back(std::string("goofy")); // Optional break point at this line.
|
||||
text_list.push_back(std::string("is"));
|
||||
text_list.push_back(std::string("smart"));
|
||||
|
||||
text_list.push_back(std::string("!!!"));
|
||||
|
||||
by_ref_and_ptr(text_list, &text_list);
|
||||
|
||||
return 0; // Set final break point at this line.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue