From: <fro...@us...> - 2008-03-19 17:42:14
|
Revision: 201 http://mspsim.svn.sourceforge.net/mspsim/?rev=201&view=rev Author: fros4943 Date: 2008-03-19 10:42:13 -0700 (Wed, 19 Mar 2008) Log Message: ----------- added methods for reading all references source files as well as all executable addresses Modified Paths: -------------- mspsim/se/sics/mspsim/util/ELFDebug.java Modified: mspsim/se/sics/mspsim/util/ELFDebug.java =================================================================== --- mspsim/se/sics/mspsim/util/ELFDebug.java 2008-03-19 17:38:19 UTC (rev 200) +++ mspsim/se/sics/mspsim/util/ELFDebug.java 2008-03-19 17:42:13 UTC (rev 201) @@ -38,7 +38,7 @@ */ package se.sics.mspsim.util; -import se.sics.mspsim.core.*; +import java.util.ArrayList; public class ELFDebug { @@ -61,7 +61,9 @@ int count = len / dbgStab.entSize; int addr = dbgStab.offset; - if (DEBUG) System.out.println("Number of stabs:" + count); + if (DEBUG) { + System.out.println("Number of stabs:" + count); + } stabs = new Stab[count]; for (int i = 0, n = count; i < n; i++) { elf.pos = addr; @@ -148,6 +150,109 @@ return null; } + public ArrayList<Integer> getExecutableAddresses() { + ArrayList<Integer> allAddresses = new ArrayList<Integer>(); + + int address = Integer.MAX_VALUE; + + String currentPath = null; + String currentFile = null; + String currentFunction = null; + int lastAddress = 0; + int currentLine = 0; + int currentLineAdr = 0; + for (Stab stab : stabs) { + switch(stab.type) { + case N_SO: + if (stab.value < address) { + if (stab.data != null && stab.data.endsWith("/")) { + currentPath = stab.data; + lastAddress = stab.value; + allAddresses.add(new Integer(lastAddress)); + currentFunction = null; + } else { + currentFile = stab.data; + lastAddress = stab.value; + allAddresses.add(new Integer(lastAddress)); + currentFunction = null; + } + } else { + /* requires sorted order of all file entries in stab section */ + if (DEBUG) { + System.out.println("FILE: Already passed address..." + + currentPath + " " + + currentFile + " " + currentFunction); + } + return allAddresses; + } + break; + case N_SLINE: + if (currentPath != null) { /* only files with path... */ + if (currentLineAdr < address) { + currentLine = stab.desc; + currentLineAdr = lastAddress + stab.value; + allAddresses.add(new Integer(currentLineAdr)); + /*if (currentLineAdr >= address) { + // Finished!!! + if (DEBUG) { + System.out.println("File: " + currentPath + " " + currentFile); + System.out.println("Function: " + currentFunction); + System.out.println("Line No: " + currentLine); + } + return new DebugInfo(currentLine, currentPath, currentFile, + currentFunction); + }*/ + } + } + break; + case N_FUN: + if (stab.value < address) { + currentFunction = stab.data; + lastAddress = stab.value; + allAddresses.add(new Integer(lastAddress)); + } else { + if (DEBUG) { + System.out.println("FUN: Already passed address..."); + } + return allAddresses; + } + break; + } + } + return allAddresses; +} + + public String[] getSourceFiles() { + String currentPath = null; + String currentFile = null; + ArrayList<String> sourceFiles = new ArrayList<String>(); + + for (Stab stab : stabs) { + if (stab.type == N_SO) { + if (stab.data != null && stab.data.endsWith("/")) { + currentPath = stab.data; + } else { + currentFile = stab.data; + + if (currentFile != null && !currentFile.isEmpty()) { + if (currentPath == null) { + sourceFiles.add(currentFile); + } else { + sourceFiles.add(currentPath + currentFile); + } + } + } + } + } + + String[] sourceFilesArray = new String[sourceFiles.size()]; + for (int i=0; i < sourceFilesArray.length; i++) { + sourceFilesArray[i] = sourceFiles.get(i); + } + + return sourceFilesArray; + } + private static class Stab { String data; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |