1"""Test that lldb has a default mask for addressable bits on Darwin arm64 ABI"""
2
3
4import os
5import re
6import subprocess
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class TestCorefileDefaultPtrauth(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM")
19    @skipIf(archs=no_match(['arm64','arm64e']))
20    @skipUnlessDarwin
21    @skipIfRemote
22    def test_lc_note(self):
23        self.build()
24        self.test_exe = self.getBuildArtifact("a.out")
25        self.create_corefile = self.getBuildArtifact("create-corefile")
26        self.corefile = self.getBuildArtifact("core")
27
28        ### Create our corefile
29        retcode = call(self.create_corefile + " " +  self.test_exe + " " + self.corefile, shell=True)
30
31        ## This corefile has no metadata telling us how many bits are
32        ## used for ptrauth signed function pointers.  We will need lldb
33        ## to fall back on its old default value for Darwin arm64 ABIs
34        ## to correctly strip the bits.
35
36        # Create a Target with our main executable binary to get it
37        # seeded in lldb's global module cache.  Then delete the Target.
38        # This way when the corefile searches for a binary with its UUID,
39        # it'll be found by that search.
40        initial_target = self.dbg.CreateTarget(self.test_exe)
41        self.dbg.DeleteTarget(initial_target)
42
43        self.target = self.dbg.CreateTarget('')
44        err = lldb.SBError()
45        self.process = self.target.LoadCore(self.corefile)
46        self.assertEqual(self.process.IsValid(), True)
47
48        # target variable should show us both the actual function
49        # pointer with ptrauth bits and the symbol it resolves to,
50        # with the ptrauth bits stripped, e.g.
51        #  (int (*)(...)) fmain = 0xe46bff0100003f90 (actual=0x0000000100003f90 a.out`main at main.c:3)
52
53        self.expect("target variable fmain", substrs=['fmain = 0x', '(actual=0x', 'main at main.c'])
54