gdb is not supported on M1 Macs; you can instead consider using lldb.
Answer from 284751067qqcom on Stack OverflowCan 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?
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
You will require a build of gdb not only configured for the correct architecture, but also object file type: remember that MacOSX/Darwin uses MachO object files where as GNU/Linux systems use ELF.
When using gdbserver, gdb is run on the development host, and reads executables and libraries in order to build a symbol-map corresponding to the target. It's for this reason that the gdb that Apple ships - which is built for Darwin and MachO binaries - doesn't work.
As for why things are as they are, this is an architectural limitation of gdb, binutils and incidentally gcc - all of which can only ever handle one target environment at once.
With remote debugging scenarios, there is often a need minimise link traffic and target memory foot-print. Remember, the comms link is sometimes a low speed serial-line. For this reason, as much as possible is done on the development host with gdbserver transacting very low-level operations.
Building a cross-gdb environment for MacOSX shouldn't pose any particular issues.
The Apple tools are going to be of little use to you unless you are using the Mach-O object format. You will need to build your own toolchain. If you have Macports installed this will be easy as it includes a port of the arm-elf-eabi toolchain. See http://www.macports.org/ports.php?by=name&substr=eabi