Debugging ESP8266 with GDBStub, and: How can I add extra parameters to (autogenerated) launch configurations?

(Sorry for “double” title, but it feels like XY problem a bit so I want to broad the context of my issue, which I do believe could be partially solved if I know answer to second part of the title)

I am working on debugging my ESP8266 with GDBStub and I noticed few annoying behaviours. Of course, the debugging experience being poor is also because of platform/hardware, not only PlatformIO, but here I am. Configuration to make it work is a bit non-standard but it works for me for the most part.

My project repo (if some files are required to insight or if anyone is interested): GitHub - AgainPsychoX/TestGDBStubForESP8266

Main problem:

  1. Cannot send data to serial.

    If I start normal serial monitor, I can pass data to serial output to interact with my app running on the embedded system. Even compiled with debugger symbols and with GDBStub breaks - which still block execution (because current ESP8266 core GDBStub implementation doesn’t have “soft” attached mode), but can be dismissed with $D#44 (without quotes):

    image

    Anyway, the point is I can’t send data while debugging in VS Code (or GDB): it just ignores everything I write OR it sends it to GDB (as command). I found potential solution: add "console": "externalTerminal" or "internalTerminal", that will hopefully open the serial console in other terminal(?).

    Problem is, the launch.json is auto-generated, so I can’t permanently change it… :confused: Is there some override system I missed? Or is there some expected way to send the data to serial port from GDB I missed?

  2. Arduino Serial.prints are mangled into separate lines, which makes it harder to read. In large amount of prints and fast rate it’s A LOT less readable.

    Executing code:

    	Serial.print(F("Hello "));
    	Serial.print(F("again!\n"));
    

    in the “Debug Console” looks like:

    image

Other things that might be related to PlatformIO, which are not important issues, but worth noticing here:

  1. There is no way to automatically discovery of debug port, as there is for monitor/upload port. I need manually specify it in platformio.ini or type target remote \\\\.\\COM13 or target remote \\.\COM13. I wish there was some method to automate it properly.

  2. Using debug_init_break makes this first breakpoint (if set) skipped anyway… Very weird. I have workaround: set debug_init_break = # (empty), and add manually command to debug_init_cmds. Not that much annoying its just one more line in the config anyway :wink:

  3. Every time I press “PIO Debug” the code is reuploaded, even despite I set debug_load_mode = modified. It doesn’t happen in project I linked, but in other a bit more complex it does. I will try find dig into it this or next weekend tho.

  4. Hitting software breakpoint (call to gdb_do_break()) opens up in void app_entry(void) in core_esp8266_main.cpp. It’s weird and only a bit annoying. In other languages there seem to be some parameters to skip/hide some elements in call stack, but it looks like specific debugger extension so I don’t know… Pointless to spend time on it I guess.

Anyway, I would be really welcome for any feedback.

Agree, GDB debugging is possible to some extent but not even close to jtag om esp32. I used this documentation that also adresses some of the cveats and limitations that you desctribe . In particular the lauch.json override, not being able to detect the COM port, etc, are a nuissance.
I have no real workarounds or suggestions I am afraid. Hope that someone at some point in time will make a better solution…