1# coding=utf8 2""" 3Test that the C++11 support for char16_t and char32_t works correctly. 4""" 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class Char1632TestCase(TestBase): 14 def setUp(self): 15 # Call super's setUp(). 16 TestBase.setUp(self) 17 # Find the line number to break for main.cpp. 18 self.source = "main.cpp" 19 self.lines = [ 20 line_number(self.source, "// breakpoint1"), 21 line_number(self.source, "// breakpoint2"), 22 ] 23 24 @expectedFailureAll( 25 compiler="icc", 26 bugnumber="ICC (13.1) does not emit the DW_TAG_base_type for char16_t and char32_t.", 27 ) 28 def test(self): 29 """Test that the C++11 support for char16_t and char32_t works correctly.""" 30 self.build() 31 exe = self.getBuildArtifact("a.out") 32 33 # Create a target by the debugger. 34 target = self.dbg.CreateTarget(exe) 35 self.assertTrue(target, VALID_TARGET) 36 37 # Set breakpoints 38 for line in self.lines: 39 lldbutil.run_break_set_by_file_and_line(self, "main.cpp", line) 40 41 # Now launch the process, and do not stop at entry point and stop at 42 # breakpoint1 43 process = target.LaunchSimple(None, None, self.get_process_working_directory()) 44 45 if not process: 46 self.fail("SBTarget.Launch() failed") 47 48 if self.TraceOn(): 49 self.runCmd("frame variable") 50 51 # Check that we correctly report the const types 52 self.expect( 53 "frame variable cs16 cs32", 54 substrs=[ 55 "(const char16_t *) cs16 = ", 56 'u"hello world ྒྙྐ"', 57 "(const char32_t *) cs32 = ", 58 'U"hello world ྒྙྐ"', 59 ], 60 ) 61 62 # Check that we correctly report the non-const types 63 self.expect( 64 "frame variable s16 s32", 65 substrs=[ 66 "(char16_t *) s16 = ", 67 'u"ﺸﺵۻ"', 68 "(char32_t *) s32 = ", 69 'U"ЕЙРГЖО"', 70 ], 71 ) 72 73 # Check that we correctly report the array types 74 self.expect( 75 "frame variable as16 as32", 76 patterns=[ 77 "\(char16_t\[[0-9]+\]\) as16 = ", 78 "\(char32_t\[[0-9]+\]\) as32 = ", 79 ], 80 substrs=['u"ﺸﺵۻ"', 'U"ЕЙРГЖО"'], 81 ) 82 83 self.runCmd("next") # step to after the string is nullified 84 85 # check that we don't crash on NULL 86 self.expect("frame variable s32", substrs=["(char32_t *) s32 = 0x00000000"]) 87 88 # continue and hit breakpoint2 89 self.runCmd("continue") 90 91 # check that the new strings show 92 self.expect( 93 "frame variable s16 s32", 94 substrs=[ 95 "(char16_t *) s16 = 0x", 96 '"色ハ匂ヘト散リヌルヲ"', 97 "(char32_t *) s32 = ", 98 '"෴"', 99 ], 100 ) 101 102 # check the same as above for arrays 103 self.expect( 104 "frame variable as16 as32", 105 patterns=[ 106 "\(char16_t\[[0-9]+\]\) as16 = ", 107 "\(char32_t\[[0-9]+\]\) as32 = ", 108 ], 109 substrs=['"色ハ匂ヘト散リヌルヲ"', '"෴"'], 110 ) 111 112 # check that zero values are properly handles 113 self.expect_expr("cs16_zero", result_summary="U+0000 u'\\0'") 114 self.expect_expr("cs32_zero", result_summary="U+0x00000000 U'\\0'") 115 116 # Check that we can run expressions that return charN_t 117 self.expect_expr("u'a'", result_type="char16_t", result_summary="U+0061 u'a'") 118 self.expect_expr( 119 "U'a'", result_type="char32_t", result_summary="U+0x00000061 U'a'" 120 ) 121