xref: /llvm-project/lldb/test/API/functionalities/disassemble/aarch64-adrp-add/TestAArch64AdrpAdd.py (revision fd35a92300a00edaf56ae94176317390677569a4)
1"""
2Test that the arm64 ADRP + ADD pc-relative addressing pair is symbolicated.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class TestAArch64AdrpAdd(TestBase):
11    @no_debug_info_test
12    @skipIfLLVMTargetMissing("AArch64")
13    def test_arm64(self):
14        src_dir = self.getSourceDir()
15        yaml_path = os.path.join(src_dir, "a.out-arm64.yaml")
16        obj_path = self.getBuildArtifact("a.out-arm64")
17        self.yaml2obj(yaml_path, obj_path)
18
19        target = self.dbg.CreateTarget(obj_path)
20        self.assertTrue(target, VALID_TARGET)
21
22        mains = target.FindFunctions("main")
23        for f in mains.symbols:
24            binaryname = f.GetStartAddress().GetModule().GetFileSpec().GetFilename()
25            if binaryname == "a.out-arm64":
26                self.disassemble_check_for_hi_and_foo(target, f, binaryname)
27
28    @no_debug_info_test
29    @skipIfLLVMTargetMissing("AArch64")
30    def test_arm64_32(self):
31        src_dir = self.getSourceDir()
32        yaml_path = os.path.join(src_dir, "a.out-arm64_32.yaml")
33        obj_path = self.getBuildArtifact("a.out-arm64_32")
34        self.yaml2obj(yaml_path, obj_path)
35
36        target = self.dbg.CreateTarget(obj_path)
37        self.assertTrue(target, VALID_TARGET)
38
39        mains = target.FindFunctions("main")
40        for f in mains.symbols:
41            binaryname = f.GetStartAddress().GetModule().GetFileSpec().GetFilename()
42            if binaryname == "a.out-arm64_32":
43                self.disassemble_check_for_hi_and_foo(target, f, binaryname)
44
45    def disassemble_check_for_hi_and_foo(self, target, func, binaryname):
46        insns = func.GetInstructions(target)
47        found_hi_string = False
48        found_foo = False
49
50        # The binary has an ADRP + ADD instruction pair which load
51        # the pc-relative address of a c-string, and loads the address
52        # of a function into a function pointer.  lldb should show
53        # that c-string and the name of that function in the disassembly
54        # comment field.
55        for i in insns:
56            if "HI" in i.GetComment(target):
57                found_hi_string = True
58            if "foo" in i.GetComment(target):
59                found_foo = True
60        if not found_hi_string or not found_foo:
61            print(
62                'Did not find "HI" string or "foo" in disassembly symbolication in %s'
63                % binaryname
64            )
65            if self.TraceOn():
66                strm = lldb.SBStream()
67                insns.GetDescription(strm)
68                print('Disassembly of main(), looking for "HI" and "foo" in comments:')
69                print(strm.GetData())
70        self.assertTrue(found_hi_string)
71        self.assertTrue(found_foo)
72