def test_with_run_command(self):
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())

        self.expect("frame variable ti", substrs=['[0] = 1'])
        self.expect("frame variable ts", substrs=['[0] = "foobar"'])
        self.expect("frame variable tt", substrs=['[0] = 1', '[1] = "baz"', '[2] = 2'])

        self.assertEqual(1, frame.GetValueForVariablePath("ti[0]").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("ti[1]").IsValid())

        self.assertEqual('"foobar"', frame.GetValueForVariablePath("ts[0]").GetSummary())
        self.assertFalse(frame.GetValueForVariablePath("ts[1]").IsValid())

        self.assertEqual(1, frame.GetValueForVariablePath("tt[0]").GetValueAsUnsigned())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("tt[1]").GetSummary())
        self.assertEqual(2, frame.GetValueForVariablePath("tt[2]").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("tt[3]").IsValid())
    def test_with_run_command(self):
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())

        self.expect("frame variable ti", substrs=['[0] = 1'])
        self.expect("frame variable ts", substrs=['[0] = "foobar"'])
        self.expect("frame variable tt", substrs=['[0] = 1', '[1] = "baz"', '[2] = 2'])

        self.assertEqual(1, frame.GetValueForVariablePath("ti[0]").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("ti[1]").IsValid())

        self.assertEqual('"foobar"', frame.GetValueForVariablePath("ts[0]").GetSummary())
        self.assertFalse(frame.GetValueForVariablePath("ts[1]").IsValid())

        self.assertEqual(1, frame.GetValueForVariablePath("tt[0]").GetValueAsUnsigned())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("tt[1]").GetSummary())
        self.assertEqual(2, frame.GetValueForVariablePath("tt[2]").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("tt[3]").IsValid())
    def test_shadowed(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, ['One', 'Two'])

        lldbutil.run_break_set_by_source_regexp(self, '// break here',
                extra_options='-f main.c', num_expected_locations=1)

        process = target.LaunchSimple(
            None, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

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

        # As we are shadowing the conflicting symbol, there should be no
        # ambiguity in this expression.
        self.expect(
            "expr int conflicting_symbol = 474747; conflicting_symbol",
            substrs=[ "474747"])
Exemple #4
0
    def test_runtime_types(self):
        """Test commands that require runtime types"""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside Test_NSString:
        line = self.lines[2]
        lldbutil.run_break_set_by_source_regexp(
            self, "NSString tests")

        self.runCmd("run", RUN_SUCCEEDED)

        # Test_NSString:
        self.runCmd("thread backtrace")
        self.expect("expression [str length]",
                    patterns=["\(NSUInteger\) \$.* ="])
        self.expect("expression str.length")
        self.expect('expression str = [NSString stringWithCString: "new"]')
        self.expect(
            'po [NSError errorWithDomain:@"Hello" code:35 userInfo:@{@"NSDescription" : @"be completed."}]',
            substrs=[
                "Error Domain=Hello",
                "Code=35",
                "be completed."])
        self.runCmd("process continue")
    def test_recursive_unique_ptr(self):
        # Tests that LLDB can handle when we have a loop in the unique_ptr
        # reference chain and that it correctly handles the different options
        # for the frame variable command in this case.
        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)
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        self.expect("frame variable f1->fp",
                    substrs=['fp = 0x'])
        self.expect("frame variable --ptr-depth=1 f1->fp",
                    substrs=['data = 2', 'fp = 0x'])
        self.expect("frame variable --ptr-depth=2 f1->fp",
                    substrs=['data = 2', 'fp = 0x', 'data = 1'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())
        self.assertEqual(2, frame.GetValueForVariablePath("f1->fp.object.data").GetValueAsUnsigned())
        self.assertEqual(2, frame.GetValueForVariablePath("f1->fp->data").GetValueAsUnsigned())
        self.assertEqual(1, frame.GetValueForVariablePath("f1->fp.object.fp.object.data").GetValueAsUnsigned())
        self.assertEqual(1, frame.GetValueForVariablePath("f1->fp->fp->data").GetValueAsUnsigned())
Exemple #6
0
    def test_recursive_unique_ptr(self):
        # Tests that LLDB can handle when we have a loop in the unique_ptr
        # reference chain and that it correctly handles the different options
        # for the frame variable command in this case.
        self.build()
        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_source_regexp(
            self, "Set break point at this line.")
        self.runCmd("run", RUN_SUCCEEDED)
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        self.expect("frame variable f1->fp",
                    substrs=['fp = 0x'])
        self.expect("frame variable --ptr-depth=1 f1->fp",
                    substrs=['data = 2', 'fp = 0x'])
        self.expect("frame variable --ptr-depth=2 f1->fp",
                    substrs=['data = 2', 'fp = 0x', 'data = 1'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())
        self.assertEqual(2, frame.GetValueForVariablePath("f1->fp.object.data").GetValueAsUnsigned())
        self.assertEqual(2, frame.GetValueForVariablePath("f1->fp->data").GetValueAsUnsigned())
        self.assertEqual(1, frame.GetValueForVariablePath("f1->fp.object.fp.object.data").GetValueAsUnsigned())
        self.assertEqual(1, frame.GetValueForVariablePath("f1->fp->fp->data").GetValueAsUnsigned())
Exemple #7
0
    def getvalue_commands(self):
        """Tests that the SBValue::GetValueAsUnsigned() API works for Swift types"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(self,r"break here",num_expected_locations=1)

        self.runCmd("run", RUN_SUCCEEDED)

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

        frame = self.frame()
        string = frame.FindVariable("aString")
        number = frame.FindVariable("aNumber")
        number.SetPreferSyntheticValue(True)
        classobject = frame.FindVariable("aClassObject")

        numberValue = number.GetValueAsUnsigned()
        self.assertTrue(numberValue == 123456, "Swift.Int does not have a valid value")

        builtinPointerValue = string.GetChildMemberWithName("str_value").GetChildMemberWithName("base").GetChildMemberWithName("value")
        self.assertTrue(builtinPointerValue != 0, "Builtin.RawPointer does not have a valid value")

        objectPointerValue = string.GetChildMemberWithName("str_value").GetChildMemberWithName("value")
        self.assertTrue(objectPointerValue != 0, "Builtin.RawPointer does not have a valid value")

        classValue = classobject.GetValueAsUnsigned()
        self.assertTrue(classValue != 0, "Class types are aggregates with pointer values")
    def test_runtime_types(self):
        """Test commands that require runtime types"""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside Test_NSString:
        line = self.lines[2]
        lldbutil.run_break_set_by_source_regexp(
            self, "NSString tests")

        self.runCmd("run", RUN_SUCCEEDED)

        # Test_NSString:
        self.runCmd("thread backtrace")
        self.expect("expression [str length]",
                    patterns=["\(NSUInteger\) \$.* ="])
        self.expect("expression str.length")
        self.expect('expression str = [NSString stringWithCString: "new"]')
        self.expect(
            'po [NSError errorWithDomain:@"Hello" code:35 userInfo:@{@"NSDescription" : @"be completed."}]',
            substrs=[
                "Error Domain=Hello",
                "Code=35",
                "be completed."])
        self.runCmd("process continue")
Exemple #9
0
    def test_shadowed(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, ['One', 'Two'])

        lldbutil.run_break_set_by_source_regexp(self,
                                                '// break here',
                                                extra_options='-f main.c',
                                                num_expected_locations=1)

        process = target.LaunchSimple(None, environment,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

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

        # As we are shadowing the conflicting symbol, there should be no
        # ambiguity in this expression.
        self.expect("expr int conflicting_symbol = 474747; conflicting_symbol",
                    substrs=["474747"])
    def test_with_run_command(self):
        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"])

        self.expect("frame variable nsp", substrs=["nsp = nullptr"])
        self.expect("frame variable isp", substrs=["isp = 123"])
        self.expect("frame variable ssp", substrs=['ssp = "foobar"'])

        self.expect("frame variable nwp", substrs=["nwp = nullptr"])
        self.expect("frame variable iwp", substrs=["iwp = 123"])
        self.expect("frame variable swp", substrs=['swp = "foobar"'])

        self.runCmd("continue")

        self.expect("frame variable nsp", substrs=["nsp = nullptr"])
        self.expect("frame variable isp", substrs=["isp = nullptr"])
        self.expect("frame variable ssp", substrs=["ssp = nullptr"])

        self.expect("frame variable nwp", substrs=["nwp = nullptr"])
        self.expect("frame variable iwp", substrs=["iwp = nullptr"])
        self.expect("frame variable swp", substrs=["swp = nullptr"])
    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 '{0!s}'".format(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");
    def test_with_run_command(self):
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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)

        ns = self.namespace
        self.look_for_content_and_continue("map", [
            '%s::unordered_map' % ns, 'size=5 {', 'hello', 'world', 'this',
            'is', 'me'
        ])

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

        self.look_for_content_and_continue("iset", [
            '%s::unordered_set' % ns, 'size=5 {', '\[\d\] = 5', '\[\d\] = 3',
            '\[\d\] = 2'
        ])

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

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

        self.look_for_content_and_continue("smset", [
            '%s::unordered_multiset' % ns, 'size=5 {',
            '(\[\d\] = "is"(\\n|.)+){2}', '(\[\d\] = "world"(\\n|.)+){2}'
        ])
    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 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 dynamic_val_commands(self):
        """Tests that dynamic values work correctly for Swift"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(
            self, "// Set a breakpoint 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'])

        self.expect(
            "frame variable",
            substrs=[
                "AWrapperClass) aWrapper",
                "SomeClass) anItem = ",
                "x = ",
                "Base<Int>) aBase = 0x",
                "v = 449493530"])
        self.expect(
            "frame variable -d run --show-types",
            substrs=[
                "AWrapperClass) aWrapper",
                "YetAnotherClass) anItem = ",
                "x = ",
                "y = ",
                "z = ",
                "Derived<Int>) aBase = 0x",
                "Base<Int>)",
                ".Base = {",
                "v = 449493530",
                "q = 3735928559"])
        self.runCmd("continue")
        self.expect(
            "frame variable",
            substrs=[
                "AWrapperClass) aWrapper",
                "SomeClass) anItem = ",
                "x = ",
                "Base<Int>) aBase = 0x",
                "v = 449493530"])
        self.expect(
            "frame variable -d run --show-types",
            substrs=[
                "AWrapperClass) aWrapper",
                "YetAnotherClass) anItem = ",
                "x = ",
                "y = ",
                "z = ",
                "Derived<Int>) aBase = 0x",
                "Base<Int>)",
                ".Base = {",
                "v = 449493530",
                "q = 3735928559"])
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

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

        self.runCmd("run", RUN_SUCCEEDED)

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

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

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type filter clear', check=False)
            self.runCmd('type synth clear', check=False)
            self.runCmd(
                "settings set target.max-children-count 256",
                check=False)

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

        self.expect('image list', substrs=self.getLibcPlusPlusLibs())

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

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

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

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

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

        self.look_for_content_and_continue(
            "smset",
            ['size=5 {', '(\[\d\] = "is"(\\n|.)+){2}',
                         '(\[\d\] = "world"(\\n|.)+){2}'])
    def dynamic_val_commands(self):
        """Tests that dynamic values work correctly for Swift"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(
            self, "// Set a breakpoint 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'])

        self.expect(
            "frame variable",
            substrs=[
                "AWrapperClass) aWrapper",
                "SomeClass) anItem = ",
                "x = ",
                "Base<Int>) aBase = 0x",
                "v = 449493530"])
        self.expect(
            "frame variable -d run --show-types",
            substrs=[
                "AWrapperClass) aWrapper",
                "YetAnotherClass) anItem = ",
                "x = ",
                "y = ",
                "z = ",
                "Derived<Int>) aBase = 0x",
                "Base<Int>)",
                ".Base = {",
                "v = 449493530",
                "q = 3735928559"])
        self.runCmd("continue")
        self.expect(
            "frame variable",
            substrs=[
                "AWrapperClass) aWrapper",
                "SomeClass) anItem = ",
                "x = ",
                "Base<Int>) aBase = 0x",
                "v = 449493530"])
        self.expect(
            "frame variable -d run --show-types",
            substrs=[
                "AWrapperClass) aWrapper",
                "YetAnotherClass) anItem = ",
                "x = ",
                "y = ",
                "z = ",
                "Derived<Int>) aBase = 0x",
                "Base<Int>)",
                ".Base = {",
                "v = 449493530",
                "q = 3735928559"])
Exemple #18
0
    def test_with_run_command(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

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

        self.runCmd("run", RUN_SUCCEEDED)

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

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

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type filter clear', check=False)
            self.runCmd('type synth clear', check=False)
            self.runCmd("settings set target.max-children-count 256",
                        check=False)

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

        self.expect('image list', substrs=self.getLibcPlusPlusLibs())

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

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

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

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

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

        self.look_for_content_and_continue("smset", [
            'size=5 {', '(\[\d\] = "is"(\\n|.)+){2}',
            '(\[\d\] = "world"(\\n|.)+){2}'
        ])
    def genericresolution_commands(self):
        """Check that we can correctly figure out the dynamic type of generic things"""
        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'])

        self.expect(
            "frame variable -d run",
            substrs=[
                "(Int) x = 123",
                "(a.OtherClass<Int>) self = 0x",
                "a.AClass = {}",
                "v = 1234567"])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                '(String) x = "hello world again"',
                '(Int) v = 1'])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                '(a.Pair<a.Generic<Int>, a.Pair<String, a.Generic<String>>>) self = 0x',
                'one = ',
                'v = 193627',
                'two = 0x',
                'one = "hello"',
                'two = (v = "world")'])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                '(a.Pair<a.Generic<Double>, a.Generic<a.Pair<String, String>>>) self = 0',
                'one = ',
                'v = 3.1',
                'two = {',
                'v = 0x',
                '(one = "this is", two = "a good thing")'])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                "(Int) x = 5",
                '(String) y = "hello world"',
                "(a.OtherClass<Int>) self = 0x",
                "a.AClass = {}",
                "v = 1234567"])
    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 '{0!s}'".format(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")
    def test_with_run_command(self):
        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 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)

        ns = self.namespace
        self.look_for_content_and_continue(
            "map", ['%s::unordered_map' %
                    ns, 'size=5 {', 'hello', 'world', 'this', 'is', 'me'])

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

        self.look_for_content_and_continue(
            "iset", ['%s::unordered_set' %
                     ns, 'size=5 {', '\[\d\] = 5', '\[\d\] = 3', '\[\d\] = 2'])

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

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

        self.look_for_content_and_continue(
            "smset", ['%s::unordered_multiset' % ns, 'size=5 {', '(\[\d\] = "is"(\\n|.)+){2}',
                      '(\[\d\] = "world"(\\n|.)+){2}'])
    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")
Exemple #23
0
    def var_commands(self):
        """Test that LLDB can effectively use the type metadata to reconstruct dynamic types for Swift"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(self, "// Set breakpoint 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'])

        self.expect("frame select 0", substrs=['foo', 'x', 'ivar'])
        self.expect("frame variable -d run -- x",
                    substrs=['(a.AClass) x',
                             'ivar = 3735928559'])  # first stop on foo
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['bar', 'x', 'y'])
        self.expect("frame variable -d run -- x y",
                    substrs=['(Int64) x', '(Float) y'])  # first stop on bar
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['foo', 'x'])
        self.expect("frame variable -d run -- x",
                    substrs=['(a.AClass) x',
                             'ivar = 3735928559'])  # second stop on foo
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['baz', 'x'])
        self.expect("frame variable -d run -- x",
                    substrs=['(a.AClass) x',
                             'ivar = 3735928559'])  # first stop on baz
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['bar', 'x'])
        self.expect("frame variable -d run -- x y",
                    substrs=['(a.AClass) x',
                             '(a.AClass) y'])  # second stop on bar
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['bat', 'x'])
        self.expect("frame variable -d run -- x",
                    substrs=['(a.ADerivedClass) x'])  # first stop on bat
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs=['bat', 'x'])
        self.expect("frame variable -d run -- x",
                    substrs=['(a.AnotherDerivedClass) x'
                             ])  # second stop on bat
        self.runCmd("continue", RUN_SUCCEEDED)
