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_LINKER = ld
PATH_SHELL = sh PATH_SHELL = sh
PATH_C_COMPILER = gcc PATH_C_COMPILER = gcc
PATH_NM=nm
NM_ARGS=
PATH_OBJDUMP=objdump PATH_OBJDUMP=objdump
OBJDUMP_ARGS=-h OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD([^,]*,[^,]*,[^)]*)" -o -H CMD_GREP_PROCESSES = grep "^PROCESS_THREAD([^,]*,[^,]*,[^)]*)" -o -H
@ -24,7 +22,8 @@ CORECOMM_TEMPLATE_FILENAME = corecomm_template.java
PATH_JAVAC = javac PATH_JAVAC = javac
DEFAULT_PROJECTDIRS = ../apps/mrm 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_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_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]*$ 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_ADDRESS_2 = [ \t]*$
MAPFILE_VAR_SIZE_1 = ^ MAPFILE_VAR_SIZE_1 = ^
MAPFILE_VAR_SIZE_2 = [ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$ 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]([^ ._][^ ]*) COMMAND_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__$ COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
NM_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$ COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
NM_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$ COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
NM_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$ 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_LINKER = ld
PATH_SHELL = sh PATH_SHELL = sh
PATH_C_COMPILER = gcc PATH_C_COMPILER = gcc
PATH_NM=nm
NM_ARGS=-C
PATH_OBJDUMP=objdump PATH_OBJDUMP=objdump
OBJDUMP_ARGS=-h OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep '^PROCESS_THREAD([^,]*,[^,]*,[^)]*)' -o -d skip -D skip -H -r 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 PATH_JAVAC = javac
DEFAULT_PROJECTDIRS = ../apps/mrm 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_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_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]*$ 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_ADDRESS_2 = [ \t]*$
MAPFILE_VAR_SIZE_1 = ^ MAPFILE_VAR_SIZE_1 = ^
MAPFILE_VAR_SIZE_2 = [ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$ 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]([^ ._][^ ]*) COMMAND_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__$ COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
NM_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$ COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
NM_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$ COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
NM_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$ 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 = COMPILER_ARGS =
LINK_COMMAND_1 = gcc -shared -Wl,-Map=$(MAPFILE) -o $(LIBFILE) LINK_COMMAND_1 = gcc -shared -Wl,-Map=$(MAPFILE) -o $(LIBFILE)
LINK_COMMAND_2 = LINK_COMMAND_2 =
PARSE_WITH_NM=false PARSE_WITH_COMMAND=false
Windows users with recent Cygwin may try: Windows users with recent Cygwin may try:
COMPILER_ARGS = -mno-cygwin -Wall -I'$(JAVA_HOME)/include' -I'$(JAVA_HOME)/include/win32' 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] [address parsing using map file]
> ant level3b > ant level3b
[address parsing using nm] [address parsing using command]
> ant level4 > ant level4
[fetching reference var] [fetching reference var]
@ -168,16 +168,16 @@ or
> ant level3b > ant level3b
3a tests parsing library addresses using the map file generated at link time. 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. At least one of the tests must pass.
After passing, the 'exttools.cfg' must be updated. After passing, the 'exttools.cfg' must be updated.
The external tools setting: The external tools setting:
PARSE_WITH_NM=true PARSE_WITH_COMMAND=true
causes COOJA (and the following tests) to use nm to parse library addresses, causes COOJA (and the following tests) to use the command to parse library addresses,
and should be used if test 3b passed. 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. causes COOJA to parse the generated map file, and should be used if test 3a passed.
</echo> </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' 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_1 = gcc -shared -Wl,-Map=$(MAPFILE) -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -o $(LIBFILE)
LINK_COMMAND_2 = LINK_COMMAND_2 =
PATH_NM=nm PARSE_WITH_COMMAND=true
NM_ARGS=-C PARSE_COMMAND=nm -C $(LIBFILE)
PARSE_WITH_NM=true

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: 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.*; import java.io.*;
@ -49,9 +49,8 @@ public class Level3b {
GUI.loadExternalToolsDefaultSettings(); GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings(); GUI.loadExternalToolsUserSettings();
System.out.println("Using nm settings: \n" + System.out.println("Using parse command settings: \n" +
"\tPATH_NM = "+ GUI.getExternalToolsSetting("PATH_NM") + "\tPARSE_COMMAND = "+ GUI.getExternalToolsSetting("PARSE_COMMAND"));
"\tNM_ARGS = "+ GUI.getExternalToolsSetting("NM_ARGS"));
System.out.println("Locating library file"); System.out.println("Locating library file");
File libFile = new File("level3b.library"); File libFile = new File("level3b.library");
@ -60,24 +59,24 @@ public class Level3b {
System.exit(1); System.exit(1);
} }
System.out.println("Loading nm data"); System.out.println("Loading command data");
Vector<String> nmData = ContikiMoteType.loadNmData(libFile); Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (nmData == null) { if (commandData == null) {
System.err.println("No nm data could be loaded"); System.err.println("No command data could be loaded");
System.exit(1); System.exit(1);
} }
System.out.println("Parsing nm data"); System.out.println("Parsing command data");
Properties addresses = new Properties(); Properties addresses = new Properties();
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses); boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) { if (!parseOK) {
System.err.println("Nm data parsing failed"); System.err.println("Command data parsing failed");
System.exit(1); System.exit(1);
} }
int relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData); int relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
int dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData); int dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
int relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData); int relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
int bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData); int bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
System.out.println("Found relative data section address: 0x" + Integer.toHexString(relDataSectionAddr)); System.out.println("Found relative data section address: 0x" + Integer.toHexString(relDataSectionAddr));
System.out.println("Found data section size: 0x" + Integer.toHexString(dataSectionSize)); 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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.*; import java.io.*;
@ -57,8 +57,8 @@ public class Level4 {
GUI.loadExternalToolsDefaultSettings(); GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings(); GUI.loadExternalToolsUserSettings();
// Should we parse addresses using map file or nm? // Should we parse addresses using map file or command?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false")); boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
Properties addresses = new Properties(); Properties addresses = new Properties();
int relDataSectionAddr = -1; int relDataSectionAddr = -1;
@ -66,9 +66,9 @@ public class Level4 {
int relBssSectionAddr = -1; int relBssSectionAddr = -1;
int bssSectionSize = -1; int bssSectionSize = -1;
if (useNm) { if (useCommand) {
// Parse nm output // Parse command output
System.out.println("Parsing using nm"); System.out.println("Parsing using command");
File libFile = new File("level4.library"); File libFile = new File("level4.library");
if (!libFile.exists()) { if (!libFile.exists()) {
@ -76,22 +76,22 @@ public class Level4 {
System.exit(1); System.exit(1);
} }
Vector<String> nmData = ContikiMoteType.loadNmData(libFile); Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (nmData == null) { if (commandData == null) {
System.err.println("No nm data could be loaded"); System.err.println("No command data could be loaded");
System.exit(1); System.exit(1);
} }
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses); boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) { if (!parseOK) {
System.err.println("Nm data parsing failed"); System.err.println("Command data parsing failed");
System.exit(1); System.exit(1);
} }
relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData); relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData); dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData); relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData); bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
} else { } else {
// Parse map file // Parse map file
System.out.println("Parsing using 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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.*; import java.io.*;
@ -64,8 +64,8 @@ public class Level5 {
GUI.loadExternalToolsDefaultSettings(); GUI.loadExternalToolsDefaultSettings();
GUI.loadExternalToolsUserSettings(); GUI.loadExternalToolsUserSettings();
// Should we parse addresses using map file or nm? // Should we parse addresses using map file or command?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false")); boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
Properties addresses = new Properties(); Properties addresses = new Properties();
int relDataSectionAddr = -1; int relDataSectionAddr = -1;
@ -73,9 +73,9 @@ public class Level5 {
int relBssSectionAddr = -1; int relBssSectionAddr = -1;
int bssSectionSize = -1; int bssSectionSize = -1;
if (useNm) { if (useCommand) {
// Parse nm output // Parse command output
System.out.println("Parsing using nm"); System.out.println("Parsing using command");
File libFile = new File("level5.library"); File libFile = new File("level5.library");
if (!libFile.exists()) { if (!libFile.exists()) {
@ -83,22 +83,22 @@ public class Level5 {
System.exit(1); System.exit(1);
} }
Vector<String> nmData = ContikiMoteType.loadNmData(libFile); Vector<String> commandData = ContikiMoteType.loadCommandData(libFile);
if (nmData == null) { if (commandData == null) {
System.err.println("No nm data could be loaded"); System.err.println("No command data could be loaded");
System.exit(1); System.exit(1);
} }
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses); boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) { if (!parseOK) {
System.err.println("Nm data parsing failed"); System.err.println("Command data parsing failed");
System.exit(1); System.exit(1);
} }
relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData); relDataSectionAddr = ContikiMoteType.loadCommandRelDataSectionAddr(commandData);
dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData); dataSectionSize = ContikiMoteType.loadCommandDataSectionSize(commandData);
relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData); relBssSectionAddr = ContikiMoteType.loadCommandRelBssSectionAddr(commandData);
bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData); bssSectionSize = ContikiMoteType.loadCommandBssSectionSize(commandData);
} else { } else {
// Parse map file // Parse map file
System.out.println("Parsing using 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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; package se.sics.cooja;
@ -148,7 +148,6 @@ public class GUI {
"PATH_SHELL", "PATH_SHELL",
"PATH_C_COMPILER", "COMPILER_ARGS", "PATH_C_COMPILER", "COMPILER_ARGS",
"PATH_LINKER", "LINK_COMMAND_1", "LINK_COMMAND_2", "PATH_LINKER", "LINK_COMMAND_1", "LINK_COMMAND_2",
"PATH_NM", "NM_ARGS",
"PATH_OBJDUMP", "OBJDUMP_ARGS", "PATH_OBJDUMP", "OBJDUMP_ARGS",
"PATH_JAVAC", "PATH_JAVAC",
@ -162,16 +161,17 @@ public class GUI {
"DEFAULT_PROJECTDIRS", "DEFAULT_PROJECTDIRS",
"CORECOMM_TEMPLATE_FILENAME", "CORECOMM_TEMPLATE_FILENAME",
"PARSE_WITH_NM",
"MAPFILE_DATA_START", "MAPFILE_DATA_SIZE", "MAPFILE_DATA_START", "MAPFILE_DATA_SIZE",
"MAPFILE_BSS_START", "MAPFILE_BSS_SIZE", "MAPFILE_BSS_START", "MAPFILE_BSS_SIZE",
"MAPFILE_VAR_NAME", "MAPFILE_VAR_NAME",
"MAPFILE_VAR_ADDRESS_1", "MAPFILE_VAR_ADDRESS_2", "MAPFILE_VAR_ADDRESS_1", "MAPFILE_VAR_ADDRESS_2",
"MAPFILE_VAR_SIZE_1", "MAPFILE_VAR_SIZE_2", "MAPFILE_VAR_SIZE_1", "MAPFILE_VAR_SIZE_2",
"NM_VAR_NAME_ADDRESS", "PARSE_WITH_COMMAND",
"NM_DATA_START", "NM_DATA_END", "PARSE_COMMAND",
"NM_BSS_START", "NM_BSS_END", "COMMAND_VAR_NAME_ADDRESS",
"COMMAND_DATA_START", "COMMAND_DATA_END",
"COMMAND_BSS_START", "COMMAND_BSS_END",
}; };
private static final int FRAME_NEW_OFFSET = 30; 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.contikimote;
@ -315,32 +315,32 @@ public class ContikiMoteType implements MoteType {
libraryClassName = CoreComm.getAvailableClassName(); libraryClassName = CoreComm.getAvailableClassName();
myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile); myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile);
// Should we parse addresses using map file or nm? // Should we parse addresses using map file or command?
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false")); boolean useCommand = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_COMMAND", "false"));
int relDataSectionAddr = -1; int relDataSectionAddr = -1;
int dataSectionSize = -1; int dataSectionSize = -1;
int relBssSectionAddr = -1; int relBssSectionAddr = -1;
int bssSectionSize = -1; int bssSectionSize = -1;
if (useNm) { if (useCommand) {
// Parse nm output // Parse command output
Vector<String> nmData = loadNmData(libFile); Vector<String> commandData = loadCommandData(libFile);
if (nmData == null) { if (commandData == null) {
logger.fatal("No nm data could be loaded"); logger.fatal("No parse command output could be loaded");
throw new MoteTypeCreationException("No nm data could be loaded"); throw new MoteTypeCreationException("No parse command output be loaded");
} }
boolean parseOK = parseNmData(nmData, varAddresses); boolean parseOK = parseCommandData(commandData, varAddresses);
if (!parseOK) { if (!parseOK) {
logger.fatal("Nm data parsing failed"); logger.fatal("Command output parsing failed");
throw new MoteTypeCreationException("Nm data parsing failed"); throw new MoteTypeCreationException("Command output parsing failed");
} }
relDataSectionAddr = loadNmRelDataSectionAddr(nmData); relDataSectionAddr = loadCommandRelDataSectionAddr(commandData);
dataSectionSize = loadNmDataSectionSize(nmData); dataSectionSize = loadCommandDataSectionSize(commandData);
relBssSectionAddr = loadNmRelBssSectionAddr(nmData); relBssSectionAddr = loadCommandRelBssSectionAddr(commandData);
bssSectionSize = loadNmBssSectionSize(nmData); bssSectionSize = loadCommandBssSectionSize(commandData);
} else { } else {
// Parse map file // Parse map file
if (!mapFile.exists()) { if (!mapFile.exists()) {
@ -461,25 +461,26 @@ public class ContikiMoteType implements MoteType {
} }
/** /**
* Parses specified nm data for variable name to addresses mappings. The * Parses specified parse command output for variable
* mappings are added to the given properties object. * name to addresses mappings. The mappings are added
* to the given properties object.
* *
* @param nmData * @param commandData
* Response from nm command on object file * Output from parse command on object file
* @param varAddresses * @param varAddresses
* Properties that should contain the name to addresses mappings. * 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) { Properties varAddresses) {
int nrNew = 0, nrOld = 0, nrMismatch = 0; int nrNew = 0, nrOld = 0, nrMismatch = 0;
Pattern pattern = Pattern.compile(GUI Pattern pattern = Pattern.compile(GUI
.getExternalToolsSetting("NM_VAR_NAME_ADDRESS")); .getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS"));
for (String nmLine : nmData) { for (String commandLine : commandData) {
Matcher matcher = pattern.matcher(nmLine); Matcher matcher = pattern.matcher(commandLine);
if (matcher.find()) { if (matcher.find()) {
// logger.debug("Parsing line: " + nmLine); // logger.debug("Parsing line: " + commandLine);
String varName = matcher.group(2); String varName = matcher.group(2);
int varAddress = Integer.parseInt(matcher.group(1), 16); int varAddress = Integer.parseInt(matcher.group(1), 16);
@ -489,7 +490,7 @@ public class ContikiMoteType implements MoteType {
} else { } else {
int oldAddress = (Integer) varAddresses.get(varName); int oldAddress = (Integer) varAddresses.get(varName);
if (oldAddress != varAddress) { if (oldAddress != varAddress) {
logger.warn("Warning, nm response not matching previous entry of: " logger.warn("Warning, command response not matching previous entry of: "
+ varName); + varName);
nrMismatch++; nrMismatch++;
} }
@ -500,11 +501,11 @@ public class ContikiMoteType implements MoteType {
} }
if (nrMismatch > 0) { if (nrMismatch > 0) {
logger.debug("Nm response parsing summary: Added " + nrNew logger.debug("Command response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld + " variables. Found " + nrOld
+ " old variables. MISMATCHING ADDRESSES: " + nrMismatch); + " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
} else { } else {
logger.debug("Nm response parsing summary: Added " + nrNew logger.debug("Command response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld + " old variables"); + " variables. Found " + nrOld + " old variables");
} }
@ -720,9 +721,9 @@ public class ContikiMoteType implements MoteType {
} }
} }
public static int loadNmRelDataSectionAddr(Vector<String> nmData) { public static int loadCommandRelDataSectionAddr(Vector<String> commandData) {
String retString = getFirstMatchGroup(nmData, GUI String retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1); .getExternalToolsSetting("COMMAND_DATA_START"), 1);
if (retString != null) { if (retString != null) {
return Integer.parseInt(retString.trim(), 16); 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; String retString;
int start, end; int start, end;
retString = getFirstMatchGroup(nmData, GUI retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1); .getExternalToolsSetting("COMMAND_DATA_START"), 1);
if (retString != null) { if (retString != null) {
start = Integer.parseInt(retString.trim(), 16); start = Integer.parseInt(retString.trim(), 16);
} else { } else {
return -1; return -1;
} }
retString = getFirstMatchGroup(nmData, GUI retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_DATA_END"), 1); .getExternalToolsSetting("COMMAND_DATA_END"), 1);
if (retString != null) { if (retString != null) {
end = Integer.parseInt(retString.trim(), 16); end = Integer.parseInt(retString.trim(), 16);
} else { } else {
@ -754,9 +755,9 @@ public class ContikiMoteType implements MoteType {
return end - start; return end - start;
} }
public static int loadNmRelBssSectionAddr(Vector<String> nmData) { public static int loadCommandRelBssSectionAddr(Vector<String> commandData) {
String retString = getFirstMatchGroup(nmData, GUI String retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1); .getExternalToolsSetting("COMMAND_BSS_START"), 1);
if (retString != null) { if (retString != null) {
return Integer.parseInt(retString.trim(), 16); 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; String retString;
int start, end; int start, end;
retString = getFirstMatchGroup(nmData, GUI retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1); .getExternalToolsSetting("COMMAND_BSS_START"), 1);
if (retString != null) { if (retString != null) {
start = Integer.parseInt(retString.trim(), 16); start = Integer.parseInt(retString.trim(), 16);
} else { } else {
return -1; return -1;
} }
retString = getFirstMatchGroup(nmData, GUI retString = getFirstMatchGroup(commandData, GUI
.getExternalToolsSetting("NM_BSS_END"), 1); .getExternalToolsSetting("COMMAND_BSS_END"), 1);
if (retString != null) { if (retString != null) {
end = Integer.parseInt(retString.trim(), 16); end = Integer.parseInt(retString.trim(), 16);
} else { } 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 * @param libraryFile
* File * File
* @return Execution response * @return Execution response
*/ */
public static Vector<String> loadNmData(File libraryFile) { public static Vector<String> loadCommandData(File libraryFile) {
Vector<String> nmData = new Vector<String>(); Vector<String> commandData = new Vector<String>();
try { try {
String nmPath = GUI.getExternalToolsSetting("PATH_NM"); String command = GUI.getExternalToolsSetting("PARSE_COMMAND");
String nmArgs = GUI.getExternalToolsSetting("NM_ARGS");
if (nmPath == null || nmPath.equals("")) { if (command == null) {
return null; return null;
} }
String[] nmExecArray; // Prepare command
if (!nmArgs.trim().equals("")) { command = command.replace("$(LIBFILE)", libraryFile.getPath().replace(File.separatorChar, '/'));
// 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();
}
String line; String line;
Process p = Runtime.getRuntime().exec(nmExecArray); Process p = Runtime.getRuntime().exec(command.split(" "));
BufferedReader input = new BufferedReader(new InputStreamReader(p BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream())); .getInputStream()));
p.getErrorStream().close(); // Ignore error stream p.getErrorStream().close(); // Ignore error stream
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
nmData.add(line); commandData.add(line);
} }
input.close(); input.close();
} catch (Exception err) { } catch (Exception err) {
@ -870,11 +856,11 @@ public class ContikiMoteType implements MoteType {
return null; return null;
} }
if (nmData == null || nmData.size() == 0) { if (commandData == null || commandData.size() == 0) {
return null; 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.mantismote;
@ -143,8 +143,8 @@ public class MantisMoteType implements MoteType {
// Parse variable name to addresses mappings using nm // Parse variable name to addresses mappings using nm
varAddresses.clear(); varAddresses.clear();
Vector<String> nmData = ContikiMoteType.loadNmData(libFile); Vector<String> nmData = ContikiMoteType.loadCommandData(libFile);
if (nmData == null || !ContikiMoteType.parseNmData(nmData, varAddresses)) { if (nmData == null || !ContikiMoteType.parseCommandData(nmData, varAddresses)) {
logger.fatal("Nm response parsing failed"); logger.fatal("Nm response parsing failed");
return false; return false;
} }