changed address parsing using nm to more generic: any command may be used

This commit is contained in:
fros4943 2007-09-18 11:33:46 +00:00
parent aa99049af0
commit 8f101f495c
10 changed files with 131 additions and 149 deletions

View File

@ -4,8 +4,6 @@ PATH_MAKE = make
PATH_LINKER = ld
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_NM=nm
NM_ARGS=
PATH_OBJDUMP=objdump
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD([^,]*,[^,]*,[^)]*)" -o -H
@ -24,7 +22,8 @@ CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
PATH_JAVAC = javac
DEFAULT_PROJECTDIRS = ../apps/mrm
PARSE_WITH_NM = false
PARSE_WITH_COMMAND = false
PARSE_COMMAND=nm $(LIBFILE)
MAPFILE_DATA_START = ^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
MAPFILE_DATA_SIZE = ^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$
MAPFILE_BSS_START = ^.bss[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
@ -34,8 +33,8 @@ MAPFILE_VAR_ADDRESS_1 = ^[ \t]*0x([0-9A-Fa-f]*)[ \t]*
MAPFILE_VAR_ADDRESS_2 = [ \t]*$
MAPFILE_VAR_SIZE_1 = ^
MAPFILE_VAR_SIZE_2 = [ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$
NM_VAR_NAME_ADDRESS = ^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)
NM_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
NM_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
NM_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
NM_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$
COMMAND_VAR_NAME_ADDRESS = ^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)
COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
COMMAND_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$

View File

@ -4,8 +4,6 @@ PATH_MAKE = make
PATH_LINKER = ld
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_NM=nm
NM_ARGS=-C
PATH_OBJDUMP=objdump
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep '^PROCESS_THREAD([^,]*,[^,]*,[^)]*)' -o -d skip -D skip -H -r
@ -24,7 +22,8 @@ CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
PATH_JAVAC = javac
DEFAULT_PROJECTDIRS = ../apps/mrm
PARSE_WITH_NM = true
PARSE_WITH_COMMAND = true
PARSE_COMMAND=nm -C $(LIBFILE)
MAPFILE_DATA_START = ^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
MAPFILE_DATA_SIZE = ^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$
MAPFILE_BSS_START = ^.bss[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
@ -34,8 +33,8 @@ MAPFILE_VAR_ADDRESS_1 = ^[ \t]*0x([0-9A-Fa-f]*)[ \t]*
MAPFILE_VAR_ADDRESS_2 = [ \t]*$
MAPFILE_VAR_SIZE_1 = ^
MAPFILE_VAR_SIZE_2 = [ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$
NM_VAR_NAME_ADDRESS = ^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)
NM_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
NM_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
NM_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
NM_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$
COMMAND_VAR_NAME_ADDRESS = ^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)
COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
COMMAND_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$

View File

@ -13,7 +13,7 @@ Linux users with the GNU toolchain may try:
COMPILER_ARGS =
LINK_COMMAND_1 = gcc -shared -Wl,-Map=$(MAPFILE) -o $(LIBFILE)
LINK_COMMAND_2 =
PARSE_WITH_NM=false
PARSE_WITH_COMMAND=false
Windows users with recent Cygwin may try:
COMPILER_ARGS = -mno-cygwin -Wall -I'$(JAVA_HOME)/include' -I'$(JAVA_HOME)/include/win32'
@ -72,7 +72,7 @@ For more information including configuration examples:
[address parsing using map file]
> ant level3b
[address parsing using nm]
[address parsing using command]
> ant level4
[fetching reference var]
@ -168,16 +168,16 @@ or
> ant level3b
3a tests parsing library addresses using the map file generated at link time.
3b tests parsing library addresses using the nm tool.
3b tests parsing library addresses using a command.
At least one of the tests must pass.
After passing, the 'exttools.cfg' must be updated.
The external tools setting:
PARSE_WITH_NM=true
causes COOJA (and the following tests) to use nm to parse library addresses,
PARSE_WITH_COMMAND=true
causes COOJA (and the following tests) to use the command to parse library addresses,
and should be used if test 3b passed.
PARSE_WITH_NM=false
PARSE_WITH_COMMAND=false
causes COOJA to parse the generated map file, and should be used if test 3a passed.
</echo>

View File