Exemple #24
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"])
Exemple #25
0
    def test_imp_ivar_type(self):
        """Test that dynamically discovered ivars of type IMP do not crash LLDB"""
        self.build()
        exe = self.getBuildArtifact("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]'])
Exemple #26
0
    def test(self):
        """Test that std::function as defined by libc++ is correctly printed by LLDB"""
        self.build()
        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'])

        f1 = self.get_variable('f1')
        f2 = self.get_variable('f2')

        if self.TraceOn():
            print(f1)
        if self.TraceOn():
            print(f2)

        self.assertTrue(f1.GetValueAsUnsigned(0) != 0, 'f1 has a valid value')
        self.assertTrue(f2.GetValueAsUnsigned(0) != 0, 'f2 has a valid value')
    def test(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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)

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

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

        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())
Exemple #28
0
    def test(self):
        """Test that std::function as defined by libc++ is correctly printed by LLDB"""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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'])

        self.expect("frame variable f1",
                    substrs=['f1 =  Function = foo(int, int)'])

        self.expect("frame variable f2",
                    substrs=['f2 =  Lambda in File main.cpp at Line 26'])

        self.expect("frame variable f3",
                    substrs=['f3 =  Lambda in File main.cpp at Line 30'])

        self.expect("frame variable f4",
                    substrs=['f4 =  Function in File main.cpp at Line 16'])

        self.expect("frame variable f5",
                    substrs=['f5 =  Function = Bar::add_num(int) const'])
    def data_formatter_commands(self):
        """Benchmark the Swift dictionary data formatter"""
        self.runCmd("file " + getBuildArtifact("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)

        sw = Stopwatch()

        sw.start()
        self.expect('frame variable -A dict', substrs=['[300]', '300'])
        sw.stop()

        print("time to print: %s" % (sw))
    def break_commands(self):
        """Tests that we can set a conditional breakpoint in Swift code"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        bkno = lldbutil.run_break_set_by_source_regexp(
            self, "Set breakpoint here")
        self.runCmd('breakpoint modify ' + str(bkno) + ' -c x==y')

        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 var x y", substrs=['x = 5', 'y = 5'])

        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame var x y", substrs=['x = 6', 'y = 6'])

        self.runCmd('breakpoint modify ' + str(bkno) + ' -c x>y')

        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame var x y", substrs=['x = 3', 'y = 1'])
Exemple #31
0
    def test(self):
        """Test that std::atomic as defined by libc++ is correctly printed by LLDB"""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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)

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

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

        s = self.get_variable('s')
        i = self.get_variable('i')

        if self.TraceOn():
            print(s)
        if self.TraceOn():
            print(i)

        self.assertTrue(i.GetValueAsUnsigned(0) == 5, "i == 5")
        self.assertTrue(s.GetNumChildren() == 2, "s has two children")
        self.assertTrue(
            s.GetChildAtIndex(0).GetValueAsUnsigned(0) == 1, "s.x == 1")
        self.assertTrue(
            s.GetChildAtIndex(1).GetValueAsUnsigned(0) == 2, "s.y == 2")
    def test(self):
        """Test that std::function as defined by libc++ is correctly printed by LLDB"""
        self.build()
        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)

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

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

        f1 = self.get_variable('f1')
        f2 = self.get_variable('f2')

        if self.TraceOn():
            print(f1)
        if self.TraceOn():
            print(f2)

        self.assertTrue(f1.GetValueAsUnsigned(0) != 0, 'f1 has a valid value')
        self.assertTrue(f2.GetValueAsUnsigned(0) != 0, 'f2 has a valid value')
Exemple #33
0
    def test_imp_ivar_type(self):
        """Test that dynamically discovered ivars of type IMP do not crash LLDB"""
        self.build()
        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]'])
    def data_formatter_commands(self):
        """Benchmark the std::map data formatter (libc++)"""
        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)
        
        sw = Stopwatch()
        
        sw.start()
        self.expect('frame variable -A map', substrs=['[300]', '300'])
        sw.stop()
            
        print("time to print: %s" % (sw))
    def break_commands(self):
        """Tests that we can set a conditional breakpoint in Swift code"""
        exe_name = self.getBuildArtifact("a.out")
        self.runCmd("file %s" % (exe_name), CURRENT_EXECUTABLE_SET)
        bkno = lldbutil.run_break_set_by_source_regexp(self,
                                                       "Set breakpoint here")
        self.runCmd('breakpoint modify ' + str(bkno) + ' -c x==y')

        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 var x y", substrs=['x = 5', 'y = 5'])

        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame var x y", substrs=['x = 6', 'y = 6'])

        self.runCmd('breakpoint modify ' + str(bkno) + ' -c x>y')

        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame var x y", substrs=['x = 3', 'y = 1'])
Exemple #36
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 = self.getBuildArtifact("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 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]'
        ])
Exemple #38
0
    def test(self):
        """Test that std::atomic as defined by libc++ is correctly printed by LLDB"""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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)

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

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

        s = self.get_variable('s')
        i = self.get_variable('i')

        if self.TraceOn():
            print(s)
        if self.TraceOn():
            print(i)

        self.assertTrue(i.GetValueAsUnsigned(0) == 5, "i == 5")
        self.assertTrue(s.GetNumChildren() == 2, "s has two children")
        self.assertTrue(
            s.GetChildAtIndex(0).GetValueAsUnsigned(0) == 1,
            "s.x == 1")
        self.assertTrue(
            s.GetChildAtIndex(1).GetValueAsUnsigned(0) == 2,
            "s.y == 2")
    def test_with_run_command(self):
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())

        self.expect("frame variable nup", substrs=['nup = nullptr'])
        self.expect("frame variable iup", substrs=['iup = 0x'])
        self.expect("frame variable sup", substrs=['sup = 0x'])

        self.expect("frame variable ndp", substrs=['ndp = nullptr'])
        self.expect("frame variable idp", substrs=['idp = 0x', 'deleter = ', 'a = 1', 'b = 2'])
        self.expect("frame variable sdp", substrs=['sdp = 0x', 'deleter = ', 'a = 3', 'b = 4'])

        self.assertEqual(123, frame.GetValueForVariablePath("iup.object").GetValueAsUnsigned())
        self.assertEqual(123, frame.GetValueForVariablePath("*iup").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("iup.deleter").IsValid())

        self.assertEqual('"foobar"', frame.GetValueForVariablePath("sup.object").GetSummary())
        self.assertEqual('"foobar"', frame.GetValueForVariablePath("*sup").GetSummary())
        self.assertFalse(frame.GetValueForVariablePath("sup.deleter").IsValid())

        self.assertEqual(456, frame.GetValueForVariablePath("idp.object").GetValueAsUnsigned())
        self.assertEqual(456, frame.GetValueForVariablePath("*idp").GetValueAsUnsigned())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("sdp.object").GetSummary())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("*sdp").GetSummary())

        idp_deleter = frame.GetValueForVariablePath("idp.deleter")
        self.assertTrue(idp_deleter.IsValid())
        self.assertEqual(1, idp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
        self.assertEqual(2, idp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())

        sdp_deleter = frame.GetValueForVariablePath("sdp.deleter")
        self.assertTrue(sdp_deleter.IsValid())
        self.assertEqual(3, sdp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
        self.assertEqual(4, sdp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())
    def test_with_run_command(self):
        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'])

        frame = self.frame()
        self.assertTrue(frame.IsValid())

        self.expect("frame variable nup", substrs=['nup = nullptr'])
        self.expect("frame variable iup", substrs=['iup = 0x'])
        self.expect("frame variable sup", substrs=['sup = 0x'])

        self.expect("frame variable ndp", substrs=['ndp = nullptr'])
        self.expect("frame variable idp", substrs=['idp = 0x', 'deleter = ', 'a = 1', 'b = 2'])
        self.expect("frame variable sdp", substrs=['sdp = 0x', 'deleter = ', 'a = 3', 'b = 4'])

        self.assertEqual(123, frame.GetValueForVariablePath("iup.object").GetValueAsUnsigned())
        self.assertEqual(123, frame.GetValueForVariablePath("*iup").GetValueAsUnsigned())
        self.assertFalse(frame.GetValueForVariablePath("iup.deleter").IsValid())

        self.assertEqual('"foobar"', frame.GetValueForVariablePath("sup.object").GetSummary())
        self.assertEqual('"foobar"', frame.GetValueForVariablePath("*sup").GetSummary())
        self.assertFalse(frame.GetValueForVariablePath("sup.deleter").IsValid())

        self.assertEqual(456, frame.GetValueForVariablePath("idp.object").GetValueAsUnsigned())
        self.assertEqual(456, frame.GetValueForVariablePath("*idp").GetValueAsUnsigned())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("sdp.object").GetSummary())
        self.assertEqual('"baz"', frame.GetValueForVariablePath("*sdp").GetSummary())

        idp_deleter = frame.GetValueForVariablePath("idp.deleter")
        self.assertTrue(idp_deleter.IsValid())
        self.assertEqual(1, idp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
        self.assertEqual(2, idp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())

        sdp_deleter = frame.GetValueForVariablePath("sdp.deleter")
        self.assertTrue(sdp_deleter.IsValid())
        self.assertEqual(3, sdp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
        self.assertEqual(4, sdp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())
    def do_test_with_run_command(self, stdlib_type):
        """Test that that file and class static variables display correctly."""

        # 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.addTearDownHook(cleanup)

        self.build(dictionary={stdlib_type: "1"})
        self.runCmd("file " + self.getBuildArtifact("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'])

        self.runCmd("frame variable has_optional")

        output = self.res.GetOutput()

        ## The variable has_optional tells us if the test program
        ## detected we have a sufficient libc++ version to support optional
        ## false means we do not and therefore should skip the test
        if output.find("(bool) has_optional = false") != -1:
            self.skipTest("Optional not supported")

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

        self.expect("frame variable number_not_engaged",
                    substrs=['Has Value=false'])

        self.expect("frame variable number_engaged",
                    substrs=['Has Value=true', 'Value = 42', '}'])

        self.expect("frame var numbers",
                    substrs=[
                        '(optional_int_vect) numbers =  Has Value=true  {',
                        'Value = size=4 {', '[0] = 1', '[1] = 2', '[2] = 3',
                        '[3] = 4', '}', '}'
                    ])

        self.expect("frame var ostring",
                    substrs=[
                        '(optional_string) ostring =  Has Value=true  {',
                        'Value = "hello"', '}'
                    ])
    def test(self):
        self.build()
        lldbutil.run_to_source_breakpoint(self, "// break here",
                                          lldb.SBFileSpec("f.cpp"))

        # Sanity check that we really have to debug info for this type.
        this = self.expect_var_path("this", type="A *")
        self.assertEquals(this.GetType().GetPointeeType().GetNumberOfFields(),
                          0, str(this))

        self.expect_var_path("af.x", value='42')

        lldbutil.run_break_set_by_source_regexp(self,
                                                "// break here",
                                                extra_options="-f g.cpp")
        self.runCmd("continue")

        self.expect_var_path("ag.a", value='47')
    def test_cross_dso_tail_calls(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, ['One', 'Two'])

        lldbutil.run_break_set_by_source_regexp(self, '// break here',
                extra_options='-f Two.c')

        process = target.LaunchSimple(
            None, environment, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # We should be stopped in the second dylib.
        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)

        # Debug helper:
        # self.runCmd("log enable -f /tmp/lldb.log lldb step")
        # self.runCmd("bt")

        # Check that the backtrace is what we expect:
        #  frame #0: 0x000000010d5e5f94 libTwo.dylib`tail_called_in_b_from_b at Two.c:7:3 [opt]
        #  frame #1: 0x000000010d5e5fa0 libTwo.dylib`tail_called_in_b_from_a [opt] [artificial]
        #  frame #2: 0x000000010d5dcf80 libOne.dylib`helper_in_a [opt] [artificial]
        #  frame #3: 0x000000010d5dcf79 libOne.dylib`tail_called_in_a_from_main at One.c:10:3 [opt]
        #  frame #4: 0x000000010d5d3f80 a.out`helper [opt] [artificial]
        #  frame #5: 0x000000010d5d3f79 a.out`main at main.c:10:3 [opt]
        expected_frames = [
                ("tail_called_in_b_from_b", False),
                ("tail_called_in_b_from_a", True),
                ("helper_in_a", True),
                ("tail_called_in_a_from_main", False),
                ("helper", True),
                ("main", False)
        ]
        for idx, (name, is_artificial) in enumerate(expected_frames):
            frame = thread.GetFrameAtIndex(idx)
            self.assertTrue(name in frame.GetDisplayFunctionName())
            self.assertEqual(frame.IsArtificial(), is_artificial)
    def genericresolution_commands(self):
        """Check that we can correctly figure out the dynamic type of generic things"""
        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'])

        self.expect("frame variable -d run",
                    substrs=[
                        "(Int) x = 123", "(a.OtherClass<Int>) self = 0x",
                        "a.AClass = {}", "v = 1234567"
                    ])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=['(String) x = "hello world again"', '(Int) v = 1'])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                '(a.Pair<a.Generic<Int>, a.Pair<String, a.Generic<String>>>) self = 0x',
                'one = ', 'v = 193627', 'two = 0x', 'one = "hello"',
                'two = (v = "world")'
            ])
        self.runCmd("continue")
        self.expect(
            "frame variable -d run",
            substrs=[
                '(a.Pair<a.Generic<Double>, a.Generic<a.Pair<String, String>>>) self = 0',
                'one = ', 'v = 3.1', 'two = {', 'v = 0x',
                '(one = "this is", two = "a good thing")'
            ])
        self.runCmd("continue")
        self.expect("frame variable -d run",
                    substrs=[
                        "(Int) x = 5", '(String) y = "hello world"',
                        "(a.OtherClass<Int>) self = 0x", "a.AClass = {}",
                        "v = 1234567"
                    ])
    def nserror_commands(self):
        """Tests that Swift displays NSError correctly"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(
            self, "// Set a breakpoint 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'])

        self.expect("frame variable -d run --ptr-depth=2", substrs=[
            '0 = " "', '1 = 0x', 'domain: "lldbrocks" - code: 3133079277 {',
            '_userInfo = ', '2 key/value pairs {',
            '0 = ', ' "x"', '1 = ', ' Int64(0)', '0 = ', ' "y"', '1 = ',
            ' Int64(0)', '0 = "x+y"', 'domain: "lldbrocks" - code: 0 {',
            '1 = ', ' Int64(3)', '1 = ', ' Int64(4)'])
Exemple #46
0
    def test_inferior_handle_sigabrt(self):
        """Inferior calls abort() and handles the resultant SIGABRT.
           Stopped at a breakpoint in the handler, verify that the backtrace
           includes the function that called abort()."""
        self.build()
        exe = self.getBuildArtifact("a.out")

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

        # launch
        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)
        self.assertState(process.GetState(), lldb.eStateStopped)
        signo = process.GetUnixSignals().GetSignalNumberFromName("SIGABRT")

        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonSignal)
        self.assertTrue(thread and thread.IsValid(),
                        "Thread should be stopped due to a signal")
        self.assertTrue(thread.GetStopReasonDataCount() >= 1,
                        "There should be data in the event.")
        self.assertEqual(thread.GetStopReasonDataAtIndex(0), signo,
                         "The stop signal should be SIGABRT")

        # Continue to breakpoint in abort handler
        bkpt = target.FindBreakpointByID(
            lldbutil.run_break_set_by_source_regexp(self,
                                                    "Set a breakpoint here"))
        threads = lldbutil.continue_to_breakpoint(process, bkpt)
        self.assertEqual(len(threads), 1, "Expected single thread")
        thread = threads[0]

        # Expect breakpoint in 'handler'
        frame = thread.GetFrameAtIndex(0)
        self.assertEqual(frame.GetDisplayFunctionName(), "handler",
                         "Unexpected break?")

        # Expect that unwinding should find 'abort_caller'
        foundFoo = False
        for frame in thread:
            if frame.GetDisplayFunctionName() == "abort_caller":
                foundFoo = True

        self.assertTrue(foundFoo,
                        "Unwinding did not find func that called abort")

        # Continue until we exit.
        process.Continue()
        self.assertState(process.GetState(), lldb.eStateExited)
        self.assertEqual(process.GetExitStatus(), 0)
