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    # PExpect uses many timeouts internally and doesn't play well
13    # under ASAN on a loaded machine..
14    @skipIfAsan
15    @skipIf(bugnumber="llvm.org/pr51833")
16    @skipIfCursesSupportMissing
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 -f main.c -p "// Break here"', substrs=["Breakpoint 1", "address ="])
22        self.expect("run", substrs=["stop reason ="])
23
24        escape_key = chr(27).encode()
25
26        # Start the GUI.
27        self.child.sendline("gui")
28
29        # Simulate a simple debugging session.
30        self.child.send("s") # step
31        self.child.expect("return 1; // In function[^\r\n]+<<< Thread 1: step in")
32        self.child.send("u") # up
33        self.child.expect_exact("func();    // Break here")
34        self.child.send("d") # down
35        self.child.expect_exact("return 1; // In function")
36        self.child.send("f") # finish
37        self.child.expect("<<< Thread 1: step out")
38        self.child.send("s") # move onto the second one
39        self.child.expect("<<< Thread 1: step in")
40        self.child.send("n") # step over
41        self.child.expect("// Dummy command 1[^\r\n]+<<< Thread 1: step over")
42        self.child.send("n")
43
44        # Test that 'up' + 'step out' steps out of the selected function.
45        self.child.send("s") # move into func_up()
46        self.child.expect("// In func_up")
47        self.child.send("s") # move into func_down()
48        self.child.expect("// In func_down")
49        self.child.send("u") # up
50        self.child.expect("// In func_up")
51        self.child.send("f") # finish
52        self.child.expect("// Dummy command 2[^\r\n]+<<< Thread 1: step out")
53        self.child.send("n")
54
55        # Press escape to quit the gui
56        self.child.send(escape_key)
57
58        self.expect_prompt()
59        self.quit()
60