2
  1. OS version: macOs Mojave 10.14.2
  2. gdb: 8.2.1 (install with brew install gdb)
  3. I have codesign successfully with

    codesign --entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)

  4. I have simple code like this:

    int main(int argc, char *argv[]) { std::cout << "hello, world" << std::endl; return 0; }

  5. gdb hang then

    zhifandeMacBook-Pro:cpp-quick-start zhifan$ g++ -g main.cpp

    zhifandeMacBook-Pro:cpp-quick-start zhifan$ gdb ./a.out
    GNU gdb (GDB) 8.2.1
    Copyright (C) 2018 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-darwin18.2.0".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://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"...
    Reading symbols from ./a.out...Reading symbols from /Users/zhifan/github/cpp-quick-start/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
    done.
    (gdb) start
    Temporary breakpoint 1 at 0x100000f54: file main.cpp, line 5.
    Starting program: /Users/zhifan/github/cpp-quick-start/a.out
    [New Thread 0x1903 of process 11780]
    [New Thread 0x1a03 of process 11780]
    During startup program terminated with signal ?, Unknown signal.
    (gdb) set startup-with-shell off
    (gdb) start
    Temporary breakpoint 2 at 0x100000f54: file main.cpp, line 5.
    Starting program: /Users/zhifan/github/cpp-quick-start/a.out
    [New Thread 0x2707 of process 11806]

My gdb hang here( [New Thread 0x2707 of process 11806]) all the time..

I can't use 8.0.1 since the issue unknown load command 0x32

what else can I do?

zhihuifan
  • 1,093
  • 2
  • 16
  • 30

3 Answers3

1

Ok, from my experience within the past two years of coding with a MacBook Pro. I have never been successful with getting gdb to work correctly. macOS uses the Xcode Developer tools for compiling. These tools include lldb which is very similar to gdb.

Here is a website that can help a bit to do this. https://lldb.llvm.org/lldb-gdb.html This is a map that directly shows gdb tools and lldb tools. Hope this helps.

1

I got gdb working on Mojave today by:

a) getting the latest gdb source archive (at time of writing, ftp://sourceware.org/pub/gdb/snapshots/current/gdb-weekly-8.2.50.20190212.tar.xz) - amongst other things, it adds handling for recognizing executables on Mac.

b) build gdb. I got errors for variable shadowing in darwin-nat.c so I edited the file and rebuilt.

c) follow steps in https://forward-in-code.blogspot.com/2018/11/mojave-vs-gdb.html

Voila!

(source: GDB on Mac/Mojave: During startup program terminated with signal ?, Unknown signal)

Joubert Nel
  • 3,154
  • 3
  • 26
  • 24
  • I got mine working with eclipse, but after a second edit and a recompile of my test code it hangs, i had to restart eclipse to get it working again.. not sure why.. – johan.i.zahri Mar 13 '19 at 04:51
  • This was the only method I've found that succeeded! 10.14.5 – evanb May 27 '19 at 10:36
  • I just recently downloaded the latest gdb from MacPorts, and was happy to see that I no longer got the 'load' error mentioned above. I code signed the code and was encouraged to see that it caught a segfault I had been tracking down. I re-compiled the code, and now, gdb hangs with the same sort of behavior described by the OP. Very annoying! I am using Mojave 10.14.3. Are the Macs days as a developer platform numbered? – Donna May 29 '19 at 10:30
  • I have been using gdb on Mojave and it _mostly_ works. But every once in a while, I get the "New Thread ..." message and gdb hangs. I found that going into the Activity Monitor, forcing gdb to quit, and then starting gdb again usually works. Other errors, such as "error reading variable ... more than max-size" often crop up. These issues with GDB, and the fact that Valgrind doesn't work so well on OSX has me nearly convinced that moving to Linux for code development is the way to go. – Donna Aug 03 '19 at 09:38
0

I couldn't agree more with @Tanner Breckenridge. gdb just doesn't work on my mac, no matter what I tried. Just use something else.

lldb seems good, and for anyone who prefers a debugger with gui like me, I suggest using Visual Studio Code or Xcode to debug your C program instead.

Lansorian
  • 149
  • 3
  • 11