def test_with_run_command(self):
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target and target.IsValid(), "Target is valid")

        file_spec = lldb.SBFileSpec ("main.cpp", False)
        breakpoint1 = target.BreakpointCreateBySourceRegex('// Set break point at this line.', file_spec)
        self.assertTrue(breakpoint1 and breakpoint1.IsValid())
        breakpoint2 = target.BreakpointCreateBySourceRegex('// Set second break point at this line.', file_spec)
        self.assertTrue(breakpoint2 and breakpoint2.IsValid())

        # Run the program, it should stop at breakpoint 1.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())
        lldbutil.skip_if_library_missing(self, target, lldbutil.PrintableRegex("libc\+\+"))
        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
        self.assertEquals(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)), 1)

        # verify our list is displayed correctly
        self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4', '[5] = 6'])

        # Continue to breakpoint 2.
        process.Continue()
        self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
        self.assertEquals(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint2)), 1)

        # The list is now inconsistent. However, we should be able to get the first three
        # elements at least (and most importantly, not crash).
        self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3'])

        # Run to completion.
        process.Continue()
        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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"])

        # 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("image list", substrs=self.getLibcPlusPlusLibs())

        self.expect("frame variable ii", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        self.expect(
            "frame variable ii", substrs=["size=6", "[0] = 0", "[1] = 1", "[2] = 2", "[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)
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        self.expect("frame variable ss", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.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)
        self.expect(
            "frame variable ss",
            substrs=["size=4", '[2] = "b"', '[3] = "c"', '[0] = "a"', '[1] = "a very long string is right here"'],
        )
        self.expect(
            "p ss",
            substrs=["size=4", '[2] = "b"', '[3] = "c"', '[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)
        self.expect(
            "frame variable ss",
            substrs=["size=3", '[0] = "a"', '[1] = "a very long string is right here"', '[2] = "c"'],
        )
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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 vBool",
            substrs = ['size=49','[0] = false','[1] = true','[18] = false','[27] = true','[36] = false','[47] = true','[48] = true'])

        self.expect("expr vBool",
            substrs = ['size=49','[0] = false','[1] = true','[18] = false','[27] = true','[36] = false','[47] = true','[48] = true'])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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"',
                    '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"',
                    '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'])

        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"',
                    '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"',
                    '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'])
Example #5
0
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        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'])

        # 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('image list', substrs=self.getLibcPlusPlusLibs())

        self.look_for_content_and_continue(
            "map", ['size=5 {', 'hello', 'world', 'this', 'is', 'me'])

        self.look_for_content_and_continue("mmap", [
            'size=6 {', 'first = 3', 'second = "this"', 'first = 2',
            'second = "hello"'
        ])

        self.look_for_content_and_continue(
            "iset", ['size=5 {', '\[\d\] = 5', '\[\d\] = 3', '\[\d\] = 2'])

        self.look_for_content_and_continue("sset", [
            'size=5 {', '\[\d\] = "is"', '\[\d\] = "world"', '\[\d\] = "hello"'
        ])

        self.look_for_content_and_continue("imset", [
            'size=6 {', '(\[\d\] = 3(\\n|.)+){3}', '\[\d\] = 2', '\[\d\] = 1'
        ])

        self.look_for_content_and_continue("smset", [
            'size=5 {', '(\[\d\] = "is"(\\n|.)+){2}',
            '(\[\d\] = "world"(\\n|.)+){2}'
        ])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line.")

        self.runCmd("run", RUN_SUCCEEDED)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        # 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('image list', substrs = self.getLibcPlusPlusLibs())

        self.look_for_content_and_continue(
            "map", ['size=5 {', 'hello', 'world', 'this', 'is', 'me'])

        self.look_for_content_and_continue(
            "mmap", ['size=6 {', 'first = 3', 'second = "this"',
                                 'first = 2', 'second = "hello"'])

        self.look_for_content_and_continue(
            "iset", ['size=5 {', '\[\d\] = 5', '\[\d\] = 3', '\[\d\] = 2'])

        self.look_for_content_and_continue(
            "sset", ['size=5 {', '\[\d\] = "is"', '\[\d\] = "world"',
                                 '\[\d\] = "hello"'])

        self.look_for_content_and_continue(
            "imset", ['size=6 {', '(\[\d\] = 3(\\n|.)+){3}',
                                  '\[\d\] = 2', '\[\d\] = 1'])

        self.look_for_content_and_continue(
            "smset",
            ['size=5 {', '(\[\d\] = "is"(\\n|.)+){2}',
                         '(\[\d\] = "world"(\\n|.)+){2}'])
