[Title] Fixed bug for running gdbserver through sdb
authordonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 18 Apr 2013 11:46:25 +0000 (20:46 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 18 Apr 2013 11:46:25 +0000 (20:46 +0900)
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/TizenDebianLaunchDelegate.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/TizenDebianLaunchDelegateForAttach.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/RPMPackageCommander.java

index 79ffd14..005b241 100644 (file)
@@ -32,7 +32,6 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
 import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 import org.eclipse.cdt.core.settings.model.ICProjectDescription;
@@ -80,6 +79,7 @@ import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.common.util.DialogUtil;
 import org.tizen.common.util.LocalPortChecker;
 import org.tizen.common.util.SWTUtil;
+import org.tizen.common.util.StringUtil;
 import org.tizen.nativecommon.build.CommonBuildMessages;
 import org.tizen.nativecommon.build.CommonConfigurationManager;
 import org.tizen.nativecommon.build.CommonProjectDependentBuilder;
@@ -97,8 +97,6 @@ import org.tizen.nativeplatform.build.PlatformProjectPackaging;
 import org.tizen.nativeplatform.launch.wizards.PlatformLaunchUtils;
 import org.tizen.nativeplatform.launch.wizards.ShowPackageStatusDialog;
 import org.tizen.nativeplatform.pkgmgr.model.LocalPackage;
-import org.tizen.nativeplatform.rootstrap.RootstrapManager;
-import org.tizen.nativeplatform.views.model.PlatformRootstrap;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.IDevice.Arch;
 import org.tizen.sdblib.SdbCommandRejectedException;
@@ -528,30 +526,39 @@ public class TizenDebianLaunchDelegate extends AbstractCLaunchDelegate {
     }
 
     protected void launchApplicationWithGDBServer(ILaunch launch, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
+       
         try {
             monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBSERVER, 1);
-            monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBSERVER);            
+            monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBSERVER);
             
-               IPath path = getHostPath(TizenPlatformConstants.HOST_GDBSERVER_PATH, config);
-               PlatformLaunchUtils launchUtils = new PlatformLaunchUtils();                    
-               launchUtils.readyGdbServer(currentDevice, tizenCommand, path);
-               
-            String gdbserverPort = config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT);           
-            String gdbserverCmd = TizenPlatformConstants.GDBSERVER_PLATFORM_CMD + " :" + gdbserverPort;
-            String execArg = setArguments(config);
-            String envCmd = setEnvironments(config);
-            String command = envCmd + gdbserverCmd + " " + execArg;
-            serverProc = currentDevice.executeShellCommand(command);
-               } catch (TimeoutException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
-               } catch (SdbCommandRejectedException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+            IPath path = getHostPath(TizenPlatformConstants.HOST_GDBSERVER_PATH, config);
+            PlatformLaunchUtils launchUtils = new PlatformLaunchUtils();
+            launchUtils.readyGdbServer(currentDevice, tizenCommand, path);
+
+            String gdbserverRunCommand = getGdbserverRunCommand(config);
+            String resultCommand = null;
+
+            // is gdbserver running now ? then
+            resultCommand = String.format(TizenPlatformConstants.PROCESS_GET_PROCESS_ID_COMMAND, gdbserverRunCommand.trim());
+            tizenCommand.run(resultCommand, null);
+            if (tizenCommand.getEndLine() != null) {
+                if (StringUtil.isInteger(tizenCommand.getEndLine().trim())) {
+                    resultCommand = String.format(TizenPlatformConstants.PROCESS_SIGKILL_COMMAND, tizenCommand.getEndLine() + TizenPlatformConstants.CMD_RESULT_CHECK);
+                    try {
+                        tizenCommand.run(resultCommand, "0");
+                    } catch (CoreException e) {
+                       newCoreException(TizenLaunchMessages.GDBSERVER_ALREADY_RUNNING, null);
+                    } catch (Exception e) {                        
+                       newCoreException(TizenLaunchMessages.GDBSERVER_ALREADY_RUNNING, null);
+                    }
+                }
+            }
+            // Run gdbserver as blocking mode!
+            tizenCommand.run(gdbserverRunCommand, null, true);
         } catch (CoreException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
-        } catch (IOException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+               newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
         } catch (Exception e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+               newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);            
         } finally {
             monitor.done();
         }
