Issues with PIO debugger

I’m seeing issues with the platformio debugger during single stepping and where breakpoints are set.

Problem 1: After stopping on a breakpoint, single stepping after the breakpoint
will not advance to the next line of code. Further single steps appear to just resume code execution.

Problem 2: Sometimes I place a breakpoint and the line it stops on is a few lines down from the breakpoint.
At first I thought that the code wasn’t compiled for debugging,

I’m running platformio running on top of vscode.

Hardware:

  1. Raspberry pi pico
  2. Raspberry pi debug probe with latest .uf2 file.

platformio.ini:

[env:pico]
platform = raspberrypi
board = pico
framework = arduino
debug_tool = cmsis-dap
upload_protocol = cmsis-dap
build_type = debug
lib_deps = 
	arduino-libraries/LiquidCrystal@^1.0.7
	sstaub/Ticker@^4.4.0

Can you provide a minimal piece of code for which this happens and the exact sequence of actions you take to see this behavior?

For problem 1 (Problem 2 to be saved for later, one thing at a time)

  1. Set breakpoint on digitalRead(p2) in the source file main.cpp
  2. Compile code using Run->Start Debugging. Wait for the program to stop on the temporary breakpoint in .platformio/packages./framework-arduino-mbed/cores/arduino/main.cpp
  3. Press the continue button to execute the code to the set breakpoint at digitalRead(p2)
  4. Attempt to step over the breakpoint. The execution will not advance to digitalRead(p3). If you press continue again, the program starts running instead of stepping to the next statement.

For problem #1 here is the simple program

#include <Arduino.h>


uint64_t ms_ticks;

void setup() {
  // put your setup code here, to run once:
  digitalRead(p2);
  digitalRead(p3);
}

void loop() {
  digitalRead(p4);
  digitalRead(p5);
  digitalRead(p6);

  // put your main code here, to run repeatedly:
}

Here is the platformio.ini file to use with the above program.

Platformio.ini:

[env:pico]
platform = raspberrypi
board = pico
framework = arduino
debug_tool = cmsis-dap
upload_protocol = cmsis-dap
build_type = debug
lib_deps = 
	arduino-libraries/LiquidCrystal@^1.0.7
	sstaub/Ticker@^4.4.0

The program may be too simple and debug optimizations (-Og) still take place.

Can you please add

debug_build_flags = -O0 -ggdb3 -g3

and try the same debugging procedure again.

That combination of build flags resolved the single stepping issue.

Regarding the suggested switch settings:

-O0 basically turns optimization off in GCC which is fine for debugging.

-g3 Level 3 includes extra information, such as all the macro definitions present in the program.

-ggdb3 seems to be a duplicate of the -g3 switch unless you know something which is not present in the GCC docs.

Need to do further testing to see if it resolves the other issue of the break point not stopping on the line of code where the break point is set.

Thank you for your help. This was an immense improvement.