Disassembling objects and executables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Disassembling objects and executables

6,304 Views
lpcware-support
Senior Contributor I

It is sometime useful to be able to view the assembly instructions generated by the compilation tools. There are a number of ways of doing this.

Disassembling using the GUI


First of all open out the project within the Project Explorer, so that you can see the files and directories within it. Assuming a default project structure, and that a build has alread occured,  two of these directories will be Debug and Release - matching the project's build configurations. Navigate into the directory matching the build configuration you are currently using.

Now if you want to disassemble the complete executable, look for the file with the .axf file extension (Arm eXecutable File), and right click over it. In the context sensitive menu that is then displayed, highlight "Binary Utilities->Disassemble". The GUI will then invoke the GNU objdump utility to generate a disassembly file, which will be launched into the editor view.

If you want to disassemble a particular source file, rather than the whole executable, open the "src" subdirectory of the Debug (or Release) directory of your project, and right click over the appropriate .o file, and then highlight "Binary Utilities->Disassemble".

Including source information


It is possible to change the default options used by the disassembler so that the assembly instructions are interleaved with the source statements. To do this,

  1. Go to Window->Preferences
  2. Select LPCXpresso
  3. Select Utilities.
  4. Add -S to the 'disassemble command'.

However, be warned that for each level of optimization beyond -O0, then the link between assembler and C source becomes more tenuous as the compiler will remove, reorder and optimize the generated code.

Automatically disassembling every build


It is also possible to automatically create a disassembly of your application every time you carry out a (successful) build (with source information included if required). Details of how to do this can be found in the FAQ Post-processing your linked application.

Automatically disassembling every object file


Sometimes you may want to create a disassembly of each generated object file each time that you carry out a build. To do this...

  1. Go to Project Properties
  2. Select C/C++ Build - Settings
  3. Select MCU C Compiler - Miscellaneous
  4. Add the following into the flag field:
    • -Wa,-ahlnds=${OutputFileBaseName}.asm

This will then generate the interleaved source/asm file during the build for each source file.

Note that the "," (comma) character is required. The -Wa is an option to the compiler which tells it to pass the following command to the assembler (the -ahlnds).

Alternatively, you can add the -save-temps to the miscellaneous compiler options. This will cause the compiler to leave the temporary .i (preprocessed source) and .s (assembler listing) files that it creates during a build in your build directory.

Disassembly during debugging


It is also possible to see the disassembly of your code whilst debugging. For more details see:

Labels (1)
Tags (2)
2 Replies

3,689 Views
aberger
Contributor V

Is there any documentation on how to read the generated .asm file, or what the -ahlnds means? (I couldn't find this command mentioned in the GCC documentation).

0 Kudos
Reply

3,671 Views
ErichStyger
Specialist I

See https://mcuoneclipse.com/2018/07/08/creating-disassembly-listings-with-gnu-tools-and-eclipse/, it explains the -a option and has a link to the GNU gcc documentation.

0 Kudos
Reply