コード例 #1
0
ファイル: TestCxxChar8_t.py プロジェクト: ddcc/llvm-project
    def test_without_process(self):
        """Test that C++ supports char8_t without a running process."""
        self.build()
        lldbutil.run_to_breakpoint_make_target(self)

        self.expect("target variable a", substrs=["char8_t", "0x61 u8'a'"])
        self.expect("target variable ab",
                substrs=["const char8_t *", 'u8"你好"'])
        self.expect("target variable abc", substrs=["char8_t[9]", 'u8"你好"'])

        self.expect_expr("a", result_type="char8_t", result_summary="0x61 u8'a'")
        self.expect_expr("ab", result_type="const char8_t *", result_summary='u8"你好"')

        # FIXME: This should work too.
        self.expect("expr abc", substrs=['u8"你好"'], matching=False)
コード例 #2
0
ファイル: TestEnumTypes.py プロジェクト: tbkka/llvm-project
    def test_api(self):
        """Test that the SBTypeEnumMember API's work correctly for enum_test_days"""
        self.build()
        target = lldbutil.run_to_breakpoint_make_target(self)

        types = target.FindTypes("enum_test_days")
        self.assertEqual(len(types), 1,
                         "Found more than one enum_test_days type...")
        type = types.GetTypeAtIndex(0)

        # First check using the Python list returned by the type:
        self.check_enum_members(type.enum_members)

        # Now use the SBTypeEnumMemberList.
        member_list = type.GetEnumMembers()
        self.check_enum_members(member_list)

        # Now check that the by name accessor works:
        for member in member_list:
            name = member.name
            check_member = member_list[name]
            self.assertTrue(check_member.IsValid(),
                            "Got a valid member for %s." % (name))
            self.assertEqual(name, check_member.name,
                             "Got back the right name")
            self.assertEqual(member.unsigned, check_member.unsigned)
コード例 #3
0
 def test_break_on_overload(self):
     self.build()
     self.target = lldbutil.run_to_breakpoint_make_target(self)
     self.check_breakpoint("a_function(int)")
     self.check_breakpoint("a_function(double)")
     self.check_breakpoint("a_function(int, double)")
     self.check_breakpoint("a_function(double, int)")
コード例 #4
0
    def test(self):
        self.build()
        target = lldbutil.run_to_breakpoint_make_target(self)

        #This should create a breakpoint with 1 location.
        bp1_id = \
            lldbutil.run_break_set_by_file_and_line(self,
                                                    "main.cpp",
                                                    self.break_1,
                                                    num_expected_locations=1)

        bp2_id = \
            lldbutil.run_break_set_by_file_and_line(self,
                                                    "main.cpp",
                                                    self.break_2,
                                                    num_expected_locations=1)

        bp3_id = \
            lldbutil.run_break_set_by_file_and_line(self,
                                                    "main.cpp",
                                                    self.break_3,
                                                    num_expected_locations=1)

        #Run the program.
        self.runCmd("run", RUN_SUCCEEDED)
        #Get the target process
        process = target.GetProcess()

        if self.TraceOn():
            print('First stop:')
            self.printThreadsStoppedByBreakpoint(process)

        thread_to_suspend = \
            lldbutil.get_one_thread_stopped_at_breakpoint_id(process,
                                                                bp1_id)
        self.assertIsNotNone(thread_to_suspend, "Should hit breakpoint 1")
        thread_to_suspend.Suspend()

        #Do not stop at bp2 and autocontinue to bp3
        target.FindBreakpointByID(bp2_id).SetAutoContinue(True)

        #Run to the third breakpoint
        self.runCmd("continue")

        if self.TraceOn():
            print('Second stop:')
            self.printThreadsStoppedByBreakpoint(process)

        stopped_thread = \
            lldbutil.get_one_thread_stopped_at_breakpoint_id(process,
                                                                bp3_id)
        self.assertIsNotNone(stopped_thread, "Should hit breakpoint 3")

        thread_to_suspend.Resume()

        #Run to completion
        self.runCmd("continue")

        #At this point, the inferior process should have exited.
        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
コード例 #5
0
 def do_test(self):
     lib_name = "libDylib.dylib"
     target = lldbutil.run_to_breakpoint_make_target(self, exe_name=lib_name)
     module = target.FindModule(lldb.SBFileSpec(lib_name))
     self.assertTrue(module.IsValid(), "Didn't find the libDylib.dylib module")
     # For now the actual version numbers are wrong for a library of 0.0.0
     # but the previous code would crash iterating over the resultant
     # list.  So we are testing that that doesn't happen.
     did_iterate = False
     for elem in module.GetVersion():
         did_iterate = True
     self.assertTrue(did_iterate, "Didn't get into the GetVersion loop")
