By default LTO (Link Time Optimization) of AVR GCC is enabled. On
atmega328p this remove most of the debugging data from the ELF file.
As a result avr-gdb can not be used fully.
For example lets take the simple Hello World application:
#include <Arduino.h>
void setup() {
Serial1.begin(9600);
}
void loop() {
Serial1.print("Hello World\n");
}
following output shows that nither Print.c nither the test_app.cpp
are writen in the ELF file as a referance to the source code for
debugging porpose (the code is compiled with -g):
$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
00000000 l df *ABS* 00000000 malloc.c
00000000 l df *ABS* 00000000
00000000 l df *ABS* 00000000 _clear_bss.o
00000000 l df *ABS* 00000000
00000000 l df *ABS* 00000000 realloc.c
00000000 l df *ABS* 00000000 _udivmodsi4.o
00000000 l df *ABS* 00000000 _exit.o
As a result this ELF file can not be used by GDB. It can not find the
source code of the currently executed code.
When we disable the LTO the output is:
$ avr-objdump -x build-a-star328PB/test_app.elf | grep df
00000000 l df *ABS* 00000000 test_app.cpp
00000000 l df *ABS* 00000000 Print.cpp
00000000 l df *ABS* 00000000 HardwareSerial.cpp
00000000 l df *ABS* 00000000 _clear_bss.o
00000000 l df *ABS* 00000000 main.cpp
00000000 l df *ABS* 00000000 wiring.c
00000000 l df *ABS* 00000000 new.cpp
00000000 l df *ABS* 00000000 _udivmodsi4.o
00000000 l df *ABS* 00000000 _exit.o
00000000 l df *ABS* 00000000
Now all source files are depicted by the ELF file. As a result avr-gdb
can use this ELF file for debugging. It depict the current source line.
Also the size of the .text section (Flash memory) is not optimiezed.
With LTO the simple Helloe World take 20264 bytes (.text). While the
build without LTO generate 3860 bytes (.text) for atmega328p.
This patch allow disabling of LTO by setting LTO=n. While keeping
LTO on by default.
Signed-off-by: Ivo Shopov <ivoshopov@gmail.com>
Find location of ard-reset-arduino before prefixing it with
PYTHON_CMD (so that 'which' failure can be detected). Also
display the resulting RESET_CMD, or user-provided RESET_CMD.
The Arduino IDE supports full usage of C++ (including the standard
library) on SAMD-based boards, so the final linking of the executable
must be done using the C++ compiler.
Closes#644.
As part of the big modularizing efforts of the Arduino project they
split out the hardware-independent layer of the Arduino "language"
from the hardware-specific cores into the dedicated 'ArduinoCore-API'
repository. As described in 'ArduinoCore-API's README, the API source
files won't reside directly in the directory of the standard Arduino
core, i.e. in 'ARDUINO_CORE_PATH', but in its 'ARDUINO_CORE_PATH/api'
subdirectory. Consequently, Arduino-Makefile won't be able to build
any projects when using an Arduino core following the new directory
structure.
Prepare for the upcoming new Arduino core directory structure by
building all 'ARDUINO_CORE_PATH/api/*.cpp' source files as well. Out
of caution, look out for and build any .c source files in that
directory, too: though there are no .c source files in the
'ArduinoCore-API' repository at the moment, in the future there might
be. Furthermore, add this directory to the list of directories to be
searched for header files: though it's not necessary to explicitly and
directly include any header file from this directory ('Arduino.h'
includes all there is), some projects might nonetheless do so, and
their build would then break.
Note that a 'make clean' will be most likely necessary when
re-building a project after switching to the new directory structure.
There is a bit of inconsistency between documentation and code
regarding the ARDUINO_QUIET variable: 'arduino-mk-vars.md' states
that ARDUINO_QUIET "Defaults to `0` (unset/disabled)", but the code
only checks whether it's defined or not, and doesn't check whether
it's set to '0' or something else.
Consequently, having 'ARDUINO_QUIET=0' in the Makefile or running
'make ARDUINO_QUIET=0' contadicts the documentation and doesn't print
the configuration. It also means that if someone in general prefers
not to see a screenful of configuration on each build and therefore
has 'ARDUINO_QUIET = 1' in the project's Makefile or 'config.mak',
then there is no way to override it from the command line in the odd
case when showing the configuration is desired.
Modify the corresponding condition in Arduino.mk to check whether
ARDUINO_QUIET is set to 0 and treat an undefined ARDUINO_QUIET
variable as "set to 0" as well.