Example #7
0
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        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 vBool",
                    substrs=[
                        'size=49', '[0] = false', '[1] = true', '[18] = false',
                        '[27] = true', '[36] = false', '[47] = true',
                        '[48] = true'
                    ])

        self.expect("expr vBool",
                    substrs=[
                        'size=49', '[0] = false', '[1] = true', '[18] = false',
                        '[27] = true', '[36] = false', '[47] = true',
                        '[48] = true'
                    ])
Example #8
0
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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.expect("frame variable ili", substrs = ['[1] = 2','[4] = 5'])
        self.expect("frame variable ils", substrs = ['[4] = "surprise it is a long string!! yay!!"'])

        self.expect('image list', substrs = self.getLibcPlusPlusLibs())
Example #9
0
    def test(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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.expect("frame variable ili", substrs = ['[1] = 2','[4] = 5'])
        self.expect("frame variable ils", substrs = ['[4] = "surprise it is a long string!! yay!!"'])

        self.expect('image list', substrs = self.getLibcPlusPlusLibs())
    def test_with_run_command(self):
        """Test that libc++ iterators format properly."""
        self.build()
        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)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        # 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('image list', substrs = self.getLibcPlusPlusLibs())

        self.expect('frame variable ivI', substrs = ['item = 3'])
        self.expect('expr ivI', substrs = ['item = 3'])

        self.expect('frame variable iimI', substrs = ['first = 0','second = 12'])
        self.expect('expr iimI', substrs = ['first = 0','second = 12'])

        self.expect('frame variable simI', substrs = ['first = "world"','second = 42'])
        self.expect('expr simI', substrs = ['first = "world"','second = 42'])

        self.expect('frame variable svI', substrs = ['item = "hello"'])
        self.expect('expr svI', substrs = ['item = "hello"'])
