xref: /llvm-project/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py (revision 6bf923d5c3daf5d66e0acf53d037a12ceff4a275)
1"""
2Test that 'gui' does not crash when adding new threads, which
3populate TreeItem's children and may be reallocated elsewhere.
4"""
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test.lldbpexpect import PExpectTest
10
11import sys
12
13
14class TestGuiSpawnThreadsTest(PExpectTest):
15    # PExpect uses many timeouts internally and doesn't play well
16    # under ASAN on a loaded machine..
17    @skipIfAsan
18    @skipIfCursesSupportMissing
19    def test_gui(self):
20        self.build()
21
22        self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100, 500))
23        self.expect(
24            'breakpoint set -f main.cpp -p "break here"',
25            substrs=["Breakpoint 1", "address ="],
26        )
27        self.expect(
28            'breakpoint set -f main.cpp -p "before join"',
29            substrs=["Breakpoint 2", "address ="],
30        )
31        self.expect("run", substrs=["stop reason ="])
32
33        escape_key = chr(27).encode()
34
35        # Start the GUI
36        self.child.sendline("gui")
37        self.child.expect_exact("Threads")
38        self.child.expect_exact(f"thread #1: tid =")
39
40        for i in range(5):
41            # Stopped at the breakpoint, continue over the thread creation
42            self.child.send("c")
43            # Check the newly created thread
44            self.child.expect_exact(f"thread #{i + 2}: tid =")
45
46        # Exit GUI.
47        self.child.send(escape_key)
48        self.expect_prompt()
49
50        self.quit()
51