macOS 下通过 GDB 调试程序会出现:

Unable to find Mach task port for process-id 1375: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
  1. 需要通过 Keychain Access Application 创建证书: code-sign-cert

  2. 需要对 gdb 进行签名,首先创建 gdb-entitlement.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>com.apple.security.cs.debugger</key>
    	<true/>
    </dict>
    
  3. 运行签名

    codesign --entitlements gdb-entitlement.xml -fs code-sign-cert $(which gdb)
    

See also: PermissionsDarwin