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_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 {','[0] = 5','[2] = 3','[3] = 2'])
        self.look_for_content_and_continue("sset",['size=5 {','[0] = "is"','[1] = "world"','[4] = "hello"'])
        self.look_for_content_and_continue("imset",['size=6 {','[0] = 3','[1] = 3','[2] = 3','[4] = 2','[5] = 1'])
        self.look_for_content_and_continue("smset",['size=5 {','[0] = "is"','[1] = "is"','[2] = "world"','[3] = "world"'])
Ejemplo n.º 2
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.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 {','[0] = 5','[2] = 3','[3] = 2'])
        self.look_for_content_and_continue("sset",['size=5 {','[0] = "is"','[1] = "world"','[4] = "hello"'])
        self.look_for_content_and_continue("imset",['size=6 {','[0] = 3','[1] = 3','[2] = 3','[4] = 2','[5] = 1'])
        self.look_for_content_and_continue("smset",['size=5 {','[0] = "is"','[1] = "is"','[2] = "world"','[3] = "world"'])
Ejemplo n.º 3
0
    def test_and_run_command(self):
        """Test expressions on register values."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        lldbutil.run_break_set_by_source_regexp(self,
                                                "break",
                                                num_expected_locations=2)

        ####################
        # First breakpoint

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

        # The breakpoint should have a hit count of 1.
        self.expect("breakpoint list -f",
                    BREAKPOINT_HIT_ONCE,
                    substrs=[' resolved, hit count = 1'])

        # Try some variables that should be visible
        self.expect("expr a",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(int) $0 = 2'])

        self.expect("expr b->m1",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(int) $1 = 3'])

        #####################
        # Second breakpoint

        self.runCmd("continue")

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list",
                    STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 1.
        self.expect("breakpoint list -f",
                    BREAKPOINT_HIT_ONCE,
                    substrs=[' resolved, hit count = 1'])

        # Try some variables that should be visible
        self.expect("expr b->m2",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(int) $2 = 5'])

        self.expect("expr c",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(int) $3 = 5'])

        self.runCmd("kill")
Ejemplo n.º 4
0
    def run_python_os_funcionality(self):
        """Test that the Python operating system plugin works correctly"""

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        cwd = os.getcwd()
        exe = os.path.join(cwd, "a.out")
        python_os_plugin_path = os.path.join(cwd, "operating_system.py")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside and outside methods that take pointers to the containing struct.
        lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")

        # Register our shared libraries for remote targets so they get automatically uploaded
        arguments = None
        environment = None 

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");
        thread = process.GetThreadByID(0x222222222);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 before we load the python OS plug-in");
        thread = process.GetThreadByID(0x333333333);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 before we load the python OS plug-in");


        # Now load the python OS plug-in which should update the thread list and we should have
        # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
        command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
        self.dbg.HandleCommand(command)

        # Verify our OS plug-in threads showed up
        thread = process.GetThreadByID(0x111111111);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        thread = process.GetThreadByID(0x222222222);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x222222222 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        thread = process.GetThreadByID(0x333333333);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x333333333 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        
        # Now clear the OS plug-in path to make the OS plug-in created threads dissappear
        self.dbg.HandleCommand("settings clear target.process.python-os-plugin-path")
        
        # Verify the threads are gone after unloading the python OS plug-in
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 after we unload the python OS plug-in");
        thread = process.GetThreadByID(0x222222222);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 after we unload the python OS plug-in");
        thread = process.GetThreadByID(0x333333333);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 after we unload the python OS plug-in");
Ejemplo n.º 5
0
    def doTest(self):
        """Test SBValue::Persist"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        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 synthetic clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        foo = self.frame().FindVariable("foo")
        bar = self.frame().FindVariable("bar")
        baz = self.frame().FindVariable("baz")

        self.assertTrue(foo.IsValid(), "foo is not valid")
        self.assertTrue(bar.IsValid(), "bar is not valid")
        self.assertTrue(baz.IsValid(), "baz is not valid")

        fooPersist = foo.Persist()
        barPersist = bar.Persist()
        bazPersist = baz.Persist()

        self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
        self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
        self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")

        self.assertTrue(
            fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
        self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4,
                        "barPersist != 4")
        self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")

        self.runCmd("continue")

        self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
        self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
        self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")

        self.assertTrue(
            fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
        self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4,
                        "barPersist != 4")
        self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")

        self.expect("expr *(%s)" % (barPersist.GetName()), substrs=['= 4'])
Ejemplo n.º 6
0
    def run_python_os_funcionality(self):
        """Test that the Python operating system plugin works correctly"""

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        cwd = os.getcwd()
        exe = os.path.join(cwd, "a.out")
        python_os_plugin_path = os.path.join(cwd, "operating_system.py")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside and outside methods that take pointers to the containing struct.
        lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")

        # Register our shared libraries for remote targets so they get automatically uploaded
        arguments = None
        environment = None 

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");
        thread = process.GetThreadByID(0x222222222);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 before we load the python OS plug-in");
        thread = process.GetThreadByID(0x333333333);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 before we load the python OS plug-in");


        # Now load the python OS plug-in which should update the thread list and we should have
        # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
        command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
        self.dbg.HandleCommand(command)

        # Verify our OS plug-in threads showed up
        thread = process.GetThreadByID(0x111111111);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        thread = process.GetThreadByID(0x222222222);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x222222222 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        thread = process.GetThreadByID(0x333333333);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x333333333 after we load the python OS plug-in");
        self.verify_os_thread_registers(thread)
        
        # Now clear the OS plug-in path to make the OS plug-in created threads dissappear
        self.dbg.HandleCommand("settings clear target.process.python-os-plugin-path")
        
        # Verify the threads are gone after unloading the python OS plug-in
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 after we unload the python OS plug-in");
        thread = process.GetThreadByID(0x222222222);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 after we unload the python OS plug-in");
        thread = process.GetThreadByID(0x333333333);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 after we unload the python OS plug-in");
Ejemplo n.º 7
0
    def test(self):
        """Test SBValue::Persist"""
        self.build()
        self.setTearDownCleanup()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        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 synthetic clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        foo = self.frame().FindVariable("foo")
        bar = self.frame().FindVariable("bar")
        baz = self.frame().FindVariable("baz")

        self.assertTrue(foo.IsValid(), "foo is not valid")
        self.assertTrue(bar.IsValid(), "bar is not valid")
        self.assertTrue(baz.IsValid(), "baz is not valid")
        
        fooPersist = foo.Persist()
        barPersist = bar.Persist()
        bazPersist = baz.Persist()

        self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
        self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
        self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")

        self.assertTrue(fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
        self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4, "barPersist != 4")
        self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")
        
        self.runCmd("continue")

        self.assertTrue(fooPersist.IsValid(), "fooPersist is not valid")
        self.assertTrue(barPersist.IsValid(), "barPersist is not valid")
        self.assertTrue(bazPersist.IsValid(), "bazPersist is not valid")

        self.assertTrue(fooPersist.GetValueAsUnsigned(0) == 10, "fooPersist != 10")
        self.assertTrue(barPersist.GetPointeeData().sint32[0] == 4, "barPersist != 4")
        self.assertTrue(bazPersist.GetSummary() == '"85"', "bazPersist != 85")
        
        self.expect("expr *(%s)" % (barPersist.GetName()), substrs = ['= 4'])
    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_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=["libc++.1.dylib", "libc++abi.dylib"])

        self.expect("frame variable ii", substrs=["size=0", "{}"])
        self.runCmd("continue")
        self.expect(
            "frame variable ii", substrs=["size=6", "[0] = 0", "[1] = 1", "[2] = 2", "[3] = 3", "[4] = 4", "[5] = 5"]
        )
        self.runCmd("continue")
        self.expect("frame variable ii", substrs=["size=7", "[2] = 2", "[3] = 3", "[6] = 6"])
        self.expect("p ii", substrs=["size=7", "[2] = 2", "[3] = 3", "[6] = 6"])
        self.expect("frame variable ii[2]", substrs=[" = 2"])
        self.runCmd("continue")
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        self.runCmd("continue")
        self.expect("frame variable ii", substrs=["size=0", "{}"])
        self.expect("frame variable ss", substrs=["size=0", "{}"])
        self.runCmd("continue")
        self.expect("frame variable ss", substrs=["size=2", '[0] = "a"', '[1] = "a very long string is right here"'])
        self.runCmd("continue")
        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"'])
        self.runCmd("continue")
        self.expect(
            "frame variable ss",
            substrs=["size=3", '[0] = "a"', '[1] = "a very long string is right here"', '[2] = "c"'],
        )
Ejemplo n.º 9
0
    def do_testObjCXXClasses(self):
        """Test ivars of Objective-C++ classes"""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp(self, "breakpoint 1", num_expected_locations=1)

        self.runCmd("run", RUN_SUCCEEDED)

        self.expect("expr f->f", "Found ivar in class", substrs=["= 3"])
    def do_testObjCXXClasses(self):
        """Test ivars of Objective-C++ classes"""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp (self, 'breakpoint 1', num_expected_locations=1) 

        self.runCmd("run", RUN_SUCCEEDED)

        self.expect("expr f->f", "Found ivar in class",
            substrs = ["= 3"])
Ejemplo n.º 11
0
    def run_python_os_step(self):
        """Test that the Python operating system plugin works correctly and allows single stepping of a virtual thread that is backed by a real thread"""

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        cwd = os.getcwd()
        exe = os.path.join(cwd, "a.out")
        python_os_plugin_path = os.path.join(cwd, "operating_system2.py")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside and outside methods that take pointers to the containing struct.
        lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")

        # Register our shared libraries for remote targets so they get automatically uploaded
        arguments = None
        environment = None 

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");


        # Now load the python OS plug-in which should update the thread list and we should have
        # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
        command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
        self.dbg.HandleCommand(command)

        # Verify our OS plug-in threads showed up
        thread = process.GetThreadByID(0x111111111);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");

        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
        line_entry = frame.GetLineEntry()

        self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stopped on line 5 in main.c")
        self.assertTrue(line_entry.GetLine() == 5, "Make sure we stopped on line 5 in main.c")

        # Now single step thread 0x111111111 and make sure it does what we need it to
        thread.StepOver()
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
        line_entry = frame.GetLineEntry()
        
        self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stepped from line 5 to line 6 in main.c")
        self.assertTrue(line_entry.GetLine() == 6, "Make sure we stepped from line 5 to line 6 in main.c")
Ejemplo n.º 12
0
    def run_python_os_step(self):
        """Test that the Python operating system plugin works correctly and allows single stepping of a virtual thread that is backed by a real thread"""

        # Set debugger into synchronous mode
        self.dbg.SetAsync(False)

        # Create a target by the debugger.
        cwd = os.getcwd()
        exe = os.path.join(cwd, "a.out")
        python_os_plugin_path = os.path.join(cwd, "operating_system2.py")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints inside and outside methods that take pointers to the containing struct.
        lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")

        # Register our shared libraries for remote targets so they get automatically uploaded
        arguments = None
        environment = None 

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
        thread = process.GetThreadByID(0x111111111);
        self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");


        # Now load the python OS plug-in which should update the thread list and we should have
        # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
        command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
        self.dbg.HandleCommand(command)

        # Verify our OS plug-in threads showed up
        thread = process.GetThreadByID(0x111111111);
        self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");

        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
        line_entry = frame.GetLineEntry()

        self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stopped on line 5 in main.c")
        self.assertTrue(line_entry.GetLine() == 5, "Make sure we stopped on line 5 in main.c")

        # Now single step thread 0x111111111 and make sure it does what we need it to
        thread.StepOver()
        
        frame = thread.GetFrameAtIndex(0)
        self.assertTrue(frame.IsValid(), "Make sure we get a frame from thread 0x111111111")
        line_entry = frame.GetLineEntry()
        
        self.assertTrue(line_entry.GetFileSpec().GetFilename() == 'main.c', "Make sure we stepped from line 5 to line 6 in main.c")
        self.assertTrue(line_entry.GetLine() == 6, "Make sure we stepped from line 5 to line 6 in main.c")
Ejemplo n.º 13
0
    def test_and_run_command(self):
        """Test expressions on register values."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        lldbutil.run_break_set_by_source_regexp(self, "break", num_expected_locations=2)

        ####################
        # First breakpoint

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

        # The breakpoint should have a hit count of 1.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
            substrs = [' resolved, hit count = 1'])

        # Try some variables that should be visible
        self.expect("expr a", VARIABLES_DISPLAYED_CORRECTLY,
            substrs = ['(int) $0 = 2'])

        self.expect("expr b->m1", VARIABLES_DISPLAYED_CORRECTLY,
            substrs = ['(int) $1 = 3'])

        #####################
        # Second breakpoint

        self.runCmd("continue")

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
            substrs = ['stopped',
                       'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 1.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
            substrs = [' resolved, hit count = 1'])

        # Try some variables that should be visible
        self.expect("expr b->m2", VARIABLES_DISPLAYED_CORRECTLY,
            substrs = ['(int) $2 = 5'])

        self.expect("expr c", VARIABLES_DISPLAYED_CORRECTLY,
            substrs = ['(int) $3 = 5'])

        self.runCmd("kill")
Ejemplo n.º 14
0
    def test_break(self):
        """Test ivars of Objective-C++ classes"""
        if self.getArchitecture() == "i386":
            self.skipTest("requires Objective-C 2.0 runtime")

        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp(self, "breakpoint 1", num_expected_locations=1)

        self.runCmd("run", RUN_SUCCEEDED)

        self.expect("expr f->f", "Found ivar in class", substrs=["= 3"])
Ejemplo n.º 15
0
    def test_break(self):
        """Test ivars of Objective-C++ classes"""
        if self.getArchitecture() == 'i386':
            self.skipTest("requires Objective-C 2.0 runtime")

        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp (self, 'breakpoint 1', num_expected_locations=1) 

        self.runCmd("run", RUN_SUCCEEDED)

        self.expect("expr f->f", "Found ivar in class",
            substrs = ["= 3"])
Ejemplo n.º 16
0
    def runTheTest(self):
        """MakeTest that dynamically discovered ivars of type IMP do not crash LLDB"""
        def cleanup():
            execute_command("make cleanup")
        self.addTearDownHook(cleanup)

        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.

        target = self.dbg.CreateTarget (exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoint

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

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple (None, None, self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        self.expect('frame variable --ptr-depth=1 --show-types -d run -- object', substrs=[
            '(MyClass *) object = 0x',
            '(void *) myImp = 0x'
        ])
        self.expect('disassemble --start-address `((MyClass*)object)->myImp`', substrs=[
            '-[MyClass init]'
        ])
Ejemplo n.º 17
0
    def test_imp_ivar_type(self):
        """Test that dynamically discovered ivars of type IMP do not crash LLDB"""
        if self.getArchitecture() == "i386":
            # rdar://problem/9946499
            self.skipTest("Dynamic types for ObjC V1 runtime not implemented")

        execute_command("make repro")

        def cleanup():
            execute_command("make cleanup")

        self.addTearDownHook(cleanup)

        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoint

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

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None, self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED)

        self.expect(
            "frame variable --ptr-depth=1 --show-types -d run -- object",
            substrs=["(MyClass *) object = 0x", "(void *) myImp = 0x"],
        )
        self.expect("disassemble --start-address `((MyClass*)object)->myImp`", substrs=["-[MyClass init]"])
Ejemplo n.º 18
0
    def test_imp_ivar_type(self):
        """Test that dynamically discovered ivars of type IMP do not crash LLDB"""
        if self.getArchitecture() == 'i386':
            # rdar://problem/9946499
            self.skipTest("Dynamic types for ObjC V1 runtime not implemented")

        execute_command("make repro")

        def cleanup():
            execute_command("make cleanup")

        self.addTearDownHook(cleanup)

        exe = os.path.join(os.getcwd(), "a.out")

        # Create a target from the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set up our breakpoint

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

        # Now launch the process, and do not stop at the entry point.
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        self.assertTrue(process.GetState() == lldb.eStateStopped,
                        PROCESS_STOPPED)

        self.expect(
            'frame variable --ptr-depth=1 --show-types -d run -- object',
            substrs=['(MyClass *) object = 0x', '(void *) myImp = 0x'])
        self.expect('disassemble --start-address `((MyClass*)object)->myImp`',
                    substrs=['-[MyClass init]'])
Ejemplo n.º 19
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.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=['libc++.1.dylib','libc++abi.dylib'])

        self.expect("frame variable ii",substrs = ["size=0","{}"])
        self.runCmd("continue")
        self.expect("frame variable ii",substrs = ["size=6","[0] = 0","[1] = 1", "[2] = 2", "[3] = 3", "[4] = 4", "[5] = 5"])
        self.runCmd("continue")
        self.expect("frame variable ii",substrs = ["size=7","[2] = 2", "[3] = 3", "[6] = 6"])
        self.expect("p ii",substrs = ["size=7","[2] = 2", "[3] = 3", "[6] = 6"])
        self.expect("frame variable ii[2]",substrs = [" = 2"])
        self.runCmd("continue")
        self.expect("frame variable ii",substrs = ["size=0","{}"])
        self.runCmd("continue")
        self.expect("frame variable ii",substrs = ["size=0","{}"])
        self.expect("frame variable ss",substrs = ["size=0","{}"])
        self.runCmd("continue")
        self.expect("frame variable ss",substrs = ["size=2",'[0] = "a"','[1] = "a very long string is right here"'])
        self.runCmd("continue")
        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"'])
        self.runCmd("continue")
        self.expect("frame variable ss",substrs = ["size=3",'[0] = "a"','[1] = "a very long string is right here"','[2] = "c"'])
Ejemplo n.º 20
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("p ii",substrs = ["size=7","[2] = 2", "[3] = 3", "[6] = 6"])
        self.expect("frame variable ii[2]",substrs = [" = 2"])
        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"'])
Ejemplo n.º 21
0
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        bkpt = self.target().FindBreakpointByID(lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line."))

        self.runCmd("run", RUN_FAILED)

        # 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())
Ejemplo n.º 22
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())
Ejemplo n.º 23
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())
Ejemplo n.º 24
0
    def data_formatter_commands(self):
        """Benchmark different ways to continue a process"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        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)

        runCmd_sw = Stopwatch()
        lldbutil_sw = Stopwatch()

        for i in range(0, 15):
            runCmd_sw.start()
            self.runCmd("continue")
            runCmd_sw.stop()

        for i in range(0, 15):
            lldbutil_sw.start()
            lldbutil.continue_to_breakpoint(self.process(), bkpt)
            lldbutil_sw.stop()

        print "runCmd: %s\nlldbutil: %s" % (runCmd_sw, lldbutil_sw)
Ejemplo n.º 25
0
    def data_formatter_commands(self):
        """Benchmark different ways to continue a process"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        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)
        
        runCmd_sw = Stopwatch()
        lldbutil_sw = Stopwatch()

        for i in range(0,15):
            runCmd_sw.start()
            self.runCmd("continue")
            runCmd_sw.stop()
        
        for i in range(0,15):
            lldbutil_sw.start()
            lldbutil.continue_to_breakpoint(self.process(), bkpt)
            lldbutil_sw.stop()
            
        print "runCmd: %s\nlldbutil: %s" % (runCmd_sw,lldbutil_sw)
Ejemplo n.º 26
0
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(self,
                                                None,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.c",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.c",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        # Breakpoint 4 - set at the same location as breakpoint 1 to test setting breakpoint commands on two breakpoints at a time
        lldbutil.run_break_set_by_file_and_line(self,
                                                None,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now add callbacks for the breakpoints just created.
        self.runCmd(
            "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4"
        )
        self.runCmd(
            "breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); print >> here, \"lldb\"; here.close()' 2"
        )
        self.runCmd(
            "breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, locations = 1" % self.line
            ],
            patterns=[
                "1: file = '.*main.c', line = %d, locations = 1" % self.line
            ])

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, locations = 1" % self.line
            ],
            patterns=[
                "1: file = '.*main.c', line = %d, locations = 1" % self.line,
                "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
                "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line
            ])

        self.expect("breakpoint command list 1",
                    "Breakpoint 1 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "frame variable --show-types --scope"
                    ])
        self.expect("breakpoint command list 2",
                    "Breakpoint 2 command ok",
                    substrs=[
                        "Breakpoint commands:", "here = open", "print >> here",
                        "here.close()"
                    ])
        self.expect("breakpoint command list 3",
                    "Breakpoint 3 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "bktptcmd.function(frame, bp_loc, internal_dict)"
                    ])

        self.expect("breakpoint command list 4",
                    "Breakpoint 4 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "frame variable --show-types --scope"
                    ])

        self.runCmd("breakpoint delete 4")

        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         extra_options="-f a.c",
                                         num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         extra_options="-f a.c -f b.c",
                                         num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(self,
                                                r"is about to return [12]0",
                                                extra_options="-f a.c -f b.c",
                                                num_expected_locations=2)

        lldbutil.run_break_set_by_source_regexp(self,
                                                r"is about to return [12]0",
                                                extra_options="-f a.c",
                                                num_expected_locations=1)

        # Run the program.  Remove 'output.txt' if it exists.
        self.RemoveTempFile("output.txt")
        self.RemoveTempFile("output2.txt")
        self.runCmd("run", RUN_SUCCEEDED)

        # Check that the file 'output.txt' exists and contains the string "lldb".

        # The 'output.txt' file should now exist.
        self.assertTrue(
            os.path.isfile("output.txt"),
            "'output.txt' exists due to breakpoint command for breakpoint 2.")
        self.assertTrue(
            os.path.isfile("output2.txt"),
            "'output2.txt' exists due to breakpoint command for breakpoint 3.")

        # Read the output file produced by running the program.
        with open('output.txt', 'r') as f:
            output = f.read()

        self.expect(output,
                    "File 'output.txt' and the content matches",
                    exe=False,
                    startstr="lldb")

        with open('output2.txt', 'r') as f:
            output = f.read()

        self.expect(output,
                    "File 'output2.txt' and the content matches",
                    exe=False,
                    startstr="lldb")

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect(
            "breakpoint command list 1",
            startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2",
            error=True,
            startstr="error: '2' is not a currently valid breakpoint id.")

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            patterns=[
                "1: file = '.*main.c', line = %d, locations = 1, resolved = 1"
                % self.line, "hit count = 1"
            ])

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=[
                "2: file = 'main.c', line = %d, locations = 1, resolved = 1" %
                self.line
            ])

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list",
                    STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f",
                    BREAKPOINT_HIT_TWICE,
                    substrs=['resolved, hit count = 2'])
Ejemplo n.º 27
0
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        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',
                               '{}'])
Ejemplo n.º 28
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"'
                    ])
Ejemplo n.º 29
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.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)

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

        self.runCmd("c")

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

        # add some more data
        self.runCmd("c")

        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"
        )
        #import time
        #time.sleep(19)
        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
        self.runCmd("c")

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

        # but check that expression does not rely on us
        # (when expression gets to call into STL code correctly, we will have to find
        # another way to check this)
        self.expect("expression numbers[6]",
                    matching=False,
                    error=True,
                    substrs=['1234567'])

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

        # clear out the vector and see that we do the right thing once again
        self.runCmd("c")

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

        self.runCmd("c")

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

        # check if we can display strings
        self.runCmd("c")

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

        self.runCmd("c")

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

        # but check that expression does not rely on us
        # (when expression gets to call into STL code correctly, we will have to find
        # another way to check this)
        self.expect("expression strings[0]",
                    matching=False,
                    error=True,
                    substrs=['goofy'])

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

        self.runCmd("c")

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

        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'])
Ejemplo n.º 31
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.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)

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

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

        # add some more data
        self.runCmd("c");
    
        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")
        #import time
        #time.sleep(19)
        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
        self.runCmd("c");

        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']);
        
        # but check that expression does not rely on us
        # (when expression gets to call into STL code correctly, we will have to find
        # another way to check this)
        self.expect("expression numbers[6]", matching=False, error=True,
            substrs = ['1234567'])

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

        # clear out the vector and see that we do the right thing once again
        self.runCmd("c")

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

        self.runCmd("c")

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

        # check if we can display strings
        self.runCmd("c")

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

        self.runCmd("c");

        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']);
        
        # but check that expression does not rely on us
        # (when expression gets to call into STL code correctly, we will have to find
        # another way to check this)
        self.expect("expression strings[0]", matching=False, error=True,
                    substrs = ['goofy'])

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

        self.runCmd("c")

        self.expect("frame variable strings",
            substrs = ['vector has 0 items'])
Ejemplo n.º 32
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.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.runCmd("frame variable ii --show-types")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

        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.runCmd("frame variable si --show-types")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

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

        self.runCmd("continue")
        self.runCmd("frame variable is --show-types")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

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

        self.runCmd("continue")
        self.runCmd("frame variable ss --show-types")

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

        self.runCmd("continue")

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

        self.runCmd("continue")

        self.expect('frame variable ss', substrs=['size=0', '{}'])
Ejemplo n.º 33
0
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True)

        # Now add callbacks for the breakpoints just created.
        self.runCmd("breakpoint command add -s command -o 'frame variable --show-types --scope' 1")
        self.runCmd(
            'breakpoint command add -s python -o \'here = open("output.txt", "w"); print >> here, "lldb"; here.close()\' 2'
        )
        self.runCmd("breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list",
            "Breakpoints 1 & 2 created",
            substrs=[
                "1: file ='main.c', line = %d, locations = 1" % self.line,
                "2: file ='main.c', line = %d, locations = 1" % self.line,
            ],
        )

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=[
                "1: file ='main.c', line = %d, locations = 1" % self.line,
                "2: file ='main.c', line = %d, locations = 1" % self.line,
            ],
            patterns=[
                "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
                "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
            ],
        )

        self.expect(
            "breakpoint command list 1",
            "Breakpoint 1 command ok",
            substrs=["Breakpoint commands:", "frame variable --show-types --scope"],
        )
        self.expect(
            "breakpoint command list 2",
            "Breakpoint 2 command ok",
            substrs=["Breakpoint commands:", "here = open", "print >> here", "here.close()"],
        )
        self.expect(
            "breakpoint command list 3",
            "Breakpoint 3 command ok",
            substrs=["Breakpoint commands:", "bktptcmd.function(frame, bp_loc, internal_dict)"],
        )

        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", extra_options="-f a.c", num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", extra_options="-f a.c -f b.c", num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(
            self, r"is about to return [12]0", extra_options="-f a.c -f b.c", num_expected_locations=2
        )

        lldbutil.run_break_set_by_source_regexp(
            self, r"is about to return [12]0", extra_options="-f a.c", num_expected_locations=1
        )

        # Run the program.  Remove 'output.txt' if it exists.
        self.RemoveTempFile("output.txt")
        self.RemoveTempFile("output2.txt")
        self.runCmd("run", RUN_SUCCEEDED)

        # Check that the file 'output.txt' exists and contains the string "lldb".

        # The 'output.txt' file should now exist.
        self.assertTrue(os.path.isfile("output.txt"), "'output.txt' exists due to breakpoint command for breakpoint 2.")
        self.assertTrue(
            os.path.isfile("output2.txt"), "'output2.txt' exists due to breakpoint command for breakpoint 3."
        )

        # Read the output file produced by running the program.
        with open("output.txt", "r") as f:
            output = f.read()

        self.expect(output, "File 'output.txt' and the content matches", exe=False, startstr="lldb")

        with open("output2.txt", "r") as f:
            output = f.read()

        self.expect(output, "File 'output2.txt' and the content matches", exe=False, startstr="lldb")

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect("breakpoint command list 1", startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2", error=True, startstr="error: '2' is not a currently valid breakpoint id."
        )

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            substrs=["1: file ='main.c', line = %d, locations = 1, resolved = 1" % self.line, "hit count = 1"],
        )

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=["2: file ='main.c', line = %d, locations = 1, resolved = 1" % self.line],
        )

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=["stopped", "stop reason = breakpoint"])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE, substrs=["resolved, hit count = 2"])
Ejemplo n.º 34
0
    def test_with_run_command(self):
        """Check that types only get completed when necessary."""
        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)

        # 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 category enable -l c++', check=False)

        self.runCmd('type category disable -l c++', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(p_type.IsTypeComplete(), 'vector<T> complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(p_type.IsTypeComplete(), 'vector<T> complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable p --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(), 'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(), 'NameAndAddress should be valid')
        self.assertFalse(name_address_type.IsTypeComplete(), 'NameAndAddress complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable guy --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(), 'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(), 'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(), 'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        if self.TraceOn():
             print('field0: ' + str(field0))
        self.assertTrue(field0.IsValid(), 'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        if self.TraceOn():
             print('string: ' + str(string))
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertFalse(string.IsTypeComplete(), 'std::string complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(), 'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(), 'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(), 'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        if self.TraceOn():
             print('field0: ' + str(field0))
        self.assertTrue(field0.IsValid(), 'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        if self.TraceOn():
             print('string: ' + str(string))
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertFalse(string.IsTypeComplete(), 'std::string complete but it should not be')

        self.runCmd('type category enable -l c++', check=False)
        self.runCmd('frame variable guy --show-types')

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(), 'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(), 'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(), 'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        self.assertTrue(field0.IsValid(), 'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertTrue(string.IsTypeComplete(), 'std::string should now be complete')
Ejemplo n.º 35
0
    def type_completion_commands(self):
        """Check that types only get completed when necessary."""
        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)

        # 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 category enable gnu-libstdc++', check=False)
            self.runCmd('type category enable libcxx', check=False)

        self.runCmd('type category disable gnu-libstdc++', check=False)
        self.runCmd('type category disable libcxx', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(p_type.IsTypeComplete(),
                         'vector<T> complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertFalse(p_type.IsTypeComplete(),
                         'vector<T> complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable p --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(),
                        'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(),
                        'NameAndAddress should be valid')
        self.assertFalse(name_address_type.IsTypeComplete(),
                         'NameAndAddress complete but it should not be')

        self.runCmd("continue")

        self.runCmd("frame variable guy --show-types")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(),
                        'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(),
                        'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(),
                        'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        if self.TraceOn():
            print 'field0: ' + str(field0)
        self.assertTrue(field0.IsValid(),
                        'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        if self.TraceOn():
            print 'string: ' + str(string)
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertFalse(string.IsTypeComplete(),
                         'std::string complete but it should not be')

        self.runCmd("continue")

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(),
                        'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(),
                        'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(),
                        'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        if self.TraceOn():
            print 'field0: ' + str(field0)
        self.assertTrue(field0.IsValid(),
                        'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        if self.TraceOn():
            print 'string: ' + str(string)
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertFalse(string.IsTypeComplete(),
                         'std::string complete but it should not be')

        self.runCmd('type category enable gnu-libstdc++', check=False)
        self.runCmd('type category enable libcxx', check=False)
        self.runCmd('frame variable guy --show-types')

        p_vector = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread(
        ).GetSelectedFrame().FindVariable('p')
        p_type = p_vector.GetType()
        self.assertTrue(p_type.IsTypeComplete(),
                        'vector<T> should now be complete')
        name_address_type = p_type.GetTemplateArgumentType(0)
        self.assertTrue(name_address_type.IsValid(),
                        'NameAndAddress should be valid')
        self.assertTrue(name_address_type.IsTypeComplete(),
                        'NameAndAddress should now be complete')
        field0 = name_address_type.GetFieldAtIndex(0)
        self.assertTrue(field0.IsValid(),
                        'NameAndAddress::m_name should be valid')
        string = field0.GetType().GetPointeeType()
        self.assertTrue(string.IsValid(), 'std::string should be valid')
        self.assertTrue(string.IsTypeComplete(),
                        'std::string should now be complete')
Ejemplo n.º 36
0
    def data_formatter_commands(self):
        """Test that that file and class static variables display correctly."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

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