43

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.

Scott Chang
  • 631
  • 1
  • 6
  • 9
  • `brew update && brew upgrade gdb`, codesigning, and the `set startup-with-shell off` config (these last two are mentioned by brew) and it looks like we’re in business. Sierra 10.12.1. – Ahmed Fasih Dec 22 '16 at 02:20

9 Answers9

64

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

  1. Quit gdb
  2. Using your text editor e.g. Sublime Text, save a file called .gdbinit in your user folder.
  3. In the file add the following: set startup-with-shell off
  4. Save the file
  5. 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

culsense
  • 25
  • 5
Salamit
  • 1,015
  • 7
  • 13
  • 33
    Does not fix the issue with OS X Sierra (for me). – user2664470 Nov 29 '16 at 17:55
  • 2
    @user2664470 it doesn't seem to work with macOS Sierra 10.12.2. What is your macOS version? – Salamit Dec 02 '16 at 07:24
  • 1
    macOS Sierra 10.12.1 – user2664470 Dec 02 '16 at 13:50
  • That could be why. Mine is macOS Sierra 10.12. Have you tried the other options blow? – Salamit Dec 02 '16 at 19:00
  • 1
    I did this in addition to the signing GDB thing, and now it works. – jrsala Feb 11 '17 at 13:50
  • @jrsala signing GDB? Do you have a link? – Salamit Feb 12 '17 at 07:15
  • 1
    @Salamit I had the "Unable to find Mach task port for process-id XYZ" error, in addition to another one I don't remember, so I followed [this](https://sourceware.org/gdb/wiki/BuildingOnDarwin). I still have to run gdb with sudo though, which defeats the purpose of codesigning it I guess? I had to switch to LLDB anyway because core files can't be read by a GNU (homebrew) GDB. **EDIT:** basically I did what Ahmed Fasih succinctly suggests in his comment on this question. – jrsala Feb 12 '17 at 10:02
  • 2
    It doesn't work for me. I am getting error message: "During startup program terminated with signal ?, Unknown signal". And I have Sierra 10.12.3. – stones333 Feb 19 '17 at 17:22
  • @stones333 did you try what Ahmed Fasih(check above) did? – Salamit Mar 17 '17 at 20:15
  • 3
    It's work for me . I'am using macOS 10.12.4 (16E195) – BlackKat Apr 12 '17 at 03:51
  • 6
    To make this work it is important to specify absolute paths to both gdb and .gdbinit This in 'Debug Configurations" -> Debugger tab. – user1008139 May 25 '17 at 16:13
  • 1
    This worked for me too macOS 10.13.4 High Sierra. I am using absolute paths in the debug configuration as suggested by https://stackoverflow.com/users/1008139/user1008139 – WolfiG May 01 '18 at 20:36
  • 2
    gdb 8.1.1 (current version) won't work on macOS 10.12.6 (mine) and later, I think so. Signing and .gdbinit instructions are simple and we can't do it wrong. I believe there is a bug in gdb 8.1.1 code. I downgraded gdb to 8.0.1 and it worked like a charm, thanks to @Hongbo Liu answered here https://stackoverflow.com/a/49104154/108616 – Tien Do Sep 20 '18 at 06:06
  • 1
    Be aware that set `startup-with-shell off` might cause huge problems later on. This step seems not to be necessary. Thanks to: https://timnash.co.uk/getting-gdb-to-semi-reliably-work-on-mojave-macos/ – Danijel Sep 20 '19 at 10:43
11

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.

enter image description here

Everything seems to be working fine, and even better as GDB.

Michał Ciołek
  • 319
  • 2
  • 9
5

This is due to a Runtime Integrity Protection feature in Sierra - you can deactivate it by following the instructions here.

  1. Reboot your system Keep command+R pressed until the Apple logo appears on the screen.
  2. Select the menu Utilities/Terminal Type "csrutil enable --without debug" in the terminal
  3. 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.

Community
  • 1
  • 1
5

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

Yannick Moy
  • 188
  • 1
  • 5
5

assume your MacOS version is 10.12.6.

  1. upgrade your gdb to version 8.0.1 brew upgrade gdb
  2. execute echo "set startup-with-shell off" >> ~/.gdbinit ( I saw this command when I installed gdb by brew )
  3. create a certificate with name gdb-cert and trust this certificate in code signing option
  4. reboot your mac
  5. execute sudo codesign -s gdb-cert /usr/local/bin/gdb
  6. done! have a fun ~

BTW,you can use lldb to replace gdb .

Jinmiao Luo
  • 143
  • 1
  • 5
  • hot to do step 3? tnx. – Eziz Durdyyev Apr 06 '18 at 16:54
  • open Keychain Access App, look at your menu. Keychain Access - Certificate Assistant - Creat a Certificate. when your have created your certificate, find it in login keychain and `⌘ + i` to view certificate info. in there you can trust this certificate manually. English is not my native language, please excuse typing errors. – Jinmiao Luo May 02 '18 at 06:04
  • thanks for suggesting `lldb` - that was the best option for me – zoecarver May 29 '18 at 14:11
  • have to execute ```touch ~/.gdbinit``` if .gdbinit not exists. – Jiho Lee May 30 '21 at 08:01
4

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:

  1. Install a newer gcc (Should take about 60 minutes - depending on your CPU etc...)

    brew install gcc

  2. Download the source code of GDB

  3. 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`

  4. Configure & Compile gdb:

    ./configure

    make CFLAGS=-Wno-error=deprecated-declarations CXXFLAGS=-Wno-error=deprecated-declarations

    sudo make install

Tomer
  • 1,594
  • 14
  • 15
4

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
fgriberi
  • 41
  • 2
  • This works on Sierra 10.12.6, check also here https://stackoverflow.com/questions/49001329/gdb-doesnt-work-on-macos-high-sierra-10-13-3/49104154#49104154 – Guglie Nov 23 '18 at 09:57
3

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

Carlos Ballock
  • 145
  • 1
  • 3
2

Update as of today (2021-04-08, Big Sur 11.2.3 (20D91), gdb version 10.1): I got it to work with some patches.

  1. Install gdb with brew install --build-from-source domq/gdb/gdb
  2. Code-sign it
  3. If gdb can't read your binary (not in executable format: file format not recognized) you might need to “un-fat” it first:
    lipo -thin x86_64 -output ls-x86_64 /bin/ls

⚠ You currently can't seem to break main — I may or may not get back to you on that soon.

DomQ
  • 4,184
  • 38
  • 37