1"""
2Test the session history command
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class SessionHistoryTestCase(TestBase):
14
15    @no_debug_info_test
16    def test_history(self):
17        self.runCmd('session history --clear', inHistory=False)
18        self.runCmd('breakpoint list', check=False, inHistory=True)  # 0
19        self.runCmd('register read', check=False, inHistory=True)  # 1
20        self.runCmd('apropos hello', check=False, inHistory=True)  # 2
21        self.runCmd('memory write', check=False, inHistory=True)  # 3
22        self.runCmd('log list', check=False, inHistory=True)  # 4
23        self.runCmd('disassemble', check=False, inHistory=True)  # 5
24        self.runCmd('expression 1', check=False, inHistory=True)  # 6
25        self.runCmd(
26            'type summary list -w default',
27            check=False,
28            inHistory=True)  # 7
29        self.runCmd('version', check=False, inHistory=True)  # 8
30        self.runCmd('frame select 1', check=False, inHistory=True)  # 9
31
32        self.expect(
33            "session history -s 3 -c 3",
34            inHistory=True,
35            substrs=[
36                '3: memory write',
37                '4: log list',
38                '5: disassemble'])
39
40        self.expect("session history -s 3 -e 3", inHistory=True,
41                    substrs=['3: memory write'])
42
43        self.expect(
44            "session history -s 6 -e 7",
45            inHistory=True,
46            substrs=[
47                '6: expression 1',
48                '7: type summary list -w default'])
49
50        self.expect("session history -c 2", inHistory=True,
51                    substrs=['0: breakpoint list', '1: register read'])
52
53        self.expect("session history -e 3 -c 1", inHistory=True,
54                    substrs=['3: memory write'])
55
56        self.expect(
57            "session history -e 2",
58            inHistory=True,
59            substrs=[
60                '0: breakpoint list',
61                '1: register read',
62                '2: apropos hello'])
63
64        self.expect(
65            "session history -s 12",
66            inHistory=True,
67            substrs=[
68                '12: session history -s 6 -e 7',
69                '13: session history -c 2',
70                '14: session history -e 3 -c 1',
71                '15: session history -e 2',
72                '16: session history -s 12'])
73
74        self.expect(
75            "session history -s end -c 3",
76            inHistory=True,
77            substrs=[
78                '15: session history -e 2',
79                '16: session history -s 12',
80                '17: session history -s end -c 3'])
81
82        self.expect(
83            "session history -s end -e 15",
84            inHistory=True,
85            substrs=[
86                '15: session history -e 2',
87                '16: session history -s 12',
88                '17: session history -s end -c 3',
89                'session history -s end -e 15'])
90
91        self.expect("session history -s 5 -c 1", inHistory=True,
92                    substrs=['5: disassemble'])
93
94        self.expect("session history -c 1 -s 5", inHistory=True,
95                    substrs=['5: disassemble'])
96
97        self.expect("session history -c 1 -e 3", inHistory=True,
98                    substrs=['3: memory write'])
99
100        self.expect(
101            "session history -c 1 -e 3 -s 5",
102            error=True,
103            inHistory=True,
104            substrs=['error: --count, --start-index and --end-index cannot be all specified in the same invocation'])
105