DEBUG: Supported debugging on windows
authordonghyuk.yang <donghyuk.yang@samsung.com>
Sun, 27 Apr 2014 12:28:41 +0000 (21:28 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Sun, 27 Apr 2014 12:28:41 +0000 (21:28 +0900)
Insert sleep(1) because GDB process is terminated on windows. I do not
exactly know why the process is terminated yet. Commit it for testing at
first.

Change-Id: I96a259f5237159c862e03fd58e146d2d15b62ef4
Signed-off-by: donghyuk.yang <donghyuk.yang@samsung.com>
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformLaunchDelegate.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformMIProcessAdapter.java

index 1539f12..0928efb 100644 (file)
@@ -31,6 +31,7 @@ import static org.tizen.sdblib.util.DeviceUtil.isOnline;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -73,12 +74,6 @@ import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.window.Window;
 import org.eclipse.ptp.remotetools.core.IRemoteCopyTools;
-import org.eclipse.ptp.remotetools.core.IRemoteExecutionTools;
-import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
-import org.eclipse.ptp.remotetools.exception.CancelException;
-import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
-import org.eclipse.ptp.remotetools.exception.RemoteExecutionException;
-import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PartInitException;
@@ -338,10 +333,10 @@ public class PlatformLaunchDelegate extends AbstractCLaunchDelegate {
                 .getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
         IPath hostPath = getHostPath(appPath, config);
         if (hostPath != null) {
-               if (!PlatformFileUtil.existsFile(hostPath.toString())) {
-                       newCoreException(PlatformLaunchMessages.CANNOT_FIND_EXECUTABLE_IN_A_HOST_ROOTSTRAP,
+            if (!PlatformFileUtil.existsFile(hostPath.toString())) {
+                newCoreException(PlatformLaunchMessages.CANNOT_FIND_EXECUTABLE_IN_A_HOST_ROOTSTRAP,
                         null);
-               }
+            }
         }
     }
 
@@ -675,64 +670,56 @@ public class PlatformLaunchDelegate extends AbstractCLaunchDelegate {
 
     protected ICDISession getDebugSession(ILaunch launch, ILaunchConfiguration config,
             IBinaryObject exeFile, IProgressMonitor monitor) throws CoreException {
-        TizenPlatformDebugger debugger = new TizenPlatformDebugger();        
+        TizenPlatformDebugger debugger = new TizenPlatformDebugger();
         if (OSChecker.isWindows()) {
-            String appPath = config
-                    .getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
-            String rootstrapId = target.getRootstrap().getId();
-            String rootstrapPath = RootstrapUtil.getRemoteRootstrapScratchPath(rootstrapId);
-            //File exec = new Path(rootstrapPath).append(appPath).toFile();
-            File exec = new Path(appPath).toFile();                    
-            return ((ICDIDebugger2) debugger).createSession(launch, exec, new SubProgressMonitor(monitor, 1));
+            String appPath = config.getAttribute(
+                    ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
+            File exec = new Path(appPath).toFile();
+            return ((ICDIDebugger2) debugger).createSession(launch, exec, new SubProgressMonitor(
+                    monitor, 1));
         } else {
             return ((ICDIDebugger2) debugger).createSession(launch, getGDBClientArgument(exeFile),
                     new SubProgressMonitor(monitor, 1));
         }
-        
+
     }
-    /*
-    public static ILaunchConfiguration createForward(ILaunchConfiguration config, IDevice device) throws CoreException, NumberFormatException, TimeoutException, SdbCommandRejectedException, IOException {
+
+    public static ILaunchConfiguration createForward(ILaunchConfiguration config, IDevice device)
+            throws CoreException, NumberFormatException, TimeoutException,
+            SdbCommandRejectedException, IOException {
         int gdbPort = 0;
         int gdbserverPort = 0;
         ILaunchConfiguration newConfiguration = config;
-
-        gdbPort = Integer.parseInt(config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT));
+        ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+        gdbPort = Integer.parseInt(config.getAttribute(
+                IGDBServerMILaunchConfigurationConstants.ATTR_PORT,
+                TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT));
         if (!LocalPortChecker.isPortAvailable(gdbPort)) {
             gdbPort = LaunchUtils.getDefaultDebugPort(device);
             if (gdbPort < 0) {
-                LaunchUtils.newCoreException(TizenLaunchMessages.CANNOT_SET_DEBUG_LOCAL_PORT_TO_NEGATIVE, null);
+                LaunchUtils.newCoreException(
+                        TizenLaunchMessages.CANNOT_SET_DEBUG_LOCAL_PORT_TO_NEGATIVE, null);
             }
             String localPort = Integer.valueOf(gdbPort).toString();
-            ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
             wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, localPort);
-            newConfiguration = wc.doSave();
             gdbPort = Integer.parseInt(localPort);
         }
-
-        gdbserverPort = Integer.parseInt(config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT));
-        IRemoteExecutionTools exectool = RemoteConnectionManager.getRemoteTools().getExecTool();
-        try {
-            
-            //exectool.executeBashCommand("/home/sdk/tizen-sdk/tools/sdb connect 172.21.111.40");
-            String cmd = String.format("/home/sdk/tizen-sdk/tools/sdb forward tcp:%d tcp:%d", gdbPort, gdbserverPort);
-            exectool.executeWithOutput("/home/sdk/tizen-sdk/tools/sdb connect 172.21.111.40");
-            String output = exectool.executeWithOutput(cmd);
-            System.out.print(output);
-        } catch (RemoteExecutionException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (RemoteConnectionException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (CancelException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        //device.createForward(gdbPort, gdbserverPort);
+        /*
+         * InetAddress.getLocalHost() should give you the IP address of this
+         * host. The problem is that a host could have lots of network
+         * interfaces, and an interface could be bound to more than one IP
+         * address.
+         */
+        InetAddress hostIp = InetAddress.getLocalHost();
+        wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, hostIp.getHostAddress());
+        newConfiguration = wc.doSave();
+        gdbserverPort = Integer.parseInt(config.getAttribute(
+                TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT,
+                TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT));
+        device.createForward(gdbPort, gdbserverPort);
 
         return newConfiguration;
     }
-    */
 
     protected void launchApplicationWithGDBClient(ILaunch launch, ILaunchConfiguration config,
             IBinaryObject exeFile, IProgressMonitor monitor) throws CoreException {
@@ -740,8 +727,11 @@ public class PlatformLaunchDelegate extends AbstractCLaunchDelegate {
             monitor.beginTask("", 2);
             monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBCLIENT);
 
-            LaunchUtils.createForward(config, currentDevice);
-            //createForward(config, currentDevice);
+            if (OSChecker.isWindows()) {
+                createForward(config, currentDevice);
+            } else {
+                LaunchUtils.createForward(config, currentDevice);
+            } 
             try {
                 debugSession = getDebugSession(launch, config, exeFile, monitor);
             } catch (CoreException e) {
@@ -924,7 +914,7 @@ public class PlatformLaunchDelegate extends AbstractCLaunchDelegate {
                     rootstrapPath = rootstrapPath.concat(exePath);
                 }
             }
-        } else {            
+        } else {
             rootstrapPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(path);
             if (rootstrapPath != null && !rootstrapPath.isEmpty()) {
                 if (canonicalPath != null && !canonicalPath.isEmpty()) {
index 33f9181..e1ac673 100644 (file)
@@ -150,8 +150,11 @@ public class PlatformMIProcessAdapter extends MIProcessAdapter {
                 PushbackInputStream pb = new PushbackInputStream(gdbProcess.getInputStream());
                 gdbInputStream = pb;
                 try {
+                    // gdb process can be terminated if remove sleep() (on windows)
+                    // TODO: why gdb process is terminated on windows?
+                    Thread.sleep(ONE_SECOND);
                     pb.unread(pb.read());
-                } catch (IOException e) {
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
                 // actually read something, then return it