brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 059fd9c Raw
52 lines · python
1import lldb2import json3import os4from lldbsuite.test.decorators import *5from lldbsuite.test.lldbtest import *6from lldbsuite.test import lldbutil7 8 9# On AArch64 systems, unused top bits of pointers can be used for other things.10@skipIf(archs=no_match(["aarch64", "arm64", "arm64e"]))11# Only run this test on systems where Top Byte Ignore is known to be enabled12# and widely available (FreeBSD has support but only since recently).13@skipUnlessPlatform(["linux"] + lldbplatformutil.getDarwinOSTriples())14class TestArmPointerMetadataStripping(TestBase):15    # Use extra_symbols.json as a template to add a new symbol whose address16    # contains non-zero high order bits set.17    def create_symbols_file(self):18        template_path = os.path.join(self.getSourceDir(), "extra_symbols.json")19        with open(template_path, "r") as f:20            symbols_data = json.load(f)21 22        target = self.dbg.GetSelectedTarget()23        symbols_data["triple"] = target.GetTriple()24 25        module = target.GetModuleAtIndex(0)26        symbols_data["uuid"] = module.GetUUIDString()27 28        json_filename = self.getBuildArtifact("extra_symbols.json")29        with open(json_filename, "w") as file:30            json.dump(symbols_data, file, indent=4)31 32        return json_filename33 34    def test(self):35        self.build()36        src = lldb.SBFileSpec("main.c")37        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(38            self, "break here", src39        )40 41        symbols_file = self.create_symbols_file()42        self.runCmd(f"target module add {symbols_file}")43 44        # The high order bits should be stripped.45        self.expect_expr("get_high_bits(&myglobal_json)", result_value="0")46 47        # Mark all bits as used for addresses and ensure bits are no longer stripped.48        self.runCmd("settings set target.process.virtual-addressable-bits 64")49        self.expect_expr(50            "get_high_bits(&myglobal_json)", result_value=str(0x1200000000000000)51        )52