Exemple #47
0
    def test(self):
        """Test that std::atomic as defined by libc++ is correctly printed by LLDB"""
        self.build()
        self.runCmd("file " + self.getBuildArtifact("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)

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

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

        s_atomic = self.get_variable('s')
        i_atomic = self.get_variable('i')

        if self.TraceOn():
            print(s_atomic)
        if self.TraceOn():
            print(i_atomic)

        # Extract the content of the std::atomic wrappers.
        self.assertEqual(s_atomic.GetNumChildren(), 1)
        s = s_atomic.GetChildAtIndex(0)
        self.assertEqual(i_atomic.GetNumChildren(), 1)
        i = i_atomic.GetChildAtIndex(0)

        if self.TraceOn():
            print(s)
        if self.TraceOn():
            print(i)

        self.assertTrue(i.GetValueAsUnsigned(0) == 5, "i == 5")
        self.assertTrue(s.GetNumChildren() == 2, "s has two children")
        self.assertTrue(
            s.GetChildAtIndex(0).GetValueAsUnsigned(0) == 1, "s.x == 1")
        self.assertTrue(
            s.GetChildAtIndex(1).GetValueAsUnsigned(0) == 2, "s.y == 2")

        # Try printing the child that points to its own parent object.
        # This should just treat the atomic pointer as a normal pointer.
        self.expect("frame var p.child", substrs=["Value = 0x"])
        self.expect("frame var p", substrs=["parent = {", "Value = 0x", "}"])
        self.expect("frame var p.child.parent",
                    substrs=["p.child.parent = {\n  Value = 0x"])
    def test_cross_object_tail_calls(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        lldbutil.run_break_set_by_source_regexp(self, '// break here',
                extra_options='-f Two.c')

        process = target.LaunchSimple(
            None, None, self.get_process_working_directory())
        self.assertTrue(process, PROCESS_IS_VALID)

        # We should be stopped in the second dylib.
        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)

        # Debug helper:
        # self.runCmd("log enable -f /tmp/lldb.log lldb step")
        # self.runCmd("bt")

        # Check that the backtrace is what we expect:
        #  frame #0: 0x000000010be73f94 a.out`tail_called_in_b_from_b at Two.c:7:3 [opt]
        #  frame #1: 0x000000010be73fa0 a.out`tail_called_in_b_from_a at Two.c:8:1 [opt] [artificial]
        #  frame #2: 0x000000010be73f80 a.out`helper_in_a at One.c:11:1 [opt] [artificial]
        #  frame #3: 0x000000010be73f79 a.out`tail_called_in_a_from_main at One.c:10:3 [opt]
        #  frame #4: 0x000000010be73f60 a.out`helper at main.c:11:3 [opt] [artificial]
        #  frame #5: 0x000000010be73f59 a.out`main at main.c:10:3 [opt]
        expected_frames = [
                ("tail_called_in_b_from_b", False),
                ("tail_called_in_b_from_a", True),
                ("helper_in_a", True),
                ("tail_called_in_a_from_main", False),
                ("helper", True),
                ("main", False)
        ]
        for idx, (name, is_artificial) in enumerate(expected_frames):
            frame = thread.GetFrameAtIndex(idx)
            self.assertTrue(name in frame.GetDisplayFunctionName())
            self.assertEqual(frame.IsArtificial(), is_artificial)
    def var_commands(self):
        """Test that LLDB can effectively use the type metadata to reconstruct dynamic types for Swift"""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_source_regexp(self,"// Set breakpoint 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'])

        self.expect("frame select 0", substrs = ['foo', 'x', 'ivar'])
        self.expect("frame variable -d run -- x", substrs = ['(a.AClass) x','ivar = 3735928559']) # first stop on foo
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['bar', 'x', 'y'])
        self.expect("frame variable -d run -- x y", substrs = ['(Int64) x', '(Float) y']) # first stop on bar
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['foo', 'x'])
        self.expect("frame variable -d run -- x", substrs = ['(a.AClass) x','ivar = 3735928559']) # second stop on foo
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['baz', 'x'])
        self.expect("frame variable -d run -- x", substrs = ['(a.AClass) x','ivar = 3735928559']) # first stop on baz
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['bar', 'x'])
        self.expect("frame variable -d run -- x y", substrs = ['(a.AClass) x', '(a.AClass) y']) # second stop on bar
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['bat', 'x'])
        self.expect("frame variable -d run -- x", substrs = ['(a.ADerivedClass) x']) # first stop on bat
        self.runCmd("continue", RUN_SUCCEEDED)

        self.expect("frame select 0", substrs = ['bat', 'x'])
        self.expect("frame variable -d run -- x", substrs = ['(a.AnotherDerivedClass) x']) # second stop on bat
        self.runCmd("continue", RUN_SUCCEEDED)
    def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
                             pattern="Set a breakpoint here"):
        exe = self.getBuildArtifact("a.out")
        self.target = self.dbg.CreateTarget(exe)
        self.assertTrue(self.target.IsValid(), "Target is not valid")

        extra_options_txt = "--auto-continue 1 "
        if additional_options:
            extra_options_txt += additional_options
        bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
                                            extra_options = extra_options_txt,
                                            num_expected_locations = num_expected_loc)
        return bpno
