score:-1

gdb 8.3;

my problem is the same as the guy above, solved by

codesign --entitlements gdb.xml -fs gdb-cert /usr/local/bin/gdb

score:0

i can recommend to follow this gist: https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d#file-codesign_gdb-md

with trick to overcome: unknown error = -2,147,414,007 during certificate creation described here: https://apple.stackexchange.com/a/309123

notes:

path for gdb installed as homebrew package should be something like: /usr/local/cellar/gdb/9.2/bin/gdb

and csrutil enable --without debug will cause a message about requesting unsupported configuration, like here: https://totalfinder.binaryage.com/system-integrity-protection

test:

○ → sw_vers -productversion
10.13.6

○ → gdb ./a.out
gnu gdb (gdb) 9.2
...
thread 3 hit breakpoint 1, main () at main.c:14
14          data_t d = {0};

score:3

i wonder if the global change in the highest voted answer here has some unintended consequences.

rather than enabling the old tiger convention, taskgated does allow signed code to run. so it might be better to just get a signed cert for gdb, similar to the answer here.

after this i was able to sudo use gdb. if you need to use gdb w/o sudo then perhaps this link will help though, disclaimer, i haven't tried it yet because using sudo is an ok solution for now`.

score:4

this is what worked for me on big sur: https://dev.to/jasonelwood/setup-gdb-on-macos-in-2020-489k. the crucial missing step from other guides was the --entitlements gdb-entitlement.xml option for codesigning:

i am copying here the file gdb-entitlement.xml for reference in case the linked site disappears: codesign --entitlements gdb-entitlement.xml -fs

where <gdb-cert> is the name of the certificate and is the path to the gdb executable

<!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.allow-jit</key><true/><key>com.apple.security.cs.allow-unsigned-executable-memory</key><true/><key>com.apple.security.cs.allow-dyld-environment-variables</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.cs.disable-executable-page-protection</key><true/><key>com.apple.security.cs.debugger</key><true/><key>com.apple.security.get-task-allow</key><true/></dict></plist>

score:5

this may not be related. you can use lldb on macos instead of gdb. you don't need this hassle to install gdb.

lldb(http://lldb.llvm.org) is already installed by default in high sierra

score:7

for anyone who using sierra 10.12.6 (and above) and homebrew, /usr/local/bin/gdb is a symbolic link to /usr/local/cellar/gdb/8.0/bin/gdb (or whatever version, e.g. 8.0.1).

you need to codesign both link and target:

codesign -fs gdb-cert /usr/local/bin/gdb
codesign -fs gdb-cert "/usr/local/cellar/gdb/8.0/bin/gdb"

or, if you have greadlink (installed via brew install coreutils):

codesign -fs gdb-cert $(which gdb)
codesign -fs gdb-cert $(greadlink -f $(which gdb))

score:9

none of this worked for me and i had to go with a long run. here is a full list of steps i've done to get it working.

  1. create a certificate to sign the gdb.

unfortunately, system certificate gave me unknown error = -2,147,414,007 which is very helpful, so i had to go with a workaround. keychain access -> create certificate ->

pick login, gdb-cert, code signing

copy/move certificate to the system keychain (enter password)

  1. select certificate (gdb-cert) click get info -> trust always
  2. disable startup-with-shell

enter in console: set startup-with-shell off

remember configuration: echo "set startup-with-shell off" >>~/.gdbinit

  1. enable root user

go to system preferences -> users & groups -> unlock it -> login options -> network account server -> join -> unlock it -> edit (menu) -> enable root user

  1. sudo killall taskgated
  2. finally sign gdb

codesign -fs gdb-cert "$(which gdb)"

  1. disable root user (step 4)
  2. reboot if still does not work. (if nothing else works, most likely it works already)

ps. i ended up using lldb because it just works (tutorial)

score:28

i experienced the same issue with gdb. i am running under mac os x 10.8.5 aka mountain lion. i am using gdb version 7.7.1.

i compiled my test program with following command:

g++ -o gdb-sample.out -g gdb-sample.cpp    

if i entered the command gdb sample.out, i get the same cryptic error message:

"unable to find mach task port for process-id 46234: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))"

this error message however is a red herring.

the solution i found that worked for me was to simply invoke gdb using the superuser acct:

sudo gdb sample.out. 

that works fine for me.

and that from that point i could run gdb example.out without using sudo.

hope this helps and works for others. rsvp if it doesn't.

score:29

i made gdb work on osx 10.9 without codesigning this way (described here):

  1. install gdb with macports. (may be you can skip it)

  2. sudo nano /system/library/launchdaemons/com.apple.taskgated.plist

    change option string from -s to -sp at line 22, col 27.

  3. reboot the computer.

  4. use gdb. if you installed it with mac ports then you must use ggdb command. or made an alias in your config file:

alias gdb='ggdb'

and use 'gdb' command then.

score:67

i upgraded to gdb 8.3 and was not able to make things working. this helped me:

codesign --entitlements gdb.xml -fs gdb-cert /usr/local/bin/gdb

where content of gdb.xml is:

<?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.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.debugger</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>

i found this solution here: https://timnash.co.uk/getting-gdb-to-semi-reliably-work-on-mojave-macos/

note: without the entitlement i was able to run gdb only with sudo.

score:154

this error occurs because osx implements a pid access policy which requires a digital signature for binaries to access other processes pids. to enable gdb access to other processes, we must first code sign the binary. this signature depends on a particular certificate, which the user must create and register with the system.

to create a code signing certificate, open the keychain access application. choose menu keychain access -> certificate assistant -> create a certificate…

choose a name for the certificate (e.g., gdb-cert), set identity type to self signed root, set certificate type to code signing and select the let me override defaults. click several times on continue until you get to the specify a location for the certificate screen, then set keychain to system.

double click on the certificate, open trust section, and set code signing to always trust. exit keychain access application.

restart the taskgated service, and sign the binary.

$ sudo killall taskgated
$ codesign -fs gdb-cert "$(which gdb)"

source http://andresabino.com/2015/04/14/codesign-gdb-on-mac-os-x-yosemite-10-10-2/

on macos 10.12 (sierra) and later, you must also

use gdb 7.12.1 or later additionally prevent gdb from using a shell to start the program to be debugged. you can use the following command for this inside gdb:

set startup-with-shell off

you can also put this last command in a file called .gdbinit in your home directory, in which case it will be applied automatically every time you start gdb

echo "set startup-with-shell off" >> ~/.gdbinit

source: https://sourceware.org/gdb/wiki/buildingondarwin


Related Query

More Query from same tag