2

I want to use gdb to debug a C extension I wrote.

I followed all the steps here to codesign my brew install gdb version of gdb: https://sourceware.org/gdb/wiki/PermissionsDarwin

However, security dump-trust-settings -d shows

SecTrustSettingsCopyCertificates: No Trust Settings were found.

Even though I selected "Always Trust" for code signing in Keychain Access. Anyway I continued with the instructions.

gdb still has the same error as when I first tried it:

% gdb -ex r --args zsh python crash.py
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin20.2.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
"0x7ffee8d454b0s": not in executable format: file format not recognized
Starting program:  python crash.py
No executable file specified.
Use the "file" or "exec-file" command.
(gdb) 
theonlygusti
  • 11,032
  • 11
  • 64
  • 119
  • The answer I gave focuses on the second part of your question; please split out the part about the codesigning instructions failing into another question, so that I may answer that one too. (FWIW I just performed a thorough rewrite of the page you cite; you might have better luck if you try to apply the instructions again.) – DomQ Apr 07 '21 at 15:52

1 Answers1

0

gdb support for so-called “fat” binaries on Mac OS X has been on-again, off-again for almost a decade now (currently broken for two+ years). You need to use the lipo utility, from Apple's Xcode command line tools, to extract only the architecture you are interested in, e.g.

lipo -thin x86_64 -output ls-x86_64 /bin/ls

Afterwards you should¹ be able to gdb it, e.g.

▶ gdb ./ls-x86_64
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
[...]
Reading symbols from ./ls-x86_64...
(No debugging symbols found in ./ls-x86_64)
(gdb) set startup-with-shell off
(gdb) run
gdb-entitlement.xml
[Inferior 1 (process 7566) exited normally]
(gdb)

¹ At the time of this writing, you need to build and use a patched version.

DomQ
  • 4,184
  • 38
  • 37