show contiki stack trace in error dialog, not just print to console

This commit is contained in:
fros4943 2010-02-21 21:50:58 +00:00
parent 5e6fd67213
commit dbd1cd7b08
3 changed files with 70 additions and 12 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MspMote.java,v 1.41 2010/02/03 19:08:40 fros4943 Exp $
* $Id: MspMote.java,v 1.42 2010/02/21 21:51:50 fros4943 Exp $
*/
package se.sics.cooja.mspmote;
@ -44,6 +44,7 @@ import java.util.Observable;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.ContikiError;
import se.sics.cooja.GUI;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
@ -343,13 +344,9 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
myCpu.stepMicros(t - lastExecute, duration);
lastExecute = t;
} catch (EmulationException e) {
if (e.getMessage().startsWith("Bad operation")) {
/* Experimental: print program counter history */
/*sendCLICommandAndPrint("trace 1000");*/ /* TODO Enable */
}
throw (RuntimeException)
new RuntimeException("Emulated exception: " + e.getMessage()).initCause(e);
String stackTraceOutput = sendCLICommandAndPrint("stacktrace");
throw (ContikiError)
new ContikiError(stackTraceOutput).initCause(e);
}
/* Schedule wakeup */
@ -376,15 +373,19 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
}*/
}
private void sendCLICommandAndPrint(String cmd) {
private String sendCLICommandAndPrint(String cmd) {
final StringBuilder sb = new StringBuilder();
LineListener tmp = new LineListener() {
public void lineRead(String line) {
logger.fatal(line);
sb.append(line + "\n");
}
};
commandListeners.add(tmp);
sendCLICommand(cmd);
commandListeners.remove(tmp);
return sb.toString();
}
public int getID() {

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of the
* Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: ContikiError.java,v 1.1 2010/02/21 21:50:58 fros4943 Exp $
*/
package se.sics.cooja;
public class ContikiError extends RuntimeException {
private static final long serialVersionUID = -6841448235846874865L;
String contikiError;
public ContikiError(String message) {
super();
this.contikiError = message;
}
public String getContikiError() {
return contikiError;
}
}

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: GUI.java,v 1.159 2010/02/03 15:49:25 fros4943 Exp $
* $Id: GUI.java,v 1.160 2010/02/21 21:51:24 fros4943 Exp $
*/
package se.sics.cooja;
@ -3654,6 +3654,17 @@ public class GUI extends Observable {
Box buttonBox = Box.createHorizontalBox();
if (exception != null) {
/* Contiki error */
if (exception instanceof ContikiError) {
String contikiError = ((ContikiError) exception).getContikiError();
MessageList list = new MessageList();
for (String l: contikiError.split("\n")) {
list.addMessage(l);
}
list.addPopupMenuItem(null, true);
tabbedPane.addTab("Contiki error", new JScrollPane(list));
}
/* Compilation output */
MessageList compilationOutput = null;
if (exception instanceof MoteTypeCreationException
@ -3666,7 +3677,7 @@ public class GUI extends Observable {
}
if (compilationOutput != null) {
compilationOutput.addPopupMenuItem(null, true);
tabbedPane.addTab("Compilation output", null, new JScrollPane(compilationOutput), null);
tabbedPane.addTab("Compilation output", new JScrollPane(compilationOutput));
}
/* Stack trace */
@ -3674,7 +3685,7 @@ public class GUI extends Observable {
PrintStream printStream = stackTrace.getInputStream(MessageList.NORMAL);
exception.printStackTrace(printStream);
stackTrace.addPopupMenuItem(null, true);
tabbedPane.addTab("Java stack trace", null, new JScrollPane(stackTrace), null);
tabbedPane.addTab("Java stack trace", new JScrollPane(stackTrace));
/* Exception message */
buttonBox.add(Box.createHorizontalStrut(10));