1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-17 11:54:33 +01:00

Redoing the error message parsing / handling. Now using Sketch.placeException() to map back to the sketch code files and line numbers. Showing more of the actual output of avr-gcc / avr-g++.

This commit is contained in:
David A. Mellis 2010-05-08 20:06:31 +00:00
parent 34579ae440
commit e5d56a1e59
4 changed files with 36 additions and 315 deletions

View File

@ -1442,7 +1442,7 @@ public class Sketch {
// first check to see if it's a .java file
for (int i = 0; i < getCodeCount(); i++) {
SketchCode code = getCode(i);
if (code.isExtension("java")) {
if (!code.isExtension(getDefaultExtension())) {
if (dotJavaFilename.equals(code.getFileName())) {
codeIndex = i;
codeLine = dotJavaLine;
@ -1452,7 +1452,7 @@ public class Sketch {
}
// If not the preprocessed file at this point, then need to get out
if (!dotJavaFilename.equals(name + ".java")) {
if (!dotJavaFilename.equals(name + ".cpp")) {
return null;
}
@ -1462,7 +1462,7 @@ public class Sketch {
for (int i = 0; i < getCodeCount(); i++) {
SketchCode code = getCode(i);
if (code.isExtension("pde")) {
if (code.isExtension(getDefaultExtension())) {
// System.out.println("preproc offset is " + code.getPreprocOffset());
// System.out.println("looking for line " + dotJavaLine);
if (code.getPreprocOffset() <= dotJavaLine) {

View File

@ -1,95 +0,0 @@
/*
* @(#)StreamRedirectThread.java 1.4 03/01/23
*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*
* Copyright (c) 1997-2001 by Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
package processing.app;
import java.io.*;
/**
* StreamRedirectThread is a thread which copies it's input to
* it's output and terminates when it completes.
*
* @version @(#) StreamRedirectThread.java 1.4 03/01/23 23:33:38
* @author Robert Field
*/
public class StreamRedirectThread extends Thread {
private final Reader in;
private final Writer out;
private static final int BUFFER_SIZE = 2048;
/**
* Set up for copy.
* @param name Name of the thread
* @param in Stream to copy from
* @param out Stream to copy to
*/
public StreamRedirectThread(String name, InputStream in, OutputStream out) {
super(name);
this.in = new InputStreamReader(in);
this.out = new OutputStreamWriter(out);
setPriority(Thread.MAX_PRIORITY-1);
}
public StreamRedirectThread(String name, Reader in, Writer out) {
super(name);
this.in = in;
this.out = out;
setPriority(Thread.MAX_PRIORITY-1);
}
/**
* Copy.
*/
public void run() {
try {
char[] cbuf = new char[BUFFER_SIZE];
int count;
//System.out.println("opening streamredirectthread");
while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) {
out.write(cbuf, 0, count);
// had to add the flush() here.. maybe shouldn't be using writer? [fry]
out.flush();
}
//System.out.println("exiting streamredirectthread");
out.flush();
} catch(IOException exc) {
System.err.println("Child I/O Transfer - " + exc);
}
}
}

View File

@ -326,142 +326,42 @@ public class Compiler implements MessageConsumer {
* and line number, which is then reported back to Editor.
*/
public void message(String s) {
// This receives messages as full lines, so a newline needs
// to be added as they're printed to the console.
//System.err.print(s);
int i;
// ignore cautions
if (s.indexOf("warning") != -1) return;
// ignore this line; the real error is on the next one
if (s.indexOf("In file included from") != -1) return;
// jikes always uses a forward slash character as its separator,
// so replace any platform-specific separator characters before
// attemping to compare
//
//String buildPathSubst = buildPath.replace(File.separatorChar, '/') + "/";
String buildPathSubst =
buildPath.replace(File.separatorChar,File.separatorChar) +
File.separatorChar;
String partialTempPath = null;
int partialStartIndex = -1; //s.indexOf(partialTempPath);
int fileIndex = -1; // use this to build a better exception
// check the main sketch file first.
partialTempPath = buildPathSubst + primaryClassName;
partialStartIndex = s.indexOf(partialTempPath);
if (partialStartIndex != -1) {
fileIndex = 0;
} else {
// wasn't there, check the other (non-pde) files in the sketch.
// iterate through the project files to see who's causing the trouble
for (int i = 0; i < sketch.getCodeCount(); i++) {
if (sketch.getCode(i).isExtension("pde")) continue;
partialTempPath = buildPathSubst + sketch.getCode(i).getFileName();
//System.out.println(partialTempPath);
partialStartIndex = s.indexOf(partialTempPath);
if (partialStartIndex != -1) {
fileIndex = i;
//System.out.println("fileIndex is " + fileIndex);
break;
}
}
//+ className + ".java";
}
// if the partial temp path appears in the error message...
//
//int partialStartIndex = s.indexOf(partialTempPath);
if (partialStartIndex != -1) {
// skip past the path and parse the int after the first colon
//
String s1 = s.substring(partialStartIndex +
partialTempPath.length() + 1);
//System.out.println(s1);
int colon = s1.indexOf(':');
if (s1.indexOf("In function") != -1 || colon == -1) {
System.err.print(s1);
//firstErrorFound = true;
return;
}
int lineNumber;
try {
lineNumber = Integer.parseInt(s1.substring(0, colon));
} catch (NumberFormatException e) {
System.err.print(s1);
return;
}
//System.out.println("pde / line number: " + lineNumber);
if (fileIndex == 0) { // main class, figure out which tab
for (int i = 1; i < sketch.getCodeCount(); i++) {
if (sketch.getCode(i).isExtension("pde")) {
//System.out.println("preprocOffset "+ sketch.getCode(i).getPreprocOffset());
if (sketch.getCode(i).getPreprocOffset() < lineNumber) {
fileIndex = i;
//System.out.println("i'm thinkin file " + i);
}
}
}
// XXX: DAM: if the lineNumber is less than sketch.getCode(0).getPreprocOffset()
// we shouldn't subtract anything from it, as the error is above the
// location where the function prototypes and #include "WProgram.h"
// were inserted.
lineNumber -= sketch.getCode(fileIndex).getPreprocOffset();
}
//String s2 = s1.substring(colon + 2);
int err = s1.indexOf(":");
if (err != -1) {
// if the first error has already been found, then this must be
// (at least) the second error found
if (firstErrorFound) {
secondErrorFound = true;
return;
}
// if executing at this point, this is *at least* the first error
firstErrorFound = true;
err += ":".length();
String description = s1.substring(err);
description = description.trim();
System.err.print(description);
//System.out.println("description = " + description);
//System.out.println("creating exception " + exception);
exception = new RunnerException(description, fileIndex, lineNumber-1, -1, false);
// NOTE!! major change here, this exception will be queued
// here to be thrown by the compile() function
//editor.error(exception);
} else {
System.err.println("i suck: " + s);
}
} else {
// this isn't the start of an error line, so don't attempt to parse
// a line number out of it.
// if the second error hasn't been discovered yet, these lines
// are probably associated with the first error message,
// which is already in the status bar, and are likely to be
// of interest to the user, so spit them to the console.
//
if (!secondErrorFound) {
System.err.println(s);
// 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);
// 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);
if (e != null) {
SketchCode code = sketch.getCode(e.getCodeIndex());
String fileName = code.isExtension(sketch.getDefaultExtension()) ? code.getPrettyName() : code.getFileName();
if (!verbose) s = fileName + ":" + e.getCodeLine() + ": error: " + e.getMessage();
if (exception == null) {
exception = e;
exception.hideStackTrace();
}
}
}
System.err.print(s);
}
/////////////////////////////////////////////////////////////////////////////

View File

@ -1,84 +0,0 @@
/*
* @(#)StreamRedirectThread.java 1.4 03/01/23
*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*
* Copyright (c) 1997-2001 by Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
package processing.app.debug;
import java.io.*;
/**
* StreamRedirectThread is a thread which copies it's input to
* it's output and terminates when it completes.
*
* @version @(#) StreamRedirectThread.java 1.4 03/01/23 23:33:38
* @author Robert Field
*/
public class StreamRedirectThread extends Thread {
private final Reader in;
private final Writer out;
private static final int BUFFER_SIZE = 2048;
/**
* Set up for copy.
* @param name Name of the thread
* @param in Stream to copy from
* @param out Stream to copy to
*/
public StreamRedirectThread(String name, InputStream in, OutputStream out) {
super(name);
this.in = new InputStreamReader(in);
this.out = new OutputStreamWriter(out);
setPriority(Thread.MAX_PRIORITY-1);
}
/**
* Copy.
*/
public void run() {
try {
char[] cbuf = new char[BUFFER_SIZE];
int count;
//System.out.println("opening streamredirectthread");
while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) {
out.write(cbuf, 0, count);
// had to add the flush() here.. maybe shouldn't be using writer? [fry]
out.flush();
}
//System.out.println("exiting streamredirectthread");
out.flush();
} catch(IOException exc) {
System.err.println("Child I/O Transfer - " + exc);
}
}
}