This documents includes some useful tools and how to use them for development and debugging.
Most of these tools print output in terminal, which can be problematic if the output is large or you want to save it.
For inspecting the contents and discarding the result I just pipe the output into less:
<command> <options> <input file> | less
For saving file, you can redirect the output into a new file:
<command> <options> <input file> > outputFile.txt
NOTE: >
redirection will overwrite the file. If you want to append to it, use >>
.
This tool is used to view contents of object files, such as .o
and .elf
.The arm toolchain provides arm-none-eabi-objdump
.
In context of executable .elf
, this can be used to disassemble a section or the entire file. With this tool you can inspect the assembly and state of sections and variables.
Command:
arm-none-eabi-objdump <options> <file.[elf/o]>
Options:
-d
: disassemble all "runnable" sections (code)-D
: disassemble all sections (code and data)-j <section name>
: used along with-d/D
will display only a selected section-C
: demangle symbol names (C++)-h
: view only headers (used alone without other options)
Dump a specific section (example: .rodata):
arm-none-eabi-objdump -D -j .rodata -C ./firmware.bin
Dump the entire file:
arm-none-eabi-objdump -D -C ./firmware.bin
View section headers:
arm-none-eabi-objdump -h ./firmware.bin
This tool is similar in function to objdump
but displays a bit more information. It is also limited to .elf
files. The arm toolchain provides arm-none-eabi-readelf
.
Command:
arm-none-eabi-readelf <options> <file.elf>
Options:
-h
: display ELF file header (file information)-S
: display sections (a bit nicer thanobjdump -h
, but missing some information)-s
: display all symbols (functions, global variables)-C
: demangle symbol names (C++), used with-s
-x <section name>
: hexdumps the section contents (4 groups of 4 byte strings per line)-p <section name>
: stringdumps the section contents
View file information:
arm-none-eabi-readelf -h ./firmware.elf
View sections headers:
arm-none-eabi-readelf -S -C ./firmware.elf
View all symbols:
arm-none-eabi-readelf -s -C ./firmware.elf
Hexdump section:
arm-none-eabi-readelf -x .rodata ./firmware.elf
Stringdump section:
arm-none-eabi-readelf -p .rodata ./firmware.elf
Hexdump is used to view and filter raw contents of a file. The output format can be changed. The utility is not specific to arm toolchain and can be found on most linux distributions already installed.
It doesn't do much, therefore it doesn't have as many options, so I use it mainly for viewing bin files:
hexdump -C <file.bin>
This command will display output in hex (two characted per byte, 16 bytes per line) as well as ascii (similar to objdump with -x
).