3

I have built GDB from source on macOS 12.0 and codesigned it. However, every time I try to debug a program, I get this:

(gdb) b main
Breakpoint 1 at 0x10000324f: file main.cpp, line 50.
(gdb) run
Starting program: /Users/tjcaul/Documents/C++/a.out 
[New Thread 0x2a03 of process 2389]

and then GDB hangs. I have been compiling C++ programs with g++. Here are some things I have tried:

  1. Compile with -g option.
  2. Compile with -ggdb option.
  3. Compile with -ggdb3 option.
  4. Run with sudo
  5. Kill and re-run gdb repeatedly.
  6. Try different binaries.
  7. Disable SIP
  8. Add more breakpoints.
  9. set startup-with-shell off in .gdbinit

I do not get taskgated / Mach Port errors; only the New Thread message.

I realize that this is a near-duplicate of this, but I didn't see a working answer on that question.

For reference, here are my versions:

$ g++ --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin21.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ gdb --version
GNU gdb (GDB) 10.2
tjcaul
  • 283

2 Answers2

0

As usual, attention to detail was the issue. I saw that g++ --version reported clang, but I didn’t think about it enough. I had assumed that GDB was the problem, not my compiler. I’m not sure why Apple linked g++ to clang++, since that’s quite misleading. This little oversight made me spend 8 months writing C++ on my phone (vi on a 60-character wide display is not my ideal IDE).

What I did to get real g++:

  1. Install gcc with Homebrew

  2. Soft-link (ln -s) gcc-11 and g++-11 from /usr/local/Cellar/ to /usr/local/bin/

  3. unhash (at least in zsh) gcc and g++, or else gcc will continue to expand to /usr/bin/clang

GDB is working most of the time now.

tjcaul
  • 283
0

This hang hits gdb bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24069

You can install gdb from this source with patch:

brew install --force --build-from-source domq/gdb/gdb  # a patched version based on 10.1

or you can

brew update
brew install gdb # use gdb 12.1

It works for me, and I found it from this link: https://gist.github.com/mike-myers-tob/9a6013124bad7ff074d3297db2c98247

lutaoact
  • 166