From dbd1cd7b087902290ef056b7ab07ec39430b4fce Mon Sep 17 00:00:00 2001 From: fros4943 Date: Sun, 21 Feb 2010 21:50:58 +0000 Subject: [PATCH] show contiki stack trace in error dialog, not just print to console --- .../src/se/sics/cooja/mspmote/MspMote.java | 19 ++++---- .../java/se/sics/cooja/ContikiError.java | 46 +++++++++++++++++++ tools/cooja/java/se/sics/cooja/GUI.java | 17 +++++-- 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 tools/cooja/java/se/sics/cooja/ContikiError.java diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index f0a690399..b4b76368a 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -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() { diff --git a/tools/cooja/java/se/sics/cooja/ContikiError.java b/tools/cooja/java/se/sics/cooja/ContikiError.java new file mode 100644 index 000000000..487fa2a62 --- /dev/null +++ b/tools/cooja/java/se/sics/cooja/ContikiError.java @@ -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; + } +} diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index abd706975..d394f5eac 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -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));