Exemplo n.º 1
0
    def test_with_run_command(self):
        """Test 'frame variable this' when stopped on a class constructor."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break on the ctor function of class C.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line,
                                                num_expected_locations=-1)

        self.runCmd("run", RUN_SUCCEEDED)

        # The test suite sometimes shows that the process has exited without stopping.
        #
        # CC=clang ./dotest.py -v -t class_types
        # ...
        # Process 76604 exited with status = 0 (0x00000000)
        self.runCmd("process status")

        # 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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # We should be stopped on the ctor function of class C.
        self.expect("frame variable --show-types this",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['C *', ' this = '])
Exemplo n.º 2
0
    def do_test(self, dictionary=None):
        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
        self.build(dictionary=dictionary)
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_symbol(self,
                                         "foo",
                                         num_expected_locations=1,
                                         sym_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # This should display correctly.
        # Note that the member fields of a = 1 and b = 2 is by design.
        self.expect(
            "frame variable --show-types *bar_ptr",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=['(bar) *bar_ptr = ', '(int) a = 1', '(int) b = 2'])

        # And so should this.
        self.expect("expression --show-types -- *bar_ptr",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(bar)', '(int) a = 1', '(int) b = 2'])
Exemplo n.º 3
0
    def do_test(self, dictionary=None):
        self.build(dictionary=dictionary)

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

        # Create the breakpoint inside function 'main'.
        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, self.shlib_names)

        # Now launch the process, and do not stop at entry point.
        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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # This should display correctly.
        self.expect("expression [j getMember]",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["= 0x"])
Exemplo n.º 4
0
    def test_frame_var_after_stop_at_implementation(self):
        """Test that we can find the implementation for an objective C type"""
        if self.getArchitecture() == 'i386':
            self.skipTest("requires modern objc runtime")
        self.build()
        self.shlib_names = ["libTestExt.dylib", "libTest.dylib"]
        self.common_setup()

        line = line_number('TestExt/TestExt.m', '// break here')
        lldbutil.run_break_set_by_file_and_line(self,
                                                'TestExt.m',
                                                line,
                                                num_expected_locations=1,
                                                loc_exact=True)

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

        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # This should display correctly.
        self.expect("expr 42",
                    "A simple expression should execute correctly",
                    substrs=["42"])
Exemplo n.º 5
0
    def test_c_local_variables(self):
        """Test local variable value."""
        self.build()

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

        # Break inside the main.
        lldbutil.run_break_set_by_file_and_line(self,
                                                self.source,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.expect("frame variable i",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(unsigned int) i = 10'])
Exemplo n.º 6
0
    def common_setup(self):
        # Run in synchronous mode
        self.dbg.SetAsync(False)

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

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(
            self, self.source, self.line, num_expected_locations=1, loc_exact=True)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, self.shlib_names)

        # Now launch the process, and do not stop at entry point.
        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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
Exemplo n.º 7
0
    def common_setup(self, line):

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

        # Create a target
        exe = self.getBuildArtifact("a.out")
        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_file_and_line(self,
                                                self.source,
                                                line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
Exemplo n.º 8
0
    def test_expr(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.m",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.runCmd("settings set target.auto-import-clang-modules true")

        self.expect("p getpid()",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["pid_t"])
Exemplo n.º 9
0
    def test_with_expr_parser(self):
        """Test 'frame variable this' and 'expr this' when stopped inside a constructor."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # rdar://problem/8516141
        # Is this a case of clang (116.1) generating bad debug info?
        #
        # Break on the ctor function of class C.
        # self.expect("breakpoint set -M C", BREAKPOINT_CREATED,
        #    startstr = "Breakpoint created: 1: name = 'C'")

        # Make the test case more robust by using line number to break,
        # instead.
        lldbutil.run_break_set_by_file_and_line(self,
                                                None,
                                                self.line,
                                                num_expected_locations=-1)

        self.runCmd("run", RUN_SUCCEEDED)

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

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # Continue on inside the ctor() body...
        self.runCmd("register read pc")
        self.runCmd("thread step-over")

        # Verify that 'frame variable this' gets the data type correct.
        self.expect("frame variable this",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['C *'])

        # Verify that frame variable --show-types this->m_c_int behaves
        # correctly.
        self.runCmd("register read pc")
        self.runCmd("expr m_c_int")
        self.expect("frame variable --show-types this->m_c_int",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    startstr='(int) this->m_c_int = 66')

        # Verify that 'expression this' gets the data type correct.
        self.expect("expression this",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['C *'])

        # rdar://problem/8430916
        # expr this->m_c_int returns an incorrect value
        #
        # Verify that expr this->m_c_int behaves correctly.
        self.expect("expression this->m_c_int",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    patterns=['\(int\) \$[0-9]+ = 66'])
