osx-cross / homebrew-avr

Homebrew AVR Toolchain
BSD 2-Clause "Simplified" License
393 stars 79 forks source link

avr-gdb: Symbol format `elf32-avr' unknown. #251

Closed mmastrac closed 2 years ago

mmastrac commented 3 years ago

I've been scratching my head over this for a while, but I cannot get the avr-gdb package here to load an elf file successfully. I tried a known-good incantation from http://blog.oddbit.com/post/2019-01-22-debugging-attiny-code-pt-1/, but something about elf32-avr is busted.

This is a repro with a simple, empty main.c (int main(void) { }):

$ avr-gcc -mmcu=atmega328p /tmp/main.c -o /tmp/main
$ avr-gdb /tmp/main
GNU gdb (GDB) 10.1
[snip]

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /tmp/main...
I'm sorry, Dave, I can't do that.  Symbol format `elf32-avr' unknown.

Uninstalled and reinstalled avr-gdb, avr-gcc and avr-binutils from this tap. Tried various combinations of flags (-g, -Og, different CPUs, etc).

Is it possible that the part of the avr-gdb formula that skips BFD/opcodes causes this? https://github.com/osx-cross/homebrew-avr/blob/master/Formula/avr-gdb.rb#L43

ladislas commented 3 years ago

I haven't used gdb in a while so I can really tell.

Maybe you're right this line causes the error. You can comment it locally and build from source to test it. If it works I'll make a fix.

mmastrac commented 3 years ago

Unfortunately, I tried a few different edits after posting that message (removing various combinations of --disable-*, install vs install-gdb) and had no luck.

It's busted, but I am really at a loss as to how it might be fixed. Hopefully someone with more experience can point me at some ideas!

felias-fogg commented 3 years ago

I also had this problem and found this clue: https://unix.stackexchange.com/questions/624486/gdb-installed-from-homebrew-on-macos-big-sur-fails-to-load-symbols-from-elf32-i3

So, I tried to insert the line "#include " at the top of bfd/elf-bfd.h and it did the job. So, in order to fix this bug, you need to include the following line in the homebrew formula right after 'mkdir "build" do': inreplace "../bfd/elf-bfd.h", "#define _LIBELFH 1", "#define _LIBELFH 1\n#include " And when you are at it, you may also want to use the new gdb version 10.2.

Cheers, Bernhard

danapplegate commented 3 years ago

I'm encountering this same issue, and unfortunately @felias-fogg 's solution hasn't worked for me. I'm on MacOS Big Sur version 11.2.3.

Neither adding the inreplace line into the formula, nor including the patch block from #255 worked for me.

danapplegate commented 3 years ago

Actually, scratch that, I was being dumb. The patch inserts from #255 worked for me, I just needed to --build-from-source when installing avr-binutils and avr-gdb. Now seems to work for me!

ladislas commented 2 years ago

Does someone want to take over #255 and the patch?

danapplegate commented 2 years ago

@ladislas Sure thing, here you go: #259

ladislas commented 2 years ago

This should now be fixed thanks to @danapplegate!

I'll close the issue now.

Feel free to open a new one if needed.