📄 contikimotetype.java
字号:
} } if (nrMismatch > 0) logger.debug("Nm response parsing summary: Added " + nrNew + " variables. Found " + nrOld + " old variables. MISMATCHING ADDRESSES: " + nrMismatch); else logger.debug("Nm response parsing summary: Added " + nrNew + " variables. Found " + nrOld + " old variables"); return (nrNew + nrOld) > 0; } /** * Copy core memory to given memory. This should not be used directly, but * instead via ContikiMote.getMemory(). * * @param mem * Memory to set */ public void getCoreMemory(SectionMoteMemory mem) { for (int i = 0; i < mem.getNumberOfSections(); i++) { int startAddr = mem.getStartAddrOfSection(i); int size = mem.getSizeOfSection(i); byte[] data = mem.getDataOfSection(i); getCoreMemory(startAddr + offsetRelToAbs, size, data); } } public String getIdentifier() { return identifier; } public void setIdentifier(String identifier) { logger.warn("Contiki mote type is read-only"); } /** * @param using Core library has system symbols information */ public void setHasSystemSymbols(boolean using) { hasSystemSymbols = using; } /** * @return Whether core library has system symbols information */ public boolean hasSystemSymbols() { return hasSystemSymbols; } /** * @return Contiki mote type's library class name */ public String getLibraryClassName() { return libraryClassName; } /** * Get relative address of variable with given name. * * @param varName * Name of variable * @return Relative memory address of variable or -1 if not found */ protected int getMapFileVarAddress(Vector<String> mapFileData, String varName) { int varAddr; String varAddrString; if ((varAddrString = varAddresses.getProperty(varName)) != null) { varAddr = Integer.parseInt(varAddrString); return varAddr; } String regExp = varAddressRegExpPrefix + varName + varAddressRegExpSuffix; String retString = getFirstMatchGroup(mapFileData, regExp, 1); if (retString != null) { varAddresses.setProperty(varName, Integer.toString(Integer.parseInt( retString.trim(), 16))); return Integer.parseInt(retString.trim(), 16); } else return -1; } private int getReferenceAbsAddr() { return myCoreComm.getReferenceAbsAddr(); } private void getCoreMemory(int start, int length, byte[] data) { myCoreComm.getMemory(start, length, data); } private void setCoreMemory(int start, int length, byte[] mem) { myCoreComm.setMemory(start, length, mem); } private static String getFirstMatchGroup(Vector<String> lines, String regexp, int groupNr) { Pattern pattern = Pattern.compile(regexp); for (int i = 0; i < lines.size(); i++) { Matcher matcher = pattern.matcher(lines.elementAt(i)); if (matcher.find()) { return matcher.group(groupNr); } } return null; } /** * Returns all variable names in both data and BSS section by parsing the map * file. These values should not be trusted completely as the parsing may * fail. * * @return Variable names found in the data and bss section */ private Vector<String> getMapFileVarNames(Vector<String> mapFileData) { Vector<String> varNames = getAllVariableNames(mapFileData, loadRelDataSectionAddr(mapFileData), loadRelDataSectionAddr(mapFileData) + loadDataSectionSize(mapFileData)); varNames.addAll(getAllVariableNames(mapFileData, loadRelBssSectionAddr(mapFileData), loadRelBssSectionAddr(mapFileData) + loadBssSectionSize(mapFileData))); return varNames; } private Vector<String> getAllVariableNames(Vector<String> lines, int startAddress, int endAddress) { Vector<String> varNames = new Vector<String>(); Pattern pattern = Pattern.compile(varNameRegExp); for (int i = 0; i < lines.size(); i++) { Matcher matcher = pattern.matcher(lines.elementAt(i)); if (matcher.find()) { if (Integer.decode(matcher.group(1)).intValue() >= startAddress && Integer.decode(matcher.group(1)).intValue() <= endAddress) { varNames.add(matcher.group(2)); } } } return varNames; } protected int getVariableSize(Vector<String> lines, String varName) { Pattern pattern = Pattern.compile(varSizeRegExpPrefix + varName + varSizeRegExpSuffix); for (int i = 0; i < lines.size(); i++) { Matcher matcher = pattern.matcher(lines.elementAt(i)); if (matcher.find()) { return Integer.decode(matcher.group(1)); } } return -1; } private static int loadRelDataSectionAddr(Vector<String> mapFileData) { String retString = getFirstMatchGroup(mapFileData, dataSectionAddrRegExp, 1); if (retString != null) return Integer.parseInt(retString.trim(), 16); else return 0; } private static int loadDataSectionSize(Vector<String> mapFileData) { String retString = getFirstMatchGroup(mapFileData, dataSectionSizeRegExp, 1); if (retString != null) return Integer.parseInt(retString.trim(), 16); else return 0; } private static int loadRelBssSectionAddr(Vector<String> mapFileData) { String retString = getFirstMatchGroup(mapFileData, bssSectionAddrRegExp, 1); if (retString != null) return Integer.parseInt(retString.trim(), 16); else return 0; } private static int loadBssSectionSize(Vector<String> mapFileData) { String retString = getFirstMatchGroup(mapFileData, bssSectionSizeRegExp, 1); if (retString != null) return Integer.parseInt(retString.trim(), 16); else return 0; } private static int getRelVarAddr(Vector<String> mapFileData, String varName) { String regExp = varAddressRegExpPrefix + varName + varAddressRegExpSuffix; String retString = getFirstMatchGroup(mapFileData, regExp, 1); if (retString != null) return Integer.parseInt(retString.trim(), 16); else return 0; } private static Vector<String> loadMapFile(File mapFile) { Vector<String> mapFileData = new Vector<String>(); try { BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(mapFile))); while (in.ready()) { mapFileData.add(in.readLine()); } } catch (FileNotFoundException e) { logger.fatal("File not found: " + e); return null; } catch (IOException e) { logger.fatal("IO error: " + e); return null; } return mapFileData; } /** * Runs external tool nm 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>(); try { String nmPath = GUI.getExternalToolsSetting("PATH_NM"); String nmArgs = GUI.getExternalToolsSetting("NM_ARGS"); if (nmPath == null || nmPath.equals("")) 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(); } String line; Process p = Runtime.getRuntime().exec(nmExecArray); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); p.getErrorStream().close(); // Ignore error stream while ((line = input.readLine()) != null) { nmData.add(line); } input.close(); } catch (Exception err) { err.printStackTrace(); return null; } if (nmData == null || nmData.size() == 0) return null; return nmData; } /** * Runs external tool objdump on given file and returns the result. * * @param libraryFile File * @return Execution response */ public static Vector<String> loadObjdumpData(File libraryFile) { Vector<String> objdumpData = new Vector<String>(); try { String objdumpPath = GUI.getExternalToolsSetting("PATH_OBJDUMP"); String objdumpArgs = GUI.getExternalToolsSetting("OBJDUMP_ARGS"); if (objdumpPath == null || objdumpPath.equals("")) return null; String[] objdumpExecArray; if (!objdumpArgs.trim().equals("")) { // Arguments need to be passed to program String[] splittedObjdumpArgs = objdumpArgs.split(" "); objdumpExecArray = new String[1 + splittedObjdumpArgs.length + 1]; objdumpExecArray[0] = objdumpPath.trim(); objdumpExecArray[objdumpExecArray.length-1] = libraryFile.getAbsolutePath(); System.arraycopy(splittedObjdumpArgs, 0, objdumpExecArray, 1, splittedObjdumpArgs.length); } else { objdumpExecArray = new String[2]; objdumpExecArray[0] = objdumpPath.trim(); objdumpExecArray[1] = libraryFile.getAbsolutePath(); } String line; Process p = Runtime.getRuntime().exec(objdumpExecArray); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); p.getErrorStream().close(); // Ignore error stream while ((line = input.readLine()) != null) { objdumpData.add(line); } input.close(); } catch (Exception err) { err.printStackTrace(); return null; } if (objdumpData == null || objdumpData.size() == 0) return null; return objdumpData; } /** * Returns simulation holding this mote type * * @return Simulation */ public Simulation getSimulation() { return mySimulation; } /** * Sets simulation holding this mote type * * @param simulation * Simulation holding this mote type */ public void setSimulation(Simulation simulation) { mySimulation = simulation; } public String getDescription() { return description; } public void setDescription(String newDescription) { description = newDescription; } /** * Returns path to contiki base dir * * @return String containing path */ public String getContikiBaseDir() { return contikiBaseDir; } /** * Sets contiki base dir to path. * * @param path * Contiki base dir */ public void setContikiBaseDir(String path) { contikiBaseDir = path; } /** * Returns path to contiki core dir * * @return String containing path */ public String getContikiCoreDir() { return contikiCoreDir; } /** * Sets contiki core dir to path. * * @param path * Contiki core dir */ public void setContikiCoreDir(String path) { contikiCoreDir = path; } /** * Returns compilation files *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -