Help for setup Debugging Arduino Uno env

Hi,
I follow the avr-stub instructions and I can’t run debug mode.
I have two problems.
The first is on my project. If I compile it with the debug env, I have the error fatal with Arduino library inside my libs :

src/main.cpp:1:10: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://platformio.org/lib/search?query=header:Arduino.h
*
*****************************************************************

 #include <Arduino.h>
          ^~~~~~~~~~~
compilation terminated.
Compiling .pio/build/unodebug/lib100/LogsFunctions/LogsFunctions.o
Compiling .pio/build/unodebug/lib8c9/ThermometreFunctions/ThermometreFuncitons.o
Compiling .pio/build/unodebug/lib364/TimeFunctions/TimeFunctions.o
*** [.pio/build/unodebug/src/main.o] Error 1
Indexing .pio/build/unodebug/libd8e/libavr-debugger.a
lib/KeysFunctions/KeysFunctions.cpp:3:10: fatal error: Arduino.h: No such file or directory

So I created a simple test project (blink Led) to test my configuration and this too does not work. The compilation is done, but I have an error.

ScreenShot 11

I see that it is a problem with the launch of the GDB, but I do not find in the doc what to do. Apart from the platformio.ini configuration, I don’t see anything else in the doc.
In this site he talks about turning off the Optimizations. But I don’t understand about where avr-debugger folder mentioned. I don’t see any platform.local.txt and C++ (GDB/LLDB) is not listed in vscode.

My platformio.ini

[env:uno]
platform = atmelavr
framework = arduino
board = uno
lib_deps = jdolinay/avr-debugger@^1.4

[env:unodebug]
platform = atmelavr
board = uno
debug_tool = avr-stub
debug_port = /dev/ttyUSB0
; Set breakpoint mode
build_flags =
  -DAVR8_BREAKPOINT_MODE=2
lib_deps = jdolinay/avr-debugger@^1.4

My main.cpp

#include <Arduino.h>

#include "app_api.h"  // only needed with flash breakpoints
#include "avr8-stub.h"
void setup() {
    // initialize GDB stub
    debug_init();
    // initialize LED digital pin as an output.
    pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
    // turn the LED on (HIGH is the voltage level)
    digitalWrite(LED_BUILTIN, HIGH);
    // wait for a second
    delay(1000);
    // turn the LED off by making the voltage LOW
    digitalWrite(LED_BUILTIN, LOW);
    // wait for a second
    delay(1000);
}

You have not specified framework = arduino in the debug environment of your platformio.ini.

Effectively, I forgot framework. This compiles greater the debug env…

But the problem with the launch GDB is not resolved

Try to consolidate everything into one platformio.ini, it might have problems selecting the correct environemnt for debugging.

[env:uno]
platform = atmelavr
framework = arduino
board = uno
debug_tool = avr-stub
debug_port = /dev/ttyUSB0
lib_deps = jdolinay/avr-debugger@^1.4

(the debug_* directives won’t have any effect during normal compilation).

Then use the project environment switcher to switch to the uno enviornment and try again.

If that still does not work, post the output of the “Debug Console” tab.

Nothing has change :confused:

========================= [SUCCESS] Took 4.98 seconds =========================
undefinedPython Exception <type 'exceptions.ImportError'> No module named gdb: 

warning: 
Could not load the Python gdb module from `/Users/jenkins/jenkins/workspace/avr-gcc-staging/label/mac-mini/objdir/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.

Reading symbols from /Users/kiwi/pCloud Drive/Programming/Arduino/debugTest/.pio/build/uno/firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = avr-stub

I don’t know what is the path /Users/jenkins/jenkins/workspace but is not on my OS

Jenkins is a build server tool used to automate the building of binaries. GDB was build that way, and so the compiled binary refers to a path it has seen at compile time on the build system. Not sure whether the python error is integretal to this though.

Just to make sure this isn’t a path problem, can you create the project in a path that contains no spaces? E.g., /Users/kiwi/debugTest. There have been problems where that was the core issue.

Otherwise I’ll have you manually invoke avr-gdb and the initialization commands to check what’s going on after that.

Yes, I can compile fine, upload in Arduino and export firmware.hex for using in Proteus

Does it debug correctly when the project is in a path with no spaces?

Indeed, I had not noticed the space. But no, it does not influence.

========================= [SUCCESS] Took 4.47 seconds =========================
undefinedPython Exception <type 'exceptions.ImportError'> No module named gdb: 

warning: 
Could not load the Python gdb module from `/Users/jenkins/jenkins/workspace/avr-gcc-staging/label/mac-mini/objdir/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.

Reading symbols from /Users/kiwi/Documents/PlatformIO/Projects/211210-092201-arduino-blink/.pio/build/uno/firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = avr-stub
PlatformIO: Initializing remote target...
.pioinit:13: Error in sourced command file:
/dev/ttyUSB0: No such file or directory.

Hold up – you are on Mac, not Linux. Pretty sure /dev/ttyUSB0 is not a thing there and you’re just giving the wrong serial port. Open a CLI and execute pio device list. What device names does it show?

1 Like