public class CSFileReader {
- private File csFile;
-
- public CSFileReader(String csFilePath) {
- csFile = new File(csFilePath);
- }
-
- public void demanglingFile() {
-
- try {
- String sdkRoot = InstallPathConfig.getSDKPath();
-
- if (sdkRoot != null && !sdkRoot.isEmpty()) {
-
- StringBuffer sb = new StringBuffer();
- StringBuffer sbFile = new StringBuffer();
-
- // 1. If windows, making cat.exe File object.
- if (isWindows()) {
- sb.append("tools");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("mingw");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("msys");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("1.0");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("bin");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("cat.exe");
- sb.append(" ");//$NON-NLS-1$
- } else if (isLinux() || isMacOS()) {
- sb.append("cat ");//$NON-NLS-1$
- } else {
- return;
- }
-
- // $INPUT_FILE
- sbFile.append("\"");//$NON-NLS-1$
- sbFile.append(csFile.getCanonicalFile().getCanonicalPath());
- sbFile.append("\"");//$NON-NLS-1$
- String strInputFile = sbFile.toString();
-
- sb.append(strInputFile);
- String strCommandCat = sb.toString();
-
- // 2. Making i386-linux-gnueabi-c++filt File object.
- sb.delete(0, sb.length());
- sb.append("tools");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("i386-linux-gnueabi-gcc-4.5");//$NON-NLS-1$
- sb.append(File.separator);
- sb.append("bin");//$NON-NLS-1$
- sb.append(File.separator);
- if (isWindows()) {
- sb.append("i386-linux-gnueabi-c++filt.exe");//$NON-NLS-1$
- } else if (isLinux() || isMacOS()) {
- sb.append("i386-linux-gnueabi-c++filt");//$NON-NLS-1$
- } else {
- return;
- }
- sb.append(" > ");//$NON-NLS-1$
-
- // $OUTPUT_FILE
- sbFile.delete(0, sbFile.length());
- sbFile.append("\"");//$NON-NLS-1$
- sbFile.append(csFile.getParentFile().getCanonicalPath());
- sbFile.append(File.separator);
- sbFile.append("copy_");//$NON-NLS-1$
- sbFile.append(csFile.getName());
- sbFile.append("\"");//$NON-NLS-1$
- String strOutputFile = sbFile.toString();
-
- sb.append(strOutputFile);
- String strCommandFilt = sb.toString();
-
- // 3. Making complete command.
- sb.delete(0, sb.length());
- sb.append(strCommandCat);
- sb.append(" | ");//$NON-NLS-1$
- sb.append(strCommandFilt);
-
- // 4. Run command.
- ProcessBuilder processBuilder = new ProcessBuilder();
- processBuilder.command(getCommand(sb.toString()));
- processBuilder.directory(new File(sdkRoot));
- Process process = processBuilder.start();
- if (process.waitFor() == 0)
- process.destroy();
-
- // Final. Change file
- strInputFile = strInputFile.substring(1, strInputFile.length() - 1);
- File fileInput = new File(strInputFile);
- fileInput.setWritable(true);
- fileInput.delete();
-
- strOutputFile = strOutputFile.substring(1, strOutputFile.length() - 1);
- File fileOutput = new File(strOutputFile);
- fileOutput.setWritable(true);
- fileOutput.renameTo(new File(strInputFile));
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- private String[] getCommand(String strCmd) {
- if (isWindows()) {
- return new String[] { "cmd", "/c", strCmd }; //$NON-NLS-1$
- } else if (isLinux() || isMacOS()) {
- return new String[] { "/bin/sh", "-c", strCmd }; //$NON-NLS-1$
- }
- return null;
- }
-
- private static final int MODE_DEFAULT = 0;
-
- private static final int MODE_HEADER = 1;
- private static final int MODE_HEADER_CRASH = 2;
- private static final int MODE_HEADER_SIGNAL = 3;
- private static final int MODE_HEADER_REGISTER_INFO = 4;
- private static final int MODE_HEADER_MEMORY = 5;
- private static final int MODE_HEADER_PACKAGE = 6;
-
- private static final int MODE_CALL_STACK_INFO = 12;
- private static final int MODE_MEMORY_MAP = 13;
- private static final int MODE_DEBUG_MESSAGE = 14;
-
- private String strSignalNumber = null;
- private int mode = MODE_DEFAULT;
-
- public CSVO parse() {
- CSVO result = null;
-
- if (csFile != null) {
- String strLine = null;
- FileReader fr = null;
- BufferedReader br = null;
-
- mode = MODE_DEFAULT;
- result = new CSVO();
-
- try {
- fr = new FileReader(csFile);
- br = new BufferedReader(fr);
-
- while ((strLine = br.readLine()) != null) {
-
- strLine = strLine.trim();
-
- switch (mode) {
- case MODE_DEFAULT:
- if (strLine.equals("S/W Version Information"))//$NON-NLS-1$
- mode = MODE_HEADER;
- else if (strLine.equals("Crash Information"))//$NON-NLS-1$
- mode = MODE_HEADER_CRASH;
- else if (strLine.equals("Package Information"))//$NON-NLS-1$
- mode = MODE_HEADER_PACKAGE;
- else if (strLine.startsWith("Register Information"))//$NON-NLS-1$
- mode = MODE_HEADER_REGISTER_INFO;
- else if (strLine.startsWith("Memory Information"))//$NON-NLS-1$
- mode = MODE_HEADER_MEMORY;
- else if (strLine.startsWith("Callstack Information"))//$NON-NLS-1$
- mode = MODE_CALL_STACK_INFO;
- else if (strLine.startsWith("Maps Information"))//$NON-NLS-1$
- mode = MODE_MEMORY_MAP;
- else if (strLine.startsWith("Latest Debug Message Information"))//$NON-NLS-1$
- mode = MODE_DEBUG_MESSAGE;
- break;
-
- case MODE_HEADER:
- if (parseHeader(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_HEADER_CRASH:
- if (parseHeaderCrash(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_HEADER_SIGNAL:
- if (parseHeaderSignal(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_HEADER_REGISTER_INFO:
- if (parseHeaderRegisterInfo(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_HEADER_PACKAGE:
- if (parseHeaderPackage(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_HEADER_MEMORY:
- if (parseHeaderMemory(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_CALL_STACK_INFO:
- if (parseCallStackInfo(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_MEMORY_MAP:
- if (parseMemoryMap(result, strLine))
- mode = MODE_DEFAULT;
- break;
-
- case MODE_DEBUG_MESSAGE:
- if (parseDebugMessage(result, strLine))
- mode = MODE_DEFAULT;
- break;
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (fr != null)
- fr.close();
- if (br != null)
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- return result;
- }
-
- /**
- * @param result
- * @param strLine
- * @return
- */
- /**
- * @param result
- * @param strLine
- * @return
- */
- private boolean parseHeader(CSVO result, String strLine) throws Exception {
-
- boolean isEnd = false;
-
- int idxSub = -1;
- String strSub = null;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- if (strLine.startsWith("Build-Number:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length());
- header.setBuildNumber(strSub);
- }
- } else if (strLine.startsWith("Build-Date:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length());
- header.setBuildDate(strSub);
- }
- } else if (strLine.startsWith("Model:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length());
- header.setModel(strSub);
- }
- } else if (strLine.startsWith("Tizen-Version:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length());
- header.setVersion(strSub);
- }
- }
- result.setHeader(header);
- }
-
- return isEnd;
- }
-
- private boolean parseHeaderCrash(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- int idxSub = -1;
- String strSub = null;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- if (strLine.startsWith("Date:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setCrashDate(strSub);
- }
- } else if (strLine.startsWith("Executable File Path:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setCrashExePath(strSub);
- }
- } else if (strLine.startsWith("Process Name:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setProcessName(strSub);
- }
- } else if (strLine.startsWith("PID:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setPID(strSub);
- }
- } else if (strLine.startsWith("Signal:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.appendSignalLine(strSub);
- mode = MODE_HEADER_SIGNAL;
- }
- }
- result.setHeader(header);
- }
-
- return isEnd;
- }
-
- private boolean parseHeaderSignal(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- if (strSignalNumber != null && !strSignalNumber.isEmpty()) {
- header.appendSignalLine(strSignalNumber);
- strSignalNumber = null;
- }
-
- header.appendSignalLine(strLine);
- result.setHeader(header);
- }
-
- return isEnd;
- }
-
- private boolean parseHeaderPackage(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- int idxSub = -1;
- String strSub = null;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- if (strLine.startsWith("Package Name:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setPackageName(strSub);
- }
- } else if (strLine.startsWith("Package Type:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setPackageType(strSub);
- }
- } else if (strLine.startsWith("Version:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setPackageVersion(strSub);
- }
- } else if (strLine.startsWith("App Name:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setAppName(strSub);
- }
- } else if (strLine.startsWith("App ID")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setAppID(strSub);
- }
- } else if (strLine.startsWith("Type:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setAppType(strSub);
- }
- } else if (strLine.startsWith("Categories:")) {//$NON-NLS-1$
- idxSub = strLine.indexOf(':');
- if (idxSub > -1) {
- strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
- header.setCategories(strSub);
- }
- }
- }
-
- return isEnd;
- }
-
- private boolean parseHeaderRegisterInfo(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- ArrayList<RegisterVO> registerList = header.getRegisterList();
- String[] strsLine = strLine.split(",");//$NON-NLS-1$
- for (String str : strsLine) {
- int idxSub = str.indexOf('=');//$NON-NLS-1$
- if (idxSub > -1) {
- RegisterVO registerVO = new RegisterVO(str.substring(0, idxSub).trim(), str.substring(idxSub + 1,
- str.length()).trim());
- registerList.add(registerVO);
- }
- }
-
- header.setRegisters(registerList);
- result.setHeader(header);
- }
-
- return isEnd;
- }
-
- private boolean parseHeaderMemory(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.isEmpty()) {
- isEnd = true;
- } else {
- HeaderVO header = result.getHeader();
-
- int idxSub = -1;
- String strSub = null;
-
- idxSub = strLine.indexOf(":");//$NON-NLS-1$
- if (idxSub > -1) {
- strSub = strLine.substring(0, idxSub).trim();
- if (strSub.equals("MemTotal")) {//$NON-NLS-1$
- header.setMemTotal(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("MemFree")) {//$NON-NLS-1$
- header.setMemFree(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("Buffers")) {//$NON-NLS-1$
- header.setBuffers(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("Cached")) {//$NON-NLS-1$
- header.setCached(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmPeak")) {//$NON-NLS-1$
- header.setVmPeak(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmSize")) {//$NON-NLS-1$
- header.setVmSize(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmLck")) {//$NON-NLS-1$
- header.setVmLck(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmPin")) {//$NON-NLS-1$
- header.setVmPin(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmHWM")) {//$NON-NLS-1$
- header.setVmHWM(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmRSS")) {//$NON-NLS-1$
- header.setVmRSS(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmData")) {//$NON-NLS-1$
- header.setVmData(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmStk")) {//$NON-NLS-1$
- header.setVmStk(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmExe")) {//$NON-NLS-1$
- header.setVmExe(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmLib")) {//$NON-NLS-1$
- header.setVmLib(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmPTE")) {//$NON-NLS-1$
- header.setVmPTE(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- } else if (strSub.equals("VmSwap")) {//$NON-NLS-1$
- header.setVmSwap(Integer.parseInt(strLine.substring(idxSub + 1, strLine.length())
- .replace(" KB", "").trim()));//$NON-NLS-1$
- }
- }
-
- result.setHeader(header);
- }
-
- return isEnd;
- }
-
- private boolean parseCallStackInfo(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.equals("End of Call Stack")) {//$NON-NLS-1$
- isEnd = true;
- } else if (strLine.startsWith("Call Stack Count:")) {//$NON-NLS-1$
- // Ignore
- } else {
- ArrayList<CallStackVO> csList = result.getCallStackList();
-
- int idxSub = -1;
- int idxL = -1, idxR = -1;
- int countP = 0;
-
- CallStackVO csVO = new CallStackVO();
-
- idxSub = strLine.indexOf(":");
- if (idxSub > -1)
- csVO.setSerialNumber(Integer.parseInt(strLine.substring(0, idxSub).trim()));
-
- // emluator vs. target
- boolean isAbnormalAddressFormat = false;
- String strAddressTemp = null;
- long addressTemp = 0l;
- idxL = strLine.indexOf('[');
- idxR = strLine.indexOf(']');
- if (idxL > -1 && idxR > -1) {
- strAddressTemp = strLine.substring(idxL + 1, idxR).trim();
- if (strAddressTemp != null) {
- try {
- if (strAddressTemp.startsWith("0x"))//$NON-NLS-1$
- strAddressTemp = strAddressTemp.substring(2, strAddressTemp.length());
- addressTemp = Long.parseLong(strAddressTemp, 16);
- } catch (NumberFormatException e) {
- isAbnormalAddressFormat = true;
- }
- }
- }
-
- if (isAbnormalAddressFormat) {
- // Target
-
- idxL = 0;
- idxR = 0;
- countP = countParentheses(strLine);
- if (countP > 0) {
- for (int i = 0; i < countP; i++) {
- idxL = strLine.indexOf("(", idxL);//$NON-NLS-1$
- if (idxL > -1) {
- idxR = strLine.indexOf(")", idxL);//$NON-NLS-1$
- if (idxR > -1) {
- if (idxL + 3 < idxR) {
- long longTemp = getAddress(strLine.substring(idxL + 1, idxR).trim());
- if (longTemp != 0) {
- csVO.setAddressS(strLine.substring(idxL + 1, idxR).trim());
- csVO.setAddressL(longTemp);
- csVO.setPayload(strLine);
-
- csList.add(csVO);
- result.setCallStackList(csList);
- break;
- } else {
- idxL = idxR;
- }
- } else {
- idxL = idxR;
- }
- }
- }
- }
- }
- } else {
- // Emulator
- csVO.setAddressS(strAddressTemp);
- csVO.setAddressL(addressTemp);
-
- if (idxSub > 0 && idxL > 0)
- csVO.setPayload(strLine.substring(idxSub, idxL).trim());
- csList.add(csVO);
- result.setCallStackList(csList);
- }
- }
-
- return isEnd;
- }
-
- private boolean parseMemoryMap(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.equals("End of Maps Information")) {//$NON-NLS-1$
- isEnd = true;
- } else if (!strLine.isEmpty()) {
- ArrayList<MemoryMapVO> memoryMapList = result.getMemoryMapList();
-
- int idxStart = 0, idxEnd = -1;
- String strSub = null;
- MemoryMapVO memoryMapVO = new MemoryMapVO();
-
- idxEnd = strLine.indexOf(" ");//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- memoryMapVO.setStartAddressS(strSub);
- memoryMapVO.setStartAddressL(Long.parseLong(strSub, 16));
- }
- idxStart = idxEnd + 1;
- idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- memoryMapVO.setEndAddressS(strSub);
- memoryMapVO.setEndAddressL(Long.parseLong(strSub, 16));
- }
- idxStart = idxEnd + 1;
- idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- memoryMapVO.setMod(strSub);
- }
- idxStart = idxEnd + 1;
- idxEnd = strLine.length();
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- memoryMapVO.setSoInfo(strSub);
- }
-
- memoryMapList.add(memoryMapVO);
- result.setMemoryMapList(memoryMapList);
- }
-
- return isEnd;
- }
-
- private boolean parseDebugMessage(CSVO result, String strLine) throws Exception {
- boolean isEnd = false;
-
- if (strLine.startsWith("end of latest dmf")) {//$NON-NLS-1$
- isEnd = true;
- } else {
- boolean isAbnormalLine = false;
- ArrayList<DebugMessageVO> debugMessageList = result.getDebugMessageList();
-
- int idxStart = -1, idxEnd = -1;
- String strSub = null;
- DebugMessageVO debugMessageVO = new DebugMessageVO();
-
- idxEnd = strLine.indexOf(" ");//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(0, idxEnd);
- idxStart = idxEnd + 1;
- idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(0, idxEnd).trim();
- debugMessageVO.setDate(strSub);
- } else {
- isAbnormalLine = true;
- }
- }
- idxStart = idxEnd + 1;
- idxEnd = strLine.indexOf("(", idxStart);//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- debugMessageVO.setTag(strSub);
- } else {
- isAbnormalLine = true;
- }
- idxStart = idxEnd + 1;
- idxEnd = strLine.indexOf(")", idxStart);//$NON-NLS-1$
- if (idxEnd > -1) {
- strSub = strLine.substring(idxStart, idxEnd).trim();
- debugMessageVO.setPID(strSub);
- } else {
- isAbnormalLine = true;
- }
- idxStart = strLine.indexOf(":", idxEnd);//$NON-NLS-1$
- if (idxStart > -1) {
- strSub = strLine.substring(idxStart + 1, strLine.length()).trim();
- debugMessageVO.setMessage(strSub);
- } else {
- isAbnormalLine = true;
- }
-
- if (!isAbnormalLine)
- debugMessageList.add(debugMessageVO);
- result.setDebugMessageList(debugMessageList);
- }
-
- return isEnd;
- }
-
- private int countParentheses(String strLine) {
- int result = 0;
- int i, len = 0;
- boolean isLeft = false;
-
- if (strLine != null)
- len = strLine.length();
-
- for (i = 0; i < len; i++) {
- if (strLine.charAt(i) == '(')
- isLeft = true;
-
- if (isLeft && strLine.charAt(i) == ')') {
- result++;
- isLeft = false;
- }
- }
-
- return result;
- }
-
- private long getAddress(String strLine) {
- long result = 0;
-
- if (strLine != null && strLine.startsWith("0x")) {//$NON-NLS-1$
- strLine = strLine.substring(3, strLine.length()).trim();
- result = Long.parseLong(strLine, 16);
- }
-
- return result;
- }
-
- /*
- * From OSChecker.java
- */
- public String PROPERTY_OS_NAME = (System.getProperty("os.name") != null) //$NON-NLS-1$
- ? System.getProperty("os.name").toLowerCase() : ""; //$NON-NLS-1$
-
- public boolean isWindows() {
- if (PROPERTY_OS_NAME.contains("windows")) { //$NON-NLS-1$
- return true;
- }
- return false;
- }
-
- public boolean isLinux() {
- if (PROPERTY_OS_NAME.contains("linux")) { //$NON-NLS-1$
- return true;
- }
- return false;
- }
-
- public boolean isMacOS() {
- if (PROPERTY_OS_NAME.contains("mac")) { //$NON-NLS-1$
- return true;
- }
- return false;
- }
+ private File csFile;
+
+ public CSFileReader(String csFilePath) {
+ csFile = new File(csFilePath);
+ }
+
+ public void demanglingFile() {
+
+ try {
+ String sdkRoot = InstallPathConfig.getSDKPath();
+
+ if (sdkRoot != null && !sdkRoot.isEmpty()) {
+
+ StringBuffer sb = new StringBuffer();
+ StringBuffer sbFile = new StringBuffer();
+
+ // 1. If windows, making cat.exe File object.
+ if (isWindows()) {
+ sb.append("tools");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("mingw");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("msys");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("1.0");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("bin");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("cat.exe");
+ sb.append(" ");//$NON-NLS-1$
+ } else if (isLinux() || isMacOS()) {
+ sb.append("cat ");//$NON-NLS-1$
+ } else {
+ return;
+ }
+
+ // $INPUT_FILE
+ sbFile.append("\"");//$NON-NLS-1$
+ sbFile.append(csFile.getCanonicalFile().getCanonicalPath());
+ sbFile.append("\"");//$NON-NLS-1$
+ String strInputFile = sbFile.toString();
+
+ sb.append(strInputFile);
+ String strCommandCat = sb.toString();
+
+ // 2. Making i386-linux-gnueabi-c++filt File object.
+ sb.delete(0, sb.length());
+ sb.append("tools");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("i386-linux-gnueabi-gcc-4.5");//$NON-NLS-1$
+ sb.append(File.separator);
+ sb.append("bin");//$NON-NLS-1$
+ sb.append(File.separator);
+ if (isWindows()) {
+ sb.append("i386-linux-gnueabi-c++filt.exe");//$NON-NLS-1$
+ } else if (isLinux() || isMacOS()) {
+ sb.append("i386-linux-gnueabi-c++filt");//$NON-NLS-1$
+ } else {
+ return;
+ }
+ sb.append(" > ");//$NON-NLS-1$
+
+ // $OUTPUT_FILE
+ sbFile.delete(0, sbFile.length());
+ sbFile.append("\"");//$NON-NLS-1$
+ sbFile.append(csFile.getParentFile().getCanonicalPath());
+ sbFile.append(File.separator);
+ sbFile.append("copy_");//$NON-NLS-1$
+ sbFile.append(csFile.getName());
+ sbFile.append("\"");//$NON-NLS-1$
+ String strOutputFile = sbFile.toString();
+
+ sb.append(strOutputFile);
+ String strCommandFilt = sb.toString();
+
+ // 3. Making complete command.
+ sb.delete(0, sb.length());
+ sb.append(strCommandCat);
+ sb.append(" | ");//$NON-NLS-1$
+ sb.append(strCommandFilt);
+
+ // 4. Run command.
+ ProcessBuilder processBuilder = new ProcessBuilder();
+ processBuilder.command(getCommand(sb.toString()));
+ processBuilder.directory(new File(sdkRoot));
+ Process process = processBuilder.start();
+ if (process.waitFor() == 0)
+ process.destroy();
+
+ // Final. Change file
+ strInputFile = strInputFile.substring(1, strInputFile.length() - 1);
+ File fileInput = new File(strInputFile);
+ fileInput.setWritable(true);
+ fileInput.delete();
+
+ strOutputFile = strOutputFile.substring(1, strOutputFile.length() - 1);
+ File fileOutput = new File(strOutputFile);
+ fileOutput.setWritable(true);
+ fileOutput.renameTo(new File(strInputFile));
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String[] getCommand(String strCmd) {
+ if (isWindows()) {
+ return new String[] { "cmd", "/c", strCmd }; //$NON-NLS-1$
+ } else if (isLinux() || isMacOS()) {
+ return new String[] { "/bin/sh", "-c", strCmd }; //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ private static final int MODE_DEFAULT = 0;
+
+ private static final int MODE_HEADER = 1;
+ private static final int MODE_HEADER_CRASH = 2;
+ private static final int MODE_HEADER_SIGNAL = 3;
+ private static final int MODE_HEADER_REGISTER_INFO = 4;
+ private static final int MODE_HEADER_MEMORY = 5;
+ private static final int MODE_HEADER_PACKAGE = 6;
+
+ private static final int MODE_CALL_STACK_INFO = 12;
+ private static final int MODE_MEMORY_MAP = 13;
+ private static final int MODE_DEBUG_MESSAGE = 14;
+
+ private String strSignalNumber = null;
+ private int mode = MODE_DEFAULT;
+
+ public CSVO parse() {
+ CSVO result = null;
+
+ if (csFile != null) {
+ String strLine = null;
+ FileReader fr = null;
+ BufferedReader br = null;
+
+ mode = MODE_DEFAULT;
+ result = new CSVO();
+
+ try {
+ fr = new FileReader(csFile);
+ br = new BufferedReader(fr);
+
+ while ((strLine = br.readLine()) != null) {
+
+ strLine = strLine.trim();
+
+ switch (mode) {
+ case MODE_DEFAULT:
+ if (strLine.equals("S/W Version Information"))//$NON-NLS-1$
+ mode = MODE_HEADER;
+ else if (strLine.equals("Crash Information"))//$NON-NLS-1$
+ mode = MODE_HEADER_CRASH;
+ else if (strLine.equals("Package Information"))//$NON-NLS-1$
+ mode = MODE_HEADER_PACKAGE;
+ else if (strLine.startsWith("Register Information"))//$NON-NLS-1$
+ mode = MODE_HEADER_REGISTER_INFO;
+ else if (strLine.startsWith("Memory Information"))//$NON-NLS-1$
+ mode = MODE_HEADER_MEMORY;
+ else if (strLine.startsWith("Callstack Information"))//$NON-NLS-1$
+ mode = MODE_CALL_STACK_INFO;
+ else if (strLine.startsWith("Maps Information"))//$NON-NLS-1$
+ mode = MODE_MEMORY_MAP;
+ else if (strLine.startsWith("Latest Debug Message Information"))//$NON-NLS-1$
+ mode = MODE_DEBUG_MESSAGE;
+ break;
+
+ case MODE_HEADER:
+ if (parseHeader(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_HEADER_CRASH:
+ if (parseHeaderCrash(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_HEADER_SIGNAL:
+ if (parseHeaderSignal(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_HEADER_REGISTER_INFO:
+ if (parseHeaderRegisterInfo(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_HEADER_PACKAGE:
+ if (parseHeaderPackage(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_HEADER_MEMORY:
+ if (parseHeaderMemory(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_CALL_STACK_INFO:
+ if (parseCallStackInfo(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_MEMORY_MAP:
+ if (parseMemoryMap(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+
+ case MODE_DEBUG_MESSAGE:
+ if (parseDebugMessage(result, strLine))
+ mode = MODE_DEFAULT;
+ break;
+ }
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fr != null)
+ fr.close();
+ if (br != null)
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * @param result
+ * @param strLine
+ * @return
+ */
+ /**
+ * @param result
+ * @param strLine
+ * @return
+ */
+ private boolean parseHeader(CSVO result, String strLine) throws Exception {
+
+ boolean isEnd = false;
+
+ int idxSub = -1;
+ String strSub = null;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ if (strLine.startsWith("Build-Number:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length());
+ header.setBuildNumber(strSub);
+ }
+ } else if (strLine.startsWith("Build-Date:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length());
+ header.setBuildDate(strSub);
+ }
+ } else if (strLine.startsWith("Model:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length());
+ header.setModel(strSub);
+ }
+ } else if (strLine.startsWith("Tizen-Version:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length());
+ header.setVersion(strSub);
+ }
+ }
+ result.setHeader(header);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseHeaderCrash(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ int idxSub = -1;
+ String strSub = null;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ if (strLine.startsWith("Date:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setCrashDate(strSub);
+ }
+ } else if (strLine.startsWith("Executable File Path:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setCrashExePath(strSub);
+ }
+ } else if (strLine.startsWith("Process Name:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setProcessName(strSub);
+ }
+ } else if (strLine.startsWith("PID:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setPID(strSub);
+ }
+ } else if (strLine.startsWith("Signal:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.appendSignalLine(strSub);
+ mode = MODE_HEADER_SIGNAL;
+ }
+ }
+ result.setHeader(header);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseHeaderSignal(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ if (strSignalNumber != null && !strSignalNumber.isEmpty()) {
+ header.appendSignalLine(strSignalNumber);
+ strSignalNumber = null;
+ }
+
+ header.appendSignalLine(strLine);
+ result.setHeader(header);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseHeaderPackage(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ int idxSub = -1;
+ String strSub = null;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ if (strLine.startsWith("Package Name:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setPackageName(strSub);
+ }
+ } else if (strLine.startsWith("Name")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ String strTitle = strLine.substring(0, idxSub).trim();
+ if (strTitle.equals("Name")) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setPackageName(strSub);
+ }
+ }
+ } else if (strLine.startsWith("Package Type:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setPackageType(strSub);
+ }
+ } else if (strLine.startsWith("Version")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setPackageVersion(strSub);
+ }
+ } else if (strLine.startsWith("Release")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ String strTitle = strLine.substring(0, idxSub).trim();
+ if (strTitle.equals("Release")) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ String ver = header.getPackageVersion();
+ if (ver != null) {
+ ver = ver + "-" + strSub;
+ header.setPackageVersion(ver);
+ }
+ }
+ }
+ } else if (strLine.startsWith("App Name:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setAppName(strSub);
+ }
+ } else if (strLine.startsWith("App ID")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setAppID(strSub);
+ }
+ } else if (strLine.startsWith("Type:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setAppType(strSub);
+ }
+ } else if (strLine.startsWith("Categories:")) {//$NON-NLS-1$
+ idxSub = strLine.indexOf(':');
+ if (idxSub > -1) {
+ strSub = strLine.substring(idxSub + 1, strLine.length()).trim();
+ header.setCategories(strSub);
+ }
+ }
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseHeaderRegisterInfo(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ ArrayList<RegisterVO> registerList = header.getRegisterList();
+ String[] strsLine = strLine.split(",");//$NON-NLS-1$
+ for (String str : strsLine) {
+ int idxSub = str.indexOf('=');//$NON-NLS-1$
+ if (idxSub > -1) {
+ RegisterVO registerVO = new RegisterVO(str.substring(0, idxSub).trim(), str
+ .substring(idxSub + 1, str.length()).trim());
+ registerList.add(registerVO);
+ }
+ }
+
+ header.setRegisters(registerList);
+ result.setHeader(header);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseHeaderMemory(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.isEmpty()) {
+ isEnd = true;
+ } else {
+ HeaderVO header = result.getHeader();
+
+ int idxSub = -1;
+ String strSub = null;
+
+ idxSub = strLine.indexOf(":");//$NON-NLS-1$
+ if (idxSub > -1) {
+ strSub = strLine.substring(0, idxSub).trim();
+ if (strSub.equals("MemTotal")) {//$NON-NLS-1$
+ header.setMemTotal(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("MemFree")) {//$NON-NLS-1$
+ header.setMemFree(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("Buffers")) {//$NON-NLS-1$
+ header.setBuffers(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("Cached")) {//$NON-NLS-1$
+ header.setCached(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmPeak")) {//$NON-NLS-1$
+ header.setVmPeak(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmSize")) {//$NON-NLS-1$
+ header.setVmSize(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmLck")) {//$NON-NLS-1$
+ header.setVmLck(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmPin")) {//$NON-NLS-1$
+ header.setVmPin(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmHWM")) {//$NON-NLS-1$
+ header.setVmHWM(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmRSS")) {//$NON-NLS-1$
+ header.setVmRSS(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmData")) {//$NON-NLS-1$
+ header.setVmData(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmStk")) {//$NON-NLS-1$
+ header.setVmStk(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmExe")) {//$NON-NLS-1$
+ header.setVmExe(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmLib")) {//$NON-NLS-1$
+ header.setVmLib(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmPTE")) {//$NON-NLS-1$
+ header.setVmPTE(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ } else if (strSub.equals("VmSwap")) {//$NON-NLS-1$
+ header.setVmSwap(Integer.parseInt(strLine
+ .substring(idxSub + 1, strLine.length()).replace(" KB", "").trim()));//$NON-NLS-1$
+ }
+ }
+
+ result.setHeader(header);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseCallStackInfo(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.equals("End of Call Stack")) {//$NON-NLS-1$
+ isEnd = true;
+ } else if (strLine.startsWith("Call Stack Count:")) {//$NON-NLS-1$
+ // Ignore
+ } else {
+ ArrayList<CallStackVO> csList = result.getCallStackList();
+
+ int idxSub = -1;
+ int idxL = -1, idxR = -1;
+ int countP = 0;
+
+ CallStackVO csVO = new CallStackVO();
+
+ idxSub = strLine.indexOf(":");
+ if (idxSub > -1)
+ csVO.setSerialNumber(Integer.parseInt(strLine.substring(0, idxSub).trim()));
+
+ // emluator vs. target
+ boolean isAbnormalAddressFormat = false;
+ String strAddressTemp = null;
+ long addressTemp = 0l;
+ idxL = strLine.indexOf('[');
+ idxR = strLine.indexOf(']');
+ if (idxL > -1 && idxR > -1) {
+ strAddressTemp = strLine.substring(idxL + 1, idxR).trim();
+ if (strAddressTemp != null) {
+ try {
+ if (strAddressTemp.startsWith("0x"))//$NON-NLS-1$
+ strAddressTemp = strAddressTemp.substring(2, strAddressTemp.length());
+ addressTemp = Long.parseLong(strAddressTemp, 16);
+ } catch (NumberFormatException e) {
+ isAbnormalAddressFormat = true;
+ }
+ }
+ }
+
+ if (isAbnormalAddressFormat) {
+ // Target
+
+ idxL = 0;
+ idxR = 0;
+ countP = countParentheses(strLine);
+ if (countP > 0) {
+ for (int i = 0; i < countP; i++) {
+ idxL = strLine.indexOf("(", idxL);//$NON-NLS-1$
+ if (idxL > -1) {
+ idxR = strLine.indexOf(")", idxL);//$NON-NLS-1$
+ if (idxR > -1) {
+ if (idxL + 3 < idxR) {
+ long longTemp = getAddress(strLine.substring(idxL + 1, idxR)
+ .trim());
+ if (longTemp != 0) {
+ csVO.setAddressS(strLine.substring(idxL + 1, idxR).trim());
+ csVO.setAddressL(longTemp);
+ csVO.setPayload(strLine);
+
+ csList.add(csVO);
+ result.setCallStackList(csList);
+ break;
+ } else {
+ idxL = idxR;
+ }
+ } else {
+ idxL = idxR;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ // Emulator
+ csVO.setAddressS(strAddressTemp);
+ csVO.setAddressL(addressTemp);
+
+ if (idxSub > 0 && idxL > 0)
+ csVO.setPayload(strLine.substring(idxSub, idxL).trim());
+ csList.add(csVO);
+ result.setCallStackList(csList);
+ }
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseMemoryMap(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.equals("End of Maps Information")) {//$NON-NLS-1$
+ isEnd = true;
+ } else if (!strLine.isEmpty()) {
+ ArrayList<MemoryMapVO> memoryMapList = result.getMemoryMapList();
+
+ int idxStart = 0, idxEnd = -1;
+ String strSub = null;
+ MemoryMapVO memoryMapVO = new MemoryMapVO();
+
+ idxEnd = strLine.indexOf(" ");//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ memoryMapVO.setStartAddressS(strSub);
+ memoryMapVO.setStartAddressL(Long.parseLong(strSub, 16));
+ }
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ memoryMapVO.setEndAddressS(strSub);
+ memoryMapVO.setEndAddressL(Long.parseLong(strSub, 16));
+ }
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ memoryMapVO.setMod(strSub);
+ }
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.length();
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ memoryMapVO.setSoInfo(strSub);
+ }
+
+ memoryMapList.add(memoryMapVO);
+ result.setMemoryMapList(memoryMapList);
+ }
+
+ return isEnd;
+ }
+
+ private boolean parseDebugMessage(CSVO result, String strLine) throws Exception {
+ boolean isEnd = false;
+
+ if (strLine.startsWith("end of latest dmf")) {//$NON-NLS-1$
+ isEnd = true;
+ } else {
+ boolean isAbnormalLine = false;
+ ArrayList<DebugMessageVO> debugMessageList = result.getDebugMessageList();
+
+ int idxStart = -1, idxEnd = -1;
+ String strSub = null;
+ DebugMessageVO debugMessageVO = new DebugMessageVO();
+
+ idxEnd = strLine.indexOf(" ");//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(0, idxEnd);
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.indexOf(" ", idxStart);//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(0, idxEnd).trim();
+ debugMessageVO.setDate(strSub);
+ } else {
+ isAbnormalLine = true;
+ }
+ }
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.indexOf("(", idxStart);//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ debugMessageVO.setTag(strSub);
+ } else {
+ isAbnormalLine = true;
+ }
+ idxStart = idxEnd + 1;
+ idxEnd = strLine.indexOf(")", idxStart);//$NON-NLS-1$
+ if (idxEnd > -1) {
+ strSub = strLine.substring(idxStart, idxEnd).trim();
+ debugMessageVO.setPID(strSub);
+ } else {
+ isAbnormalLine = true;
+ }
+ idxStart = strLine.indexOf(":", idxEnd);//$NON-NLS-1$
+ if (idxStart > -1) {
+ strSub = strLine.substring(idxStart + 1, strLine.length()).trim();
+ debugMessageVO.setMessage(strSub);
+ } else {
+ isAbnormalLine = true;
+ }
+
+ if (!isAbnormalLine)
+ debugMessageList.add(debugMessageVO);
+ result.setDebugMessageList(debugMessageList);
+ }
+
+ return isEnd;
+ }
+
+ private int countParentheses(String strLine) {
+ int result = 0;
+ int i, len = 0;
+ boolean isLeft = false;
+
+ if (strLine != null)
+ len = strLine.length();
+
+ for (i = 0; i < len; i++) {
+ if (strLine.charAt(i) == '(')
+ isLeft = true;
+
+ if (isLeft && strLine.charAt(i) == ')') {
+ result++;
+ isLeft = false;
+ }
+ }
+
+ return result;
+ }
+
+ private long getAddress(String strLine) {
+ long result = 0;
+
+ if (strLine != null && strLine.startsWith("0x")) {//$NON-NLS-1$
+ strLine = strLine.substring(3, strLine.length()).trim();
+ result = Long.parseLong(strLine, 16);
+ }
+
+ return result;
+ }
+
+ /*
+ * From OSChecker.java
+ */
+ public String PROPERTY_OS_NAME = (System.getProperty("os.name") != null) //$NON-NLS-1$
+ ? System.getProperty("os.name").toLowerCase() : ""; //$NON-NLS-1$
+
+ public boolean isWindows() {
+ if (PROPERTY_OS_NAME.contains("windows")) { //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isLinux() {
+ if (PROPERTY_OS_NAME.contains("linux")) { //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isMacOS() {
+ if (PROPERTY_OS_NAME.contains("mac")) { //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
}