From 4222d0adcdd485609e080311fc54d4f7a8ecbb9a Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Wed, 28 Mar 2012 14:44:59 +0200 Subject: [PATCH] bugfixed parsing of files read from mspsim --- .../src/se/sics/cooja/mspmote/MspMote.java | 9 +-- .../se/sics/cooja/mspmote/MspMoteType.java | 62 ++++++++++--------- 2 files changed, 34 insertions(+), 37 deletions(-) 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 ecc77fafa..1e0662046 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 @@ -36,7 +36,6 @@ import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Observable; @@ -582,9 +581,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc /* Match file */ Hashtable lineTable = debuggingInfo.get(file); if (lineTable == null) { - Enumeration fileEnum = debuggingInfo.keys(); - while (fileEnum.hasMoreElements()) { - File f = fileEnum.nextElement(); + for (File f: debuggingInfo.keySet()) { if (f != null && f.getName().equals(file.getName())) { lineTable = debuggingInfo.get(f); break; @@ -598,9 +595,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc /* Match line number */ Integer address = lineTable.get(lineNr); if (address != null) { - Enumeration lineEnum = lineTable.keys(); - while (lineEnum.hasMoreElements()) { - Integer l = lineEnum.nextElement(); + for (Integer l: lineTable.keySet()) { if (l != null && l.intValue() == lineNr) { /* Found line address */ return lineTable.get(l); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java index c55ef47bb..324132ee3 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteType.java @@ -317,7 +317,7 @@ public abstract class MspMoteType implements MoteType { logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial"); intfClass = MspSerial.class.getName(); } - + Class moteInterfaceClass = simulation.getGUI().tryLoadClass(this, MoteInterface.class, intfClass); @@ -368,7 +368,7 @@ public abstract class MspMoteType implements MoteType { private static ELF loadELF(String filepath) throws IOException { return ELF.readELF(filepath); } - + private ELF elf; /* cached */ public ELF getELF() throws IOException { if (elf == null) { @@ -379,9 +379,9 @@ public abstract class MspMoteType implements MoteType { } return elf; } - + private Hashtable> debuggingInfo = null; /* cached */ - public Hashtable> getFirmwareDebugInfo() + public Hashtable> getFirmwareDebugInfo() throws IOException { if (debuggingInfo == null) { debuggingInfo = getFirmwareDebugInfo(getELF()); @@ -407,33 +407,35 @@ public abstract class MspMoteType implements MoteType { for (int address: addresses) { DebugInfo info = elf.getDebugInfo(address); - - if (info != null && info.getPath() != null && info.getFile() != null && info.getLine() >= 0) { - - /* Nasty Cygwin-Windows fix */ - String path = info.getPath(); - if (path.contains("/cygdrive/")) { - int index = path.indexOf("/cygdrive/"); - char driveCharacter = path.charAt(index+10); - - path = path.replace("/cygdrive/" + driveCharacter + "/", driveCharacter + ":/"); - } - - File file = new File(path, info.getFile()); - try { - file = file.getCanonicalFile(); - } catch (IOException e) { - } catch (java.security.AccessControlException e) { - } - - Hashtable lineToAddrHash = fileToLineHash.get(file); - if (lineToAddrHash == null) { - lineToAddrHash = new Hashtable(); - fileToLineHash.put(file, lineToAddrHash); - } - - lineToAddrHash.put(info.getLine(), address); + if (info == null) { + continue; } + if (info.getPath() == null && info.getFile() == null) { + continue; + } + if (info.getLine() < 0) { + continue; + } + + File file; + if (info.getPath() != null) { + file = new File(info.getPath(), info.getFile()); + } else { + file = new File(info.getFile()); + } + try { + file = file.getCanonicalFile(); + } catch (IOException e) { + } catch (java.security.AccessControlException e) { + } + + Hashtable lineToAddrHash = fileToLineHash.get(file); + if (lineToAddrHash == null) { + lineToAddrHash = new Hashtable(); + fileToLineHash.put(file, lineToAddrHash); + } + + lineToAddrHash.put(info.getLine(), address); } return fileToLineHash;