1"""
2Test the 'gui' shortcut 'b' (toggle breakpoint).
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test.lldbpexpect import PExpectTest
9
10class TestGuiBasicDebugCommandTest(PExpectTest):
11
12    # PExpect uses many timeouts internally and doesn't play well
13    # under ASAN on a loaded machine..
14    @skipIfAsan
15    @skipIfCursesSupportMissing
16    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
17    def test_gui(self):
18        self.build()
19
20        self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500))
21        self.expect('br set -o true -f main.c -p "// First break here"', substrs=["Breakpoint 1", "address ="])
22        self.expect("run", substrs=["stop reason ="])
23
24        self.child.sendline("breakpoint list")
25        self.child.expect_exact("No breakpoints currently set.")
26
27        escape_key = chr(27).encode()
28        down_key = chr(27)+'OB' # for vt100 terminal (lldbexpect sets TERM=vt100)
29
30        # Start the GUI.
31        self.child.sendline("gui")
32        self.child.expect_exact("Sources") # wait for gui
33
34        # Go to next line, set a breakpoint.
35        self.child.send(down_key)
36        self.child.send('b')
37        self.child.send(escape_key)
38        self.expect_prompt()
39        self.child.sendline("breakpoint list")
40        self.child.expect("2: file = '[^']*main.c', line = 3,.*")
41        self.child.sendline("gui")
42        self.child.expect_exact("Sources")
43
44        # Go two lines down ("gui" resets position), set a breakpoint.
45        self.child.send(down_key)
46        self.child.send(down_key)
47        self.child.send('b')
48        self.child.send(escape_key)
49        self.expect_prompt()
50        self.child.sendline("breakpoint list")
51        self.child.expect("2: file = '[^']*main.c', line = 3,")
52        self.child.expect("3: file = '[^']*main.c', line = 4,")
53        self.child.sendline("gui")
54        self.child.expect_exact("Sources")
55
56        # Toggle both the breakpoints (remove them).
57        self.child.send(down_key)
58        self.child.send('b')
59        self.child.send(down_key)
60        self.child.send('b')
61        self.child.send(escape_key)
62        self.expect_prompt()
63        self.child.sendline("breakpoint list")
64        self.child.expect_exact("No breakpoints currently set.")
65        self.child.sendline("gui")
66        self.child.expect_exact("Sources")
67
68        # Press escape to quit the gui
69        self.child.send(escape_key)
70
71        self.expect_prompt()
72        self.quit()
73