PlatformIO Community

Using Debugger with Externally build binary

I’ve found PlatformIO while investigating if there is a way for the VSCode debugger to show disassembly, registers, or memory areas. And while the integrated debugging interfaces don’t seem to be able to do that, PlatformIO can. Unfortunately, the program I wish to debug is not a PlatformIO project (and this is beyond my control).

I did some initial tests, but in order to do anything, “pio debug” seems to require the platform, framework, and board fields to be set and also insists on building the project before attempting to debug, which of course is failing.

I was wondering if there is a way to still use the debugger-goodness in such a scenario where the project itself is not managed my PIO. Are my efforts in vain or is there possibly a way to achieve that?

As a fallback all of this is achievable in VSCode’s debug console using direct gdb commands.

  • info registers or short i r to show all register contents
  • x/10i $pc “examine 10 instructions starting at the current program counter” shows the next few instructions
  • disassemble main dissassembles the main() function
  • x/10x 0x1234567 “examine 10 hex words at an address” (address can also be substituted with &variable or buffer_variable)

See official gdb docs and some cheat sheets.

There also is an issue at about this, it’s relatively long, but maybe some other extension / method is recommended in there that helps you better than CLI commands.

pio debug pulls all the needed information out of the platformio.ini which references a platform, framework, board, build rules etc. etc., so it really needs a PlatformIO project as a base.

I’m thinking about a crude hack where you create a dummy PIO project but modify the GDB load commands to load a premade .elf file (which comes out of your project’s normal build process) and the source paths. That is anti-methodical to everything PlatformIO stands and is a Frankenstein monster, but may work. I’ll test it when I have some time.