aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/pointer-nonaddressable-bits/TestArmPointerMetadataStripping.py
blob: 059fd9cf4ba7f765a7c1fbe17136890fe082a7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
        )