xref: /llvm-project/lldb/test/API/commands/frame/select/TestFrameSelect.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest 'frame select' command.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
899451b44SJordan Rupprecht
999451b44SJordan Rupprecht
10*2238dcc3SJonas Devlieghereclass TestFrameSelect(TestBase):
1199451b44SJordan Rupprecht    @no_debug_info_test
1299451b44SJordan Rupprecht    @skipIfWindows
1399451b44SJordan Rupprecht    def test_relative(self):
1499451b44SJordan Rupprecht        self.build()
1599451b44SJordan Rupprecht
16*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
17*2238dcc3SJonas Devlieghere            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
18*2238dcc3SJonas Devlieghere        )
1999451b44SJordan Rupprecht
2099451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["nested2() at"])
2199451b44SJordan Rupprecht        self.expect("frame select -r -1", substrs=["nested3() at"])
2299451b44SJordan Rupprecht
23*2238dcc3SJonas Devlieghere        self.expect(
24*2238dcc3SJonas Devlieghere            "frame select -r -1",
25*2238dcc3SJonas Devlieghere            error=True,
26*2238dcc3SJonas Devlieghere            substrs=["Already at the bottom of the stack."],
27*2238dcc3SJonas Devlieghere        )
28*2238dcc3SJonas Devlieghere        self.expect(
29*2238dcc3SJonas Devlieghere            "frame select -r -2147483647",
30*2238dcc3SJonas Devlieghere            error=True,
31*2238dcc3SJonas Devlieghere            substrs=["Already at the bottom of the stack."],
32*2238dcc3SJonas Devlieghere        )
33*2238dcc3SJonas Devlieghere        self.expect(
34*2238dcc3SJonas Devlieghere            "frame select -r -2147483648",
35*2238dcc3SJonas Devlieghere            error=True,
36*2238dcc3SJonas Devlieghere            substrs=["error: invalid frame offset argument '-2147483648'"],
37*2238dcc3SJonas Devlieghere        )
38*2238dcc3SJonas Devlieghere        self.expect(
39*2238dcc3SJonas Devlieghere            "frame select -r -2147483649",
40*2238dcc3SJonas Devlieghere            error=True,
41*2238dcc3SJonas Devlieghere            substrs=["error: invalid frame offset argument '-2147483649'"],
42*2238dcc3SJonas Devlieghere        )
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["nested2() at"])
4599451b44SJordan Rupprecht        self.expect("frame select -r -2", substrs=["nested3() at"])
4699451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["nested2() at"])
4799451b44SJordan Rupprecht        self.expect("frame select -r -2147483647", substrs=["nested3() at"])
4899451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["nested2() at"])
49*2238dcc3SJonas Devlieghere        self.expect(
50*2238dcc3SJonas Devlieghere            "frame select -r -2147483648",
51*2238dcc3SJonas Devlieghere            error=True,
52*2238dcc3SJonas Devlieghere            substrs=["error: invalid frame offset argument '-2147483648'"],
53*2238dcc3SJonas Devlieghere        )
54*2238dcc3SJonas Devlieghere        self.expect(
55*2238dcc3SJonas Devlieghere            "frame select -r -2147483649",
56*2238dcc3SJonas Devlieghere            error=True,
57*2238dcc3SJonas Devlieghere            substrs=["error: invalid frame offset argument '-2147483649'"],
58*2238dcc3SJonas Devlieghere        )
5999451b44SJordan Rupprecht
6099451b44SJordan Rupprecht        self.expect("frame select -r 100")
61*2238dcc3SJonas Devlieghere        self.expect(
62*2238dcc3SJonas Devlieghere            "frame select -r 1",
63*2238dcc3SJonas Devlieghere            error=True,
64*2238dcc3SJonas Devlieghere            substrs=["Already at the top of the stack."],
65*2238dcc3SJonas Devlieghere        )
6699451b44SJordan Rupprecht
6799451b44SJordan Rupprecht    @no_debug_info_test
6899451b44SJordan Rupprecht    @skipIfWindows
6999451b44SJordan Rupprecht    def test_mixing_relative_and_abs(self):
7099451b44SJordan Rupprecht        self.build()
7199451b44SJordan Rupprecht
72*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
73*2238dcc3SJonas Devlieghere            self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")
74*2238dcc3SJonas Devlieghere        )
7599451b44SJordan Rupprecht
7699451b44SJordan Rupprecht        # The function associated with each frame index can change depending
7799451b44SJordan Rupprecht        # on the function calling main (e.g. `start`), so this only tests that
7899451b44SJordan Rupprecht        # the frame index number is correct. We test the actual functions
7999451b44SJordan Rupprecht        # in the relative test.
8099451b44SJordan Rupprecht
8199451b44SJordan Rupprecht        # Jump to the top of the stack.
8299451b44SJordan Rupprecht        self.expect("frame select 0", substrs=["frame #0"])
8399451b44SJordan Rupprecht
8499451b44SJordan Rupprecht        # Run some relative commands.
8599451b44SJordan Rupprecht        self.expect("up", substrs=["frame #1"])
8699451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["frame #2"])
8799451b44SJordan Rupprecht        self.expect("frame select -r -1", substrs=["frame #1"])
8899451b44SJordan Rupprecht
8999451b44SJordan Rupprecht        # Test that absolute indices still work.
9099451b44SJordan Rupprecht        self.expect("frame select 2", substrs=["frame #2"])
9199451b44SJordan Rupprecht        self.expect("frame select 1", substrs=["frame #1"])
9299451b44SJordan Rupprecht        self.expect("frame select 3", substrs=["frame #3"])
9399451b44SJordan Rupprecht        self.expect("frame select 0", substrs=["frame #0"])
9499451b44SJordan Rupprecht        self.expect("frame select 1", substrs=["frame #1"])
9599451b44SJordan Rupprecht
9699451b44SJordan Rupprecht        # Run some other relative frame select commands.
9799451b44SJordan Rupprecht        self.expect("down", substrs=["frame #0"])
9899451b44SJordan Rupprecht        self.expect("frame select -r 1", substrs=["frame #1"])
9999451b44SJordan Rupprecht        self.expect("frame select -r -1", substrs=["frame #0"])
10099451b44SJordan Rupprecht
10199451b44SJordan Rupprecht        # Test that absolute indices still work.
10299451b44SJordan Rupprecht        self.expect("frame select 2", substrs=["frame #2"])
10399451b44SJordan Rupprecht        self.expect("frame select 1", substrs=["frame #1"])
10499451b44SJordan Rupprecht        self.expect("frame select 3", substrs=["frame #3"])
10599451b44SJordan Rupprecht        self.expect("frame select 0", substrs=["frame #0"])
106