xref: /llvm-project/lldb/test/API/lang/c/vla/TestVLA.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1import lldb
2from lldbsuite.test.lldbtest import *
3from lldbsuite.test.decorators import *
4import lldbsuite.test.lldbutil as lldbutil
5
6
7class TestVLA(TestBase):
8    @skipIf(compiler="clang", compiler_version=["<", "8.0"])
9    def test_variable_list(self):
10        self.build()
11        _, process, _, _ = lldbutil.run_to_source_breakpoint(
12            self, "break here", lldb.SBFileSpec("main.c")
13        )
14
15        # Make sure no helper expressions show up in frame variable.
16        var_opts = lldb.SBVariablesOptions()
17        var_opts.SetIncludeArguments(False)
18        var_opts.SetIncludeLocals(True)
19        var_opts.SetInScopeOnly(True)
20        var_opts.SetIncludeStatics(False)
21        var_opts.SetIncludeRuntimeSupportValues(False)
22        var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget)
23        all_locals = self.frame().GetVariables(var_opts)
24        for value in all_locals:
25            self.assertNotIn("vla_expr", value.name)
26
27    @decorators.skipIf(compiler="clang", compiler_version=["<", "8.0"])
28    def test_vla(self):
29        self.build()
30        _, process, _, _ = lldbutil.run_to_source_breakpoint(
31            self, "break here", lldb.SBFileSpec("main.c")
32        )
33
34        def test(a):
35            children = []
36            for i in range(a):
37                name = "[%d]" % i
38                value = str(a - i)
39                self.expect_var_path("vla" + name, type="int", value=value)
40                self.expect_expr("vla" + name, result_type="int", result_value=value)
41                children.append(ValueCheck(name=name, value=value))
42            self.expect_var_path("vla", type="int[]", children=children)
43            self.expect("expr vla", error=True, substrs=["incomplete"])
44
45        test(2)
46        process.Continue()
47        test(4)
48