@@ -593,6 +600,18 @@ public class TizenDebianLaunchDelegate extends AbstractCLaunchDelegate {
             monitor.done();
         }
     }
+    
+    protected String getGdbserverRunCommand(ILaunchConfiguration config) 
+               throws CoreException, Exception {
+        
+        String gdbserverPort = config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT);           
+        String gdbserverCmd = TizenPlatformConstants.GDBSERVER_PLATFORM_CMD + " :" + gdbserverPort;
+        String execArg = setArguments(config);
+        String envCmd = setEnvironments(config);
+        String command = envCmd + gdbserverCmd + " " + execArg;
+
+        return command;
+    }   
 
     protected void setDebugConfigAttributes(ILaunchConfiguration config) throws CoreException {
         ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
index a146d21..40ac9b3 100644 (file)
@@ -45,6 +45,7 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.core.ILaunchManager;
 import org.tizen.common.TizenPlatformConstants;
 import org.tizen.common.util.DialogUtil;
+import org.tizen.common.util.StringUtil;
 import org.tizen.nativecommon.build.SmartBuildInterface;
 import org.tizen.nativecommon.build.exception.SBIException;
 import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants;
@@ -52,7 +53,6 @@ import org.tizen.nativecommon.launch.TizenLaunchMessages;
 import org.tizen.nativeplatform.build.PlatformConfigurationManager;
 import org.tizen.nativeplatform.launch.wizards.PlatformLaunchUtils;
 import org.tizen.nativeplatform.pkgmgr.model.LocalPackage;
-import org.tizen.nativeplatform.rootstrap.RootstrapManager;
 import org.tizen.sdblib.SdbCommandRejectedException;
 import org.tizen.sdblib.TimeoutException;
 
@@ -97,40 +97,61 @@ public class TizenDebianLaunchDelegateForAttach extends TizenDebianLaunchDelegat
     }
     
     @Override
-    protected void launchApplicationWithGDBServer(ILaunch launch, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {        
+    protected void launchApplicationWithGDBServer(ILaunch launch, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
+       
         try {
             monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBSERVER, 1);
             monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBSERVER);
             
-               IPath path = getHostPath(TizenPlatformConstants.HOST_GDBSERVER_PATH, config);
-               PlatformLaunchUtils launchUtils = new PlatformLaunchUtils();                    
-               launchUtils.readyGdbServer(currentDevice, tizenCommand, path);
-
+            IPath path = getHostPath(TizenPlatformConstants.HOST_GDBSERVER_PATH, config);
+            PlatformLaunchUtils launchUtils = new PlatformLaunchUtils();
+            launchUtils.readyGdbServer(currentDevice, tizenCommand, path);
+            
             if (pid.equals(Integer.valueOf(-1)) || pid.equals(Integer.valueOf(0))) {
                 newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER + ICDTLaunchConfigurationConstants.ERR_NO_PROCESSID, null);
             }
 
-            String gdbserverPort = config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT);            
-            String commandArguments =  ":" + gdbserverPort + TizenPlatformConstants.ATTACH_OPTION + pid;
-            String gdbserverCmd = TizenPlatformConstants.GDBSERVER_PLATFORM_CMD + " " + commandArguments;
-            String envCmd = setEnvironments(config);
-            String command = envCmd + gdbserverCmd;
-            serverProc = currentDevice.executeShellCommand(command);
-               } catch (TimeoutException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
-               } catch (SdbCommandRejectedException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+            String gdbserverRunCommand = getGdbserverRunCommand(config);
+            String resultCommand = null;
+
+            // is gdbserver running now ? then
+            resultCommand = String.format(TizenPlatformConstants.PROCESS_GET_PROCESS_ID_COMMAND, gdbserverRunCommand.trim());
+            tizenCommand.run(resultCommand, null);
+            if (tizenCommand.getEndLine() != null) {
+                if (StringUtil.isInteger(tizenCommand.getEndLine().trim())) {
+                    resultCommand = String.format(TizenPlatformConstants.PROCESS_SIGKILL_COMMAND, tizenCommand.getEndLine() + TizenPlatformConstants.CMD_RESULT_CHECK);
+                    try {
+                        tizenCommand.run(resultCommand, "0");
+                    } catch (CoreException e) {
+                       newCoreException(TizenLaunchMessages.GDBSERVER_ALREADY_RUNNING, null);
+                    } catch (Exception e) {                        
+                       newCoreException(TizenLaunchMessages.GDBSERVER_ALREADY_RUNNING, null);
+                    }
+                }
+            }
+            // Run gdbserver as blocking mode!
+            tizenCommand.run(gdbserverRunCommand, null, true);
         } catch (CoreException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
-        } catch (IOException e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+               newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
         } catch (Exception e) {
-            newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+               newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);            
         } finally {
             monitor.done();
         }
     }
     
