72 lines · python
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 lldbutil8 9 10class TestAArch64AdrpAdd(TestBase):11 @no_debug_info_test12 @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_test29 @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 = False48 found_foo = False49 50 # The binary has an ADRP + ADD instruction pair which load51 # the pc-relative address of a c-string, and loads the address52 # of a function into a function pointer. lldb should show53 # that c-string and the name of that function in the disassembly54 # comment field.55 for i in insns:56 if "HI" in i.GetComment(target):57 found_hi_string = True58 if "foo" in i.GetComment(target):59 found_foo = True60 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 % binaryname64 )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