It is a problem that appeared when I first updated to macOS Sierra yesterday.
GDB itself is running OK. However, somehow, it cannot run my program. When I type \'run
Multiple solutions that worked for Sierra 10.12.0 do not work with Sierra 10.12.1. With this version, you need an updated version of GDB (patch committed at FSF on Nov 9), in addition to disabling spawning of shell with 'set startup-with-shell off'. See instructions at http://blog.adacore.com/gnat-on-macos-sierra
This is due to a Runtime Integrity Protection feature in Sierra - you can deactivate it by following the instructions here.
- Reboot your system Keep command+R pressed until the Apple logo appears on the screen.
- Select the menu Utilities/Terminal Type "csrutil enable --without debug" in the terminal
- Finally, reboot your machine again
Note that disabling this will lower the security of your system, so doing the above should really be your decision.
Another impact of this change is that the DYLD_LIBRARY_PATH variable is no longer reset when spawning new processes via the shell. This variable is used by the dynamic linker to find dynamic libraries. It takes precedence over the search path coded in the executables, so is considered as unsafe by the OS. As a result, macOS by default unsets the variable so that the executable you spawn uses its own libraries. We recommend using the DYLD_FALLBACK_LIBRARY_PATH instead, which comes after the application's library search path, in case some libraries are still not found.
This works for me:
Unlink current gdb: brew unlink gdb
Install gdb 8.0.1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb
Optional: avoid upgrade gdb with brew pin gdb
I know my answer is not specifically related to GDB, but since I also had some difficulties making GDB to work myself, I'd like to recommend you to give a try on LLDB. For me, it worked like a charm:
https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-terminal-workflow-tutorial.html
Since Xcode itself now uses LLDB instead of GDB, this can be a more convenient alternative for Mac users. And, in my particular case, it integrated much easier in Eclipse than GDB:
https://wiki.eclipse.org/CDT/User/FAQ#How_do_I_get_the_LLDB_debugger.3F
assume your MacOS version is 10.12.6.
brew upgrade gdb
echo "set startup-with-shell off" >> ~/.gdbinit
( I saw this command when I installed gdb by brew )gdb-cert
and trust this certificate in code signing optionsudo codesign -s gdb-cert /usr/local/bin/gdb
BTW,you can use lldb to replace gdb .
This is how I easily fixed the issue. [Update: based on feedback received and yet to be verified, it seems that this solution works with macOS Sierra 10.12 but not with macOS Sierra 10.12.2]
See video instructions here
.gdbinit
in your user folder.set startup-with-shell off
Sources
https://discussions.apple.com/thread/7684629?start=0&tstart=0
Where is .gdbinit is located and how can I edit it?
https://sourceware.org/gdb/onlinedocs/gdb/Starting.html