def breakpoint_creation_by_filespec_python(self):
        """Use Python APIs to create a breakpoint by (filespec, line)."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        filespec = target.GetExecutable()
        self.assertTrue(filespec, VALID_FILESPEC)

        fsDir = filespec.GetDirectory()
        fsFile = filespec.GetFilename()

        self.assertTrue(fsDir == os.getcwd() and fsFile == "a.out",
                        "FileSpec matches the executable")

        bpfilespec = lldb.SBFileSpec("main.cpp", False)

        breakpoint = target.BreakpointCreateByLocation(bpfilespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint),
                    BREAKPOINT_CREATED,
                    exe=False,
                    substrs=['main.cpp', str(self.line)])

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

        if not process:
            self.fail("SBTarget.Launch() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The filename of frame #0 should be 'main.cpp' and the line number
        # should be 93.
        self.expect("%s:%d" % (lldbutil.get_filenames(thread)[0],
                               lldbutil.get_line_numbers(thread)[0]),
                    "Break correctly at main.cpp:%d" % self.line,
                    exe=False,
                    startstr="main.cpp:")
        ### clang compiled code reported main.cpp:94?
        ### startstr = "main.cpp:93")

        # We should be stopped on the breakpoint with a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        process.Continue()
Пример #2
0
    def describe_threads(self):
        ret = []
        for x in self.inferior_process:
            id = x.GetIndexID()
            reason = x.GetStopReason()
            status = "stopped" if x.IsStopped() else "running"
            reason_str = lldbutil.stop_reason_to_str(reason)
            if reason == lldb.eStopReasonBreakpoint:
                bpid = x.GetStopReasonDataAtIndex(0)
                bp = self.inferior_target.FindBreakpointByID(bpid)
                reason_str = "%s hit %d times" % (lldbutil.get_description(bp),
                                                  bp.GetHitCount())
            elif reason == lldb.eStopReasonWatchpoint:
                watchid = x.GetStopReasonDataAtIndex(0)
                watch = self.inferior_target.FindWatchpointByID(watchid)
                reason_str = "%s hit %d times" % (
                    lldbutil.get_description(watch), watch.GetHitCount())
            elif reason == lldb.eStopReasonSignal:
                reason_str = "signal %s" % (
                    signal_names[x.GetStopReasonDataAtIndex(0)])

            location = "\t".join([
                lldbutil.get_description(x.GetFrameAtIndex(i))
                for i in range(x.GetNumFrames())
            ])
            ret.append("thread %d %s due to %s at\n\t%s" %
                       (id, status, reason_str, location))
        return ret
Пример #3
0
    def bitfields_variable_python(self):
        """Use Python APIs to inspect a bitfields variable."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

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

        # The stop reason of the thread should be breakpoint.
        thread = target.GetProcess().GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        # Lookup the "bits" variable which contains 8 bitfields.
        frame = thread.GetFrameAtIndex(0)
        bits = frame.FindVariable("bits")
        self.DebugSBValue(bits)
        self.assertTrue(
            bits.GetTypeName() == "Bits" and bits.GetNumChildren() == 8
            and bits.GetByteSize() == 4,
            "(Bits)bits with byte size of 4 and 8 children")

        # Notice the pattern of int(b1.GetValue(), 0).  We pass a base of 0
        # so that the proper radix is determined based on the contents of the
        # string.
        b1 = bits.GetChildAtIndex(0)
        self.DebugSBValue(b1)
        self.assertTrue(
            b1.GetName() == "b1" and b1.GetTypeName() == "uint32_t:1"
            and b1.IsInScope() and int(b1.GetValue(), 0) == 1,
            'bits.b1 has type uint32_t:1, is in scope, and == 1')

        b7 = bits.GetChildAtIndex(6)
        self.DebugSBValue(b7)
        self.assertTrue(
            b7.GetName() == "b7" and b7.GetTypeName() == "uint32_t:7"
            and b7.IsInScope() and int(b7.GetValue(), 0) == 127,
            'bits.b7 has type uint32_t:7, is in scope, and == 127')

        four = bits.GetChildAtIndex(7)
        self.DebugSBValue(four)
        self.assertTrue(
            four.GetName() == "four" and four.GetTypeName() == "uint32_t:4"
            and four.IsInScope() and int(four.GetValue(), 0) == 15,
            'bits.four has type uint32_t:4, is in scope, and == 15')

        # Now kill the process, and we are done.
        rc = target.GetProcess().Kill()
        self.assertTrue(rc.Success())
