xcodeinstruments

"Failed to gain authorization" when using Instruments


I'm trying to use Instruments to track memory allocations in a binary. When I attach Instruments to the process, it gives me the error "Failed to gain authorization". I followed the instructions here (https://developer.apple.com/forums/thread/681687?login=true&page=1#767994022) and added the "get-task-allow" entitlement. Here is the output from codesign -d:

codesign -dvvv --entitlements=- /Users/ccleve/.pgrx/16.0/pgrx-install/bin/psql

Executable=/Users/ccleve/.pgrx/16.0/pgrx-install/bin/psql
Identifier=psql-55554944e8e26ef3f50637679e1c2d5ded7430a8
Format=Mach-O thin (arm64)
CodeDirectory v=20400 size=6342 flags=0x2(adhoc) hashes=187+7 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha256=1b033acfe360f3efe957c00c5b0436bb2e686d61
CandidateCDHashFull sha256=1b033acfe360f3efe957c00c5b0436bb2e686d61c71347c05bc36fb2c653fae2
Hash choices=sha256
CMSDigest=1b033acfe360f3efe957c00c5b0436bb2e686d61c71347c05bc36fb2c653fae2
CMSDigestType=2
Launch Constraints:
        None
CDHash=1b033acfe360f3efe957c00c5b0436bb2e686d61
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=0 size=12
[Dict]
        [Key] com.apple.security.get-task-allow
        [Value]
                [Bool] true

How do I fix this?


Solution

  • Your output looks fine. Could you explain more about what your new error from Instruments is?

    Just for clarity here's what worked for me.

    1. create a debug.plist file
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>com.apple.security.get-task-allow</key>
            <true/>
        </dict>
    </plist>
    
    1. Sign your executable from the terminal
    codesign -s - -v -f --entitlements /path/to/debug.plist /path/to/executable
    

    Sources

    https://developer.apple.com/forums/thread/681687

    https://cocoaphony.micro.blog