29

I have installed GDB on Mac OS X and to test that it works I have used this following C program.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {

    int *my_array = (int *) malloc(5 * sizeof(int));
    int i;
    for (i = 0; i < 1000000; i++) {
        my_array[i] = i;
    }

    free(my_array);

    return 0;

}

I have an error when compiling it, which is normal (segmentation fault)

However, when adding the -g flag in the compiling command and running gdb on my compiled program, I have this message after launching the command run

During startup program terminated with signal ?, Unknown signal.

Really don't know where it comes from. I have added a certificate to ensure that gdb works correctly on OS X but I have found nothing to fix this issue.

Pierre P.
  • 1,055
  • 2
  • 14
  • 26

5 Answers5

32

From this answer: https://stackoverflow.com/a/40437725/1060955

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” [Exclude the quotation marks] in your user folder.

In the file add the following: “set startup-with-shell off” [Exclude the quotation marks]

Save the file

gdb should now work

Sources

https://stackoverflow.com/a/40437725/1060955

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

Community
  • 1
  • 1
Parth Mehrotra
  • 2,712
  • 1
  • 23
  • 31
  • Worked for me after signing gdb. To simplify, you can run these commands from Terminal: `touch ~/.gdbinit;set startup-with-shell off>~/.gdbinit` – W.K.S Feb 18 '17 at 21:05
  • 8
    the commands is wrong. `touch ~/.gdbinit;echo "set startup-with-shell off">~/.gdbinit` is right – user3875388 Aug 27 '17 at 12:11
  • 1
    Unlike the above comment, if you do not want to delete your current `~/.gdbinit`: `touch ~/.gdbinit; echo "set startup-with-shell off" >> ~/.gdbinit` – Herpes Free Engineer Jan 06 '19 at 12:23
27

If you're on Sierra , that's expected. GDB isn't compatible with macOS Sierra , even the last release (7.12).

We should maybe wait for another release of GDB , or for another update for macOS in order to get the bug fixed.

Houssem Nouira
  • 324
  • 3
  • 7
  • 7
    See http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra. – dbrank0 Oct 19 '16 at 06:54
  • 4
    Be sure to scroll down, there might be a solution listed below – Parth Mehrotra Oct 03 '17 at 15:07
  • 1
    Also, just for the records, it doesn't work on High Sierra (Version: 10.13.2 (17C88)) either. I get the same error: `During startup program terminated with signal ?, Unknown signal.` – user6490375 Jan 15 '18 at 02:38
11

I installed gdb via Homebrew. At the end of the installation it says:

On 10.12 (Sierra) or later with SIP, you need to run this:

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

This was necessary to make it work. Also I had to make sure the .gdbinit was set in the Eclipse Debug configuration

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Muhammad
  • 129
  • 1
  • 4
  • It works on High Sierra 10.13.2 together with gdb 8.0 (installed from sources) and Visual Studio Code. – padamowski Jan 15 '18 at 22:22
  • 1
    GDB Manual for gdb version 8.2.50.20190106-git; page 28 states for this error: `(the error) which indicates the shell or the wrapper specified with ‘exec-wrapper’ crashed, not your program.`, hence this solution worked. – Herpes Free Engineer Jan 06 '19 at 12:27
5

For me it worked perfectly on MacOS Sierra Version 10.12.4 by just uninstalling and installing gdb as,

  1. Uninstall GDB

$ brew uninstall gdb

  1. Install GDB

$ brew install gdb

This will install latest gdb which is compatible with MacOS Sierra.

Hope this help to anyone!

Pankaj
  • 234
  • 3
  • 14
2

Sierra (10.12) doesn't seem to support gdb. I tried following a tutorial that had me create a certificate. Afterwards, when I ran gdb, I got the same error mentioned.

Apple uses lldb. It works well, and can integrate with Eclipse, I've been told. Here is a link.

audrow
  • 143
  • 1
  • 9
  • Downvoted because Sierra will support gdb if you follow the instructions above. echo "set startup-with-shell off" >> ~/.gdbinit You also have to create a certificate for gdb to work: See: https://stackoverflow.com/questions/49001329/gdb-doesnt-work-on-macos-high-sierra-10-13-3 Yes, it's a hassle but it's worth having gdb. You can optionally run 'brew doctor' to make sure your code is up to date. – vwvan Sep 21 '18 at 03:23