Files
llvm-project/lldb/test/API/pointer-nonaddressable-bits/TestArmPointerMetadataStripping.py
David Spickett b21dd44dbc [lldb][test] Enable non-address bit WritePointerToMemory test on Linux (#157435)
First added in #153585 for Darwin only. All Linux AArch64 systems also
have Top Byte Ignore enabled in userspace so the test "just works"
there.

FreeBSD has very recently gained Top Byte Ignore support:
4c6c27d3fb

However it's so recent, I don't want to assume it'll be available on any
random FreeBSD system out there.

There isn't really a good place to put this test, so I put it in the top
level of API, next to the other non-address bit test that didn't have a
good home either.
2025-09-19 16:00:33 +01:00

52 lines
1.9 KiB
Python

import lldb
import json
import os
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
# On AArch64 systems, unused top bits of pointers can be used for other things.
@skipIf(archs=no_match(["aarch64", "arm64", "arm64e"]))
# Only run this test on systems where Top Byte Ignore is known to be enabled
# and widely available (FreeBSD has support but only since recently).
@skipUnlessPlatform(["linux"] + lldbplatformutil.getDarwinOSTriples())
class TestArmPointerMetadataStripping(TestBase):
# Use extra_symbols.json as a template to add a new symbol whose address
# contains non-zero high order bits set.
def create_symbols_file(self):
template_path = os.path.join(self.getSourceDir(), "extra_symbols.json")
with open(template_path, "r") as f:
symbols_data = json.load(f)
target = self.dbg.GetSelectedTarget()
symbols_data["triple"] = target.GetTriple()
module = target.GetModuleAtIndex(0)
symbols_data["uuid"] = module.GetUUIDString()
json_filename = self.getBuildArtifact("extra_symbols.json")
with open(json_filename, "w") as file:
json.dump(symbols_data, file, indent=4)
return json_filename
def test(self):
self.build()
src = lldb.SBFileSpec("main.c")
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "break here", src
)
symbols_file = self.create_symbols_file()
self.runCmd(f"target module add {symbols_file}")
# The high order bits should be stripped.
self.expect_expr("get_high_bits(&myglobal_json)", result_value="0")
# Mark all bits as used for addresses and ensure bits are no longer stripped.
self.runCmd("settings set target.process.virtual-addressable-bits 64")
self.expect_expr(
"get_high_bits(&myglobal_json)", result_value=str(0x1200000000000000)
)