1"""
2Test 'frame select' command.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9class TestFrameSelect(TestBase):
10
11    @no_debug_info_test
12    @skipIfWindows
13    def test_relative(self):
14        self.build()
15
16        lldbutil.run_to_source_breakpoint(self,
17            "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
18
19        self.expect("frame select -r 1", substrs=["nested2() at"])
20        self.expect("frame select -r -1", substrs=["nested3() at"])
21
22        self.expect("frame select -r -1", error=True, substrs=["Already at the bottom of the stack."])
23        self.expect("frame select -r -2147483647", error=True, substrs=["Already at the bottom of the stack."])
24        self.expect("frame select -r -2147483648", error=True, substrs=["error: invalid frame offset argument '-2147483648'"])
25        self.expect("frame select -r -2147483649", error=True, substrs=["error: invalid frame offset argument '-2147483649'"])
26
27        self.expect("frame select -r 1", substrs=["nested2() at"])
28        self.expect("frame select -r -2", substrs=["nested3() at"])
29        self.expect("frame select -r 1", substrs=["nested2() at"])
30        self.expect("frame select -r -2147483647", substrs=["nested3() at"])
31        self.expect("frame select -r 1", substrs=["nested2() at"])
32        self.expect("frame select -r -2147483648", error=True, substrs=["error: invalid frame offset argument '-2147483648'"])
33        self.expect("frame select -r -2147483649", error=True, substrs=["error: invalid frame offset argument '-2147483649'"])
34
35        self.expect("frame select -r 100")
36        self.expect("frame select -r 1", error=True, substrs=["Already at the top of the stack."])
37
38    @no_debug_info_test
39    @skipIfWindows
40    def test_mixing_relative_and_abs(self):
41        self.build()
42
43        lldbutil.run_to_source_breakpoint(self,
44            "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
45
46        # The function associated with each frame index can change depending
47        # on the function calling main (e.g. `start`), so this only tests that
48        # the frame index number is correct. We test the actual functions
49        # in the relative test.
50
51        # Jump to the top of the stack.
52        self.expect("frame select 0", substrs=["frame #0"])
53
54        # Run some relative commands.
55        self.expect("up", substrs=["frame #1"])
56        self.expect("frame select -r 1", substrs=["frame #2"])
57        self.expect("frame select -r -1", substrs=["frame #1"])
58
59        # Test that absolute indices still work.
60        self.expect("frame select 2", substrs=["frame #2"])
61        self.expect("frame select 1", substrs=["frame #1"])
62        self.expect("frame select 3", substrs=["frame #3"])
63        self.expect("frame select 0", substrs=["frame #0"])
64        self.expect("frame select 1", substrs=["frame #1"])
65
66        # Run some other relative frame select commands.
67        self.expect("down", substrs=["frame #0"])
68        self.expect("frame select -r 1", substrs=["frame #1"])
69        self.expect("frame select -r -1", substrs=["frame #0"])
70
71        # Test that absolute indices still work.
72        self.expect("frame select 2", substrs=["frame #2"])
73        self.expect("frame select 1", substrs=["frame #1"])
74        self.expect("frame select 3", substrs=["frame #3"])
75        self.expect("frame select 0", substrs=["frame #0"])
76