1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5from lldbsuite.test_event.build_exception import BuildError
6
7class TestCase(TestBase):
8
9    mydir = TestBase.compute_mydir(__file__)
10
11    NO_DEBUG_INFO_TESTCASE = True
12
13    def build_and_run(self, test_file):
14        """
15        Tries building the given test source and runs to the first breakpoint.
16        Returns false if the file fails to build due to an unsupported calling
17        convention on the current test target. Returns true if building and
18        running to the breakpoint succeeded.
19        """
20        try:
21            self.build(dictionary={
22                "C_SOURCES" : test_file,
23                "CFLAGS_EXTRAS" : "-Werror"
24            })
25        except BuildError as e:
26             # Test source failed to build. Check if it failed because the
27             # calling convention argument is unsupported/unknown in which case
28             # the test should be skipped.
29             error_msg = str(e)
30             # Clang gives an explicit error when a calling convention is
31             # not supported.
32             if "calling convention is not supported for this target" in error_msg:
33               return False
34             # GCC's has two different generic warnings it can emit.
35             if "attribute ignored" in error_msg:
36               return False
37             if "attribute directive ignored " in error_msg:
38               return False
39             # We got a different build error, so raise it again to fail the
40             # test.
41             raise
42        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec(test_file))
43        return True
44
45    def test_regcall(self):
46        if not self.build_and_run("regcall.c"):
47            return
48        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
49
50    @expectedFailureDarwin(archs=["arm64", "arm64e"]) # rdar://84528755
51    def test_ms_abi(self):
52        if not self.build_and_run("ms_abi.c"):
53            return
54        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
55
56    def test_stdcall(self):
57        if not self.build_and_run("stdcall.c"):
58            return
59        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
60
61    def test_vectorcall(self):
62        if not self.build_and_run("vectorcall.c"):
63            return
64        self.expect_expr("func(1.0)", result_type="int", result_value="1")
65
66    def test_fastcall(self):
67        if not self.build_and_run("fastcall.c"):
68            return
69        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
70
71    def test_pascal(self):
72        if not self.build_and_run("pascal.c"):
73            return
74        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
75
76    def test_sysv_abi(self):
77        if not self.build_and_run("sysv_abi.c"):
78            return
79        self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
80