@ -6,6 +6,5 @@ PATH_C_COMPILER = gcc
COMPILER_ARGS = -Wall -D_JNI_IMPLEMENTATION_ -I'$(JAVA_HOME)/include' -I'$(JAVA_HOME)/include/win32'
LINK_COMMAND_1 = gcc -shared -Wl,-Map=$(MAPFILE) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -o $(LIBFILE)
LINK_COMMAND_2 =
PATH_NM=nm
NM_ARGS=-C
PARSE_WITH_NM=true
PARSE_WITH_COMMAND=true
PARSE_COMMAND=nm -C $(LIBFILE)

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: Level3b.java,v 1.1 2007/09/10 14:06:23 fros4943 Exp $
* $Id: Level3b.java,v 1.2 2007/09/18 11:35:10 fros4943 Exp $
*/
import java.io.*;
@ -49,9 +49,8 @@ public class Level3b {
GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings();
System.out.println("Using nm settings: \n" +
"\tPATH_NM = "+ GUI.getExternalToolsSetting("PATH_NM") +
"\tNM_ARGS = "+ GUI.getExternalToolsSetting("NM_ARGS"));
System.out.println("Using parse command settings: \n" +
"\tPARSE_COMMAND = "+ GUI.getExternalToolsSetting("PARSE_COMMAND"));
System.out.println("Locating library file");
File libFile = new File("level3b.library");
@ -60,24 +59,24 @@ public class Level3b {
System.exit(1);
}
System.out.println("Loading nm data");
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
if (nmData == null) {
System.err.println("No nm data could be loaded");
System.out.println("Loading command data");
Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (commandData == null) {
System.err.println("No command data could be loaded");
System.exit(1);
}
System.out.println("Parsing nm data");
System.out.println("Parsing command data");
Properties addresses = new Properties();
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses);
boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) {
System.err.println("Nm data parsing failed");
System.err.println("Command data parsing failed");
System.exit(1);
}
int relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData);
int dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData);
int relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData);
int bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData);
int relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
int dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
int relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
int bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
System.out.println("Found relative data section address: 0x" + Integer.toHexString(relDataSectionAddr));
System.out.println("Found data section size: 0x" + Integer.toHexString(dataSectionSize));

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: Level4.java,v 1.2 2007/09/10 14:07:12 fros4943 Exp $
* $Id: Level4.java,v 1.3 2007/09/18 11:35:11 fros4943 Exp $
*/
import java.io.*;
@ -57,8 +57,8 @@ public class Level4 {
GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings();
// Should we parse addresses using map file or nm?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false"));
// Should we parse addresses using map file or command?
boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
Properties addresses = new Properties();
int relDataSectionAddr = -1;
@ -66,9 +66,9 @@ public class Level4 {
int relBssSectionAddr = -1;
int bssSectionSize = -1;
if (useNm) {
// Parse nm output
System.out.println("Parsing using nm");
if (useCommand) {
// Parse command output
System.out.println("Parsing using command");
File libFile = new File("level4.library");
if (!libFile.exists()) {
@ -76,22 +76,22 @@ public class Level4 {
System.exit(1);
}
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
if (nmData == null) {
System.err.println("No nm data could be loaded");
Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (commandData == null) {
System.err.println("No command data could be loaded");
System.exit(1);
}
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses);
boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) {
System.err.println("Nm data parsing failed");
System.err.println("Command data parsing failed");
System.exit(1);
}
relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData);
dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData);
relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData);
bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData);
relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
} else {
// Parse map file
System.out.println("Parsing using map file");

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: Level5.java,v 1.3 2007/09/10 14:07:12 fros4943 Exp $
* $Id: Level5.java,v 1.4 2007/09/18 11:35:11 fros4943 Exp $
*/
import java.io.*;
@ -64,8 +64,8 @@ public class Level5 {
GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings();
// Should we parse addresses using map file or nm?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false"));
// Should we parse addresses using map file or command?
boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
Properties addresses = new Properties();
int relDataSectionAddr = -1;
@ -73,9 +73,9 @@ public class Level5 {
int relBssSectionAddr = -1;
int bssSectionSize = -1;
if (useNm) {
// Parse nm output
System.out.println("Parsing using nm");
if (useCommand) {
// Parse command output
System.out.println("Parsing using command");
File libFile = new File("level5.library");
if (!libFile.exists()) {
@ -83,22 +83,22 @@ public class Level5 {
System.exit(1);
}
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
if (nmData == null) {
System.err.println("No nm data could be loaded");
Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (commandData == null) {
System.err.println("No command data could be loaded");
System.exit(1);
}
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses);
boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) {
System.err.println("Nm data parsing failed");
System.err.println("Command data parsing failed");
System.exit(1);
}
relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData);
dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData);
relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData);
bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData);
relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
} else {
// Parse map file
System.out.println("Parsing using map file");

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.59 2007/09/10 14:04:50 fros4943 Exp $
* $Id: GUI.java,v 1.60 2007/09/18 11:33:46 fros4943 Exp $
*/
package se.sics.cooja;
@ -148,7 +148,6 @@ public class GUI {
"PATH_SHELL",
"PATH_C_COMPILER", "COMPILER_ARGS",
"PATH_LINKER", "LINK_COMMAND_1", "LINK_COMMAND_2",
"PATH_NM", "NM_ARGS",
"PATH_OBJDUMP", "OBJDUMP_ARGS",
"PATH_JAVAC",
@ -162,16 +161,17 @@ public class GUI {
"DEFAULT_PROJECTDIRS",
"CORECOMM_TEMPLATE_FILENAME",
"PARSE_WITH_NM",
"MAPFILE_DATA_START", "MAPFILE_DATA_SIZE",
"MAPFILE_BSS_START", "MAPFILE_BSS_SIZE",
"MAPFILE_VAR_NAME",
"MAPFILE_VAR_ADDRESS_1", "MAPFILE_VAR_ADDRESS_2",
"MAPFILE_VAR_SIZE_1", "MAPFILE_VAR_SIZE_2",
"NM_VAR_NAME_ADDRESS",
"NM_DATA_START", "NM_DATA_END",
"NM_BSS_START", "NM_BSS_END",
"PARSE_WITH_COMMAND",
"PARSE_COMMAND",
"COMMAND_VAR_NAME_ADDRESS",
"COMMAND_DATA_START", "COMMAND_DATA_END",
"COMMAND_BSS_START", "COMMAND_BSS_END",
};
private static final int FRAME_NEW_OFFSET = 30;

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ContikiMoteType.java,v 1.19 2007/09/10 14:05:34 fros4943 Exp $
* $Id: ContikiMoteType.java,v 1.20 2007/09/18 11:33:58 fros4943 Exp $
*/
package se.sics.cooja.contikimote;
@ -315,32 +315,32 @@ public class ContikiMoteType implements MoteType {
libraryClassName = CoreComm.getAvailableClassName();
myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile);
// Should we parse addresses using map file or nm?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false"));
// Should we parse addresses using map file or command?
boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
int relDataSectionAddr = -1;
int dataSectionSize = -1;
int relBssSectionAddr = -1;
int bssSectionSize = -1;
if (useNm) {
// Parse nm output
Vector<String> nmData = loadNmData(libFile);
if (nmData == null) {
logger.fatal("No nm data could be loaded");
throw new MoteTypeCreationException("No nm data could be loaded");
if (useCommand) {
// Parse command output
Vector<String> commandData = loadCommandData(libFile);
if (commandData == null) {
logger.fatal("No parse command output could be loaded");
throw new MoteTypeCreationException("No parse command output be loaded");
}
boolean parseOK = parseNmData(nmData, varAddresses);
boolean parseOK = parseCommandData(commandData, varAddresses);
if (!parseOK) {
logger.fatal("Nm data parsing failed");
throw new MoteTypeCreationException("Nm data parsing failed");
logger.fatal("Command output parsing failed");
throw new MoteTypeCreationException("Command output parsing failed");
}
relDataSectionAddr = loadNmRelDataSectionAddr(nmData);
dataSectionSize = loadNmDataSectionSize(nmData);
relBssSectionAddr = loadNmRelBssSectionAddr(nmData);
bssSectionSize = loadNmBssSectionSize(nmData);
relDataSectionAddr = loadCommandRelDataSectionAddr(commandData);
dataSectionSize = loadCommandDataSectionSize(commandData);
relBssSectionAddr = loadCommandRelBssSectionAddr(commandData);
bssSectionSize = loadCommandBssSectionSize(commandData);
} else {
// Parse map file
if (!mapFile.exists()) {
@ -461,25 +461,26 @@ public class ContikiMoteType implements MoteType {
}
/**
* Parses specified nm data for variable name to addresses mappings. The
* mappings are added to the given properties object.
* Parses specified parse command output for variable
* name to addresses mappings. The mappings are added
* to the given properties object.
*
* @param nmData
* Response from nm command on object file
* @param commandData
* Output from parse command on object file
* @param varAddresses
* Properties that should contain the name to addresses mappings.
*/
public static boolean parseNmData(Vector<String> nmData,
public static boolean parseCommandData(Vector<String> commandData,
Properties varAddresses) {
int nrNew = 0, nrOld = 0, nrMismatch = 0;
Pattern pattern = Pattern.compile(GUI
.getExternalToolsSetting("NM_VAR_NAME_ADDRESS"));
for (String nmLine : nmData) {
Matcher matcher = pattern.matcher(nmLine);
.getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS"));
for (String commandLine : commandData) {
Matcher matcher = pattern.matcher(commandLine);
if (matcher.find()) {
// logger.debug("Parsing line: " + nmLine);
// logger.debug("Parsing line: " + commandLine);
String varName = matcher.group(2);
int varAddress = Integer.parseInt(matcher.group(1), 16);
@ -489,7 +490,7 @@ public class ContikiMoteType implements MoteType {
} else {
int oldAddress = (Integer) varAddresses.get(varName);
if (oldAddress != varAddress) {
logger.warn("Warning, nm response not matching previous entry of: "
logger.warn("Warning, command response not matching previous entry of: "
+ varName);
nrMismatch++;
}
@ -500,11 +501,11 @@ public class ContikiMoteType implements MoteType {
}
if (nrMismatch > 0) {
logger.debug("Nm response parsing summary: Added " + nrNew
logger.debug("Command response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld
+ " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
} else {
logger.debug("Nm response parsing summary: Added " + nrNew
logger.debug("Command response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld + " old variables");
}
@ -720,9 +721,9 @@ public class ContikiMoteType implements MoteType {
}
}
public static int loadNmRelDataSectionAddr(Vector<String> nmData) {
String retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1);
public static int loadCommandRelDataSectionAddr(Vector<String> commandData) {
String retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_DATA_START"), 1);
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
@ -731,20 +732,20 @@ public class ContikiMoteType implements MoteType {
}
}
public static int loadNmDataSectionSize(Vector<String> nmData) {
public static int loadCommandDataSectionSize(Vector<String> commandData) {
String retString;
int start, end;
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1);
retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_DATA_START"), 1);
if (retString != null) {
start = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_END"), 1);
retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_DATA_END"), 1);
if (retString != null) {
end = Integer.parseInt(retString.trim(), 16);
} else {
@ -754,9 +755,9 @@ public class ContikiMoteType implements MoteType {
return end - start;
}
public static int loadNmRelBssSectionAddr(Vector<String> nmData) {
String retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1);
public static int loadCommandRelBssSectionAddr(Vector<String> commandData) {
String retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_BSS_START"), 1);
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
@ -765,20 +766,20 @@ public class ContikiMoteType implements MoteType {
}
}
public static int loadNmBssSectionSize(Vector<String> nmData) {
public static int loadCommandBssSectionSize(Vector<String> commandData) {
String retString;
int start, end;
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1);
retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_BSS_START"), 1);
if (retString != null) {
start = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_END"), 1);
retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("COMMAND_BSS_END"), 1);
if (retString != null) {
end = Integer.parseInt(retString.trim(), 16);
} else {
@ -822,47 +823,32 @@ public class ContikiMoteType implements MoteType {
}
/**
* Runs external tool nm on given file and returns the result.
* Executes parse command on given file and returns the result.
*
* @param libraryFile
* File
* @return Execution response
*/
public static Vector<String> loadNmData(File libraryFile) {
Vector<String> nmData = new Vector<String>();
public static Vector<String> loadCommandData(File libraryFile) {
Vector<String> commandData = new Vector<String>();
try {
String nmPath = GUI.getExternalToolsSetting("PATH_NM");
String nmArgs = GUI.getExternalToolsSetting("NM_ARGS");
String command = GUI.getExternalToolsSetting("PARSE_COMMAND");
if (nmPath == null || nmPath.equals("")) {
if (command == null) {
return null;
}
String[] nmExecArray;
if (!nmArgs.trim().equals("")) {
// Arguments need to be passed to program
String[] splittedNmArgs = nmArgs.split(" ");
nmExecArray = new String[1 + splittedNmArgs.length + 1];
nmExecArray[0] = nmPath.trim();
nmExecArray[nmExecArray.length - 1] = libraryFile.getAbsolutePath();
System.arraycopy(splittedNmArgs, 0, nmExecArray, 1,
splittedNmArgs.length);
} else {
nmExecArray = new String[2];
nmExecArray[0] = nmPath.trim();
nmExecArray[1] = libraryFile.getAbsolutePath();
}
// Prepare command
command = command.replace("$(LIBFILE)", libraryFile.getPath().replace(File.separatorChar, '/'));
String line;
Process p = Runtime.getRuntime().exec(nmExecArray);
Process p = Runtime.getRuntime().exec(command.split(" "));
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
p.getErrorStream().close(); // Ignore error stream
while ((line = input.readLine()) != null) {
nmData.add(line);
commandData.add(line);
}
input.close();
} catch (Exception err) {
@ -870,11 +856,11 @@ public class ContikiMoteType implements MoteType {
return null;
}
if (nmData == null || nmData.size() == 0) {
if (commandData == null || commandData.size() == 0) {
return null;
}
return nmData;
return commandData;
}
/**

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MantisMoteType.java,v 1.4 2007/04/03 16:18:04 fros4943 Exp $
* $Id: MantisMoteType.java,v 1.5 2007/09/18 11:33:58 fros4943 Exp $
*/
package se.sics.cooja.mantismote;
@ -143,8 +143,8 @@ public class MantisMoteType implements MoteType {
// Parse variable name to addresses mappings using nm
varAddresses.clear();
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
if (nmData == null || !ContikiMoteType.parseNmData(nmData, varAddresses)) {
Vector<String> nmData = ContikiMoteType.loadCommandData(libFile);
if (nmData == null || !ContikiMoteType.parseCommandData(nmData, varAddresses)) {
logger.fatal("Nm response parsing failed");
return false;
}