问题
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' and 'enter', it immediately crashes with the information:
During startup program terminated with signal SIG113, Real-time event 113.
My GDB is based on homebrew. So today, I uninstalled the whole homebrew package and reinstalled it. After the codesign step, I still faced the same error.
I tried 'sudo' and a few other things. Google had no idea what happened. So I was wondering if you guys might have some magical solution.
回答1:
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
- Quit gdb
- Using your text editor e.g. Sublime Text, save a file called
.gdbinit
in your user folder. - In the file add the following:
set startup-with-shell off
- Save the file
- gdb should now work
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
回答2:
I got the same error after updating to macOS Sierra. Temporarily I changed debugger to LLDB using the library lldbmi2:
1. git clone https://github.com/freedib/lldbmi2.git lldbmi2
2. cd lldbmi2
3. mkdir build
4. cd build
5. cmake ../
6. make
7. sudo make install
Once lldbmi2 is installed, you can debug your application by creating a new C/C++ Application in Debug Configurations... and change the GDB debugger (in Debugger tab) from gdb to lldbmi2. Options to lldbmi2 may be set there. Something like /usr/local/bin/lldbmi2 --log.
Everything seems to be working fine, and even better as GDB.
回答3:
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.
回答4:
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
回答5:
assume your MacOS version is 10.12.6.
- upgrade your gdb to version 8.0.1
brew upgrade gdb
- execute
echo "set startup-with-shell off" >> ~/.gdbinit
( I saw this command when I installed gdb by brew ) - create a certificate with name
gdb-cert
and trust this certificate in code signing option - reboot your mac
- execute
sudo codesign -s gdb-cert /usr/local/bin/gdb
- done! have a fun ~
BTW,you can use lldb to replace gdb .
回答6:
I've been having multiple issues with Sierra.
For starters my code that had worked on previous OSX versions has stopped working on this version. Nor would it compile.In addition GDB from brew is a complete mess. To add on that other 3rd party libraries got broken (e.g. libevent).
("Good job" Apple).
After "upgrading" to Sierra I suggest the following steps to get GDB working:
Install a newer gcc (Should take about 60 minutes - depending on your CPU etc...)
brew install gcc
Download the source code of GDB
Since gcc and g++ are aliased to the old gcc and g++ make sure to link it to the newer gcc and g++ e.g.:
export CC=`which gcc-6`
export CXX=`which gxx-6`
Configure & Compile gdb:
./configure
make CFLAGS=-Wno-error=deprecated-declarations CXXFLAGS=-Wno-error=deprecated-declarations
sudo make install
回答7:
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
回答8:
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
来源:https://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra