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.
Answer from Andrew on Stack OverflowGDB 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"
That's because gdb is not yet out for Apple silicon (ARM architecture). In fact, neither is gcc. If you run gcc --version, you will see that in fact your mac is aliasing gcc to clang (Apple clang).
What brew is telling you is that you cannot use gdb for natively compiled code. What you are using, that is aarch64-elf-gdb, is a debugger for cross-platform development. In other words, Apple mac users developing for Linux, writing elf binaries. Obviously, you won't be able to use those binaries on your mac.
Addendum: The other answer is correct about one thing. Your best bet now for native binaries is LLDB. But you will have to learn slightly different syntax.
I didn't use GDB on macOS before. But I guess the issue you have is that some security technologies on macOS are different than MS Windows. You probably need some extra config for code signing and system integrity protection(SIP) so that GDB can debug your C program. To be honest, it might be complex and I 'm not sure how to set those up.
I reckon there's a more macOS-adopted alternative :
You can try LLDB if you don't need to stick with GDB. LLDB is generally more integrated with macOS, including the ARM64 architecture. It's also the default debugger in Xcode.
There's also tutorials of how to set up and use LLDB
Cheers
Hey! I know this isn't an Asahi Linux question, but you people will probably know more than your generic r/m2 or whatever the sub is. Has anyone gotten gdb installed in osx? I just want to debug a simple C program, so I'm also happy to use whatever cli alternative you might have.
Can I use GCC and GDB on an M1 Mac? I was wandering if it could support my development of my University assignment (they require GCC). I was also wandering if I could develop application with OpenGL with the Apple Chip?
Someone that is using them can help me?