--- /dev/null
+/*
+ * Address Sanitizer LaunchDelegate Class
+ *
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Karthik Bhat <kv.bhat@samsung.com>
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * - SRIB
+ *
+ */
+
+package org.eclipse.linuxtools.asan;
+
+import java.io.IOException;
+
+import org.tizen.common.connection.ConnectionPlugin;
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
+import org.tizen.sdblib.exception.TimeoutException;
+
+public class AsanUtil {
+
+ public static String[] runCommandReturningResult(String command) {
+ IDevice device = ConnectionPlugin.getDefault().getCurrentDevice();
+ CommonReceiver commonReceiver = new CommonReceiver();
+ String[] result = null;
+ try {
+ device.executeShellCommand(command, commonReceiver);
+ result = commonReceiver.getOutput();
+ } catch (TimeoutException e) {
+ e.printStackTrace();
+ } catch (SdbCommandRejectedException e) {
+ e.printStackTrace();
+ } catch (ShellCommandUnresponsiveException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ commonReceiver.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+}
String binaryName = null;
if (CommandManager.isEmulator()) {
Arch arch = ConnectionPlugin.getDefault().getCurrentDevice().getArch();
- if(arch.getArch().equals("x86_64")){
+ if (arch.getArch().equals("x86_64")) {
for (String fileName : binaryFiles) {
if (fileName.contains("x86_64") && fileName.contains("symbolizer")) {
binaryName = String.valueOf(fileName);
break;
}
}
- }
- else{
+ } else {
for (String fileName : binaryFiles) {
if (fileName.contains("i386") && fileName.contains("symbolizer")) {
binaryName = String.valueOf(fileName);
String fullcommand = "";
String appId = null;
appId = ProjectUtil.getAppId(project);
+ String execName = ProjectUtil.getExecutableName(config);
if (appId == null) {
newCoreException("The profiling failed because the application was terminated abnormally", null);
ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
if (monitor.isCanceled())
throw new OperationCanceledException();
- runApplication(config, launch, fullcommand, appId, monitor, launchConsole);
+ runApplication(config, launch, fullcommand, execName, monitor, launchConsole);
monitor.worked(2);
} catch (AsanCanceledException e) {
e.printStackTrace();
}
- public static String[] runCommandReturningResult(String command) {
- IDevice device = ConnectionPlugin.getDefault().getCurrentDevice();
- CommonReceiver commonReceiver = new CommonReceiver();
- String[] result = null;
- try {
- device.executeShellCommand(command, commonReceiver);
- result = commonReceiver.getOutput();
- } catch (TimeoutException e) {
- e.printStackTrace();
- } catch (SdbCommandRejectedException e) {
- e.printStackTrace();
- } catch (ShellCommandUnresponsiveException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- commonReceiver.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return result;
- }
-
- private void runApplication(ILaunchConfiguration config, ILaunch launch, String command, final String appId,
+ private void runApplication(ILaunchConfiguration config, ILaunch launch, String command, final String execName,
final IProgressMonitor monitor, ConsoleManager launchConsole) throws AsanCanceledException, CoreException {
Process Proc = CommandManager.runApplication(command);
+ Thread thread = null;
+ ProcessMonitor runnable = null;
if (Proc == null) {
newCoreException("The profiling failed because the application was terminated abnormally", null);
}
try {
- new Thread() {
- public void run() {
- while (true) {
- if (monitor.isCanceled()) {
- String cmd = "ps -ef | grep \"" + appId + "\"";
- String[] res = runCommandReturningResult(cmd);
-
- String space[] = res[0].split(" +");
- String killCmd = null;
- String platformVersion = "2.4.0";
- try {
- platformVersion = ConnectionPlugin.getDefault().getCurrentDevice().getPlatformInfo()
- .getPlatformVersion();
- } catch (TimeoutException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (SdbCommandRejectedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
- String versionInfo[] = platformVersion.split("\\.");
- if (Integer.parseInt(versionInfo[0]) >= 3)
- killCmd = "kill " + space[1];
- else
- killCmd = "su -c \"kill " + space[1] + "\"";
- runCommandReturningResult(killCmd);
- return;
-
- }
- }
- }
- }.start();
+ runnable = new ProcessMonitor(monitor, execName);
+ thread = new Thread(runnable);
+ thread.start();
Proc.waitFor();
int done = 0;
while (done == 0) {
- String cmd = "ps -ef | grep \"" + appId + "\"";
- String[] res = runCommandReturningResult(cmd);
+ String cmd = "ps -ef | grep -e \"/" + execName + " \"";
+ String[] res = AsanUtil.runCommandReturningResult(cmd);
int size = res.length;
int i;
- String regx = "(.*)opt(.*)" + appId + ".bin(.*)";
+ String subStr = "bin/"+ execName+" ";
for (i = 0; i < size; ++i) {
- if (res[i].matches(regx)) {
+ if (res[i].contains(subStr)) {
done = 0;
break;
}
e.printStackTrace();
}
+ if (thread != null && runnable != null) {
+ runnable.terminate();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
String path = project.getLocation().toOSString();
IDevice device = ConnectionPlugin.getDefault().getCurrentDevice();
CopyAsanReport(device, path + File.separator);
--- /dev/null
+/*
+ * Address Sanitizer LaunchDelegate Class
+ *
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Karthik Bhat <kv.bhat@samsung.com>
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * - SRIB
+ *
+ */
+
+package org.eclipse.linuxtools.asan;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.tizen.common.connection.ConnectionPlugin;
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.TimeoutException;
+
+public class ProcessMonitor implements Runnable {
+ private volatile boolean running = true;
+ private IProgressMonitor monitor;
+ private String execName;
+
+ ProcessMonitor(IProgressMonitor monitor, String execName) {
+ this.monitor = monitor;
+ this.execName = execName;
+ }
+
+ public void terminate() {
+ running = false;
+ }
+
+ private boolean reportGenerated() {
+ String cmd = "ls -l /tmp/reportASAN.txt";
+ String[] res = AsanUtil.runCommandReturningResult(cmd);
+ if (res == null || res.length == 0)
+ return false;
+ if(res[0].contains("No such file or directory"))
+ return false;
+ return true;
+ }
+
+ private void terminateApp(String execName) {
+ String cmd = "ps -ef | grep -e \"/" + execName + " \"";
+ String[] res = AsanUtil.runCommandReturningResult(cmd);
+
+ String space[] = res[0].split(" +");
+ String killCmd = null;
+ String platformVersion = "2.4.0";
+ try {
+ platformVersion = ConnectionPlugin.getDefault().getCurrentDevice().getPlatformInfo().getPlatformVersion();
+ } catch (TimeoutException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (SdbCommandRejectedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ String versionInfo[] = platformVersion.split("\\.");
+ if (Integer.parseInt(versionInfo[0]) >= 3)
+ killCmd = "kill " + space[1];
+ else
+ killCmd = "su -c \"kill " + space[1] + "\"";
+ AsanUtil.runCommandReturningResult(killCmd);
+ return;
+ }
+
+ @Override
+ public void run() {
+ while (running) {
+ if (monitor.isCanceled() || reportGenerated()) {
+ terminateApp(execName);
+ }
+
+ }
+
+ }
+
+}