import java.net.Socket;
import java.nio.channels.FileLock;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
public class IDECommunicator implements Runnable {
private static final DALogger DA_LOG = DALogger.getInstance();
-
+
private static final int MAXBUFSIZE = 1024;
private static final String IDE_DA_COMMUNICATION_TYPE_1 = "STATUS";//$NON-NLS-1$
// private final int MSG_INDEX_CMD = 0;
private static final int MSG_INDEX_DEVICE = 1;
- private static final int MSG_INDEX_APPID = 2;
- private static final int MSG_INDEX_APPNAME = 3;
- private static final int MSG_LENGTH = 4;
+ private static final int MSG_INDEX_PROJECT_TYPE = 2;
+ private static final int MSG_INDEX_BINARY_OF_TARGET = 3;
+ private static final int MSG_INDEX_EXECUTABLE_PATH = 4;
+ private static final int MSG_INDEX_LOCAL_PACKAGE_PATH = 5;
+ private static final int MSG_DEFAULT_LENGTH = 5;
+
+ // project type string
+ private static final String PROJECT_TYPE_OSP = "1";
+ private static final String PROJECT_TYPE_EFL = "2";
+ private static final String PROJECT_TYPE_WEBAPP = "3";
+ private static final String PROJECT_TYPE_LIBRARY = "4";
+
private static final int APPNAME_LENGTH = 20;
private static BufferedWriter writer = null;
// trace Application
private void autoStartApplication(String[] strMsg) {
- if (strMsg.length < MSG_LENGTH) {
+ if (strMsg.length < MSG_DEFAULT_LENGTH) {
DA_LOG.debug("wrong message format!!");
return;
}
ToolbarArea.getInstance().setToolbarStartStopState(false);
+
final String deviceName = new String(strMsg[MSG_INDEX_DEVICE].trim());
- final String appid = new String(strMsg[MSG_INDEX_APPID].trim());
- final String appName = new String(strMsg[MSG_INDEX_APPNAME].trim());
+ final String projectType = new String(
+ strMsg[MSG_INDEX_PROJECT_TYPE].trim());
+ final String binaryOfTarget = new String(
+ strMsg[MSG_INDEX_BINARY_OF_TARGET].trim());
+ final String executablePath = new String(
+ strMsg[MSG_INDEX_EXECUTABLE_PATH].trim());
+ List<String> localPackagePathList = new ArrayList<String>();
+ for (int i = MSG_INDEX_LOCAL_PACKAGE_PATH; i < strMsg.length; i++) {
+ localPackagePathList.add(new String(strMsg[i].trim()));
+ }
if (isOpenWelcomeDlg()) {
DA_LOG.debug("Start -AutoRun Waiting...");
synchronized (getWaitingWelcomeDlg()) {
try {
- getWaitingWelcomeDlg().wait((long)configurationWaitingTimeMs);
+ getWaitingWelcomeDlg().wait(
+ (long) configurationWaitingTimeMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
DA_LOG.debug("End - AutoRun Waiting");
}
- DA_LOG.debug("auto start : " + appid);
+ DA_LOG.debug("auto start : " + binaryOfTarget);
DeviceInfo device = DACommunicator.getDeviceByName(deviceName);
GlobalInformation.setCurrentDeviceInfo(device);
-
DACommunicator.getAppListFromTarget();
- AppInfo appInfo = DACommunicator.getPkgInfoByAppPkgId(appid);
+
+ AppInfo appInfo = null;
+ final String appName;
+ if (projectType.equals(PROJECT_TYPE_OSP)
+ || projectType.equals(PROJECT_TYPE_EFL)
+ || projectType.equals(PROJECT_TYPE_WEBAPP)) {
+ appInfo = DACommunicator.getPkgInfoByAppPkgId(binaryOfTarget);
+ appName = binaryOfTarget;
+ } else {
+ // TODO : get appInfo from executable path
+ appName = executablePath;
+ }
+
if (null == appInfo) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
ToolbarArea.getInstance().setToolbarStartStopState(true);
}
});
- DA_LOG.debug("invalid application name :" + appid);
- return;
- }
- final String appLabel = appInfo.getInfo(AppInfo.LABEL_INDEX);
- DA_LOG.debug("IDE recv - deviceName: " + deviceName
- + " appName : " + appLabel);
-
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- ToolbarArea.getInstance().setDeviceComboText(deviceName);
- ToolbarArea.getInstance().setAppComboText(appLabel);
- ToolbarArea.getInstance().startTrace();
+ DA_LOG.debug("invalid application name :" + appName);
+ } else {
+ if(localPackagePathList.size() > 0) {
+ appInfo.setLocalPackagePath(localPackagePathList);
}
- });
+
+ final String appLabel = appInfo.getInfo(AppInfo.LABEL_INDEX);
+ DA_LOG.debug("IDE recv - deviceName: " + deviceName + " appName : "
+ + appLabel);
- SingletonFocusManager.setFocusToDA();
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ ToolbarArea.getInstance().setDeviceComboText(deviceName);
+ ToolbarArea.getInstance().setAppComboText(appLabel);
+ ToolbarArea.getInstance().startTrace();
+ }
+ });
+
+ SingletonFocusManager.setFocusToDA();
+ }
}
private void popupMessage(final String message) {
package org.tizen.dynamicanalyzer.project;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.tizen.dynamicanalyzer.common.ElfSymbolExtracter;
import org.tizen.dynamicanalyzer.common.GlobalInformation;
+import org.tizen.dynamicanalyzer.common.path.PathManager;
import org.tizen.dynamicanalyzer.constant.CommonConstants;
import org.tizen.dynamicanalyzer.model.AddrSymbolPair;
import org.tizen.dynamicanalyzer.swap.channel.control.ApplicationInst;
import org.tizen.dynamicanalyzer.swap.channel.control.BinaryInfo;
+import org.tizen.dynamicanalyzer.util.DALogger;
import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
public class AppInfo {
public static final String FLAG_ZERO = "0";//$NON-NLS-1$
public static final String FLAG_ONE = "1";//$NON-NLS-1$
+ private static final DALogger DA_LOG = DALogger.getInstance();
+
/**
- * String : target binary key - AnalyzerUtil.getTargetBinaryKey(targetPath)
- * BinaryInfo : target binary info
+ * String : target binary key - AnalyzerUtil.getTargetBinaryKey(targetPath)
+ * BinaryInfo : target binary info
*/
private HashMap<String, BinaryInfo> binaryInfoMap = new HashMap<String, BinaryInfo>();
+ private List<String> localPackagePath = null;
private String installTime = null;
private String execFileName = null;
// }
public List<AddrSymbolPair> getSymbols(String sourceBinaryPath) {
+ List<AddrSymbolPair> fromDebug = 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 (fromDebug == null) {
+ List<AddrSymbolPair> fromExec = getSymbolsFromBinary(sourceBinaryPath);
+ return fromExec;
+ } else {
+ return fromDebug;
+ }
+ }
+
+ public List<AddrSymbolPair> getSymbolsFromBinary(String sourceBinaryPath) {
if (null == sourceBinaryPath || sourceBinaryPath.isEmpty()) {
return null;
}
return symbolExtractor.getAddrSymbolPairs();
}
+ public List<AddrSymbolPair> getSymbolsFromDebugRpm(String debugRpmPath) {
+ String debugFilePath = null;
+
+ if (null == debugRpmPath || debugRpmPath.isEmpty()) {
+ return null;
+ }
+ // check rpm file exists
+ File debugInfoRpmFile = new File(debugRpmPath);
+ if (!debugInfoRpmFile.exists() || debugInfoRpmFile.isDirectory()) {
+ return null;
+ }
+ // 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 null;
+ }
+ }
+ String copiedRpmPath = null;
+ String destPath = rpmPath + File.separator + debugInfoRpmFile.getName();
+ if (AnalyzerUtil.copyFile(debugRpmPath, destPath)) {
+ copiedRpmPath = destPath;
+ } else {
+ return null;
+ }
+
+ // extract rpm file
+ if (null != copiedRpmPath) {
+ 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);
+ 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 info file extract failed... : "
+ + errorStr);
+ return null;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ // check debuginfo file path
+ if (debugInfoRpmFile.getName().contains("debuginfo")) {
+ String debugCmd = PathManager.DA_TOOL_FOLDER_PATH + File.separator
+ + "debuginfo.sh -f " + rpmPath + CommonConstants.SPACE
+ + appInfo.get(LABEL_INDEX) + ".debug";
+ try {
+ Runtime rt = Runtime.getRuntime();
+ Process process = rt.exec(debugCmd);
+ 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("debug info file find failed... : " + errorStr);
+ return null;
+ }
+ debugFilePath = rpmPath + line.substring(1, line.length());
+ DA_LOG.debug("DEBUG PATH : " + debugFilePath);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return null;
+ }
+ // TODO: handle source rpm package
+
+ // future extension for normal executable
+ } else if (debugInfoRpmFile.getName().contains("debug-")) {
+ String debugCmd = PathManager.DA_TOOL_FOLDER_PATH + File.separator
+ + "debuginfo.sh -f " + rpmPath + CommonConstants.SPACE
+ + appInfo.get(LABEL_INDEX);
+ try {
+ Runtime rt = Runtime.getRuntime();
+ Process process = rt.exec(debugCmd);
+ 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("debug info file find failed... : " + errorStr);
+ return null;
+ }
+ debugFilePath = rpmPath + line.substring(1, line.length());
+ DA_LOG.debug("DEBUG PATH : " + debugFilePath);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return null;
+ }
+ } else {
+ return null;
+ }
+
+ if (null == debugFilePath || debugFilePath.isEmpty()) {
+ return null;
+ } else {
+ return getSymbolsFromBinary(debugFilePath);
+ }
+ }
+
public String getExecFileName(int type) {
if (null == execFileName) {
String execPath = appInfo.get(EXEC_INDEX);
public String getExecPath() {
String exec = appInfo.get(EXEC_INDEX);
- exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps");
+ // exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps");
if (getAppType().contains(APPTYPE_CPP)) {
exec += ".exe";
}
public String getAppType() {
return appInfo.get(APPTYPE_INDEX);
}
+
+ public List<String> getLocalPackagePath() {
+ // return read only list
+ return Collections.unmodifiableList(localPackagePath);
+ }
+
+ public void setLocalPackagePath(List<String> localPackagePath) {
+ this.localPackagePath = localPackagePath;
+ }
}