Debug ELF/Dwarf Binaries in VS Code without a Project or Build

Sometimes, all what I have is a ELF/Dwarf binary, and I need to debug it. I don’t want to build it, only debug it. The NXP VS Code extension makes that possible. I simply import the binary and start debugging.

Debugging Executable
Debugging Executable

Outline

This article describes how to import an embedded ELF/Dwarf (.elf or .axf) file without project for debugging. ELF/Dwarf files are the standard binaries for targets and cross development. They include the code. They also contain debug information if it has not been stripped.

For this, I use the ‘Import’ on an executable in VS Code. After that, I can debug it right away.

Prerequisites

Install the NXP extension into VS Code (extension identifier nxpsemiconductors.mcuxpresso or https://marketplace.visualstudio.com/items?itemName=NXPSemiconductors.mcuxpresso)

Import

Click on the NXP extension icon in the side bar and use ‘Import Project‘:

Import Project
Import Project

Executable

Then select ‘Executable‘:

Import Executable
Import Executable

Then browse to the ELF/Dwarf file you want to debug: In my case it is

c:\tmp\LPC55S16_blinky.elf

and it is detected as ‘executable’:

Executable file path
Executable file path

Next, I can specify a folder where VS Code can store the settings. I’m using the

c:\tmp\binary

location:

location to store the settings
location to store the settings

Toolchain

Next I specify the toolchain which includes the GDB for debugging:

Toolchain selection
Toolchain selection

Finally, press ‘Import’:

Import
Import

Debug

This creates an entry for the executable in the side view with a ‘debug/run’ icon I can use:

Debug Icon
Debug Icon

MCU Selection

Using the executable the first time, I get asked about what MCU I want to use:

MCU Selection

After this: I’m debugging that executable:

Debugging Executable
Debugging Executable

Assembly Level Debugging

Based on the debug information, VS code is using the source file information present in the ELF/Dwarf file. Ideally, I have the source files available. If not, I still can debug it on assembly level instruction level:

Assembly Level Debugging
Assembly Level Debugging

Summary

Using VS Code with the NXP MCUXpresso Extension, it is surprisingly easy to debug the binary. There’s no need to import or build project. All I need to do is point to the executable. Then, I select the toolchain for the GDB and device I want to use. This is very useful for a quick check of a binary on an embedded target board. All I need is the binary with VS Code. Then, I can start debugging it. If I have the sources available, I even can do source-level-debugging. Or I can debug on assembly instruction level.

Happy debugging 🙂

Links

7 thoughts on “Debug ELF/Dwarf Binaries in VS Code without a Project or Build

  1. To get to your “Debugging Executable” with the C source listing you still need the C source for the project, right? You just don’t have to build it to start debugging? And you’re saying even if you don’t have the original C source you can still debug on the assembly level? Or are you saying you can embed the C source code inside the debug executable itself? Sorry for my little bit of confusion, but this is very interesting to me.

    Like

    • Yes, for source level debugging you need one or more source files. The reason is that the ELF/Dwarf file does not contain the sources, but references them. So you would have to have them somewhere on your machine. So the source code itself is not baked into the executable, it is outside.
      I hope this makes it clear.

      Like

  2. Hello Erich,

    It works also when the *.elf file is not part of other project ? (and/or compiled outside of MCUXpresso infrastructure ?)

    Thanks!

    Like

    • Hi Andrei,
      yes. Any .elf file works. No dependency on any tool chains. The only dependency would be that the GDB used for debugging needs to be compatible with the ELF/Dwarf file used. But this is usually the case, unless you have a really weird tool chain.

      Like

  3. This only works if the elf file contains debug info, not all elf files contain this, maybe this is obvious, but was not explicitly stated, without debug info, you don’t get source level debugging, you only see assembly and branch to address, you don’t get function or variable names, call stack decoding and anything directly related to source code.

    Like

    • Yes, that’s correct. Having the debug information included is the norm in the embedded (MCU) space, as it is not the ELF file which is loaded on the target, but only the code/data of it.

      Like

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.