Exemple #51
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)
        
        bkpt = self.target().FindBreakpointByID(lldbutil.run_break_set_by_source_regexp (self, "Set break point at this line."))

        self.runCmd("run", RUN_SUCCEEDED)

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

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

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type filter clear', check=False)
            self.runCmd('type synth clear', check=False)
            self.runCmd("settings set target.max-children-count 256", check=False)

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

        self.expect('image list', substrs = self.getLibcPlusPlusLibs())

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

        self.runCmd( "frame variable has_optional" )

        output = self.res.GetOutput()

        ## The variable has_optional tells us if the test program
        ## detected we have a sufficient libc++ version to support optional
        ## false means we do not and therefore should skip the test
        if output.find("(bool) has_optional = false") != -1 :
           self.skipTest( "Optional not supported" ) 

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

        self.expect("frame variable number_not_engaged",
                    substrs=['Has Value=false'])

        self.expect("frame variable number_engaged",
                    substrs=['Has Value=true',
                             'Value = 42',
                             '}'])

        self.expect("frame var numbers",
                    substrs=['(optional_int_vect) numbers =  Has Value=true  {',
                             'Value = size=4 {',
                               '[0] = 1',
                               '[1] = 2',
                               '[2] = 3',
                               '[3] = 4',
                               '}',
                             '}'])

        self.expect("frame var ostring",
                    substrs=['(optional_string) ostring =  Has Value=true  {',
                        'Value = "hello"',
                        '}'])
    def data_formatter_commands(self):
        """Benchmark different ways to continue a process"""
        self.runCmd("file "+self.getBuildArtifact("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))
    def test(self):
        """Test that that file and class static variables display correctly."""
        self.build()
        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)

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

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

        self.expect("frame variable ili", substrs = ['[1] = 2','[4] = 5'])
        self.expect("frame variable ils", substrs = ['[4] = "surprise it is a long string!! yay!!"'])

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

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

        self.runCmd("run", RUN_SUCCEEDED)

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

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type filter clear', check=False)
            self.runCmd('type synth clear', check=False)
            self.runCmd(
                "settings set target.max-children-count 256",
                check=False)

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

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

        self.runCmd(
            "type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e")

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

        self.runCmd("c")

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

        self.runCmd("c")

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

        self.runCmd("c")

        self.expect("frame variable ii",
                    substrs=['map has 9 items',
                             '[5] = ',
                             'first = 5',
                             'second = 0',
                             '[7] = ',
                             'first = 7',
                             'second = 1'])

        self.expect("p ii",
                    substrs=['map has 9 items',
                             '[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 ='])

        self.expect("frame variable ii[8]", matching=True,
                    substrs=['1234567'])

        # 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("c")

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

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

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

        self.runCmd("c")

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

        self.runCmd("c")

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

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

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

        # check that MightHaveChildren() gets it right
        self.assertTrue(
            self.frame().FindVariable("si").MightHaveChildren(),
            "si.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 si[0]", matching=False, error=True,
        #            substrs = ['first = ', 'zero'])

        self.runCmd("c")

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

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

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

        self.runCmd("c")

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

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

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

        # check that MightHaveChildren() gets it right
        self.assertTrue(
            self.frame().FindVariable("is").MightHaveChildren(),
            "is.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 is[0]", matching=False, error=True,
        #            substrs = ['first = ', 'goofy'])

        self.runCmd("c")

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

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

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

        self.runCmd("c")

        self.expect("frame variable ss",
                    substrs=['map has 4 items',
                             '[0] = ',
                             'second = \"hello\"',
                             'first = \"ciao\"',
                             '[1] = ',
                             'second = \"house\"',
                             'first = \"casa\"',
                             '[2] = ',
                             'second = \"cat\"',
                             'first = \"gatto\"',
                             '[3] = ',
                             'second = \"..is always a Mac!\"',
                             'first = \"a Mac..\"'])

        self.expect("p ss",
                    substrs=['map has 4 items',
                             '[0] = ',
                             'second = \"hello\"',
                             'first = \"ciao\"',
                             '[1] = ',
                             'second = \"house\"',
                             'first = \"casa\"',
                             '[2] = ',
                             'second = \"cat\"',
                             'first = \"gatto\"',
                             '[3] = ',
                             'second = \"..is always a Mac!\"',
                             'first = \"a Mac..\"'])

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

        # check that MightHaveChildren() gets it right
        self.assertTrue(
            self.frame().FindVariable("ss").MightHaveChildren(),
            "ss.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 ss[3]", matching=False, error=True,
        #            substrs = ['gatto'])

        self.runCmd("c")

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