8943b25966808821d059c097bde7456798b7651c
[openbsd] /
1 # coding=utf8
2 """
3 Test lldb data formatter subsystem.
4 """
5
6
7
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class LibcxxStringDataFormatterTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line number to break at.
22         self.line = line_number('main.cpp', '// Set break point at this line.')
23         ns = 'ndk' if lldbplatformutil.target_is_android() else ''
24         self.namespace = 'std::__' + ns + '1'
25
26     @add_test_categories(["libc++"])
27     @expectedFailureAll(bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android")
28     def test_with_run_command(self):
29         """Test that that file and class static variables display correctly."""
30         self.build()
31         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
32
33         lldbutil.run_break_set_by_file_and_line(
34             self, "main.cpp", self.line, num_expected_locations=-1)
35
36         self.runCmd("run", RUN_SUCCEEDED)
37
38         # The stop reason of the thread should be breakpoint.
39         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                     substrs=['stopped',
41                              'stop reason = breakpoint'])
42
43         # This is the function to remove the custom formats in order to have a
44         # clean slate for the next test case.
45         def cleanup():
46             self.runCmd('type format clear', check=False)
47             self.runCmd('type summary clear', check=False)
48             self.runCmd('type filter clear', check=False)
49             self.runCmd('type synth clear', check=False)
50             self.runCmd(
51                 "settings set target.max-children-count 256",
52                 check=False)
53
54         # Execute the cleanup function during test case tear down.
55         self.addTearDownHook(cleanup)
56
57         ns = self.namespace
58         self.expect(
59             "frame variable",
60             substrs=[
61                 '(%s::wstring) wempty = L""'%ns,
62                 '(%s::wstring) s = L"hello world! מזל טוב!"'%ns,
63                 '(%s::wstring) S = L"!!!!"'%ns,
64                 '(const wchar_t *) mazeltov = 0x',
65                 'L"מזל טוב"',
66                 '(%s::string) empty = ""'%ns,
67                 '(%s::string) q = "hello world"'%ns,
68                 '(%s::string) Q = "quite a long std::strin with lots of info inside it"'%ns,
69                 '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"'%ns,
70                 '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'%ns,
71                 '(%s::u16string) u16_string = u"ß水氶"'%ns,
72                 # FIXME: This should have a 'u' prefix.
73                 '(%s::u16string) u16_empty = ""'%ns,
74                 '(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns,
75                 # FIXME: This should have a 'U' prefix.
76                 '(%s::u32string) u32_empty = ""'%ns,
77                 '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, '
78                 '%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns),
79         ])
80
81         self.runCmd("n")
82
83         TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne")
84         summaryOptions = lldb.SBTypeSummaryOptions()
85         summaryOptions.SetCapping(lldb.eTypeSummaryUncapped)
86         uncappedSummaryStream = lldb.SBStream()
87         TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions)
88         uncappedSummary = uncappedSummaryStream.GetData()
89         self.assertTrue(uncappedSummary.find("someText") > 0,
90                         "uncappedSummary does not include the full string")
91         summaryOptions.SetCapping(lldb.eTypeSummaryCapped)
92         cappedSummaryStream = lldb.SBStream()
93         TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions)
94         cappedSummary = cappedSummaryStream.GetData()
95         self.assertTrue(
96             cappedSummary.find("someText") <= 0,
97             "cappedSummary includes the full string")
98
99         self.expect_expr("s", result_type=ns+"::wstring", result_summary='L"hello world! מזל טוב!"')
100
101         self.expect(
102             "frame variable",
103             substrs=[
104                 '(%s::wstring) S = L"!!!!!"'%ns,
105                 '(const wchar_t *) mazeltov = 0x',
106                 'L"מזל טוב"',
107                 '(%s::string) q = "hello world"'%ns,
108                 '(%s::string) Q = "quite a long std::strin with lots of info inside it"'%ns,
109                 '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"'%ns,
110                 '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'%ns,
111                 '(%s::u16string) u16_string = u"ß水氶"'%ns,
112                 '(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns,
113                 '(%s::u32string) u32_empty = ""'%ns,
114                 '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, '
115                 '%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns),
116         ])