+    protected String getGdbserverRunCommand(ILaunchConfiguration config) 
+               throws CoreException, Exception {        
+        
+        String gdbserverPort = config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT);            
+        String commandArguments =  ":" + gdbserverPort + TizenPlatformConstants.ATTACH_OPTION + pid;
+        String gdbserverCmd = TizenPlatformConstants.GDBSERVER_PLATFORM_CMD + " " + commandArguments;
+        String envCmd = setEnvironments(config);
+        String command = envCmd + gdbserverCmd;
+
+        return command;
+    }  
+    
     private void setAttachProcess(ILaunchConfiguration config) throws CoreException {
        final PlatformLaunchUtils launchUtils = new PlatformLaunchUtils();
        String processName = config.getAttribute(ITizenLaunchConfigurationConstants.ATTR_PROCESSNAME_OPTION, "");
index 28d91d3..c55ec71 100644 (file)
@@ -533,24 +533,26 @@ public class RPMPackageCommander {
                String result = rec.getLog()[0];
                int firstIndex = result.indexOf("<pkg>");
                int lastIndex = result.lastIndexOf("</pkg>");
-               result = result.substring(firstIndex, lastIndex);
-               String[] splitStr = result.split("</pkg>");
-               
-               for (String s : splitStr) {
-                       s = s.replaceAll(" ", "").replaceAll("<pkg>", "");
-                       String[] part = s.split(",");
-                       if (part.length == 3) {
-                               String name = part[0];
-                               String version = part[1];
-                               String arch = part[2];
-                               Package pkg = packageHash.get(name);
-                               if (pkg == null) {
-                                       packageHash.put(name, new Package(name, version, "", arch));
-                               } else {
-                                       pkg.setInstalledVersion(version);
+               if (firstIndex >= 0 || lastIndex >= 0 ) {
+                       result = result.substring(firstIndex, lastIndex);
+                       String[] splitStr = result.split("</pkg>");
+                       for (String s : splitStr) {
+                               s = s.replaceAll(" ", "").replaceAll("<pkg>", "");
+                               String[] part = s.split(",");
+                               if (part.length == 3) {
+                                       String name = part[0];
+                                       String version = part[1];
+                                       String arch = part[2];
+                                       Package pkg = packageHash.get(name);
+                                       if (pkg == null) {
+                                               packageHash.put(name, new Package(name, version, "", arch));
+                                       } else {
+                                               pkg.setInstalledVersion(version);
+                                       }
                                }
                        }
                }
+                               
 
                Enumeration<Package> e = packageHash.elements();
                while (e.hasMoreElements()) {
@@ -703,7 +705,7 @@ public class RPMPackageCommander {
 
        private static void actionBeforeUseZypperDevice(IDevice device) {
                if (device.isEmulator()) {
-                       PackageManagerOuputReceiver rec = getNewOuputReceiver();
+                       PackageManagerOuputReceiver rec = getNewOuputReceiverWithConsole();
                        //rec.cleanLog();
                        String command = String
                                        .format("sed -i \"s/# arch = s390/arch = i686/g\" /etc/zypp/zypp.conf");