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