gdb fails with “Unable to find Mach task port for process-id” error

后端 未结 12 2090
青春惊慌失措
青春惊慌失措 2020-11-28 19:02

My app runs fine but gdb fails to debug it with the following error

(gdb) run
Starting program: /path/to/app 
Unable to find Mach task port for process-id 83         


        
12条回答
  •  误落风尘
    2020-11-28 19:28

    These instructions work for OSX High Sierra and avoid running gdb as root (yuck!). I recently updated from OSX 10.13.2 to 10.3.3. I think this is when gdb 8.0.1 (installed w/ homebrew) started failing for me.

    I had difficulty with other people's instructions. After different instructions, everything was a mess. So I started a fresh. I more or less followed these instructions.

    Clean the mess :

    1. brew uninstall --force gdb # This deletes _all_ versions of gdb on the machine
    2. In Applications -> Utilities -> Keychain Access, I deleted all previous gdb certificates and keys (be sure you know what you're doing here!). It's unclear if this is necessary, but since I'd buggered up trying to create those certificates and keys using other instructions I eliminated them anyways. I had keys and certificates in both login and system.

    Now reinstall gdb.

    1. brew install gdb
    2. Within Keychain Access, go to menu Keychain Access-> Certificate Assistant -> Create a Certificate
    3. Check "Let me override defaults" and set
    Name : gdb-cert
    Identity Type: Self Signed Root
    Certificate Type : Code Signing
    
    [X] Let me override defaults
    
    1. On 1st Certificate Information page:
    Serial Number : 1
    Validity Period (days): 3650
    
    1. On 2nd Certificate Information page, I left all fields blank except those already filled in.

    2. On Key Pair Information page, I left the defaults

    Key Size : 2048
    Algorithm : RSA
    
    1. On Key Usage Extension page, I left the defaults checked.
    [X] Include Key Usage Extension
    [X] This extension is critical
    Capabilities:
    [X] Signature
    
    1. On Extended Key Usage Extension page, I left the defaults checked.
    [X] Include Extended Key Usage Extension
    [X] This extension is critical
    Capabilities:
    [X] Code Signing
    
    1. On Basic Constraints Extension Page, nothing was checked (default).

    2. On Subject Alternate Name Extension page, I left the default checked and didn't add anything else.

    [X] Include Subject Alternate Name Extension
    
    1. On Specify a Location for the certificate page, I set
    Keychain: System
    
    1. I clicked Create and was prompted for my password.

    2. Back in the Keychain Access app, I went to System and right clicked on gdb-cert and under dropdown menu Trust, I changed all the fields to Always Trust.

    3. Rebooted computer.

    4. At the Terminal, I ran codesign -s gdb-cert /usr/local/bin/gdb. I entered my password when prompted.

    5. At the Terminal, I ran echo "set startup-with-shell off" >> ~/.gdbinit

    6. I ran gdb myprogram and then start within the gdb console. Here, I believe, it prompted for me for my password. After that, all subsequent runs, it did not prompt for my password.

提交回复
热议问题