Skip to content

Patches to fix various -W -Wall warnings, enabling -W -Wall flags, .map and .lst files, and more verbose size report #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
150 changes: 112 additions & 38 deletions app/src/processing/app/debug/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Compiler implements MessageConsumer {
String buildPath;
String primaryClassName;
boolean verbose;
PrintWriter outputFile = null;

RunnerException exception;

Expand Down Expand Up @@ -179,8 +180,25 @@ public boolean compile(Sketch sketch,
baseCommandLinker.add("-L" + buildPath);
baseCommandLinker.add("-lm");

if (Preferences.getBoolean("compiler.map_file"))
baseCommandLinker.add("-Wl,-Map," + sketch.getFolder() + File.separator + sketch.getName() + ".map");

execAsynchronously(baseCommandLinker);

// 4a. create the size output
if (Preferences.getBoolean("compiler.detailed_size")) {
List baseCommandsize = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-size",
"-C",
"--mcu=" + boardPreferences.get("build.mcu"),
buildPath + File.separator + primaryClassName + ".elf"//,
//" > ",
//sketch.getFolder() + File.separator + sketch.getName() + ".size"
}));

execAsynchronously(baseCommandsize);
}

List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-objcopy",
"-O",
Expand Down Expand Up @@ -210,6 +228,18 @@ public boolean compile(Sketch sketch,
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex");
execAsynchronously(commandObjcopy);

// 7. produce the .lst file
if (Preferences.getBoolean("compiler.lst_file")) {
List baseCommandObjdump = new ArrayList(Arrays.asList(new String[] {
avrBasePath + "avr-objdump",
"-d",
"-S",
buildPath + File.separator + primaryClassName + ".elf"
}));

execAsynchronously(baseCommandObjdump, sketch.getFolder() + File.separator + sketch.getName() + ".lst");
}

return true;
}

