1"""
2Test the 'gui' shortcuts 's','n','f','u','d' (step in, step over, step out, up, down)
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    mydir = TestBase.compute_mydir(__file__)
13
14    # PExpect uses many timeouts internally and doesn't play well
15    # under ASAN on a loaded machine..
16    @skipIfAsan
17    @skipIfCursesSupportMissing
18    @expectedFailureAll(archs=["aarch64"], oslist=["linux"])
19    def test_gui(self):
20        self.build()
21
22        self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500))
23        self.expect('br set -f main.c -p "// Break here"', substrs=["Breakpoint 1", "address ="])
24        self.expect("run", substrs=["stop reason ="])
25
26        escape_key = chr(27).encode()
27
28        # Start the GUI and close the welcome window.
29        self.child.sendline("gui")
30        self.child.send(escape_key)
31
32        # Simulate a simple debugging session.
33        self.child.send("s") # step
34        self.child.expect("return 1; // In function[^\r\n]+<<< Thread 1: step in")
35        self.child.send("u") # up
36        self.child.expect_exact("func(); // Break here")
37        self.child.send("d") # down
38        self.child.expect_exact("return 1; // In function")
39        self.child.send("f") # finish
40        self.child.expect("func\(\); // Break here[^\r\n]+<<< Thread 1: step out")
41        self.child.send("s") # move onto the second one
42        self.child.expect("func\(\); // Second[^\r\n]+<<< Thread 1: step in")
43        self.child.send("n") # step over
44        self.child.expect("return 0;[^\r\n]+<<< Thread 1: step over")
45
46        # Press escape to quit the gui
47        self.child.send(escape_key)
48
49        self.expect_prompt()
50        self.quit()
51