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

后端 未结 12 2037
青春惊慌失措
青春惊慌失措 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:10

    It works when I change to sudo gdb executableFileName! :)

    0 讨论(0)
  • 2020-11-28 19:12

    You need to create a certificate and sign gdb:

    • Open application “Keychain Access” (/Applications/Utilities/Keychain Access.app)
    • Open menu /Keychain Access/Certificate Assistant/Create a Certificate...
    • Choose a name (gdb-cert in the example), set “Identity Type” to “Self Signed Root”, set “Certificate Type” to “Code Signing” and select the “Let me override defaults”. Click “Continue”. You might want to extend the predefined 365 days period to 3650 days.
    • Click several times on “Continue” until you get to the “Specify a Location For The Certificate” screen, then set “Keychain to System”.
    • If you can't store the certificate in the “System” keychain, create it in the “login” keychain, then export it. You can then import it into the “System” keychain.
    • In keychains select “System”, and you should find your new certificate. Use the context menu for the certificate, select “Get Info”, open the “Trust” item, and set “Code Signing” to “Always Trust”.
    • You must quit “Keychain Access” application in order to use the certificate and restart “taskgated” service by killing the current running “taskgated” process. Alternatively you can restart your computer.
    • Finally you can sign gdb:

      sudo codesign -s gdb-cert /usr/local/bin/ggdb

      sudo ggdb ./myprog

    0 讨论(0)
  • 2020-11-28 19:17

    This link had the clearest and most detailed step-by-step to make this error disappear for me.

    In my case I had to have the key as a "System" key otherwise it did not work (which not every url mentions).

    Also killing taskgated is a viable (and quicker) alternative to having to restart.

    I also uninstalled MacPorts before I started this process and uninstalled the current gdb using brew uninstall gdb.

    0 讨论(0)
  • 2020-11-28 19:17

    I followed this tutorial, and everything is OK.

    0 讨论(0)
  • 2020-11-28 19:19

    This is a weird approach but it worked for me(MacOs HighSierra 10.13.3). Install CLion. It comes with gdb. Once run the gdb using Terminal. Copy the gdb program to your usr/local/bin/. No problem of signin, sudo etc.

    0 讨论(0)
  • 2020-11-28 19:24

    Here is a really useful guide which solved my problem(OSX 10.13.6).

    1. Open Keychain Access
    2. In the menu, open Keychain Access > Certificate Assistant > Create a certificate
    3. Give it a name (e.g. gdbc)
      • Identity type: Self Signed Root
      • Certificate type: Code Signing
      • Check: let me override defaults
    4. Continue until it prompts you for: "specify a location for..."
    5. Set Keychain location to System
    6. Create a certificate and close assistant.
    7. Find the certificate in System keychains, right click it > get info (or just double click it)
    8. Expand Trust, set Code signing to always trust
    9. Restart taskgated in terminal: killall taskgated
    10. Run codesign -fs gdbc /usr/local/bin/gdb in terminal: this asks for the root password
    0 讨论(0)
提交回复
热议问题