Пример #4
0
    def test_with_python_api(self):
        """Use Python APIs to create a breakpoint by (filespec, line)."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

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

        filespec = target.GetExecutable()
        self.assertTrue(filespec, VALID_FILESPEC)

        fsDir = os.path.normpath(filespec.GetDirectory())
        fsFile = filespec.GetFilename()

        self.assertTrue(fsDir == os.getcwd() and fsFile == "a.out",
                        "FileSpec matches the executable")

        bpfilespec = lldb.SBFileSpec("main.cpp", False)

        breakpoint = target.BreakpointCreateByLocation(bpfilespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False,
            substrs = ['main.cpp',
                       str(self.line)])

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

        if not process:
            self.fail("SBTarget.Launch() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The filename of frame #0 should be 'main.cpp' and the line number
        # should be 93.
        self.expect("%s:%d" % (lldbutil.get_filenames(thread)[0],
                               lldbutil.get_line_numbers(thread)[0]),
                    "Break correctly at main.cpp:%d" % self.line, exe=False,
            startstr = "main.cpp:")
            ### clang compiled code reported main.cpp:94?
            ### startstr = "main.cpp:93")

        # We should be stopped on the breakpoint with a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        process.Continue()
Пример #5
0
    def step_out_with_python(self):
        self.step_out_thread.StepOut()

        reason = self.step_out_thread.GetStopReason()
        self.assertEqual(lldb.eStopReasonPlanComplete, reason,
            "Expected thread stop reason 'plancomplete', but got '%s'" % lldbutil.stop_reason_to_str(reason))

        # Verify location after stepping out
        frame = self.step_out_thread.GetFrameAtIndex(0)
        desc = lldbutil.get_description(frame.GetLineEntry())
        expect = "main.cpp:%d" % self.step_out_destination
        self.assertTrue(expect in desc, "Expected %s but thread stopped at %s" % (expect, desc))
Пример #6
0
    def step_out_with_python(self):
        self.step_out_thread.StepOut()

        reason = self.step_out_thread.GetStopReason()
        self.assertEqual(lldb.eStopReasonPlanComplete, reason,
            "Expected thread stop reason 'plancomplete', but got '%s'" % lldbutil.stop_reason_to_str(reason))

        # Verify location after stepping out
        frame = self.step_out_thread.GetFrameAtIndex(0)
        desc = lldbutil.get_description(frame.GetLineEntry())
        expect = "main.cpp:%d" % self.step_out_destination
        self.assertTrue(expect in desc, "Expected %s but thread stopped at %s" % (expect, desc))
    def class_types_constructor_name(self):
        """Check whether the constructor name has the class name prepended."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        filespec = target.GetExecutable()
        self.assertTrue(filespec, VALID_FILESPEC)

        fsDir = filespec.GetDirectory()
        fsFile = filespec.GetFilename()

        self.assertTrue(fsDir == os.getcwd() and fsFile == "a.out",
                        "FileSpec matches the executable")

        bpfilespec = lldb.SBFileSpec("main.cpp", False)

        breakpoint = target.BreakpointCreateByLocation(bpfilespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint),
                    BREAKPOINT_CREATED,
                    exe=False,
                    substrs=['main.cpp', str(self.line)])

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

        if not process:
            self.fail("SBTarget.Launch() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        frame = thread.frames[0]
        self.assertTrue(frame.IsValid(), "Got a valid frame.")

        self.assertTrue("C::C" in frame.name,
                        "Constructor name includes class name.")
Пример #8
0
 def switch_to_thread_with_stop_reason(self, stop_reason):
     """
     Run the 'thread list' command, and select the thread with stop reason as
     'stop_reason'.  If no such thread exists, no select action is done.
     """
     from lldbutil import stop_reason_to_str
     self.runCmd('thread list')
     output = self.res.GetOutput()
     thread_line_pattern = re.compile("^[ *] thread #([0-9]+):.*stop reason = %s" %
                                      stop_reason_to_str(stop_reason))
     for line in output.splitlines():
         matched = thread_line_pattern.match(line)
         if matched:
             self.runCmd('thread select %s' % matched.group(1))
Пример #9
0
 def switch_to_thread_with_stop_reason(self, stop_reason):
     """
     Run the 'thread list' command, and select the thread with stop reason as
     'stop_reason'.  If no such thread exists, no select action is done.
     """
     from lldbutil import stop_reason_to_str
     self.runCmd('thread list')
     output = self.res.GetOutput()
     thread_line_pattern = re.compile("^[ *] thread #([0-9]+):.*stop reason = %s" %
                                      stop_reason_to_str(stop_reason))
     for line in output.splitlines():
         matched = thread_line_pattern.match(line)
         if matched:
             self.runCmd('thread select %s' % matched.group(1))
Пример #10
0
    def test_with_constructor_name (self):
        """Test 'frame variable this' and 'expr this' when stopped inside a constructor."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

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

        filespec = target.GetExecutable()
        self.assertTrue(filespec, VALID_FILESPEC)

        fsDir = os.path.normpath(filespec.GetDirectory())
        fsFile = filespec.GetFilename()

        self.assertTrue(fsDir == os.getcwd() and fsFile == "a.out",
                        "FileSpec matches the executable")

        bpfilespec = lldb.SBFileSpec("main.cpp", False)

        breakpoint = target.BreakpointCreateByLocation(bpfilespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False,
            substrs = ['main.cpp',
                       str(self.line)])

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

        if not process:
            self.fail("SBTarget.Launch() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        frame = thread.frames[0]
        self.assertTrue (frame.IsValid(), "Got a valid frame.")

        self.assertTrue ("C::C" in frame.name, "Constructor name includes class name.")
Пример #11
0
    def test_print_ivars_correctly(self):
        self.build()
        # See: <rdar://problem/8717050> lldb needs to use the ObjC runtime symbols for ivar offsets
        # Only fails for the ObjC 2.0 runtime.
        exe = os.path.join(os.getcwd(), "a.out")

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

        break1 = target.BreakpointCreateByLocation(self.main_source, self.line)
        self.assertTrue(break1, VALID_BREAKPOINT)

        # 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.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Make sure we stopped at the first breakpoint.

        cur_frame = thread.GetFrameAtIndex(0)

        line_number = cur_frame.GetLineEntry().GetLine()
        self.assertTrue(line_number == self.line, "Hit the first breakpoint.")

        my_var = cur_frame.FindVariable("my")
        self.assertTrue(my_var, "Made a variable object for my")

        str_var = cur_frame.FindVariable("str")
        self.assertTrue(str_var, "Made a variable object for str")

        # Now make sure that the my->str == str:

        my_str_var = my_var.GetChildMemberWithName("str")
        self.assertTrue(my_str_var, "Found a str ivar in my")

        str_value = int(str_var.GetValue(), 0)

        my_str_value = int(my_str_var.GetValue(), 0)

        self.assertTrue(str_value == my_str_value,
                        "Got the correct value for my->str")
Пример #12
0
    def test_print_ivars_correctly (self):
        self.build()
        # See: <rdar://problem/8717050> lldb needs to use the ObjC runtime symbols for ivar offsets
        # Only fails for the ObjC 2.0 runtime.
        exe = os.path.join(os.getcwd(), "a.out")

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

        break1 = target.BreakpointCreateByLocation(self.main_source, self.line)
        self.assertTrue(break1, VALID_BREAKPOINT)

        # 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.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Make sure we stopped at the first breakpoint.

        cur_frame = thread.GetFrameAtIndex(0)

        line_number = cur_frame.GetLineEntry().GetLine()
        self.assertTrue (line_number == self.line, "Hit the first breakpoint.")

        my_var = cur_frame.FindVariable("my")
        self.assertTrue(my_var, "Made a variable object for my")

        str_var = cur_frame.FindVariable("str")
        self.assertTrue(str_var, "Made a variable object for str")

        # Now make sure that the my->str == str:

        my_str_var = my_var.GetChildMemberWithName("str")
        self.assertTrue(my_str_var, "Found a str ivar in my")

        str_value = int(str_var.GetValue(), 0)

        my_str_value = int(my_str_var.GetValue(), 0)

        self.assertTrue(str_value == my_str_value, "Got the correct value for my->str")
Пример #13
0
    def test_with_process_launch_api(self):
        """Create target, breakpoint, launch a process, and then kill it."""
        self.build(dictionary=self.d)
        self.setTearDownCleanup(dictionary=self.d)
        target = self.dbg.CreateTarget(self.exe)

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line1)

        # The default state after breakpoint creation should be enabled.
        self.assertTrue(breakpoint.IsEnabled(),
                        "Breakpoint should be enabled after creation")

        breakpoint.SetEnabled(False)
        self.assertTrue(not breakpoint.IsEnabled(),
                        "Breakpoint.SetEnabled(False) works")

        breakpoint.SetEnabled(True)
        self.assertTrue(breakpoint.IsEnabled(),
                        "Breakpoint.SetEnabled(True) works")

        # rdar://problem/8364687
        # SBTarget.Launch() issue (or is there some race condition)?

        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())
        # The following isn't needed anymore, rdar://8364687 is fixed.
        #
        # Apply some dances after LaunchProcess() in order to break at "main".
        # It only works sometimes.
        #self.breakAfterLaunch(process, "main")

        process = target.GetProcess()
        self.assertTrue(process, PROCESS_IS_VALID)

        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
Пример #14
0
    def test_with_process_launch_api(self):
        """Create target, breakpoint, launch a process, and then kill it."""
        self.build(dictionary=self.d)
        self.setTearDownCleanup(dictionary=self.d)
        target = self.dbg.CreateTarget(self.exe)

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line1)

        # The default state after breakpoint creation should be enabled.
        self.assertTrue(breakpoint.IsEnabled(),
                        "Breakpoint should be enabled after creation")

        breakpoint.SetEnabled(False)
        self.assertTrue(not breakpoint.IsEnabled(),
                        "Breakpoint.SetEnabled(False) works")

        breakpoint.SetEnabled(True)
        self.assertTrue(breakpoint.IsEnabled(),
                        "Breakpoint.SetEnabled(True) works")

        # rdar://problem/8364687
        # SBTarget.Launch() issue (or is there some race condition)?

        process = target.LaunchSimple (None, None, self.get_process_working_directory())
        # The following isn't needed anymore, rdar://8364687 is fixed.
        #
        # Apply some dances after LaunchProcess() in order to break at "main".
        # It only works sometimes.
        #self.breakAfterLaunch(process, "main")

        process = target.GetProcess()
        self.assertTrue(process, PROCESS_IS_VALID)

        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
Пример #15
0
    def describe_threads(self):
        ret = []
        for x in self.inferior_process:
            id = x.GetIndexID()
            reason = x.GetStopReason()
            status = "stopped" if x.IsStopped() else "running"
            reason_str = lldbutil.stop_reason_to_str(reason)
            if reason == lldb.eStopReasonBreakpoint:
                bpid = x.GetStopReasonDataAtIndex(0)
                bp = self.inferior_target.FindBreakpointByID(bpid)
                reason_str = "%s hit %d times" % (lldbutil.get_description(bp), bp.GetHitCount())
            elif reason == lldb.eStopReasonWatchpoint:
                watchid = x.GetStopReasonDataAtIndex(0)
                watch = self.inferior_target.FindWatchpointByID(watchid)
                reason_str = "%s hit %d times" % (lldbutil.get_description(watch), watch.GetHitCount())
            elif reason == lldb.eStopReasonSignal:
                reason_str = "signal %s" % (signal_names[x.GetStopReasonDataAtIndex(0)])

            location = "\t".join([lldbutil.get_description(x.GetFrameAtIndex(i)) for i in range(x.GetNumFrames())])
            ret.append("thread %d %s due to %s at\n\t%s" % (id, status, reason_str, location))
        return ret
Пример #16
0
    def __update_selected_thread(self):
        debugger = self.debugger
        proc = debugger.GetSelectedTarget().GetProcess()
        if proc.IsValid():
            curr_thread = proc.GetSelectedThread()
            current_thread_stop_reason = curr_thread.GetStopReason()

            other_thread = lldb.SBThread()
            plan_thread = lldb.SBThread()
            if not curr_thread.IsValid() \
                or current_thread_stop_reason == lldb.eStopReasonInvalid \
                or current_thread_stop_reason == lldb.eStopReasonNone:
                for t in proc:
                    t_stop_reason = t.GetStopReason()
                    if t_stop_reason == lldb.eStopReasonInvalid \
                        or t_stop_reason == lldb.eStopReasonNone:
                        pass
                    elif t_stop_reason == lldb.eStopReasonTrace \
                        or t_stop_reason == lldb.eStopReasonBreakpoint \
                        or t_stop_reason == lldb.eStopReasonWatchpoint \
                        or t_stop_reason == lldb.eStopReasonSignal \
                        or t_stop_reason == lldb.eStopReasonException:
                        debug(debugDriver, 'thread stop reason: ' + lldbutil.stop_reason_to_str(current_thread_stop_reason))
                        if not other_thread:
                            other_thread = t
                        elif t_stop_reason == lldb.eStopReasonPlanComplete:
                            if not plan_thread:
                                plan_thread = t

                if plan_thread:
                    proc.SetSelectedThread(plan_thread)
                elif other_thread:
                    proc.SetSelectedThread(other_thread)
                else:
                    if curr_thread:
                        thread = curr_thread
                    else:
                        thread = proc.GetThreadAtIndex(0)

                    proc.SetSelectedThread(thread)
Пример #17
0
    def test_evaluate_expression_python(self):
        """Test SBFrame.EvaluateExpression() API for evaluating an expression."""
        self.buildDefault()

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

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

        # Create the breakpoint.
        filespec = lldb.SBFileSpec("main.cpp", False)
        breakpoint = target.BreakpointCreateByLocation(filespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint),
                    BREAKPOINT_CREATED,
                    exe=False,
                    substrs=['main.cpp', str(self.line)])

        # Launch the process, and do not stop at the entry point.
        # Pass 'X Y Z' as the args, which makes argc == 4.
        process = target.LaunchSimple(['X', 'Y', 'Z'], None,
                                      self.get_process_working_directory())

        if not process:
            self.fail("SBTarget.LaunchProcess() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The filename of frame #0 should be 'main.cpp' and function is main.
        self.expect(lldbutil.get_filenames(thread)[0],
                    "Break correctly at main.cpp",
                    exe=False,
                    startstr="main.cpp")
        self.expect(lldbutil.get_function_names(thread)[0],
                    "Break correctly at main()",
                    exe=False,
                    startstr="main")

        # We should be stopped on the breakpoint with a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        #
        # Use Python API to evaluate expressions while stopped in a stack frame.
        #
        frame = thread.GetFrameAtIndex(0)

        val = frame.EvaluateExpression("2.234")
        self.expect(val.GetValue(),
                    "2.345 evaluated correctly",
                    exe=False,
                    startstr="2.234")
        self.expect(val.GetTypeName(),
                    "2.345 evaluated correctly",
                    exe=False,
                    startstr="double")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("argc")
        self.expect(val.GetValue(),
                    "Argc evaluated correctly",
                    exe=False,
                    startstr="4")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[1]")
        self.expect(val.GetValue(),
                    "Argv[1] evaluated correctly",
                    exe=False,
                    startstr="'X'")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[2]")
        self.expect(val.GetValue(),
                    "Argv[2] evaluated correctly",
                    exe=False,
                    startstr="'Y'")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[3]")
        self.expect(val.GetValue(),
                    "Argv[3] evaluated correctly",
                    exe=False,
                    startstr="'Z'")
        self.DebugSBValue(val)

        callee_break = target.BreakpointCreateByName("a_function_to_call",
                                                     None)
        self.assertTrue(callee_break.GetNumLocations() > 0)

        # Make sure ignoring breakpoints works from the command line:
        self.expect("expression -i true -- a_function_to_call()",
                    substrs=['(int) $', ' 1'])
        self.assertTrue(callee_break.GetHitCount() == 1)

        # Now try ignoring breakpoints using the SB API's:
        options = lldb.SBExpressionOptions()
        options.SetIgnoreBreakpoints(True)
        value = frame.EvaluateExpression('a_function_to_call()', options)
        self.assertTrue(value.IsValid())
        self.assertTrue(value.GetValueAsSigned(0) == 2)
        self.assertTrue(callee_break.GetHitCount() == 2)
Пример #18
0
    def bitfields_variable_python(self):
        """Use Python APIs to inspect a bitfields variable."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        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.
        thread = target.GetProcess().GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        # Lookup the "bits" variable which contains 8 bitfields.
        frame = thread.GetFrameAtIndex(0)
        bits = frame.FindVariable("bits")
        self.DebugSBValue(bits)
        self.assertTrue(bits.GetTypeName() == 'Bits',
                        "bits.GetTypeName() == 'Bits'")
        self.assertTrue(bits.GetNumChildren() == 10,
                        "bits.GetNumChildren() == 10")
        test_compiler = self.getCompiler()
        if "gcc" in test_compiler:
            # Clang ignores the align attribute, so this structure isn't padded out to
            # 32 bytes there as the test author intended.  Suppress this test for clang
            # till somebody has a chance to go rewrite the test source to be this big portably.
            self.assertTrue(bits.GetByteSize() == 32,
                            "bits.GetByteSize() == 32")

        # Notice the pattern of int(b1.GetValue(), 0).  We pass a base of 0
        # so that the proper radix is determined based on the contents of the
        # string.
        b1 = bits.GetChildMemberWithName("b1")
        self.DebugSBValue(b1)
        self.assertTrue(
            b1.GetName() == "b1" and b1.GetTypeName() == "uint32_t:1"
            and b1.IsInScope() and int(b1.GetValue(), 0) == 1,
            'bits.b1 has type uint32_t:1, is in scope, and == 1')

        b7 = bits.GetChildMemberWithName("b7")
        self.DebugSBValue(b7)
        self.assertTrue(
            b7.GetName() == "b7" and b7.GetTypeName() == "uint32_t:7"
            and b7.IsInScope() and int(b7.GetValue(), 0) == 127,
            'bits.b7 has type uint32_t:7, is in scope, and == 127')

        four = bits.GetChildMemberWithName("four")
        self.DebugSBValue(four)
        self.assertTrue(
            four.GetName() == "four" and four.GetTypeName() == "uint32_t:4"
            and four.IsInScope() and int(four.GetValue(), 0) == 15,
            'bits.four has type uint32_t:4, is in scope, and == 15')

        # Now kill the process, and we are done.
        rc = target.GetProcess().Kill()
        self.assertTrue(rc.Success())
Пример #19
0
    def static_variable_python(self):
        """Test Python APIs on file and class static variables."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

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

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Get the SBValue of 'A::g_points' and 'g_points'.
        frame = thread.GetFrameAtIndex(0)

        # arguments =>     False
        # locals =>        False
        # statics =>       True
        # in_scope_only => False
        valList = frame.GetVariables(False, False, True, False)

        for val in valList:
            self.DebugSBValue(val)
            self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal)
            name = val.GetName()
            self.assertTrue(name in ['g_points', 'A::g_points'])
            if name == 'g_points':
                self.assertTrue(val.GetNumChildren() == 2)
            elif name == 'A::g_points' and self.getCompiler() in ['clang', 'llvm-gcc']:
                # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.        
                self.assertTrue(val.GetNumChildren() == 2)
                child1 = val.GetChildAtIndex(1)
                self.DebugSBValue(child1)
                child1_x = child1.GetChildAtIndex(0)
                self.DebugSBValue(child1_x)
                self.assertTrue(child1_x.GetTypeName() == 'int' and
                                child1_x.GetValue() == '11')

        # SBFrame.FindValue() should also work.
        val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'A::g_points')

        # Also exercise the "parameter" and "local" scopes while we are at it.
        val = frame.FindValue("argc", lldb.eValueTypeVariableArgument)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'argc')

        val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'argv')

        val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'hello_world')
Пример #20
0
    def test_evaluate_expression_python(self):
        """Test SBFrame.EvaluateExpression() API for evaluating an expression."""
        self.buildDefault()

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

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

        # Create the breakpoint.
        filespec = lldb.SBFileSpec("main.cpp", False)
        breakpoint = target.BreakpointCreateByLocation(filespec, self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Verify the breakpoint just created.
        self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False,
            substrs = ['main.cpp',
                       str(self.line)])

        # Launch the process, and do not stop at the entry point.
        # Pass 'X Y Z' as the args, which makes argc == 4.
        process = target.LaunchSimple (['X', 'Y', 'Z'], None, self.get_process_working_directory())

        if not process:
            self.fail("SBTarget.LaunchProcess() failed")

        if process.GetState() != lldb.eStateStopped:
            self.fail("Process should be in the 'stopped' state, "
                      "instead the actual state is: '%s'" %
                      lldbutil.state_type_to_str(process.GetState()))

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The filename of frame #0 should be 'main.cpp' and function is main.
        self.expect(lldbutil.get_filenames(thread)[0],
                    "Break correctly at main.cpp", exe=False,
            startstr = "main.cpp")
        self.expect(lldbutil.get_function_names(thread)[0],
                    "Break correctly at main()", exe=False,
            startstr = "main")

        # We should be stopped on the breakpoint with a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        #
        # Use Python API to evaluate expressions while stopped in a stack frame.
        #
        frame = thread.GetFrameAtIndex(0)

        val = frame.EvaluateExpression("2.234")
        self.expect(val.GetValue(), "2.345 evaluated correctly", exe=False,
            startstr = "2.234")
        self.expect(val.GetTypeName(), "2.345 evaluated correctly", exe=False,
            startstr = "double")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("argc")
        self.expect(val.GetValue(), "Argc evaluated correctly", exe=False,
            startstr = "4")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[1]")
        self.expect(val.GetValue(), "Argv[1] evaluated correctly", exe=False,
            startstr = "'X'")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[2]")
        self.expect(val.GetValue(), "Argv[2] evaluated correctly", exe=False,
            startstr = "'Y'")
        self.DebugSBValue(val)

        val = frame.EvaluateExpression("*argv[3]")
        self.expect(val.GetValue(), "Argv[3] evaluated correctly", exe=False,
            startstr = "'Z'")
        self.DebugSBValue(val)

        callee_break = target.BreakpointCreateByName ("a_function_to_call", None)
        self.assertTrue(callee_break.GetNumLocations() > 0)

        # Make sure ignoring breakpoints works from the command line:
        self.expect("expression -i true -- a_function_to_call()",
                    substrs = ['(int) $', ' 1'])
        self.assertTrue (callee_break.GetHitCount() == 1)

        # Now try ignoring breakpoints using the SB API's:
        options = lldb.SBExpressionOptions()
        options.SetIgnoreBreakpoints(True)
        value = frame.EvaluateExpression('a_function_to_call()', options)
        self.assertTrue (value.IsValid())
        self.assertTrue (value.GetValueAsSigned(0) == 2)
        self.assertTrue (callee_break.GetHitCount() == 2)
Пример #21
0
    def array_types_python(self):
        """Use Python APIs to inspect variables with array types."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Sanity check the print representation of breakpoint.
        bp = repr(breakpoint)
        self.expect(bp,
                    msg="Breakpoint looks good",
                    exe=False,
                    substrs=[
                        "file ='main.c'",
                        "line = %d" % self.line, "locations = 1"
                    ])
        self.expect(bp,
                    msg="Breakpoint is not resolved as yet",
                    exe=False,
                    matching=False,
                    substrs=["resolved = 1"])

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

        # Sanity check the print representation of process.
        proc = repr(process)
        self.expect(proc,
                    msg="Process looks good",
                    exe=False,
                    substrs=["state = stopped", "executable = a.out"])

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Sanity check the print representation of thread.
        thr = repr(thread)
        self.expect(thr,
                    "Thread looks good with stop reason = breakpoint",
                    exe=False,
                    substrs=["tid = 0x%4.4x" % thread.GetThreadID()])

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        # The breakpoint should be resolved by now.
        bp = repr(breakpoint)
        self.expect(bp,
                    "Breakpoint looks good and is resolved",
                    exe=False,
                    substrs=[
                        "file ='main.c'",
                        "line = %d" % self.line, "locations = 1"
                    ])

        # Sanity check the print representation of frame.
        frame = thread.GetFrameAtIndex(0)
        frm = repr(frame)
        self.expect(frm,
                    "Frame looks good with correct index %d" %
                    frame.GetFrameID(),
                    exe=False,
                    substrs=["#%d" % frame.GetFrameID()])

        # Lookup the "strings" string array variable and sanity check its print
        # representation.
        variable = frame.FindVariable("strings")
        var = repr(variable)
        self.expect(var,
                    "Variable for 'strings' looks good with correct name",
                    exe=False,
                    substrs=["%s" % variable.GetName()])
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 4,
                        "Variable 'strings' should have 4 children")

        child3 = variable.GetChildAtIndex(3)
        self.DebugSBValue(child3)
        self.assertTrue(child3.GetSummary() == '"Guten Tag"',
                        'strings[3] == "Guten Tag"')

        # Lookup the "char_16" char array variable.
        variable = frame.FindVariable("char_16")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 16,
                        "Variable 'char_16' should have 16 children")

        # Lookup the "ushort_matrix" ushort[] array variable.
        # Notice the pattern of int(child0_2.GetValue(), 0).  We pass a
        # base of 0 so that the proper radix is determined based on the contents
        # of the string.  Same applies to long().
        variable = frame.FindVariable("ushort_matrix")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 2,
                        "Variable 'ushort_matrix' should have 2 children")
        child0 = variable.GetChildAtIndex(0)
        self.DebugSBValue(child0)
        self.assertTrue(child0.GetNumChildren() == 3,
                        "Variable 'ushort_matrix[0]' should have 3 children")
        child0_2 = child0.GetChildAtIndex(2)
        self.DebugSBValue(child0_2)
        self.assertTrue(
            int(child0_2.GetValue(), 0) == 3, "ushort_matrix[0][2] == 3")

        # Lookup the "long_6" char array variable.
        variable = frame.FindVariable("long_6")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 6,
                        "Variable 'long_6' should have 6 children")
        child5 = variable.GetChildAtIndex(5)
        self.DebugSBValue(child5)
        self.assertTrue(long(child5.GetValue(), 0) == 6, "long_6[5] == 6")

        # Last, check that "long_6" has a value type of eValueTypeVariableLocal
        # and "argc" has eValueTypeVariableArgument.
        from lldbutil import value_type_to_str
        self.assertTrue(
            variable.GetValueType() == lldb.eValueTypeVariableLocal,
            "Variable 'long_6' should have '%s' value type." %
            value_type_to_str(lldb.eValueTypeVariableLocal))
        argc = frame.FindVariable("argc")
        self.DebugSBValue(argc)
        self.assertTrue(
            argc.GetValueType() == lldb.eValueTypeVariableArgument,
            "Variable 'argc' should have '%s' value type." %
            value_type_to_str(lldb.eValueTypeVariableArgument))
