Enable ASAN report generation in services,appcontrol.
authorKarthik Bhat <kv.bhat>
Mon, 23 Jan 2017 07:52:18 +0000 (13:22 +0530)
committerKarthik Bhat <kv.bhat>
Mon, 23 Jan 2017 08:30:19 +0000 (14:00 +0530)
Change-Id: I86aede60264965956510a0d390a409c5bc5d1cfa
Signed-off-by: Karthik Bhat <kv.bhat>
org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/AsanUtil.java [new file with mode: 0644]
org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/LaunchDelegate.java
org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/ProcessMonitor.java [new file with mode: 0644]

diff --git a/org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/AsanUtil.java b/org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/AsanUtil.java
new file mode 100644 (file)
index 0000000..dfc71fa
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  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;
+       }
+}
index 16bf8b7..76c155b 100644 (file)
@@ -249,15 +249,14 @@ public class LaunchDelegate extends TizenLaunchDelegate {
                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);
@@ -355,6 +354,7 @@ public class LaunchDelegate extends TizenLaunchDelegate {
                        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);
@@ -365,7 +365,7 @@ public class LaunchDelegate extends TizenLaunchDelegate {
                                        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();
@@ -389,86 +389,30 @@ public class LaunchDelegate extends TizenLaunchDelegate {
 
        }
 
-       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;
                                        }
@@ -483,6 +427,15 @@ public class LaunchDelegate extends TizenLaunchDelegate {
                        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);
diff --git a/org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/ProcessMonitor.java b/org.eclipse.linuxtools.asan/src/org/eclipse/linuxtools/asan/ProcessMonitor.java
new file mode 100644 (file)
index 0000000..37a0256
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ *  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);
+                       }
+
+               }
+
+       }
+
+}