brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · d08099f Raw
68 lines · python
1"""2Test that addresses of functions compiled for Arm Thumb include the Thumb mode3bit (bit 0 of the address) when resolved and used in expressions.4"""5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class TestThumbFunctionAddr(TestBase):13    def do_thumb_function_test(self, language):14        self.build(dictionary={"CFLAGS_EXTRAS": f"-x {language} -mthumb"})15 16        exe = self.getBuildArtifact("a.out")17        line = line_number("main.c", "// Set break point at this line.")18        self.runCmd("target create %s" % exe)19        bpid = lldbutil.run_break_set_by_file_and_line(self, "main.c", line)20 21        self.runCmd("run")22        self.assertIsNotNone(23            lldbutil.get_one_thread_stopped_at_breakpoint_id(self.process(), bpid),24            "Process is not stopped at breakpoint",25        )26 27        # The compiler set this, so the mode bit will be included here.28        a_function_addr_var = (29            self.thread().GetFrameAtIndex(0).FindVariable("a_function_addr")30        )31        self.assertTrue(a_function_addr_var.IsValid())32        a_function_addr = a_function_addr_var.GetValueAsUnsigned()33        self.assertTrue(a_function_addr & 1)34 35        self.expect("p/x a_function_addr", substrs=[f"0x{a_function_addr:08x}"])36        # If lldb did not pay attention to the mode bit this would SIGILL trying37        # to execute Thumb encodings in Arm mode.38        self.expect("expression -- a_function()", substrs=["= 123"])39 40        # We cannot call GetCallableLoadAdress via. the API, so we expect this41        # to not have the bit set as it's treating it as a non-function symbol.42        found_function = self.target().FindFunctions("a_function")[0]43        self.assertTrue(found_function.IsValid())44        found_function = found_function.GetFunction()45        self.assertTrue(found_function.IsValid())46        found_function_addr = found_function.GetStartAddress()47        a_function_load_addr = found_function_addr.GetLoadAddress(self.target())48        self.assertEqual(a_function_load_addr, a_function_addr & ~1)49 50        # image lookup should not include the mode bit.51        a_function_file_addr = found_function_addr.GetFileAddress()52        self.expect(53            "image lookup -n a_function", substrs=[f"0x{a_function_file_addr:08x}"]54        )55 56    # This test is run for C and C++ because the two will take different paths57    # trying to resolve the function's address.58 59    @skipIf(archs=no_match(["arm$"]))60    @skipIf(archs=["arm64"])61    def test_function_addr_c(self):62        self.do_thumb_function_test("c")63 64    @skipIf(archs=no_match(["arm$"]))65    @skipIf(archs=["arm64"])66    def test_function_addr_cpp(self):67        self.do_thumb_function_test("c++")68