def do_test(self): """Test that Swift.String formats properly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") s1 = self.frame.FindVariable("s1") s2 = self.frame.FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame.FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue( uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") IContainZerosASCII = self.frame.FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame.FindVariable("IContainZerosUnicode") lldbutil.check_variable(self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable(self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"')
def data_formatter_commands(self): """Test that that file and class static variables display correctly.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1) 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']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect("frame variable", substrs = ['(std::__1::wstring) s = L"hello world! מזל טוב!"', '(std::__1::wstring) S = L"!!!!"', '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"']) self.runCmd("n") TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne"); summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream,summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream,summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue(cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.expect("frame variable", substrs = ['(std::__1::wstring) s = L"hello world! מזל טוב!"', '(std::__1::wstring) S = L"!!!!!"', '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"'])
def test_swift_string_variables(self): """Test that Swift.String formats properly""" self.build() lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) s1 = self.frame().FindVariable("s1") s2 = self.frame().FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.assertTrue( cappedSummary.endswith('"...'), "cappedSummary ends with quote dot dot dot") IContainZerosASCII = self.frame().FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame().FindVariable("IContainZerosUnicode") IContainEscapes = self.frame().FindVariable("IContainEscapes") lldbutil.check_variable( self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable( self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"') lldbutil.check_variable( self, IContainEscapes, summary='"Hello\\u{8}\\n\\u{8}\\u{8}\\nGoodbye"') self.expect( 'expression -l objc++ -- (char*)"Hello\b\b\b\b\bGoodbye"', substrs=['"Hello\\b\\b\\b\\b\\bGoodbye"'])
def do_test(self): """Test that Swift.String formats properly""" self.build() lldbutil.run_to_source_breakpoint( self, 'Set breakpoint here', lldb.SBFileSpec('main.swift')) s1 = self.frame().FindVariable("s1") s2 = self.frame().FindVariable("s2") lldbutil.check_variable(self, s1, summary='"Hello world"') lldbutil.check_variable(self, s2, summary='"ΞΕΛΛΘ"') TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") IContainZerosASCII = self.frame().FindVariable("IContainZerosASCII") IContainZerosUnicode = self.frame().FindVariable("IContainZerosUnicode") lldbutil.check_variable( self, IContainZerosASCII, summary='"a\\0b\\0c\\0d"') lldbutil.check_variable( self, IContainZerosUnicode, summary='"HFIHЗIHF\\0VЭHVHЗ90HGЭ"')
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) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=-1) 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']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) is_64_bit = self.process().GetAddressByteSize() == 8 # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) ns = self.namespace self.expect( "frame variable", substrs=[ '(%s::wstring) wempty = L""' % ns, '(%s::wstring) s = L"hello world! מזל טוב!"' % ns, '(%s::wstring) S = L"!!!!"' % ns, '(const wchar_t *) mazeltov = 0x', 'L"מזל טוב"', '(%s::string) empty = ""' % ns, '(%s::string) q = "hello world"' % ns, '(%s::string) Q = "quite a long std::strin with lots of info inside it"' % ns, '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' % ns, '(%s::u16string) u16_string = u"ß水氶"' % ns, # FIXME: This should have a 'u' prefix. '(%s::u16string) u16_empty = ""' % ns, '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns, # FIXME: This should have a 'U' prefix. '(%s::u32string) u32_empty = ""' % ns, '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' '%s::allocator<unsigned char> >) uchar = "aaaaa"' % (ns, ns, ns), ]) self.runCmd("n") TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue( uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.expect_expr("s", result_type=ns + "::wstring", result_summary='L"hello world! מזל טוב!"') self.expect( "frame variable", substrs=[ '(%s::wstring) S = L"!!!!!"' % ns, '(const wchar_t *) mazeltov = 0x', 'L"מזל טוב"', '(%s::string) q = "hello world"' % ns, '(%s::string) Q = "quite a long std::strin with lots of info inside it"' % ns, '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' % ns, '(%s::u16string) u16_string = u"ß水氶"' % ns, '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns, '(%s::u32string) u32_empty = ""' % ns, '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' '%s::allocator<unsigned char> >) uchar = "aaaaa"' % (ns, ns, ns), ]) # The test assumes that std::string is in its cap-size-data layout. is_alternate_layout = ( 'arm' in self.getArchitecture()) and self.platformIsDarwin() if is_64_bit and not is_alternate_layout: self.expect("frame variable garbage1", substrs=['garbage1 = Summary Unavailable']) self.expect("frame variable garbage2", substrs=['garbage2 = Summary Unavailable']) self.expect("frame variable garbage3", substrs=['garbage3 = Summary Unavailable']) self.expect("frame variable garbage4", substrs=['garbage4 = Summary Unavailable']) self.expect("frame variable garbage5", substrs=['garbage5 = Summary Unavailable'])
def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( self, "Set break point at this line.", self.main_spec) frame = thread.frames[0] # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) is_64_bit = self.process().GetAddressByteSize() == 8 # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) ns = self.namespace self.expect( "frame variable", substrs=[ '(%s::wstring) wempty = L""' % ns, '(%s::wstring) s = L"hello world! מזל טוב!"' % ns, '(%s::wstring) S = L"!!!!"' % ns, '(const wchar_t *) mazeltov = 0x', 'L"מזל טוב"', '(%s::string) empty = ""' % ns, '(%s::string) q = "hello world"' % ns, '(%s::string) Q = "quite a long std::strin with lots of info inside it"' % ns, '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' % ns, '(%s::u16string) u16_string = u"ß水氶"' % ns, # FIXME: This should have a 'u' prefix. '(%s::u16string) u16_empty = ""' % ns, '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns, # FIXME: This should have a 'U' prefix. '(%s::u32string) u32_empty = ""' % ns, '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' '%s::allocator<unsigned char> >) uchar = "aaaaa"' % (ns, ns, ns), '(%s::string *) null_str = nullptr' % ns, ]) thread.StepOver() TheVeryLongOne = frame.FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue( uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.expect_expr("s", result_type=ns + "::wstring", result_summary='L"hello world! מזל טוב!"') self.expect( "frame variable", substrs=[ '(%s::wstring) S = L"!!!!!"' % ns, '(const wchar_t *) mazeltov = 0x', 'L"מזל טוב"', '(%s::string) q = "hello world"' % ns, '(%s::string) Q = "quite a long std::strin with lots of info inside it"' % ns, '(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns, '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"' % ns, '(%s::u16string) u16_string = u"ß水氶"' % ns, '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns, '(%s::u32string) u32_empty = ""' % ns, '(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' '%s::allocator<unsigned char> >) uchar = "aaaaa"' % (ns, ns, ns), '(%s::string *) null_str = nullptr' % ns, ]) # The test assumes that std::string is in its cap-size-data layout. is_alternate_layout = ( 'arm' in self.getArchitecture()) and self.platformIsDarwin() if is_64_bit and not is_alternate_layout: self.expect("frame variable garbage1", substrs=['garbage1 = Summary Unavailable']) self.expect("frame variable garbage2", substrs=[r'garbage2 = "\xfa\xfa\xfa\xfa"']) self.expect("frame variable garbage3", substrs=[r'garbage3 = "\xf0\xf0"']) self.expect("frame variable garbage4", substrs=['garbage4 = Summary Unavailable']) self.expect("frame variable garbage5", substrs=['garbage5 = Summary Unavailable']) # Finally, make sure that if the string is not readable, we give an error: bkpt_2 = target.BreakpointCreateBySourceRegex( "Break here to look at bad string", self.main_spec) self.assertEqual(bkpt_2.GetNumLocations(), 1, "Got one location") threads = lldbutil.continue_to_breakpoint(process, bkpt_2) self.assertEqual(len(threads), 1, "Stopped at second breakpoint") frame = threads[0].frames[0] var = frame.FindVariable("in_str") self.assertTrue(var.GetError().Success(), "Made variable") summary = var.GetSummary() self.assertEqual(summary, "Summary Unavailable", "No summary for bad value")
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) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line1, num_expected_locations=-1) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line2, num_expected_locations=-1) 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']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect_var_path('wempty', type='std::wstring_view', summary='L""') self.expect_var_path('s', type='std::wstring_view', summary='L"hello world! מזל טוב!"') self.expect_var_path('S', type='std::wstring_view', summary='L"!!!!"') self.expect_var_path('empty', type='std::string_view', summary='""') self.expect_var_path('q_source', type='std::string', summary='"hello world"') self.expect_var_path('q', type='std::string_view', summary='"hello world"') self.expect_var_path( 'Q', type='std::string_view', summary='"quite a long std::strin with lots of info inside it"') self.expect_var_path('IHaveEmbeddedZeros', type='std::string_view', summary='"a\\0b\\0c\\0d"') self.expect_var_path( 'IHaveEmbeddedZerosToo', type='std::wstring_view', summary='L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"') self.expect_var_path('u16_string', type='std::u16string_view', summary='u"ß水氶"') self.expect_var_path('u16_empty', type='std::u16string_view', summary='""') self.expect_var_path('u32_string', type='std::u32string_view', summary='U"🍄🍅🍆🍌"') self.expect_var_path('u32_empty', type='std::u32string_view', summary='""') self.expect_var_path( 'uchar_source', type= 'std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> >', summary='"aaaaaaaaaa"') self.expect_var_path( 'uchar', type= 'std::basic_string_view<unsigned char, std::char_traits<unsigned char> >', summary='"aaaaa"') self.expect_var_path('oops', type='std::string_view', summary='"Hellooo World\\n"') # GetSummary returns None so can't be checked by expect_var_path, so we # use the str representation instead null_obj = self.frame().GetValueForVariablePath('null_str') self.assertEqual(null_obj.GetSummary(), "Summary Unavailable") self.assertEqual(str(null_obj), '(std::string_view *) null_str = nullptr') self.runCmd("n") TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne") summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream, summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue( uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream, summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue( cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.expect_expr("s", result_type="std::wstring_view", result_summary='L"hello world! מזל טוב!"') self.expect_var_path('wempty', type='std::wstring_view', summary='L""') self.expect_var_path('s', type='std::wstring_view', summary='L"hello world! מזל טוב!"') self.expect_var_path('S', type='std::wstring_view', summary='L"!!!!"') self.expect_var_path('empty', type='std::string_view', summary='""') self.expect_var_path('q_source', type='std::string', summary='"Hello world"') self.expect_var_path('q', type='std::string_view', summary='"Hello world"') self.expect_var_path( 'Q', type='std::string_view', summary='"quite a long std::strin with lots of info inside it"') self.expect_var_path('IHaveEmbeddedZeros', type='std::string_view', summary='"a\\0b\\0c\\0d"') self.expect_var_path( 'IHaveEmbeddedZerosToo', type='std::wstring_view', summary='L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"') self.expect_var_path('u16_string', type='std::u16string_view', summary='u"ß水氶"') self.expect_var_path('u16_empty', type='std::u16string_view', summary='""') self.expect_var_path('u32_string', type='std::u32string_view', summary='U"🍄🍅🍆🍌"') self.expect_var_path('u32_empty', type='std::u32string_view', summary='""') self.expect_var_path( 'uchar_source', type= 'std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> >', summary='"aaaaaaaaaa"') self.expect_var_path( 'uchar', type= 'std::basic_string_view<unsigned char, std::char_traits<unsigned char> >', summary='"aaaaa"') self.runCmd('cont') self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) broken_obj = self.frame().GetValueForVariablePath('in_str_view') self.assertEqual(broken_obj.GetSummary(), "Summary Unavailable")