From f154ab1bed00f76e72291bc3184593cb222898eb Mon Sep 17 00:00:00 2001 From: woojin Date: Sat, 17 May 2014 16:40:04 +0900 Subject: [PATCH] [Feature] enable source view for efl application [Description] 1. use source rpm package provided by IDE 2. rename elfsymbolextracter 3. modify checking routine for functions in Application Change-Id: Iade3898720263643c5c6bfc295a42e400b044591 --- ...ymbolExtracter.java => ElfSymbolExtractor.java} | 4 +- .../listeners/TableTooltipListener.java | 30 ++- .../org/tizen/dynamicanalyzer/project/AppInfo.java | 230 ++++++++++++++++----- .../swap/callstack/BaseCallstackManager.java | 3 +- .../swap/communicator/Communicator30.java | 4 +- package/build.linux | 4 + 6 files changed, 205 insertions(+), 70 deletions(-) rename org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/{ElfSymbolExtracter.java => ElfSymbolExtractor.java} (97%) diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtracter.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtractor.java similarity index 97% rename from org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtracter.java rename to org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtractor.java index 34936d5..2e90683 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtracter.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/ElfSymbolExtractor.java @@ -35,12 +35,12 @@ import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf.Symbol; import org.tizen.dynamicanalyzer.model.AddrSymbolPair; -public class ElfSymbolExtracter { +public class ElfSymbolExtractor { private String sourcePath = null; private HashMap symbolMap = null; private List addrSymbolPairs = null; - public ElfSymbolExtracter() { + public ElfSymbolExtractor() { symbolMap = new HashMap(); addrSymbolPairs = new ArrayList(); } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/TableTooltipListener.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/TableTooltipListener.java index 9bc388b..50b51df 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/TableTooltipListener.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/TableTooltipListener.java @@ -46,11 +46,13 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.common.AnalyzerConstants; import org.tizen.dynamicanalyzer.common.AnalyzerManager; +import org.tizen.dynamicanalyzer.common.GlobalInformation; import org.tizen.dynamicanalyzer.common.SymbolManager; import org.tizen.dynamicanalyzer.common.SymbolManager.SourceLine; import org.tizen.dynamicanalyzer.communicator.IDECommunicator; import org.tizen.dynamicanalyzer.constant.CommonConstants; import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; +import org.tizen.dynamicanalyzer.project.AppInfo; import org.tizen.dynamicanalyzer.resources.ColorResources; import org.tizen.dynamicanalyzer.resources.FontResources; import org.tizen.dynamicanalyzer.resources.ImageResources; @@ -465,16 +467,22 @@ public class TableTooltipListener implements Listener { BinarySettingData binData = BinarySettingManager.getInstance() .getRealBinarySetting(libName); - if (null != binData && null != binData.getUserSourcePath() + if (null != binData) { + if (null != binData.getUserSourcePath() && !binData.getUserSourcePath().isEmpty()) { - String fileName = getSourceFilePath(sourceLine.getFilePath()); - filePath = binData.getUserSourcePath() + File.separator + fileName; - } else { - if (!isLibrary(libName)) { - filePath = sourceLine.getFilePath(); + String fileName = getSourceFilePath(sourceLine.getFilePath()); + filePath = binData.getUserSourcePath() + File.separator + fileName; } else { filePath = binData.getDebugSourcePath() - + sourceLine.getFilePath(); + + sourceLine.getFilePath(); + } + } else { + AppInfo appInfo = GlobalInformation.getCurrentApplication(); + if (appInfo.getMainBinaryInfo().getTargetBinaryPath().equals(libName) + && appInfo.getAppType().contains(AppInfo.APPTYPE_CAPP)) { + filePath = appInfo.getSourcePath() + sourceLine.getFilePath(); + } else { + filePath = sourceLine.getFilePath(); } } return filePath; @@ -588,7 +596,13 @@ public class TableTooltipListener implements Listener { path = binInfo.getTempBinaryPath(); } } else { - path = binInfo.getTempBinaryPath(); + AppInfo appInfo = GlobalInformation.getCurrentApplication(); + if (binInfo.equals(appInfo.getMainBinaryInfo()) + && appInfo.getAppType().contains(AppInfo.APPTYPE_CAPP)) { + path = appInfo.getDebugFilePath(); + } else { + path = binInfo.getTempBinaryPath(); + } } SourceLine sl = SymbolManager.addr2line(path, addr, isPieBuild, baseAddr); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java index 5163903..099beed 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java @@ -35,7 +35,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import org.tizen.dynamicanalyzer.common.ElfSymbolExtracter; +import org.tizen.dynamicanalyzer.common.ElfSymbolExtractor; import org.tizen.dynamicanalyzer.common.GlobalInformation; import org.tizen.dynamicanalyzer.common.path.PathManager; import org.tizen.dynamicanalyzer.constant.CommonConstants; @@ -66,6 +66,10 @@ public class AppInfo { public static final String APPTYPE_WEB = "webapp";//$NON-NLS-1$ public static final String FLAG_ZERO = "0";//$NON-NLS-1$ public static final String FLAG_ONE = "1";//$NON-NLS-1$ + + public static final String DEBUGPKGTYPE_DEBUG = "debug-";//$NON-NLS-1$ + public static final String DEBUGPKGTYPE_DEBUGINFO = "debuginfo";//$NON-NLS-1$ + public static final String DEBUGPKGTYPE_DEBUGSOURCE = "debugsource";//$NON-NLS-1$ private static final DALogger DA_LOG = DALogger.getInstance(); @@ -78,8 +82,10 @@ public class AppInfo { private String installTime = null; private String execFileName = null; + private String debugFilePath = null; + private String sourcePath = null; - private ElfSymbolExtracter symbolExtractor = new ElfSymbolExtracter(); + private ElfSymbolExtractor symbolExtractor = new ElfSymbolExtractor(); public String getInstallTime() { return installTime; @@ -88,6 +94,22 @@ public class AppInfo { public void setInstallTime(String installTime) { this.installTime = installTime; } + + public String getDebugFilePath() { + return debugFilePath; + } + + public void setDebugFilePath(String debugFilePath) { + this.debugFilePath = debugFilePath; + } + + public String getSourcePath() { + return sourcePath; + } + + public void setSourcePath(String sourcePath) { + this.sourcePath = sourcePath; + } private List appInfo = new ArrayList(); @@ -105,32 +127,23 @@ public class AppInfo { return appInfo.get(index); } - // public BinaryInfo getBinInfo() { - // return binInfo; - // } - - // public void setBinInfo(BinaryInfo binInfo) { - // this.binInfo = binInfo; - // } - public List getSymbols(String sourceBinaryPath) { - List fromDebug = null; + List symbols = null; if (localPackagePath != null) { int psize = localPackagePath.size(); for (int i = 0; i < psize; i++) { - if (localPackagePath.get(i).contains("debuginfo")) { - fromDebug = getSymbolsFromDebugRpm(localPackagePath.get(i)); - break; + if (localPackagePath.get(i) + .contains(DEBUGPKGTYPE_DEBUGINFO)) { + getDebugFilePathFromDebugRpm(localPackagePath.get(i)); + } else if (localPackagePath.get(i) + .contains(DEBUGPKGTYPE_DEBUGSOURCE)) { + getSourcePathFromSourceRpm(localPackagePath.get(i)); } } } - if (fromDebug == null) { - List fromExec = getSymbolsFromBinary(sourceBinaryPath); - return fromExec; - } else { - return fromDebug; - } + symbols = getSymbolsFromBinary(sourceBinaryPath); + return symbols; } public List getSymbolsFromBinary(String sourceBinaryPath) { @@ -143,16 +156,18 @@ public class AppInfo { return symbolExtractor.getAddrSymbolPairs(); } - public List getSymbolsFromDebugRpm(String debugRpmPath) { + //TODO: refactoring - make rpm copy/extraction code to utility function + + public void getDebugFilePathFromDebugRpm(String debugRpmPath) { String debugFilePath = null; if (null == debugRpmPath || debugRpmPath.isEmpty()) { - return null; + return; } // check rpm file exists File debugInfoRpmFile = new File(debugRpmPath); if (!debugInfoRpmFile.exists() || debugInfoRpmFile.isDirectory()) { - return null; + return; } // copy rpm file String rpmPath = PathManager.DA_RPM_PATH + File.separator @@ -161,7 +176,7 @@ public class AppInfo { if (!rpms.exists()) { if (!rpms.mkdirs()) { DA_LOG.debug("rpm directory create failed..."); - return null; + return; } } String copiedRpmPath = null; @@ -169,7 +184,7 @@ public class AppInfo { if (AnalyzerUtil.copyFile(debugRpmPath, destPath)) { copiedRpmPath = destPath; } else { - return null; + return; } // extract rpm file @@ -177,13 +192,7 @@ public class AppInfo { String toolPath = PathManager.DA_TOOL_FOLDER_PATH + File.separator + "debuginfo.sh"; String[] command = null; - // TODO: handle source rpm package - // if (null != debugRpmSourcePath) { - // command = new String[] { toolPath, "-r", rpmPath, - // debugRpmPath, debugRpmSourcePath }; - // } else { command = new String[] { toolPath, "-d", rpmPath, debugRpmPath }; - // } try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec(command); @@ -206,22 +215,22 @@ public class AppInfo { String errorStr = error.readLine(); DA_LOG.debug("debug info file extract failed... : " + errorStr); - return null; + return; } } catch (IOException e) { e.printStackTrace(); - return null; + return; } catch (InterruptedException e) { e.printStackTrace(); - return null; + return; } } // check debuginfo file path - if (debugInfoRpmFile.getName().contains("debuginfo")) { + if (debugInfoRpmFile.getName().contains(DEBUGPKGTYPE_DEBUGINFO)) { String debugCmd = PathManager.DA_TOOL_FOLDER_PATH + File.separator + "debuginfo.sh -f " + rpmPath + CommonConstants.SPACE - + appInfo.get(LABEL_INDEX) + ".debug"; + + getExecFileName() + ".debug"; try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec(debugCmd); @@ -234,24 +243,24 @@ public class AppInfo { new InputStreamReader(process.getErrorStream())); String errorStr = error.readLine(); DA_LOG.debug("debug info file find failed... : " + errorStr); - return null; + return; } debugFilePath = rpmPath + line.substring(1, line.length()); DA_LOG.debug("DEBUG PATH : " + debugFilePath); } catch (IOException e) { e.printStackTrace(); - return null; + return; } catch (InterruptedException e) { e.printStackTrace(); - return null; + return; } - // TODO: handle source rpm package - // future extension for normal executable - } else if (debugInfoRpmFile.getName().contains("debug-")) { + // future extension for applications with normal debug package + } else if (debugInfoRpmFile.getName() + .contains(DEBUGPKGTYPE_DEBUG)) { String debugCmd = PathManager.DA_TOOL_FOLDER_PATH + File.separator + "debuginfo.sh -f " + rpmPath + CommonConstants.SPACE - + appInfo.get(LABEL_INDEX); + + getExecFileName(); try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec(debugCmd); @@ -264,33 +273,140 @@ public class AppInfo { new InputStreamReader(process.getErrorStream())); String errorStr = error.readLine(); DA_LOG.debug("debug info file find failed... : " + errorStr); - return null; + return; } debugFilePath = rpmPath + line.substring(1, line.length()); DA_LOG.debug("DEBUG PATH : " + debugFilePath); } catch (IOException e) { e.printStackTrace(); - return null; + return; } catch (InterruptedException e) { e.printStackTrace(); - return null; + return; } } else { - return null; + return; } - if (null == debugFilePath || debugFilePath.isEmpty()) { - return null; + if (null != debugFilePath && !debugFilePath.isEmpty()) { + setDebugFilePath(debugFilePath); + } + return; + } + + public void getSourcePathFromSourceRpm(String sourceRpmPath) { + if (null == sourceRpmPath || sourceRpmPath.isEmpty()) { + return; + } + + // check rpm file exists + File debugsourceRpmFile = new File(sourceRpmPath); + if (!debugsourceRpmFile.exists() || debugsourceRpmFile.isDirectory()) { + return; + } + + // get source project name + // (ex. pr-debugsource-0.0.0-1.1.i586.rpm -> pr-0.0.0) + String debugsourceRpmFileName = debugsourceRpmFile.getName(); + int index = debugsourceRpmFileName.indexOf(DEBUGPKGTYPE_DEBUGSOURCE); + String project = debugsourceRpmFileName.substring(0, index); + String[] splitSrcRpmFileName = debugsourceRpmFileName + .split(CommonConstants.DASH); + String version = splitSrcRpmFileName[splitSrcRpmFileName.length - 2]; + String projectName = project + version; + + // copy rpm file + String rpmPath = PathManager.DA_RPM_PATH + File.separator + + appInfo.get(LABEL_INDEX); + File rpms = new File(rpmPath); + if (!rpms.exists()) { + if (!rpms.mkdirs()) { + DA_LOG.debug("rpm directory create failed..."); + return; + } + } + String copiedRpmPath = null; + String destPath = rpmPath + File.separator + debugsourceRpmFileName; + if (AnalyzerUtil.copyFile(sourceRpmPath, destPath)) { + copiedRpmPath = destPath; } else { - return getSymbolsFromBinary(debugFilePath); + return; } - } - public String getExecFileName(int type) { + // extract rpm file + if (null != copiedRpmPath) { + String toolPath = PathManager.DA_TOOL_FOLDER_PATH + File.separator + + "debuginfo.sh"; + String[] command = null; + command = new String[] { toolPath, "-d", rpmPath, sourceRpmPath }; + + try { + Runtime rt = Runtime.getRuntime(); + Process process = rt.exec(command); + process.waitFor(); + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + String line = null; + int lineCount = 0; + while (null != (line = reader.readLine())) { + lineCount++; + if (lineCount == 1) { + DA_LOG.debug("CHANGE DIR : " + line); + } else { + DA_LOG.debug("EXTRACT RPM : " + line); + } + } + if (lineCount == 0) { + BufferedReader error = new BufferedReader( + new InputStreamReader(process.getErrorStream())); + String errorStr = error.readLine(); + DA_LOG.debug("debug source file extract failed... : " + + errorStr); + return; + } + } catch (IOException e) { + e.printStackTrace(); + return; + } catch (InterruptedException e) { + e.printStackTrace(); + return; + } + } + + // check debugsource file path + String sourceCmd = PathManager.DA_TOOL_FOLDER_PATH + File.separator + + "debuginfo.sh -f " + rpmPath + CommonConstants.SPACE + + projectName + CommonConstants.ASTERISK; + try { + Runtime rt = Runtime.getRuntime(); + Process process = rt.exec(sourceCmd); + process.waitFor(); + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream())); + String line = reader.readLine(); + if (null == line) { + BufferedReader error = new BufferedReader( + new InputStreamReader(process.getErrorStream())); + String errorStr = error.readLine(); + DA_LOG.debug("source file path get failed... : " + errorStr); + return; + } + setSourcePath(rpmPath); + DA_LOG.debug("SOURCE PATH : " + sourcePath); + } catch (IOException e) { + e.printStackTrace(); + return; + } catch (InterruptedException e) { + e.printStackTrace(); + return; + } + } + + public String getExecFileName() { if (null == execFileName) { - String execPath = appInfo.get(EXEC_INDEX); - String[] splitPath = execPath.split(CommonConstants.SLASH); - if (type == ApplicationInst.APPTYPE_TIZEN) { + String[] splitPath = appInfo.get(EXEC_INDEX) + .split(CommonConstants.SLASH); + if (getAppType().contains(APPTYPE_CPP)) { execFileName = splitPath[splitPath.length - 1] + CommonConstants.EXTENSION_EXEC_FILE; } else { @@ -331,9 +447,9 @@ public class AppInfo { public String getExecPath() { String exec = appInfo.get(EXEC_INDEX); - // exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps"); if (getAppType().contains(APPTYPE_CPP)) { - exec += ".exe"; + exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps"); + exec += CommonConstants.EXTENSION_EXEC_FILE; } return exec; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/BaseCallstackManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/BaseCallstackManager.java index 80e18da..65cdf9a 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/BaseCallstackManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/BaseCallstackManager.java @@ -169,7 +169,8 @@ public abstract class BaseCallstackManager { } public boolean checkUserCall(String input) { - if (input.contains(AnalyzerConstants.USER_BIN_POS)) { + AppInfo appInfo = GlobalInformation.getCurrentApplication(); + if (appInfo.getMainBinaryInfo().getTargetBinaryPath().equals(input)) { return true; } return false; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java index 388568a..2936cb6 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java @@ -56,7 +56,7 @@ import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.common.AnalyzerConstants; import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.AnalyzerShellCommands; -import org.tizen.dynamicanalyzer.common.ElfSymbolExtracter; +import org.tizen.dynamicanalyzer.common.ElfSymbolExtractor; import org.tizen.dynamicanalyzer.common.ErrorCode; import org.tizen.dynamicanalyzer.common.GlobalInformation; import org.tizen.dynamicanalyzer.common.HostResult; @@ -971,7 +971,7 @@ public class Communicator30 extends BaseCommunicator { } String localPath = binInfo.getTempBinaryPath(); - ElfSymbolExtracter symbolExtractor = new ElfSymbolExtracter(); + ElfSymbolExtractor symbolExtractor = new ElfSymbolExtractor(); if (!symbolExtractor.makeSymbol(localPath)) { failedCount++; continue; diff --git a/package/build.linux b/package/build.linux index 5888e77..f1dbd5e 100755 --- a/package/build.linux +++ b/package/build.linux @@ -309,8 +309,12 @@ packaging_bfiles() { install_ide_path=${INSTALL_DIR}/${ide_root_path_name} bfile_dir=org.tizen.dynamicanalyzer.workbench/dynamic-analyzer ##install_lib_path=${INSTALL_DIR}/${ide_lib_path_name} blib_dir=org.tizen.dynamicanalyzer.workbench/dynamic-analyzer/library + tool_dir=tool + debugbinary=debuginfo.sh cp -rf ${SRCDIR}/${bfile_dir}/config ${install_ide_path}/ + mkdir -p ${install_ide_path}/${tool_dir} + cp -rf ${SRCDIR}/${bfile_dir}/${tool_dir}/${debugbinary} ${install_ide_path}/${tool_dir}/ ## cp -rf ${SRCDIR}/${bfile_dir}/xml ${install_ide_path}/ ## cp -rf ${SRCDIR}/${blib_dir}/* ${install_lib_path}/ } -- 2.7.4