コード例 #6
0
 def do_test(self):
     lib_name = "libDylib.dylib"
     target = lldbutil.run_to_breakpoint_make_target(self, exe_name=lib_name)
     module = target.FindModule(lldb.SBFileSpec(lib_name))
     self.assertTrue(module.IsValid(), "Didn't find the libDylib.dylib module")
     # For now the actual version numbers are wrong for a library of 0.0.0
     # but the previous code would crash iterating over the resultant
     # list.  So we are testing that that doesn't happen.
     did_iterate = False
     for elem in module.GetVersion():
         did_iterate = True
     self.assertTrue(did_iterate, "Didn't get into the GetVersion loop")
コード例 #7
0
    def make_target_and_import(self):
        target = lldbutil.run_to_breakpoint_make_target(self)
        interp = self.dbg.GetCommandInterpreter()
        error = lldb.SBError()

        script_name = os.path.join(self.getSourceDir(), "resolver.py")
        source_name = os.path.join(self.getSourceDir(), "main.c")

        command = "command script import " + script_name
        result = lldb.SBCommandReturnObject()
        interp.HandleCommand(command, result)
        self.assertTrue(result.Succeeded(), "com scr imp failed: %s"%(result.GetError()))
        return target
コード例 #8
0
    def test(self):
        self.build()
        target = lldbutil.run_to_breakpoint_make_target(self)
        exe_module = self.find_module(target, 'a.out')

        num_comp_units = exe_module.GetNumCompileUnits()
        self.assertEqual(num_comp_units, 3)

        comp_unit = self.find_comp_unit(exe_module, 'compile_unit1.c')
        cu_type = self.find_type(comp_unit.GetTypes(), 'compile_unit1_type')
        self.assertTrue(exe_module == cu_type.GetModule())

        comp_unit = self.find_comp_unit(exe_module, 'compile_unit2.c')
        cu_type = self.find_type(comp_unit.GetTypes(), 'compile_unit2_type')
        self.assertTrue(exe_module == cu_type.GetModule())
コード例 #9
0
 def make_target(self):
     return lldbutil.run_to_breakpoint_make_target(self)
コード例 #10
0
    def do_test_stop_at_entry(self, synchronous, remote):
        """Test the normal launch path in either sync or async mode"""
        self.build()

        target = lldbutil.run_to_breakpoint_make_target(self)
        launch_info = target.GetLaunchInfo()
        launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
        old_async = self.dbg.GetAsync()

        def cleanup():
            self.dbg.SetAsync(old_async)

        self.addTearDownHook(cleanup)

        if not synchronous:
            self.dbg.SetAsync(True)
            listener = lldb.SBListener("test-process-listener")
            mask = listener.StartListeningForEventClass(
                self.dbg, lldb.SBProcess.GetBroadcasterClassName(),
                lldb.SBProcess.eBroadcastBitStateChanged)
            self.assertEqual(mask, lldb.SBProcess.eBroadcastBitStateChanged,
                             "Got right mask for listener")
            launch_info.SetListener(listener)
        else:
            self.dbg.SetAsync(False)

        if remote:
            self.setup_remote_platform()

        error = lldb.SBError()

        process = target.Launch(launch_info, error)
        self.assertSuccess(error, "Launch failed")
        # If we are asynchronous, we have to wait for the events:
        if not synchronous:
            listener = launch_info.GetListener()
            event = lldb.SBEvent()
            result = listener.WaitForEvent(30, event)
            self.assertTrue(result, "Timed out waiting for event from process")
            state = lldb.SBProcess.GetStateFromEvent(event)
            self.assertState(state, lldb.eStateStopped,
                             "Didn't get a stopped state after launch")

        # Okay, we should be stopped.  Make sure we are indeed at the
        # entry point.  I only know how to do this on darwin:
        self.assertEqual(len(process.threads), 1,
                         "Should only have one thread at entry")
        thread = process.threads[0]
        frame = thread.GetFrameAtIndex(0)
        stop_func = frame.name
        self.assertEqual(stop_func, "_dyld_start")

        # Now make sure that we can resume the process and have it exit.
        error = process.Continue()
        self.assertSuccess(error, "Error continuing")
        # Fetch events till we get eStateExited:
        if not synchronous:
            # Get events till exited.
            listener = launch_info.GetListener()
            event = lldb.SBEvent()
            # We get two running events in a row here???  That's a bug
            # but not the one I'm testing for, so for now just fetch as
            # many as were sent.
            num_running = 0
            state = lldb.eStateRunning
            while state == lldb.eStateRunning:
                num_running += 1
                result = listener.WaitForEvent(30, event)
                self.assertTrue(result, "Timed out waiting for running")
                state = lldb.SBProcess.GetStateFromEvent(event)
                if num_running == 1:
                    self.assertState(state, lldb.eStateRunning,
                                     "Got running event")
            # The last event we should get is the exited event
            self.assertState(state, lldb.eStateExited, "Got exit event")
        else:
            # Make sure that the process has indeed exited
            state = process.GetState()
            self.assertState(state, lldb.eStateExited)