Exemplo n.º 10
0
    def breakpoint_ignore_count(self):
        """Exercise breakpoint ignore count with 'breakpoint set -i <count>'."""
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Create a breakpoint in main.c at line1.
        lldbutil.run_break_set_by_file_and_line(self,
                                                'main.c',
                                                self.line1,
                                                extra_options='-i 1',
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now run the program.
        self.runCmd("run", RUN_SUCCEEDED)

        # The process should be stopped at this point.
        self.expect("process status",
                    PROCESS_STOPPED,
                    patterns=['Process .* stopped'])

        # Also check the hit count, which should be 2, due to ignore count of
        # 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=2)

        # The frame #0 should correspond to main.c:37, the executable statement
        # in function name 'c'.  And frame #2 should point to main.c:45.
        self.expect(
            "thread backtrace",
            STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT,
            #substrs = ["stop reason = breakpoint"],
            patterns=[
                "frame #0.*main.c:%d" % self.line1,
                "frame #2.*main.c:%d" % self.line2
            ])

        # continue -i 1 is the same as setting the ignore count to 1 again, try that:
        # Now run the program.
        self.runCmd("process continue -i 1", RUN_SUCCEEDED)

        # The process should be stopped at this point.
        self.expect("process status",
                    PROCESS_STOPPED,
                    patterns=['Process .* stopped'])

        # Also check the hit count, which should be 2, due to ignore count of
        # 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=4)

        # The frame #0 should correspond to main.c:37, the executable statement
        # in function name 'c'.  And frame #2 should point to main.c:45.
        self.expect(
            "thread backtrace",
            STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT,
            #substrs = ["stop reason = breakpoint"],
            patterns=[
                "frame #0.*main.c:%d" % self.line1,
                "frame #1.*main.c:%d" % self.line5
            ])
Exemplo n.º 11
0
    def test_expr(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

        # Enable logging of the imported AST.
        log_file = self.getBuildArtifact("lldb-ast-log.txt")
        self.runCmd("log enable lldb ast -f '%s'" % log_file)

        self.expect(
            "expr -l objc++ -- @import Darwin; 3",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=[
                "int",
                "3"])

        # This expr command imports __sFILE with definition
        # (FILE is a typedef to __sFILE.)
        self.expect(
            "expr *fopen(\"/dev/zero\", \"w\")",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=[
                "FILE",
                "_close"])

        # Check that the AST log contains exactly one definition of __sFILE.
        f = open(log_file)
        log_lines = f.readlines()
        f.close()
        os.remove(log_file)
        self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"),
                         1)

        self.expect("expr *myFile", VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["a", "5", "b", "9"])

        self.expect(
            "expr MIN((uint64_t)2, (uint64_t)3)",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=[
                "uint64_t",
                "2"])

        self.expect("expr stdin", VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["(FILE *)", "0x"])
Exemplo n.º 12
0
    def test_and_run_command(self):
        """Test 'frame variable var_name' on some variables with array types."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=False)

        self.runCmd("run", RUN_SUCCEEDED)

        # The test suite sometimes shows that the process has exited without stopping.
        #
        # CC=clang ./dotest.py -v -t array_types
        # ...
        # Process 76604 exited with status = 0 (0x00000000)
        self.runCmd("process status")

        # 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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

        # Issue 'variable list' command on several array-type variables.

        self.expect(
            "frame variable --show-types strings",
            VARIABLES_DISPLAYED_CORRECTLY,
            startstr='(char *[4])',
            substrs=[
                '(char *) [0]',
                'Hello',
                '(char *) [1]',
                'Hola',
                '(char *) [2]',
                'Bonjour',
                '(char *) [3]',
                'Guten Tag'])

        self.expect(
            "frame variable --show-types --raw -- char_16",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=[
                '(char) [0]',
                '(char) [15]'])

        self.expect(
            "frame variable --show-types ushort_matrix",
            VARIABLES_DISPLAYED_CORRECTLY,
            startstr='(unsigned short[2][3])')

        self.expect(
            "frame variable --show-types long_6",
            VARIABLES_DISPLAYED_CORRECTLY,
            startstr='(long[6])')
Exemplo n.º 13
0
    def test_memory_find(self):
        """Test the 'memory find' command."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break in main() after the variables are assigned values.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # Test the memory find commands.

        # Empty search string should be handled.
        self.expect(
            'memory find -s "" `stringdata` `stringdata+16`',
            error=True,
            substrs=["error: search string must have non-zero length."])

        self.expect(
            'memory find -s "in const" `stringdata` `stringdata+(int)strlen(stringdata)`',
            substrs=['data found at location: 0x', '69 6e 20 63', 'in const'])

        # Invalid expr is an error.
        self.expect(
            'memory find -e "not_a_symbol" `&bytedata[0]` `&bytedata[15]`',
            error=True,
            substrs=[
                "error: expression evaluation failed. pass a string instead"
            ])

        self.expect(
            'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
            substrs=['data found at location: 0x', '22 33 44 55 66'])

        self.expect(
            'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[2]`',
            substrs=['data not found within the range.'])

        self.expect('memory find -s "nothere" `stringdata` `stringdata+5`',
                    substrs=['data not found within the range.'])

        self.expect('memory find -s "nothere" `stringdata` `stringdata+10`',
                    substrs=['data not found within the range.'])
Exemplo n.º 14
0
    def test_expr(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.m",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.expect("expr @import Darwin; 3",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["int", "3"])

        self.expect("expr getpid()",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["pid_t"])

        self.expect("expr @import Foundation; 4",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["int", "4"])

        # Type lookup should still work and print something reasonable
        # for types from the module.
        self.expect("type lookup NSObject", substrs=["instanceMethod"])

        self.expect("expr string.length",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["NSUInteger", "5"])

        self.expect("expr array.count",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["NSUInteger", "3"])

        self.expect("p *[NSURL URLWithString:@\"http://lldb.llvm.org\"]",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["NSURL", "isa", "_urlString"])

        self.expect("p [NSURL URLWithString:@\"http://lldb.llvm.org\"].scheme",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["http"])
        # Test that the NULL macro still works with a loaded module.
        self.expect_expr("int *i = NULL; i == NULL", result_value="true")
Exemplo n.º 15
0
    def runToBreakpoint(self):
        self.build()
        self._target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, '// Set breakpoint 0 here.',
            lldb.SBFileSpec('main.m', False))

        # 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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
    def run_tests(self):
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(
            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

        d1 = self.frame().FindVariable("d1")
        d1.SetPreferSyntheticValue(True)
        d1.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)

        self.assertEqual(
            d1.GetNumChildren(), 1,
            "dictionary has != 1 child elements")
        pair = d1.GetChildAtIndex(0)
        pair.SetPreferSyntheticValue(True)
        pair.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)

        self.assertEqual(
            pair.GetNumChildren(), 2,
            "pair has != 2 child elements")

        key = pair.GetChildMemberWithName("key")
        value = pair.GetChildMemberWithName("value")

        key.SetPreferSyntheticValue(True)
        key.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
        value.SetPreferSyntheticValue(True)
        value.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)

        self.assertEqual(
            key.GetSummary(), '@"key"',
            "key doesn't contain key")
        self.assertEqual(
            value.GetSummary(), '@"value"',
            "value doesn't contain value")
