1
\$\begingroup\$

I want to see the assembly code of my code written in the Arduino IDE. What I've tried is:

Sketch > Export compiled binary

Then, I found that I have a gcc toolset in my ESP8266 directory in:

Documents\ArduinoData\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\bin>

And there I have a xtensa-lx106-elf-objdump.exe

So I tried to run this objdump on the outputted compiled binary, but I got:

PS> xtensa-lx106-elf-objdump.exe -D <path/to/binfile>
file format not recognized
\$\endgroup\$
5
  • \$\begingroup\$ What was the cmdline you typed to get that error? \$\endgroup\$
    – Kartman
    Aug 11, 2021 at 6:37
  • \$\begingroup\$ By binary, do you mean literally the .bin output, or .hex or .elf? \$\endgroup\$
    – Justme
    Aug 11, 2021 at 6:46
  • \$\begingroup\$ Well, when you click on the "Export compiled binary" in the IDE, you get a .bin file \$\endgroup\$
    – YoavKlein
    Aug 11, 2021 at 6:48
  • \$\begingroup\$ How do you expect objdump to understand what the binary file contains? How would it know what is code or data in the binary and where they are located? Try giving it an executable, an .elf file which does contain that information. Or maybe force the linking stage to produce an assembly listing of the executable, so you don't even have to disassemble anything? \$\endgroup\$
    – Justme
    Aug 11, 2021 at 8:32
  • \$\begingroup\$ @Justme, I don't know much about the low-level details of these. My guess was that this bin file was compiled using this toolchain (i.e. xtensa-lx106-elf-g++.exe and xtensa...ld.exe) so that the objdump tool (provided by the same toolchain) would know about the structure of the produced file. \$\endgroup\$
    – YoavKlein
    Aug 11, 2021 at 8:40

1 Answer 1

0
\$\begingroup\$

-D is for disassemble -b bin tells objdump to expect a bin file

There may be ways to inject compiler/linker directives in Arduino, but I would not know. Platformio certainly does allow this, so you could get the asm as emitted from the compiler.

\$\endgroup\$
2
  • \$\begingroup\$ It gives me: "invalid bfd target". Any idea? \$\endgroup\$
    – YoavKlein
    Aug 11, 2021 at 7:49
  • \$\begingroup\$ the binary contains very little information. but since arduino either outputs, or is configurable to (additionally) output elf files, it would be better to use objdump on the elf file instead. For maximal understandability, make sure you turn off compiler optimizations and enable debug before compiling. \$\endgroup\$
    – moe fear
    Feb 27 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.