PlatformIO Community

Debugging with PlatformIO: Part 1. Back to the Basics

Debugging is an inseparable part of the development process. People make mistakes, so our code doesn’t do what we expect once in a while. Often such problems happen at the worst possible time. That’s why it’s a good idea to master debugging techniques and skills to more precisely isolate the source code of a problem and fix it in a timely manner.

In the Debugging with PlatformIO series, we will be exploring the debugging capabilities of the PlatformIO ecosystem. Read more :point_right:

4 Likes

Hi,
Thanks for this great article. It helps a lot. It works perfectly when I use Visual Studio Code but I get an popup window with an error message when I try to use the debugger with VSCodium.
The error message I am getting is :
Failed to load symbols from executable file: ENOENT: no such file or directory, scandir

I have not found a hit in google yet. Is there something particular I need to configure in VSCodium ?
Any suggestion on how to progress to fine what is wrong will be greatly appreciated.
Best regards
Bruno

PlatformIO is designed for Microsoft VSCode and has several issues with VSCode derivatives, e.g. per https://github.com/platformio/platformio-vscode-ide/issues/1802#issuecomment-930173774 for code intellisense.

If debugging is not working properly in some derivative, try opening an issue at https://github.com/platformio/platformio-vscode-ide/issues to get it tracked.

1 Like

This is a great article and it works perfectly for me. I have a question though…
I have a library project I have written which I include in many of my Arduino projects. I would now like to add unit tests to this library project, however I am confused about the use of src/include/lib folders. My library project uses src/include folders for the code. All the examples I have seen for creating unit tests require the source code to be in the lib folder. This implies either:

  1. I shouldnt be using the src/include folders for the code in my library project, I should put it in lib

…or…

  1. I can’t have unit tests in the same project as my library code. I.e. I must create a dedicated test project and copy the source code from my library project into the lib folder of the test project.

Could someone please clarify this for me.

Thanks a lot.

Could you share a link to your library?

I cant send a link because It is a private library. However my question was for a very simple generalised case, for any library written for Arduino. Assuming the src/include folders are being used for the library source files (multiple h/cpp files each for a class of single responsibility), is it possible to use the “test” folder in that same project to write unit tests for those classes? It seems I have to create a new project where the source for the system under test resides within the lib folder.

So my library project is structured like this (showing how I would LIKE the test folder to be used):

|--lib (empty, no external dependencies)
|--include
|  |- reader.h
|  |- writer.h
|--src
|  |- reader.cpp
|  |- writer.cpp
|--test
|  |- main.cpp
|  |- reader_tests.cpp
|  |- writer_tests.cpp

However it seems from all the examples that the structure has to be like this:

|--lib
|  |--my_library
|  |  |- reader.h
|  |  |- reader.cpp
|  |  |- writer.h
|  |  |- writer.cpp
|--include (empty)
|--src
|  |- main.cpp (entry for test)
|--test
|  |- reader_tests.cpp
|  |- writer_tests.cpp

which implies I cannot have the tests within the same project as my source.

Thanks again for your help.

For unit tests, the code in src/ is not compiled unless test_build_project_src = yes.

Code to be unit-tested should optimally be its own library.

Note the notes that the documentation has on this and the “Warning”.

1 Like