Videos
GDB has not (yet) been ported to MacOS running on the M2 (AArch64) architecture. Even GDB for MacOS on the old x86-64 was not very well tested as far as I know.
I believe lldb might be available for the MacOS/M2 target, but I know nothing about installing this debugger on MacOS.
If you really want to use gdb on mac, which is as Andrew stated, not well tested, you can use x86_64 version of brew:
First, you need to install x86_64 brew:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Then, you can install gdb right away using:
arch -x86_64 zsh
arch -x86_64 brew install gdb
In addition, you might want need to alias x86_64 brew by adding it to your .zshrc
alias x86brew='arch -x86_64 /usr/local/bin/brew'
So you can just use "x86brew" to install without having to "arch -x86_64 zsh"
After hours and hours of searching, I finally found an obscure gist identifying the issue and detailing the solution.
TL;DR The GNU Debugger requires a patch before it can work with MacOS. gdb v8.0.1 is the last known good version of GDB for MacOS.
Uninstall the latest version of
gdb(i.e. v8.1)brew uninstall --force gdbForce Homebrew to install a version of
gdbwith the patch for MacOS.brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c3128a5c335bd2fa75ffba9d721e9910134e4644/Formula/gdb.rbUse the existing certificate to codesign the new install of
gdbcodesign -f -s "<GNU GDB Certificate>" $(which gdb)
Now, gdb works as expected!
Special thanks to https://github.com/marcoparente and https://github.com/lokoum for their gist comments!
I got gdb working on Mojave yesterday 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
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)
Figured out what the issue was, turns out that clang really doesn't like when you try and use strncmp without first including string.h. Meanwhile gcc is perfectly happy to compile elf-bfd.h without including string.h. As a result, even though GDB will compile on macOS, it simply refuses to load any ELF files because the ELF code isn't compiled correctly. The fix is just to add #include <string.h> to the top of elf-bfd.h and GDB will correctly load ELF binaries.
For macos if you are using brew you can install and use i386-elf-gdb - https://formulae.brew.sh/formula/i386-elf-gdb.
brew install i386-elf-gdb
download the most recent GDB from https://www.sourceware.org/gdb/download/
expand the gdb-7.12.1.tar.xz file:
tar xopf gdb-7.12.1.tar.xzcd gdb-7.12.1in terminal to open the gdb folderthen follow the instructions in the README file in the gdb folder, or simply follow the following steps:
./configure, wait for the terminalmakeand wait again (which can take some time)sudo make install
Now gdb is installed at /usr/local/bin/
Note that you might want to try/use LLDB (lldb) instead. This is now the default (don't know about 10.12, but on 10.13 it is installed, when you install the Xcode utilities). It even comes with a nice curses GUI, but otherwise a shell very similar to GDB.