xref: /llvm-project/lldb/test/API/functionalities/thread/ignore_suspended/TestIgnoreSuspendedThread.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
13b43f006SIlya Bukonkin"""
23b43f006SIlya BukonkinTest that suspended threads do not affect should-stop decisions.
33b43f006SIlya Bukonkin"""
43b43f006SIlya Bukonkin
53b43f006SIlya Bukonkinimport lldb
63b43f006SIlya Bukonkinfrom lldbsuite.test.decorators import *
73b43f006SIlya Bukonkinfrom lldbsuite.test.lldbtest import *
83b43f006SIlya Bukonkinimport lldbsuite.test.lldbutil as lldbutil
93b43f006SIlya Bukonkin
103b43f006SIlya Bukonkin
113b43f006SIlya Bukonkinclass IgnoreSuspendedThreadTestCase(TestBase):
123b43f006SIlya Bukonkin    NO_DEBUG_INFO_TESTCASE = True
133b43f006SIlya Bukonkin
143b43f006SIlya Bukonkin    def setUp(self):
153b43f006SIlya Bukonkin        # Call super's setUp().
163b43f006SIlya Bukonkin        TestBase.setUp(self)
173b43f006SIlya Bukonkin        # Find the line numbers for our breakpoints.
18*2238dcc3SJonas Devlieghere        self.break_1 = line_number("main.cpp", "// Set first breakpoint here")
19*2238dcc3SJonas Devlieghere        self.break_2 = line_number("main.cpp", "// Set second breakpoint here")
20*2238dcc3SJonas Devlieghere        self.break_3 = line_number("main.cpp", "// Set third breakpoint here")
213b43f006SIlya Bukonkin
223b43f006SIlya Bukonkin    def printThreadsStoppedByBreakpoint(self, process):
23*2238dcc3SJonas Devlieghere        stopped_threads = lldbutil.get_stopped_threads(
24*2238dcc3SJonas Devlieghere            process, lldb.eStopReasonBreakpoint
25*2238dcc3SJonas Devlieghere        )
263b43f006SIlya Bukonkin        for thread in stopped_threads:
273b43f006SIlya Bukonkin            break_id = thread.GetStopReasonDataAtIndex(0)
28*2238dcc3SJonas Devlieghere            print(
29*2238dcc3SJonas Devlieghere                "Thread "
30*2238dcc3SJonas Devlieghere                + str(thread.GetThreadID())
31*2238dcc3SJonas Devlieghere                + " stopped at breakpoint "
32*2238dcc3SJonas Devlieghere                + str(break_id)
33*2238dcc3SJonas Devlieghere            )
343b43f006SIlya Bukonkin
353b43f006SIlya Bukonkin    def test(self):
363b43f006SIlya Bukonkin        self.build()
373b43f006SIlya Bukonkin        target = lldbutil.run_to_breakpoint_make_target(self)
383b43f006SIlya Bukonkin
393b43f006SIlya Bukonkin        # This should create a breakpoint with 1 location.
40*2238dcc3SJonas Devlieghere        bp1_id = lldbutil.run_break_set_by_file_and_line(
41*2238dcc3SJonas Devlieghere            self, "main.cpp", self.break_1, num_expected_locations=1
42*2238dcc3SJonas Devlieghere        )
433b43f006SIlya Bukonkin
44*2238dcc3SJonas Devlieghere        bp2_id = lldbutil.run_break_set_by_file_and_line(
45*2238dcc3SJonas Devlieghere            self, "main.cpp", self.break_2, num_expected_locations=1
46*2238dcc3SJonas Devlieghere        )
473b43f006SIlya Bukonkin
48*2238dcc3SJonas Devlieghere        bp3_id = lldbutil.run_break_set_by_file_and_line(
49*2238dcc3SJonas Devlieghere            self, "main.cpp", self.break_3, num_expected_locations=1
50*2238dcc3SJonas Devlieghere        )
513b43f006SIlya Bukonkin
523b43f006SIlya Bukonkin        # Run the program.
533b43f006SIlya Bukonkin        self.runCmd("run", RUN_SUCCEEDED)
543b43f006SIlya Bukonkin        # Get the target process
553b43f006SIlya Bukonkin        process = target.GetProcess()
563b43f006SIlya Bukonkin
573b43f006SIlya Bukonkin        if self.TraceOn():
58*2238dcc3SJonas Devlieghere            print("First stop:")
593b43f006SIlya Bukonkin            self.printThreadsStoppedByBreakpoint(process)
603b43f006SIlya Bukonkin
61*2238dcc3SJonas Devlieghere        thread_to_suspend = lldbutil.get_one_thread_stopped_at_breakpoint_id(
62*2238dcc3SJonas Devlieghere            process, bp1_id
63*2238dcc3SJonas Devlieghere        )
643b43f006SIlya Bukonkin        self.assertIsNotNone(thread_to_suspend, "Should hit breakpoint 1")
653b43f006SIlya Bukonkin        thread_to_suspend.Suspend()
663b43f006SIlya Bukonkin
673b43f006SIlya Bukonkin        # Do not stop at bp2 and autocontinue to bp3
683b43f006SIlya Bukonkin        target.FindBreakpointByID(bp2_id).SetAutoContinue(True)
693b43f006SIlya Bukonkin
703b43f006SIlya Bukonkin        # Run to the third breakpoint
713b43f006SIlya Bukonkin        self.runCmd("continue")
723b43f006SIlya Bukonkin
733b43f006SIlya Bukonkin        if self.TraceOn():
74*2238dcc3SJonas Devlieghere            print("Second stop:")
753b43f006SIlya Bukonkin            self.printThreadsStoppedByBreakpoint(process)
763b43f006SIlya Bukonkin
77*2238dcc3SJonas Devlieghere        stopped_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
78*2238dcc3SJonas Devlieghere            process, bp3_id
79*2238dcc3SJonas Devlieghere        )
80*2238dcc3SJonas Devlieghere        self.assertIsNotNone(stopped_thread, "Should hit breakpoint 3")
813b43f006SIlya Bukonkin
823b43f006SIlya Bukonkin        thread_to_suspend.Resume()
833b43f006SIlya Bukonkin
843b43f006SIlya Bukonkin        # Run to completion
853b43f006SIlya Bukonkin        self.runCmd("continue")
863b43f006SIlya Bukonkin
873b43f006SIlya Bukonkin        # At this point, the inferior process should have exited.
88*2238dcc3SJonas Devlieghere        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
89