brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · b3bed43 Raw
115 lines · python
1import lldb2from lldbsuite.test.decorators import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5 6 7class ExprDefinitionInDylibTestCase(TestBase):8 9    @skipIf(10        compiler="clang",11        compiler_version=["<", "22"],12        bugnumber="Required Clang flag not supported",13    )14    @skipIfWindows15    def test_with_structor_linkage_names(self):16        """17        Tests that we can call functions whose definition18        is in a different LLDB module than it's declaration.19        """20        self.build(dictionary={"CXXFLAGS_EXTRAS": "-gstructor-decl-linkage-names"})21 22        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))23        self.assertTrue(target, VALID_TARGET)24 25        env = self.registerSharedLibrariesWithTarget(target, ["lib"])26 27        breakpoint = lldbutil.run_break_set_by_file_and_line(28            self, "main.cpp", line_number("main.cpp", "return")29        )30 31        process = target.LaunchSimple(None, env, self.get_process_working_directory())32 33        self.assertIsNotNone(34            lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), breakpoint)35        )36 37        self.expect_expr("f.method()", result_value="-72", result_type="int")38 39        self.expect_expr("Foo(10)", result_type="Foo")40 41        self.expect_expr("Base()", result_type="Base")42 43        self.expect_expr("Bar()", result_type="Bar")44 45        # Test a more complex setup: expression that has a three bases:46        # 1. definition is in local module47        # 2. definition is in different module48        # 3. definition is in expression context (and has it's own virtual base)49        self.expect_expr(50            "struct ExprBase : virtual Foo { int z; ExprBase() : Foo(11) { z = x; } }; struct Expr : virtual Local, virtual Foo, virtual ExprBase { int w; Expr() : Local(), Foo(12), ExprBase() { w = y; } }; Expr tmp; tmp",51            result_type="Expr",52            result_children=[53                ValueCheck(54                    name="Local",55                    children=[56                        ValueCheck(57                            name="Foo", children=[ValueCheck(name="x", value="12")]58                        ),59                        ValueCheck(name="y", value="12"),60                    ],61                ),62                ValueCheck(name="Foo", children=[ValueCheck(name="x", value="12")]),63                ValueCheck(64                    name="ExprBase",65                    children=[66                        ValueCheck(67                            name="Foo", children=[ValueCheck(name="x", value="12")]68                        ),69                        ValueCheck(name="z", value="12"),70                    ],71                ),72                ValueCheck(name="w", value="12"),73            ],74        )75 76    @skipIfWindows77    def test_no_structor_linkage_names(self):78        """79        Tests that if structor declarations don't have linkage names, we can't80        call ABI-tagged constructors. But non-tagged ones are fine.81        """82        # In older versions of Clang the -gno-structor-decl-linkage-names83        # behaviour was the default.84        if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(85            [">=", "22.0"]86        ):87            self.build(88                dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"}89            )90        else:91            self.build()92 93        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))94        self.assertTrue(target, VALID_TARGET)95 96        env = self.registerSharedLibrariesWithTarget(target, ["lib"])97 98        breakpoint = lldbutil.run_break_set_by_file_and_line(99            self, "main.cpp", line_number("main.cpp", "return")100        )101 102        process = target.LaunchSimple(None, env, self.get_process_working_directory())103 104        self.assertIsNotNone(105            lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), breakpoint)106        )107 108        self.expect_expr("f.method()", result_value="-72", result_type="int")109 110        self.expect_expr("Foo(10)", result_type="Foo")111 112        self.expect("expr Base()", error=True)113 114        self.expect("expr Bar()", error=True)115