Example #11
0
    def test_with_run_command(self):
        """Test that libc++ iterators format properly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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('image list', substrs = self.getLibcPlusPlusLibs())

        self.expect('frame variable ivI', substrs = ['item = 3'])
        self.expect('expr ivI', substrs = ['item = 3'])

        self.expect('frame variable iimI', substrs = ['first = 0','second = 12'])
        self.expect('expr iimI', substrs = ['first = 0','second = 12'])

        self.expect('frame variable simI', substrs = ['first = "world"','second = 42'])
        self.expect('expr simI', substrs = ['first = "world"','second = 42'])

        self.expect('frame variable svI', substrs = ['item = "hello"'])
        self.expect('expr svI', substrs = ['item = "hello"'])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        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"',
                '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"',
                '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
            ])

        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"',
                '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"',
                '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
            ])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line,
                                                num_expected_locations=-1)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line2,
                                                num_expected_locations=-1)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line3,
                                                num_expected_locations=-1)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line4,
                                                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.runCmd("frame variable numbers_list --show-types")
        self.runCmd(
            "type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e"
        )
        self.runCmd("type format add -f hex int")

        self.expect("frame variable numbers_list --raw",
                    matching=False,
                    substrs=['list has 0 items', '{}'])

        self.expect("frame variable numbers_list",
                    substrs=['list has 0 items', '{}'])

        self.expect("p numbers_list", substrs=['list has 0 items', '{}'])

        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs=['list has 1 items', '[0] = ', '0x12345678'])

        self.runCmd("n")
        self.runCmd("n")
        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs=[
                        'list has 4 items', '[0] = ', '0x12345678', '[1] =',
                        '0x11223344', '[2] =', '0xbeeffeed', '[3] =',
                        '0x00abba00'
                    ])

        self.runCmd("n")
        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs=[
                        'list has 6 items', '[0] = ', '0x12345678',
                        '0x11223344', '0xbeeffeed', '0x00abba00', '[4] =',
                        '0x0abcdef0', '[5] =', '0x0cab0cab'
                    ])

        self.expect("p numbers_list",
                    substrs=[
                        'list has 6 items', '[0] = ', '0x12345678',
                        '0x11223344', '0xbeeffeed', '0x00abba00', '[4] =',
                        '0x0abcdef0', '[5] =', '0x0cab0cab'
                    ])

        # check access-by-index
        self.expect("frame variable numbers_list[0]", substrs=['0x12345678'])
        self.expect("frame variable numbers_list[1]", substrs=['0x11223344'])

        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs=['list has 0 items', '{}'])

        self.runCmd("n")
        self.runCmd("n")
        self.runCmd("n")
        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs=[
                        'list has 4 items', '[0] = ', '1', '[1] = ', '2',
                        '[2] = ', '3', '[3] = ', '4'
                    ])

        # check that MightHaveChildren() gets it right
        self.assertTrue(
            self.frame().FindVariable("numbers_list").MightHaveChildren(),
            "numbers_list.MightHaveChildren() says False for non empty!")

        self.runCmd("type format delete int")

        self.runCmd("c")

        self.expect("frame variable text_list",
                    substrs=[
                        'list has 3 items', '[0]', 'goofy', '[1]', 'is', '[2]',
                        'smart'
                    ])

        # check that MightHaveChildren() gets it right
        self.assertTrue(
            self.frame().FindVariable("text_list").MightHaveChildren(),
            "text_list.MightHaveChildren() says False for non empty!")

        self.expect(
            "p text_list",
            substrs=['list has 3 items', '\"goofy\"', '\"is\"', '\"smart\"'])

        self.runCmd("n")

        # check access-by-index
        self.expect("frame variable text_list[0]", substrs=['goofy'])
        self.expect("frame variable text_list[3]", substrs=['!!!'])

        self.runCmd("continue")

        # check that the list provider correctly updates if elements move
        countingList = self.frame().FindVariable("countingList")
        countingList.SetPreferDynamicValue(True)
        countingList.SetPreferSyntheticValue(True)

        self.assertTrue(
            countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141,
            "list[0] == 3141")
        self.assertTrue(
            countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3141,
            "list[1] == 3141")

        self.runCmd("continue")

        self.assertTrue(
            countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141,
            "uniqued list[0] == 3141")
        self.assertTrue(
            countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3142,
            "uniqued list[1] == 3142")
Example #14
0
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        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'])

        # 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('image list', substrs = self.getLibcPlusPlusLibs())
                
        self.expect('frame variable ii',
            substrs = ['size=0',
                       '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ii',
                    substrs = ['size=2',
                               '[0] = ',
                               'first = 0',
                               'second = 0',
                               '[1] = ',
                               'first = 1',
                               'second = 1'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ii',
                    substrs = ['size=4',
                               '[2] = ',
                               'first = 2',
                               'second = 0',
                               '[3] = ',
                               'first = 3',
                               'second = 1'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable ii",
                    substrs = ['size=8',
                               '[5] = ',
                               'first = 5',
                               'second = 0',
                               '[7] = ',
                               'first = 7',
                               'second = 1'])

        self.expect("p ii",
                    substrs = ['size=8',
                               '[5] = ',
                               'first = 5',
                               'second = 0',
                               '[7] = ',
                               'first = 7',
                               'second = 1'])

        # check access-by-index
        self.expect("frame variable ii[0]",
                    substrs = ['first = 0',
                               'second = 0']);
        self.expect("frame variable ii[3]",
                    substrs = ['first =',
                               'second =']);

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("ii").MightHaveChildren(), "ii.MightHaveChildren() says False for non empty!")

        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression ii[8]", matching=False, error=True,
        #            substrs = ['1234567'])

        self.runCmd("continue");
        
        self.expect('frame variable ii',
                    substrs = ['size=0',
                               '{}'])

        self.expect('frame variable si',
                    substrs = ['size=0',
                               '{}'])

        self.runCmd("continue");

        self.expect('frame variable si',
                    substrs = ['size=1',
                               '[0] = ',
                               'first = \"zero\"',
                               'second = 0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable si",
                    substrs = ['size=4',
                               '[0] = ',
                               'first = \"zero\"',
                               'second = 0',
                                '[1] = ',
                                'first = \"one\"',
                                'second = 1',
                                '[2] = ',
                                'first = \"two\"',
                                'second = 2',
                                '[3] = ',
                                'first = \"three\"',
                                'second = 3'])

        self.expect("p si",
                    substrs = ['size=4',
                               '[0] = ',
                               'first = \"zero\"',
                               'second = 0',
                               '[1] = ',
                               'first = \"one\"',
                               'second = 1',
                               '[2] = ',
                               'first = \"two\"',
                               'second = 2',
                               '[3] = ',
                               'first = \"three\"',
                               'second = 3'])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("si").MightHaveChildren(), "si.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable si[0]",
                    substrs = ['first = ', 'one',
                               'second = 1']);
        
        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression si[0]", matching=False, error=True,
        #            substrs = ['first = ', 'zero'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        self.expect('frame variable si',
                    substrs = ['size=0',
                               '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        self.expect('frame variable is',
                    substrs = ['size=0',
                               '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable is",
                    substrs = ['size=4',
                               '[0] = ',
                               'second = \"goofy\"',
                               'first = 85',
                               '[1] = ',
                               'second = \"is\"',
                               'first = 1',
                               '[2] = ',
                               'second = \"smart\"',
                               'first = 2',
                               '[3] = ',
                               'second = \"!!!\"',
                               'first = 3'])
        
        self.expect("p is",
                    substrs = ['size=4',
                               '[0] = ',
                               'second = \"goofy\"',
                               'first = 85',
                               '[1] = ',
                               'second = \"is\"',
                               'first = 1',
                               '[2] = ',
                               'second = \"smart\"',
                               'first = 2',
                               '[3] = ',
                               'second = \"!!!\"',
                               'first = 3'])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("is").MightHaveChildren(), "is.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable is[0]",
                    substrs = ['first = ',
                               'second =']);
        
        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression is[0]", matching=False, error=True,
        #            substrs = ['first = ', 'goofy'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        self.expect('frame variable is',
                    substrs = ['size=0',
                               '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        self.expect('frame variable ss',
                    substrs = ['size=0',
                               '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable ss",
                    substrs = ['size=3',
                               '[0] = ',
                               'second = \"hello\"',
                               'first = \"ciao\"',
                               '[1] = ',
                               'second = \"house\"',
                               'first = \"casa\"',
                               '[2] = ',
                               'second = \"cat\"',
                               'first = \"gatto\"'])
        
        self.expect("p ss",
                    substrs = ['size=3',
                               '[0] = ',
                               'second = \"hello\"',
                               'first = \"ciao\"',
                               '[1] = ',
                               'second = \"house\"',
                               'first = \"casa\"',
                               '[2] = ',
                               'second = \"cat\"',
                               'first = \"gatto\"'])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("ss").MightHaveChildren(), "ss.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable ss[2]",
                    substrs = ['gatto', 'cat']);
        
        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression ss[3]", matching=False, error=True,
        #            substrs = ['gatto'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        self.expect('frame variable ss',
                    substrs = ['size=0',
                               '{}'])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        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)
        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line2, num_expected_locations=-1)
        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line3, num_expected_locations=-1)
        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line4, num_expected_locations=-1)

        self.runCmd("run", RUN_SUCCEEDED)

        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        # 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.runCmd("frame variable numbers_list --show-types")
        self.runCmd("type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e")
        self.runCmd("type format add -f hex int")

        self.expect("frame variable numbers_list --raw", matching=False,
                    substrs = ['list has 0 items',
                               '{}'])

        self.expect("frame variable numbers_list",
                    substrs = ['list has 0 items',
                               '{}'])

        self.expect("p numbers_list",
                    substrs = ['list has 0 items',
                               '{}'])

        self.runCmd("n")

        self.expect("frame variable numbers_list",
                    substrs = ['list has 1 items',
                               '[0] = ',
                               '0x12345678'])

        self.runCmd("n");self.runCmd("n");self.runCmd("n");

        self.expect("frame variable numbers_list",
                    substrs = ['list has 4 items',
                               '[0] = ',
                               '0x12345678',
                               '[1] =',
                               '0x11223344',
                               '[2] =',
                               '0xbeeffeed',
                               '[3] =',
                               '0x00abba00'])

        self.runCmd("n");self.runCmd("n");

        self.expect("frame variable numbers_list",
                    substrs = ['list has 6 items',
                               '[0] = ',
                               '0x12345678',
                               '0x11223344',
                               '0xbeeffeed',
                               '0x00abba00',
                               '[4] =',
                               '0x0abcdef0',
                               '[5] =',
                               '0x0cab0cab'])

        self.expect("p numbers_list",
                    substrs = ['list has 6 items',
                               '[0] = ',
                               '0x12345678',
                               '0x11223344',
                               '0xbeeffeed',
                               '0x00abba00',
                               '[4] =',
                               '0x0abcdef0',
                               '[5] =',
                               '0x0cab0cab'])

        # check access-by-index
        self.expect("frame variable numbers_list[0]",
                    substrs = ['0x12345678']);
        self.expect("frame variable numbers_list[1]",
                    substrs = ['0x11223344']);

        self.runCmd("n")
            
        self.expect("frame variable numbers_list",
                    substrs = ['list has 0 items',
                               '{}'])

        self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n");
            
        self.expect("frame variable numbers_list",
                    substrs = ['list has 4 items',
                               '[0] = ', '1',
                               '[1] = ', '2',
                               '[2] = ', '3',
                               '[3] = ', '4'])            

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("numbers_list").MightHaveChildren(), "numbers_list.MightHaveChildren() says False for non empty!")

        self.runCmd("type format delete int")

        self.runCmd("c")

        self.expect("frame variable text_list",
                    substrs = ['list has 3 items',
                               '[0]', 'goofy',
                               '[1]', 'is',
                               '[2]', 'smart'])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("text_list").MightHaveChildren(), "text_list.MightHaveChildren() says False for non empty!")

        self.expect("p text_list",
                    substrs = ['list has 3 items',
                               '\"goofy\"',
                               '\"is\"',
                               '\"smart\"'])
        
        self.runCmd("n")

        # check access-by-index
        self.expect("frame variable text_list[0]",
                    substrs = ['goofy']);
        self.expect("frame variable text_list[3]",
                    substrs = ['!!!']);
                    
        self.runCmd("continue")
        
        # check that the list provider correctly updates if elements move
        countingList = self.frame().FindVariable("countingList")
        countingList.SetPreferDynamicValue(True)
        countingList.SetPreferSyntheticValue(True)
        
        self.assertTrue(countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141, "list[0] == 3141")
        self.assertTrue(countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3141, "list[1] == 3141")
        
        self.runCmd("continue")

        self.assertTrue(countingList.GetChildAtIndex(0).GetValueAsUnsigned(0) == 3141, "uniqued list[0] == 3141")
        self.assertTrue(countingList.GetChildAtIndex(1).GetValueAsUnsigned(0) == 3142, "uniqued list[1] == 3142")
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        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'])

        # 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('image list', substrs=self.getLibcPlusPlusLibs())

        self.expect('frame variable ii', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ii',
                    substrs=[
                        'size=2', '[0] = ', 'first = 0', 'second = 0',
                        '[1] = ', 'first = 1', 'second = 1'
                    ])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ii',
                    substrs=[
                        'size=4', '[2] = ', 'first = 2', 'second = 0',
                        '[3] = ', 'first = 3', 'second = 1'
                    ])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable ii",
                    substrs=[
                        'size=8', '[5] = ', 'first = 5', 'second = 0',
                        '[7] = ', 'first = 7', 'second = 1'
                    ])

        self.expect("p ii",
                    substrs=[
                        'size=8', '[5] = ', 'first = 5', 'second = 0',
                        '[7] = ', 'first = 7', 'second = 1'
                    ])

        # check access-by-index
        self.expect("frame variable ii[0]",
                    substrs=['first = 0', 'second = 0'])
        self.expect("frame variable ii[3]", substrs=['first =', 'second ='])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("ii").MightHaveChildren(),
                        "ii.MightHaveChildren() says False for non empty!")

        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression ii[8]", matching=False, error=True,
        #            substrs = ['1234567'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ii', substrs=['size=0', '{}'])

        self.expect('frame variable si', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect(
            'frame variable si',
            substrs=['size=1', '[0] = ', 'first = \"zero\"', 'second = 0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable si",
                    substrs=[
                        'size=4', '[0] = ', 'first = \"zero\"', 'second = 0',
                        '[1] = ', 'first = \"one\"', 'second = 1', '[2] = ',
                        'first = \"two\"', 'second = 2', '[3] = ',
                        'first = \"three\"', 'second = 3'
                    ])

        self.expect("p si",
                    substrs=[
                        'size=4', '[0] = ', 'first = \"zero\"', 'second = 0',
                        '[1] = ', 'first = \"one\"', 'second = 1', '[2] = ',
                        'first = \"two\"', 'second = 2', '[3] = ',
                        'first = \"three\"', 'second = 3'
                    ])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("si").MightHaveChildren(),
                        "si.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable si[0]",
                    substrs=['first = ', 'one', 'second = 1'])

        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression si[0]", matching=False, error=True,
        #            substrs = ['first = ', 'zero'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable si', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable is', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable is",
                    substrs=[
                        'size=4', '[0] = ', 'second = \"goofy\"', 'first = 85',
                        '[1] = ', 'second = \"is\"', 'first = 1', '[2] = ',
                        'second = \"smart\"', 'first = 2', '[3] = ',
                        'second = \"!!!\"', 'first = 3'
                    ])

        self.expect("p is",
                    substrs=[
                        'size=4', '[0] = ', 'second = \"goofy\"', 'first = 85',
                        '[1] = ', 'second = \"is\"', 'first = 1', '[2] = ',
                        'second = \"smart\"', 'first = 2', '[3] = ',
                        'second = \"!!!\"', 'first = 3'
                    ])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("is").MightHaveChildren(),
                        "is.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable is[0]", substrs=['first = ', 'second ='])

        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression is[0]", matching=False, error=True,
        #            substrs = ['first = ', 'goofy'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable is', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ss', substrs=['size=0', '{}'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable ss",
                    substrs=[
                        'size=3', '[0] = ', 'second = \"hello\"',
                        'first = \"ciao\"', '[1] = ', 'second = \"house\"',
                        'first = \"casa\"', '[2] = ', 'second = \"cat\"',
                        'first = \"gatto\"'
                    ])

        self.expect("p ss",
                    substrs=[
                        'size=3', '[0] = ', 'second = \"hello\"',
                        'first = \"ciao\"', '[1] = ', 'second = \"house\"',
                        'first = \"casa\"', '[2] = ', 'second = \"cat\"',
                        'first = \"gatto\"'
                    ])

        # check that MightHaveChildren() gets it right
        self.assertTrue(self.frame().FindVariable("ss").MightHaveChildren(),
                        "ss.MightHaveChildren() says False for non empty!")

        # check access-by-index
        self.expect("frame variable ss[2]", substrs=['gatto', 'cat'])

        # check that the expression parser does not make use of
        # synthetic children instead of running code
        # TOT clang has a fix for this, which makes the expression command here succeed
        # since this would make the test fail or succeed depending on clang version in use
        # this is safer commented for the time being
        #self.expect("expression ss[3]", matching=False, error=True,
        #            substrs = ['gatto'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect('frame variable ss', substrs=['size=0', '{}'])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        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'])

        # 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('image list', substrs=self.getLibcPlusPlusLibs())

        self.expect("frame variable ii", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        self.expect("frame variable ii",
                    substrs=[
                        "size=6", "[0] = 0", "[1] = 1", "[2] = 2", "[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)
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        self.expect("frame variable ss", substrs=["size=0", "{}"])
        lldbutil.continue_to_breakpoint(self.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)
        self.expect("frame variable ss",
                    substrs=[
                        "size=4", '[2] = "b"', '[3] = "c"', '[0] = "a"',
                        '[1] = "a very long string is right here"'
                    ])
        self.expect("p ss",
                    substrs=[
                        "size=4", '[2] = "b"', '[3] = "c"', '[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)
        self.expect("frame variable ss",
                    substrs=[
                        "size=3", '[0] = "a"',
                        '[1] = "a very long string is right here"', '[2] = "c"'
                    ])
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        
        lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+"))

        bkpt = self.target().FindBreakpointByID(lldbutil.run_break_set_by_source_regexp (self, "break here"))

        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)

        # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
        self.expect("frame variable numbers",
            substrs = ['numbers = size=0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)
        
        # first value added
        self.expect("frame variable numbers",
                    substrs = ['numbers = size=1',
                               '[0] = 1',
                               '}'])

        # add some more data
        lldbutil.continue_to_breakpoint(self.process(), bkpt)
    
        self.expect("frame variable numbers",
                    substrs = ['numbers = size=4',
                               '[0] = 1',
                               '[1] = 12',
                               '[2] = 123',
                               '[3] = 1234',
                               '}'])

        self.expect("p numbers",
                    substrs = ['$', 'size=4',
                               '[0] = 1',
                               '[1] = 12',
                               '[2] = 123',
                               '[3] = 1234',
                               '}'])

        
        # check access to synthetic children
        self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect")
        self.expect('frame variable numbers',
                    substrs = ['item 0 is 1']);
        
        self.runCmd("type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect")
        self.expect('frame variable numbers',
                    substrs = ['item 0 is 1']);
        # move on with synths
        self.runCmd("type summary delete std::int_vect")
        self.runCmd("type summary delete int_vect")

        # add some more data
        lldbutil.continue_to_breakpoint(self.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']);

        # clear out the vector and see that we do the right thing once again
        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable numbers",
            substrs = ['numbers = size=0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        # first value added
        self.expect("frame variable numbers",
                    substrs = ['numbers = size=1',
                               '[0] = 7',
                               '}'])

        # check if we can display strings
        self.expect("frame variable strings",
            substrs = ['goofy',
                       'is',
                       'smart'])

        self.expect("p strings",
                    substrs = ['goofy',
                               'is',
                               'smart'])

        # test summaries based on synthetic children
        self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e")
        self.expect("frame variable strings",
                    substrs = ['vector has 3 items',
                               'goofy',
                               'is',
                               'smart'])

        self.expect("p strings",
                    substrs = ['vector has 3 items',
                               'goofy',
                               'is',
                               'smart'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable strings",
                    substrs = ['vector has 4 items'])
        
        # check access-by-index
        self.expect("frame variable strings[0]",
                    substrs = ['goofy']);
        self.expect("frame variable strings[1]",
                    substrs = ['is']);

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable strings",
            substrs = ['vector has 0 items'])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.skip_if_library_missing(self, self.target(),
                                         lldbutil.PrintableRegex("libc\+\+"))

        bkpt = self.target().FindBreakpointByID(
            lldbutil.run_break_set_by_source_regexp(self, "break here"))

        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)

        # empty vectors (and storage pointers SHOULD BOTH BE NULL..)
        self.expect("frame variable numbers", substrs=['numbers = size=0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        # first value added
        self.expect("frame variable numbers",
                    substrs=['numbers = size=1', '[0] = 1', '}'])

        # add some more data
        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable numbers",
                    substrs=[
                        'numbers = size=4', '[0] = 1', '[1] = 12', '[2] = 123',
                        '[3] = 1234', '}'
                    ])

        self.expect("p numbers",
                    substrs=[
                        '$', 'size=4', '[0] = 1', '[1] = 12', '[2] = 123',
                        '[3] = 1234', '}'
                    ])

        # check access to synthetic children
        self.runCmd(
            "type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect"
        )
        self.expect('frame variable numbers', substrs=['item 0 is 1'])

        self.runCmd(
            "type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect"
        )
        self.expect('frame variable numbers', substrs=['item 0 is 1'])
        # move on with synths
        self.runCmd("type summary delete std::int_vect")
        self.runCmd("type summary delete int_vect")

        # add some more data
        lldbutil.continue_to_breakpoint(self.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'])

        # clear out the vector and see that we do the right thing once again
        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable numbers", substrs=['numbers = size=0'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        # first value added
        self.expect("frame variable numbers",
                    substrs=['numbers = size=1', '[0] = 7', '}'])

        # check if we can display strings
        self.expect("frame variable strings", substrs=['goofy', 'is', 'smart'])

        self.expect("p strings", substrs=['goofy', 'is', 'smart'])

        # test summaries based on synthetic children
        self.runCmd(
            "type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e"
        )
        self.expect("frame variable strings",
                    substrs=['vector has 3 items', 'goofy', 'is', 'smart'])

        self.expect("p strings",
                    substrs=['vector has 3 items', 'goofy', 'is', 'smart'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable strings", substrs=['vector has 4 items'])

        # check access-by-index
        self.expect("frame variable strings[0]", substrs=['goofy'])
        self.expect("frame variable strings[1]", substrs=['is'])

        lldbutil.continue_to_breakpoint(self.process(), bkpt)

        self.expect("frame variable strings", substrs=['vector has 0 items'])