experimental: removed objdump dependency

This commit is contained in:
fros4943 2008-03-19 17:27:35 +00:00
parent 759b98d05c
commit f659204238

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MspCodeWatcher.java,v 1.4 2008/03/19 15:26:18 fros4943 Exp $ * $Id: MspCodeWatcher.java,v 1.5 2008/03/19 17:27:35 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote.plugins; package se.sics.cooja.mspmote.plugins;
@ -37,9 +37,7 @@ import java.awt.event.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.basic.BasicComboBoxRenderer; import javax.swing.plaf.basic.BasicComboBoxRenderer;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -74,7 +72,7 @@ public class MspCodeWatcher extends VisPlugin {
private JLabel filenameLabel; private JLabel filenameLabel;
private Vector<File> files; private Vector<File> sourceFilesAlpha;
private JComboBox fileComboBox; private JComboBox fileComboBox;
/** /**
@ -110,27 +108,25 @@ public class MspCodeWatcher extends VisPlugin {
JPanel controlPanel = new JPanel(); JPanel controlPanel = new JPanel();
// Extract files found in debugging info /* Create source file list */
files = new Vector<File>(); File[] sourceFiles = getAllSourceFileNames();
Enumeration fileEnum = debuggingInfo.keys(); sourceFilesAlpha = new Vector<File>();
while (fileEnum.hasMoreElements()) { for (File file: sourceFiles) {
File file = (File) fileEnum.nextElement(); /* Insert files alphabetically */
// Insert file on correct position
int index = 0; int index = 0;
for (index=0; index < files.size(); index++) { for (index=0; index < sourceFilesAlpha.size(); index++) {
if (file.getName().compareToIgnoreCase(files.get(index).getName()) < 0) { if (file.getName().compareToIgnoreCase(sourceFilesAlpha.get(index).getName()) < 0) {
break; break;
} }
} }
files.add(index, file); sourceFilesAlpha.add(index, file);
} }
String[] fileNames = new String[files.size() + 1]; String[] sourceFilesAlphaArray = new String[sourceFilesAlpha.size() + 1];
fileNames[0] = "[view sourcefile]"; sourceFilesAlphaArray[0] = "[view sourcefile]";
for (int i=0; i < files.size(); i++) { for (int i=0; i < sourceFilesAlpha.size(); i++) {
fileNames[i+1] = files.get(i).getName(); sourceFilesAlphaArray[i+1] = sourceFilesAlpha.get(i).getName();
} }
fileComboBox = new JComboBox(fileNames); fileComboBox = new JComboBox(sourceFilesAlphaArray);
fileComboBox.setSelectedIndex(0); fileComboBox.setSelectedIndex(0);
fileComboBox.addActionListener(new ActionListener() { fileComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -145,7 +141,7 @@ public class MspCodeWatcher extends VisPlugin {
setBackground(list.getSelectionBackground()); setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground()); setForeground(list.getSelectionForeground());
if (index > 0) { if (index > 0) {
list.setToolTipText(files.get(index-1).getPath()); list.setToolTipText(sourceFilesAlpha.get(index-1).getPath());
} }
} else { } else {
setBackground(list.getBackground()); setBackground(list.getBackground());
@ -216,7 +212,7 @@ public class MspCodeWatcher extends VisPlugin {
return; return;
} }
File selectedFile = files.get(index-1); File selectedFile = sourceFilesAlpha.get(index-1);
Vector<String> codeData = readTextFile(selectedFile); Vector<String> codeData = readTextFile(selectedFile);
codeUI.displayNewCode(selectedFile, codeData, -1); codeUI.displayNewCode(selectedFile, codeData, -1);
codeFile = null; codeFile = null;
@ -577,6 +573,9 @@ public class MspCodeWatcher extends VisPlugin {
// Try locate source file // Try locate source file
File oldCodeFile = codeFile; File oldCodeFile = codeFile;
updateCurrentSourceCodeFile(); updateCurrentSourceCodeFile();
if (codeFile == null) {
return;
}
// If found and not already loaded, load source file // If found and not already loaded, load source file
if (oldCodeFile == null || !oldCodeFile.getPath().equals(codeFile.getPath())) { if (oldCodeFile == null || !oldCodeFile.getPath().equals(codeFile.getPath())) {
@ -609,10 +608,19 @@ public class MspCodeWatcher extends VisPlugin {
codeFile = null; codeFile = null;
try { try {
DebugInfo debugInfo = mspMote.myELFModule.getDebugInfo(mspMote.getCPU().reg[MSP430.PC]); DebugInfo debugInfo = mspMote.getELF().getDebugInfo(mspMote.getCPU().reg[MSP430.PC]);
if (debugInfo == null) {
return;
}
/* Nasty Cygwin-Windows fix */ /* Nasty Cygwin-Windows fix */
String path = debugInfo.getPath(); String path = debugInfo.getPath();
if (path == null) {
return;
}
if (path.contains("/cygdrive/")) { if (path.contains("/cygdrive/")) {
int index = path.indexOf("/cygdrive/"); int index = path.indexOf("/cygdrive/");
char driveCharacter = path.charAt(index+10); char driveCharacter = path.charAt(index+10);
@ -624,89 +632,75 @@ public class MspCodeWatcher extends VisPlugin {
lineNumber = debugInfo.getLine(); lineNumber = debugInfo.getLine();
} catch (Exception e) { } catch (Exception e) {
logger.fatal(e); logger.fatal("Exception: " + e);
codeFile = null; codeFile = null;
lineNumber = -1; lineNumber = -1;
} }
} }
private Hashtable<File, Hashtable<Integer, Integer>> getFirmwareDebugInfo() { private File[] getAllSourceFileNames() {
return getFirmwareDebugInfo(moteType.getELFFile()); String[] sourceFiles = mspMote.getELF().debug.getSourceFiles();
} Vector<File> files = new Vector<File>();
/** for (String sourceFile: sourceFiles) {
* Tries to read debugging information from firmware file using objdump. /* Nasty Cygwin-Windows fix */
* if (sourceFile.contains("/cygdrive/")) {
* @return Hashtable with debugging information int index = sourceFile.indexOf("/cygdrive/");
*/ char driveCharacter = sourceFile.charAt(index+10);
public static Hashtable<File, Hashtable<Integer, Integer>> getFirmwareDebugInfo(File firmware) { sourceFile = sourceFile.replace("/cygdrive/" + driveCharacter + "/", driveCharacter + ":/");
Hashtable<File, Hashtable<Integer, Integer>> debuggingInfo =
new Hashtable<File, Hashtable<Integer, Integer>>();
Hashtable<Integer, Integer> currentHashtable = null;
try {
String[] cmd = new String[]{
"objdump",
"-g",
firmware.getPath()
};
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input =
new BufferedReader(
new InputStreamReader(
p.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
line = line.trim();
/* Check for new source file */
if (line.endsWith(":")) {
String fileName = line.substring(0, line.length()-1);
fileName = fileName.replace("/cygdrive/c/", "c:/");
currentHashtable = null;
// Try path unchanged
File file = new File(fileName);
if (currentHashtable == null && file.exists()) {
currentHashtable = new Hashtable<Integer, Integer>();
debuggingInfo.put(file, currentHashtable);
}
// Try adding firmwarepath
file = new File(firmware.getParent(), fileName);
if (currentHashtable == null && file.exists()) {
currentHashtable = new Hashtable<Integer, Integer>();
debuggingInfo.put(file, currentHashtable);
}
if (currentHashtable == null) { // TODO Currently always true
logger.warn("Can't locate file: " + fileName);
}
}
/* Check for source file line info */
if (currentHashtable != null && line.startsWith("/* file ")) {
String[] lineInfo = line.split(" ");
String lineNrString = lineInfo[lineInfo.length-4];
String addressString = lineInfo[lineInfo.length-2];
int lineNr = Integer.parseInt(lineNrString);
int address = Integer.parseInt(addressString.substring(2), 16);
currentHashtable.put(new Integer(lineNr), new Integer(address));
}
} }
input.close(); File file = new File(sourceFile);
if (!file.exists() || !file.isFile()) {
} catch (Exception e) { logger.warn("Can't locate source file, skipping: " + file.getPath());
logger.fatal("Error while calling objdump: " + e); } else {
files.add(file);
}
} }
return debuggingInfo;
File[] filesArray = new File[files.size()];
for (int i=0; i < filesArray.length; i++) {
filesArray[i] = files.get(i);
}
return filesArray;
}
private Hashtable<File, Hashtable<Integer, Integer>> getFirmwareDebugInfo() {
/* Fetch all executable addresses */
ArrayList<Integer> addresses = mspMote.getELF().debug.getExecutableAddresses();
Hashtable<File, Hashtable<Integer, Integer>> fileToLineHash =
new Hashtable<File, Hashtable<Integer, Integer>>();
for (int address: addresses) {
DebugInfo info = mspMote.getELF().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());
Hashtable<Integer, Integer> lineToAddrHash = fileToLineHash.get(file);
if (lineToAddrHash == null) {
lineToAddrHash = new Hashtable<Integer, Integer>();
fileToLineHash.put(file, lineToAddrHash);
}
lineToAddrHash.put(info.getLine(), address);
}
}
return fileToLineHash;
} }
/** /**