A known issue when PlatformIO rebuilds the project every time when the user flashes the board in the release mode and later starts debugging.
Replace
BUILD_DIR = os.path.join("$PROJECT_BUILD_DIR", "$PIOENV")
to
BUILD_DIR = os.path.join("$PROJECT_BUILD_DIR", "$PIOENV", "$BUILD_TYPE")
A known issue when PlatformIO rebuilds the project every time when the user flashes the board in the release mode and later starts debugging.
Replace
to