Expand Down Expand Up @@ -261,6 +291,14 @@ private List<File> compileFiles(String avrBasePath,
* Either succeeds or throws a RunnerException fit for public consumption.
*/
private void execAsynchronously(List commandList) throws RunnerException {
execAsynchronouslyFile (commandList, null);
}

private void execAsynchronously(List commandList, String outputFileName) throws RunnerException {
execAsynchronouslyFile (commandList, outputFileName);
}

private void execAsynchronouslyFile(List commandList, String outputFileName) throws RunnerException {
String[] command = new String[commandList.size()];
commandList.toArray(command);
int result = 0;
Expand All @@ -275,6 +313,19 @@ private void execAsynchronously(List commandList) throws RunnerException {
firstErrorFound = false; // haven't found any errors yet
secondErrorFound = false;

if (outputFileName != null)
{
try {
File filename = new File (outputFileName);
FileWriter fout = new FileWriter (filename);
outputFile = new PrintWriter (fout, true);
} catch (IOException e) {
RunnerException re = new RunnerException(e.getMessage());
re.hideStackTrace();
throw re;
}
}

Process process;

try {
Expand Down Expand Up @@ -321,9 +372,15 @@ private void execAsynchronously(List commandList) throws RunnerException {
re.hideStackTrace();
throw re;
}

if (outputFile != null)
{
outputFile.flush ();
outputFile.close ();
outputFile = null;
}
}


/**
* Part of the MessageConsumer interface, this is called
* whenever a piece (usually a line) of error message is spewed
Expand All @@ -333,49 +390,54 @@ private void execAsynchronously(List commandList) throws RunnerException {
public void message(String s) {
int i;

// remove the build path so people only see the filename
// can't use replaceAll() because the path may have characters in it which
// have meaning in a regular expression.
if (!verbose) {
while ((i = s.indexOf(buildPath + File.separator)) != -1) {
s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length());
if (outputFile != null)
outputFile.print (s);
else
{
// remove the build path so people only see the filename
// can't use replaceAll() because the path may have characters in it which
// have meaning in a regular expression.
if (!verbose) {
while ((i = s.indexOf(buildPath + File.separator)) != -1) {
s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length());
}
}
}

// look for error line, which contains file name, line number,
// and at least the first line of the error message
String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*";
String[] pieces = PApplet.match(s, errorFormat);

// look for error line, which contains file name, line number,
// and at least the first line of the error message
String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*";
String[] pieces = PApplet.match(s, errorFormat);

// if (pieces != null && exception == null) {
// exception = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);
// if (exception != null) exception.hideStackTrace();
// }

if (pieces != null) {
RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);

// replace full file path with the name of the sketch tab (unless we're
// in verbose mode, in which case don't modify the compiler output)
if (e != null && !verbose) {
SketchCode code = sketch.getCode(e.getCodeIndex());
String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName();
s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();

if (pieces != null) {
RunnerException e = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);

// replace full file path with the name of the sketch tab (unless we're
// in verbose mode, in which case don't modify the compiler output)
if (e != null && !verbose) {
SketchCode code = sketch.getCode(e.getCodeIndex());
String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName();
s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();
}

if (pieces[3].trim().equals("SPI.h: No such file or directory")) {
e = new RunnerException("Please import the SPI library from the Sketch > Import Library menu.");
s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." +
"\nYou appear to be using it or another library that depends on the SPI library.";
}

if (exception == null && e != null) {
exception = e;
exception.hideStackTrace();
}
}

if (pieces[3].trim().equals("SPI.h: No such file or directory")) {
e = new RunnerException("Please import the SPI library from the Sketch > Import Library menu.");
s += "\nAs of Arduino 0019, the Ethernet library depends on the SPI library." +
"\nYou appear to be using it or another library that depends on the SPI library.";
}

if (exception == null && e != null) {
exception = e;
exception.hideStackTrace();
}

System.err.print(s);
}

System.err.print(s);
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -411,13 +473,19 @@ static private List getCommandCompilerC(String avrBasePath, List includePaths,
"-c", // compile, don't link
"-g", // include debugging info (so errors include line numbers)
"-Os", // optimize for size
"-w", // surpress all warnings
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
"-mmcu=" + boardPreferences.get("build.mcu"),
"-DF_CPU=" + boardPreferences.get("build.f_cpu"),
"-DARDUINO=" + Base.REVISION,
}));

if (!Preferences.getBoolean("compiler.show_all_warnings"))
baseCommandCompiler.add("-w"); // suppress all warnings
else {
baseCommandCompiler.add("-W"); // show all warnings
baseCommandCompiler.add("-Wall"); // be aggressive with warnings
}

for (int i = 0; i < includePaths.size(); i++) {
baseCommandCompiler.add("-I" + (String) includePaths.get(i));
Expand All @@ -439,7 +507,6 @@ static private List getCommandCompilerCPP(String avrBasePath,
"-c", // compile, don't link
"-g", // include debugging info (so errors include line numbers)
"-Os", // optimize for size
"-w", // surpress all warnings
"-fno-exceptions",
"-ffunction-sections", // place each function in its own section
"-fdata-sections",
Expand All @@ -448,6 +515,13 @@ static private List getCommandCompilerCPP(String avrBasePath,
"-DARDUINO=" + Base.REVISION,
}));

if (!Preferences.getBoolean("compiler.show_all_warnings"))
baseCommandCompilerCPP.add("-w"); // suppress all warnings
else {
baseCommandCompilerCPP.add("-W"); // show all warnings
baseCommandCompilerCPP.add("-Wall"); // be aggressive with warnings
}

for (int i = 0; i < includePaths.size(); i++) {
baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i));
}
Expand Down
4 changes: 0 additions & 4 deletions hardware/arduino/cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ int HardwareSerial::read(void)

void HardwareSerial::flush()
{
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Print::write(const uint8_t *buffer, size_t size)

void Print::print(const String &s)
{
for (int i = 0; i < s.length(); i++) {
for (unsigned int i = 0; i < s.length(); i++) {
write(s[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/cores/arduino/WInterrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "WConstants.h"
#include "wiring_private.h"

volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;

void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/cores/arduino/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ String::String( const long value, const int base )
String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, 10);
ultoa(value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/cores/arduino/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class String
int lastIndexOf( char ch, unsigned int fromIndex ) const;
int lastIndexOf( const String &str ) const;
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
const unsigned int length( ) const { return _length; }
unsigned int length( ) const { return _length; }
void setCharAt(unsigned int index, const char ch);
unsigned char startsWith( const String &prefix ) const;
unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
Expand Down
66 changes: 33 additions & 33 deletions hardware/arduino/cores/arduino/pins_arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,50 +81,50 @@
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
&DDRA,
&DDRB,
&DDRC,
&DDRD,
&DDRE,
&DDRF,
&DDRG,
&DDRH,
(uint16_t) &DDRA,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
(uint16_t) &DDRF,
(uint16_t) &DDRG,
(uint16_t) &DDRH,
NOT_A_PORT,
&DDRJ,
&DDRK,
&DDRL,
(uint16_t) &DDRJ,
(uint16_t) &DDRK,
(uint16_t) &DDRL,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
&PORTA,
&PORTB,
&PORTC,
&PORTD,
&PORTE,
&PORTF,
&PORTG,
&PORTH,
(uint16_t) &PORTA,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
(uint16_t) &PORTF,
(uint16_t) &PORTG,
(uint16_t) &PORTH,
NOT_A_PORT,
&PORTJ,
&PORTK,
&PORTL,
(uint16_t) &PORTJ,
(uint16_t) &PORTK,
(uint16_t) &PORTL,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PIN,
&PINA,
&PINB,
&PINC,
&PIND,
&PINE,
&PINF,
&PING,
&PINH,
(uint16_t) &PINA,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
(uint16_t) &PINF,
(uint16_t) &PING,
(uint16_t) &PINH,
NOT_A_PIN,
&PINJ,
&PINK,
&PINL,
(uint16_t) &PINJ,
(uint16_t) &PINK,
(uint16_t) &PINL,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
Expand Down
16 changes: 8 additions & 8 deletions hardware/arduino/cores/arduino/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
#define TIMER5C 16

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t SS = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK = 52;
static const uint8_t SS = 53;
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK = 52;
#else
const static uint8_t SS = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK = 13;
static const uint8_t SS = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK = 13;
#endif

// On the ATmega1280, the addresses of some of the port registers are
Expand Down
Loading