Пример #22
0
    def static_variable_python(self):
        """Test Python APIs on file and class static variables."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # 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.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Get the SBValue of 'A::g_points' and 'g_points'.
        frame = thread.GetFrameAtIndex(0)

        # arguments =>     False
        # locals =>        False
        # statics =>       True
        # in_scope_only => False
        valList = frame.GetVariables(False, False, True, False)

        for val in valList:
            self.DebugSBValue(val)
            name = val.GetName()
            self.assertTrue(name in ['g_points', 'A::g_points'])
            if name == 'g_points':
                self.assertTrue(
                    val.GetValueType() == lldb.eValueTypeVariableStatic)
                self.assertTrue(val.GetNumChildren() == 2)
            elif name == 'A::g_points' and self.getCompiler() in [
                    'clang', 'llvm-gcc'
            ]:
                # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.
                self.assertTrue(
                    val.GetValueType() == lldb.eValueTypeVariableGlobal)
                self.assertTrue(val.GetNumChildren() == 2)
                child1 = val.GetChildAtIndex(1)
                self.DebugSBValue(child1)
                child1_x = child1.GetChildAtIndex(0)
                self.DebugSBValue(child1_x)
                self.assertTrue(child1_x.GetTypeName() == 'int'
                                and child1_x.GetValue() == '11')

        # SBFrame.FindValue() should also work.
        val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'A::g_points')

        # Also exercise the "parameter" and "local" scopes while we are at it.
        val = frame.FindValue("argc", lldb.eValueTypeVariableArgument)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'argc')

        val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'argv')

        val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
        self.DebugSBValue(val)
        self.assertTrue(val.GetName() == 'hello_world')
Пример #23
0
    def test_and_python_api(self):
        """Use Python APIs to inspect a bitfields variable."""
        self.build()
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        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.
        thread = target.GetProcess().GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        # Lookup the "bits" variable which contains 8 bitfields.
        frame = thread.GetFrameAtIndex(0)
        bits = frame.FindVariable("bits")
        self.DebugSBValue(bits)
        self.assertTrue(bits.GetTypeName() == 'Bits', "bits.GetTypeName() == 'Bits'");
        self.assertTrue(bits.GetNumChildren() == 10, "bits.GetNumChildren() == 10");
        test_compiler = self.getCompiler()
        self.assertTrue(bits.GetByteSize() == 32, "bits.GetByteSize() == 32");

        # Notice the pattern of int(b1.GetValue(), 0).  We pass a base of 0
        # so that the proper radix is determined based on the contents of the
        # string.
        b1 = bits.GetChildMemberWithName("b1")
        self.DebugSBValue(b1)
        self.assertTrue(b1.GetName() == "b1" and
                        b1.GetTypeName() == "uint32_t:1" and
                        b1.IsInScope() and
                        int(b1.GetValue(), 0) == 1,
                        'bits.b1 has type uint32_t:1, is in scope, and == 1')

        b7 = bits.GetChildMemberWithName("b7")
        self.DebugSBValue(b7)
        self.assertTrue(b7.GetName() == "b7" and
                        b7.GetTypeName() == "uint32_t:7" and
                        b7.IsInScope() and
                        int(b7.GetValue(), 0) == 127,
                        'bits.b7 has type uint32_t:7, is in scope, and == 127')

        four = bits.GetChildMemberWithName("four")
        self.DebugSBValue(four)
        self.assertTrue(four.GetName() == "four" and
                        four.GetTypeName() == "uint32_t:4" and
                        four.IsInScope() and
                        int(four.GetValue(), 0) == 15,
                        'bits.four has type uint32_t:4, is in scope, and == 15')

        # Now kill the process, and we are done.
        rc = target.GetProcess().Kill()
        self.assertTrue(rc.Success())
Пример #24
0
    def array_types_python(self):
        """Use Python APIs to inspect variables with array types."""
        exe = os.path.join(os.getcwd(), "a.out")

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

        breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
        self.assertTrue(breakpoint, VALID_BREAKPOINT)

        # Sanity check the print representation of breakpoint.
        bp = str(breakpoint)
        self.expect(bp, msg="Breakpoint looks good", exe=False,
            substrs = ["file = 'main.c'",
                       "line = %d" % self.line,
                       "locations = 1"])
        self.expect(bp, msg="Breakpoint is not resolved as yet", exe=False, matching=False,
            substrs = ["resolved = 1"])

        # 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)

        # Sanity check the print representation of process.
        proc = str(process)
        self.expect(proc, msg="Process looks good", exe=False,
            substrs = ["state = stopped",
                       "executable = a.out"])

        # The stop reason of the thread should be breakpoint.
        thread = process.GetThreadAtIndex(0)
        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
            from lldbutil import stop_reason_to_str
            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
                      stop_reason_to_str(thread.GetStopReason()))

        # Sanity check the print representation of thread.
        thr = str(thread)
        # TODO(zturner): Whether the TID is printed in hex or decimal should be controlled by a setting,
        # and this test should read the value of the setting.  This check is currently hardcoded to
        # match the check in Core/FormatEntity.cpp in the function FormatEntity::Format() for
        # the Entry::Type::ThreadID case of the switch statement.
        if self.getPlatform() == "linux" or self.getPlatform() == "freebsd":
            tidstr = "tid = %u" % thread.GetThreadID()
        else:
            tidstr = "tid = 0x%4.4x" % thread.GetThreadID()
        self.expect(thr, "Thread looks good with stop reason = breakpoint", exe=False,
            substrs = [tidstr])

        # The breakpoint should have a hit count of 1.
        self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)

        # The breakpoint should be resolved by now.
        bp = str(breakpoint)
        self.expect(bp, "Breakpoint looks good and is resolved", exe=False,
            substrs = ["file = 'main.c'",
                       "line = %d" % self.line,
                       "locations = 1"])

        # Sanity check the print representation of frame.
        frame = thread.GetFrameAtIndex(0)
        frm = str(frame)
        self.expect(frm,
                    "Frame looks good with correct index %d" % frame.GetFrameID(),
                    exe=False,
            substrs = ["#%d" % frame.GetFrameID()])

        # Lookup the "strings" string array variable and sanity check its print
        # representation.
        variable = frame.FindVariable("strings")
        var = str(variable)
        self.expect(var, "Variable for 'strings' looks good with correct name", exe=False,
            substrs = ["%s" % variable.GetName()])
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 4,
                        "Variable 'strings' should have 4 children")

        child3 = variable.GetChildAtIndex(3)
        self.DebugSBValue(child3)
        self.assertTrue(child3.GetSummary() == '"Guten Tag"',
                        'strings[3] == "Guten Tag"')

        # Lookup the "char_16" char array variable.
        variable = frame.FindVariable("char_16")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 16,
                        "Variable 'char_16' should have 16 children")

        # Lookup the "ushort_matrix" ushort[] array variable.
        # Notice the pattern of int(child0_2.GetValue(), 0).  We pass a
        # base of 0 so that the proper radix is determined based on the contents
        # of the string.  Same applies to long().
        variable = frame.FindVariable("ushort_matrix")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 2,
                        "Variable 'ushort_matrix' should have 2 children")
        child0 = variable.GetChildAtIndex(0)
        self.DebugSBValue(child0)
        self.assertTrue(child0.GetNumChildren() == 3,
                        "Variable 'ushort_matrix[0]' should have 3 children")
        child0_2 = child0.GetChildAtIndex(2)
        self.DebugSBValue(child0_2)
        self.assertTrue(int(child0_2.GetValue(), 0) == 3,
                        "ushort_matrix[0][2] == 3")

        # Lookup the "long_6" char array variable.
        variable = frame.FindVariable("long_6")
        self.DebugSBValue(variable)
        self.assertTrue(variable.GetNumChildren() == 6,
                        "Variable 'long_6' should have 6 children")
        child5 = variable.GetChildAtIndex(5)
        self.DebugSBValue(child5)
        self.assertTrue(long(child5.GetValue(), 0) == 6,
                        "long_6[5] == 6")

        # Last, check that "long_6" has a value type of eValueTypeVariableLocal
        # and "argc" has eValueTypeVariableArgument.
        from lldbutil import value_type_to_str
        self.assertTrue(variable.GetValueType() == lldb.eValueTypeVariableLocal,
                        "Variable 'long_6' should have '%s' value type." %
                        value_type_to_str(lldb.eValueTypeVariableLocal))
        argc = frame.FindVariable("argc")
        self.DebugSBValue(argc)
        self.assertTrue(argc.GetValueType() == lldb.eValueTypeVariableArgument,
                        "Variable 'argc' should have '%s' value type." %
                        value_type_to_str(lldb.eValueTypeVariableArgument))