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/
Answer from aFactoria on Stack Overflowdownload 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.
Does installing GDB on a mac usually take a while? or is it only me?
segmentation fault - how to install gdb on MacBook Air m2 - Stack Overflow
gdb compiler - Apple Community
GCC and GDB on M1 Macs
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"