Exemplo n.º 17
0
    def breakpoint_locations_test(self):
        """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
        self.set_breakpoint()

        # The 'breakpoint disable 3.*' command should fail gracefully.
        self.expect("breakpoint disable 3.*",
                    "Disabling an invalid breakpoint should fail gracefully",
                    error=True,
                    startstr="error: '3' is not a valid breakpoint ID.")

        # The 'breakpoint disable 1.*' command should disable all 3 locations.
        self.expect(
            "breakpoint disable 1.*",
            "All 3 breakpoint locatons disabled correctly",
            startstr="3 breakpoints disabled.")

        # Run the program.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should not stopped on any breakpoint at all.
        self.expect("process status", "No stopping on any disabled breakpoint",
                    patterns=["^Process [0-9]+ exited with status = 0"])

        # The 'breakpoint enable 1.*' command should enable all 3 breakpoints.
        self.expect(
            "breakpoint enable 1.*",
            "All 3 breakpoint locatons enabled correctly",
            startstr="3 breakpoints enabled.")

        # The 'breakpoint disable 1.1' command should disable 1 location.
        self.expect(
            "breakpoint disable 1.1",
            "1 breakpoint locatons disabled correctly",
            startstr="1 breakpoints disabled.")

        # Run the program again.  We should stop on the two breakpoint
        # locations.
        self.runCmd("run", RUN_SUCCEEDED)

        # Stopped once.
        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=["stop reason = breakpoint 1."])

        # Continue the program, there should be another stop.
        self.runCmd("process continue")

        # Stopped again.
        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=["stop reason = breakpoint 1."])

        # At this point, 1.1 has a hit count of 0 and the other a hit count of
        # 1".
        lldbutil.check_breakpoint(self, bpno = 1, expected_locations = 3, expected_resolved_count = 2, expected_hit_count = 2)
        lldbutil.check_breakpoint(self, bpno = 1, location_id = 1,  expected_location_resolved = False, expected_location_hit_count = 0)
        lldbutil.check_breakpoint(self, bpno = 1, location_id = 2, expected_location_resolved = True, expected_location_hit_count = 1)
        lldbutil.check_breakpoint(self, bpno = 1, location_id = 3, expected_location_resolved = True, expected_location_hit_count = 1)
Exemplo n.º 18
0
    def runToBreakpoint(self):
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
Exemplo n.º 19
0
    def test(self):
        """Test breakpoint works correctly with dead-code stripping."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break by function name f1 (live code).
        lldbutil.run_break_set_by_symbol(self,
                                         "f1",
                                         num_expected_locations=1,
                                         module_name="a.out")

        # Break by function name f2 (dead code).
        lldbutil.run_break_set_by_symbol(self,
                                         "f2",
                                         num_expected_locations=0,
                                         module_name="a.out")

        # Break by function name f3 (live code).
        lldbutil.run_break_set_by_symbol(self,
                                         "f3",
                                         num_expected_locations=1,
                                         module_name="a.out")

        self.runCmd("run", RUN_SUCCEEDED)

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

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.runCmd("continue")

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

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=3, expected_hit_count=1)
Exemplo n.º 20
0
    def test(self):
        """Test that variables with signed types display correctly."""
        self.build()

        # Run in synchronous mode
        self.dbg.SetAsync(False)

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

        lldbutil.run_break_set_by_file_and_line(self,
                                                self.source,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now launch the process, and do not stop at entry point.
        process = target.LaunchSimple(None, None,
                                      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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # Execute the puts().
        self.runCmd("thread step-over")

        # Test that signed types display correctly.
        self.expect("frame variable --show-types --no-args",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    patterns=[
                        "\((short int|short)\) the_signed_short = 99",
                        "\((signed char|char)\) the_signed_char = 'c'"
                    ],
                    substrs=[
                        "(int) the_signed_int = 99",
                        "(long) the_signed_long = 99",
                        "(long long) the_signed_long_long = 99"
                    ])
Exemplo n.º 21
0
    def test_global_variable_hydration(self):
        self.build()
        self.common_setup()

        lldbutil.run_break_set_by_file_and_line(self,
                                                self.source,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now launch the process, and do not stop at entry point.
        process = self.target.LaunchSimple(
            None, self.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"],
        )

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.expect(
            "target variable --shlib a.out",
            "Breakpoint in a.out should have hydrated the debug info",
            substrs=["global_shared = 897"],
        )

        self.expect(
            "target variable --shlib " + self.shared_lib_name,
            "shared library should not have debug info by default",
            matching=False,
            substrs=["global_foo"],
        )

        self.expect(
            "target variable global_foo --shlib " + self.shared_lib_name,
            "Match global_foo in symbol table should hydrate debug info",
            matching=True,
            substrs=["global_foo = 321"],
        )
Exemplo n.º 22
0
    def common_setup(self, strip):

        if strip:
            exe = self.getBuildArtifact("stripped/a.out")
        else:
            exe = self.getBuildArtifact("a.out")
        # Create a target by the debugger.
        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Create the breakpoint inside function 'main'.
        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Register our shared libraries for remote targets so they get
        # automatically uploaded
        environment = self.registerSharedLibrariesWithTarget(
            target, self.shlib_names)

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

        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the foo function which takes a bar_ptr argument.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.m",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
Exemplo n.º 23
0
    def test_memory_cache(self):
        """Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break in main() after the variables are assigned values.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # Read a chunk of memory containing &my_ints[0]. The number of bytes read
        # must be greater than m_L2_cache_line_byte_size to make sure the L1
        # cache is used.
        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')

        # Check the value of my_ints[0] is the same as set in main.cpp.
        line = self.res.GetOutput().splitlines()[100]
        self.assertEquals(0x00000042, int(line.split(':')[1], 0))

        # Change the value of my_ints[0] in memory.
        self.runCmd("memory write -s 4 `&my_ints` AA")

        # Re-read the chunk of memory. The cache line should have been
        # flushed because of the 'memory write'.
        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')

        # Check the value of my_ints[0] have been updated correctly.
        line = self.res.GetOutput().splitlines()[100]
        self.assertEquals(0x000000AA, int(line.split(':')[1], 0))
Exemplo n.º 24
0
    def test_frame_var_after_stop_at_implementation(self):
        """Test that we can find the implementation for an objective C type"""
        if self.getArchitecture() == 'i386':
            self.skipTest("requires modern objc runtime")
        self.build()

        lldbutil.run_to_source_breakpoint(
            self, '// Set breakpoint where Bar is an implementation',
            lldb.SBFileSpec("Bar.m", False))

        self.expect('breakpoint set -p "// Set breakpoint in main"')
        self.runCmd("continue", RUN_SUCCEEDED)

        # Run at stop at main
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # This should display correctly.
        self.expect("frame variable foo->_bar->_hidden_ivar",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
Exemplo n.º 25
0
    def test_and_run_command(self):
        """Test interpreted and JITted expressions on constant values."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break inside the main.
        lldbutil.run_break_set_by_symbol(self,
                                         "main",
                                         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'])

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.runCmd("next")
        self.runCmd("next")

        # Try frame variable.
        self.expect("frame variable index",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['(int32_t) index = 512'])

        # Try an interpreted expression.
        self.expect("expr (index + 512)",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['1024'])

        # Try a JITted expression.
        self.expect("expr (int)getpid(); (index - 256)",
                    VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=['256'])

        self.runCmd("kill")
Exemplo n.º 26
0
    def test_source_line_breakpoint(self):
        self.build()
        self.common_setup()

        lldbutil.run_break_set_by_file_and_line(self,
                                                "foo.c",
                                                4,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now launch the process, and do not stop at entry point.
        process = self.target.LaunchSimple(
            None, self.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"],
        )
        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        thread = process.GetSelectedThread()
        stack_frames = lldbutil.get_stack_frames(thread)
        self.assertGreater(len(stack_frames), 2)

        leaf_frame = stack_frames[0]
        self.assertEqual("foo.c",
                         leaf_frame.GetLineEntry().GetFileSpec().GetFilename())
        self.assertEqual(4, leaf_frame.GetLineEntry().GetLine())

        parent_frame = stack_frames[1]
        self.assertEqual(
            "shared.c",
            parent_frame.GetLineEntry().GetFileSpec().GetFilename())
        self.assertEqual(7, parent_frame.GetLineEntry().GetLine())
Exemplo n.º 27
0
    def test_expr(self):
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
        lldbutil.run_break_set_by_file_and_line(
            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

        self.runCmd(
            "settings set target.clang-module-search-paths \"" +
            self.getSourceDir() +
            "\"")

        self.expect("expr @import myModule; 3", VARIABLES_DISPLAYED_CORRECTLY,
                    substrs=["int", "3"])

        self.expect(
            "expr private_func()",
            VARIABLES_DISPLAYED_CORRECTLY,
            substrs=[
                "int",
                "5"])

        self.expect("expr MY_MIN(2,3)", "#defined macro was found",
                    substrs=["int", "2"])

        self.expect("expr MY_MAX(2,3)", "#undefd macro was correctly not found",
                    error=True)
Exemplo n.º 28
0
    def run_load_unload(self):
        """Test breakpoint by name works correctly with dlopen'ing."""
        self.copy_shlibs_to_remote()

        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break by function name a_function (not yet loaded).
        lldbutil.run_break_set_by_symbol(self,
                                         "a_function",
                                         num_expected_locations=0)

        self.runCmd("run", RUN_SUCCEEDED)

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

        # The breakpoint should have a hit count of 1.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        # Issue the 'continue' command.  We should stop agaian at a_function.
        # The stop reason of the thread should be breakpoint and at a_function.
        self.runCmd("continue")

        # rdar://problem/8508987
        # The a_function breakpoint should be encountered twice.
        self.expect(
            "thread list",
            STOPPED_DUE_TO_BREAKPOINT,
            substrs=['stopped', 'a_function', 'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 2.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=2)
Exemplo n.º 29
0
    def test_apropos_with_process(self):
        """Test that apropos env doesn't crash trying to touch the process plugin command."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break in main() after the variables are assigned values.
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.cpp",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)

        self.runCmd('apropos env')
Exemplo n.º 30
0
    def test_nested_alias(self):
        """Test that an alias can reference other aliases without crashing."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Break in main() after the variables are assigned values.
        lldbutil.run_break_set_by_file_and_line(
            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)

        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.
        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)

        # This is the function to remove the custom aliases in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('command unalias read', check=False)
            self.runCmd('command unalias rd', check=False)
            self.runCmd('command unalias fo', check=False)
            self.runCmd('command unalias foself', check=False)
            self.runCmd('command unalias add_two', check=False)
            self.runCmd('command unalias two', check=False)

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

        self.runCmd('command alias read memory read -f A')
        self.runCmd('command alias rd read -c 3')

        self.expect(
            'memory read -f A -c 3 `&my_ptr[0]`',
            substrs=[
                'deadbeef',
                'main.cpp:',
                'feedbeef'])
        self.expect(
            'rd `&my_ptr[0]`',
            substrs=[
                'deadbeef',
                'main.cpp:',
                'feedbeef'])

        self.expect(
            'memory read -f A -c 3 `&my_ptr[0]`',
            substrs=['deadfeed'],
            matching=False)
        self.expect('rd `&my_ptr[0]`', substrs=['deadfeed'], matching=False)

        self.runCmd('command alias fo frame variable -O --')
        self.runCmd('command alias foself fo self')

        self.expect(
            'help foself',
            substrs=[
                '--show-all-children',
                '--raw-output'],
            matching=False)
        self.expect(
            'help foself',
            substrs=[
                'Show variables for the current',
                'stack frame.'],
            matching=True)

        # Check that foself was resolved and is now independent of 'fo'.
        self.runCmd('command unalias fo')
        self.expect(
            'help foself',
            substrs=[
                'Show variables for the current',
                'stack frame.'],
            matching=True)

        # Check that aliases can be created for raw input commands.
        self.expect('command alias two expr -- 2')
        self.expect('command alias add_two two +')
        self.expect('add_two 3', patterns=[' = 5$'])