[Title] Fixed issue for setting breakpoint on running gdb
authordonghyuk.yang <donghyuk.yang@samsung.com>
Tue, 20 Nov 2012 08:00:31 +0000 (17:00 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Tue, 20 Nov 2012 08:00:31 +0000 (17:00 +0900)
12 files changed:
org.tizen.nativeplatform/META-INF/MANIFEST.MF
org.tizen.nativeplatform/plugin.xml
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ITizenLaunchConfigurationConstants.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformCommandFactory.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformMIProcessAdapter.java [new file with mode: 0644]
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/launch/ui/shortcut/TizenDebianProjectAttachLaunchShortcut.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/TizenDebianProjectCoredumpLaunchShortcut.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/TizenDebianProjectLaunchShortcut.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/wizards/PlatformLaunchUtils.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncher.java

index 5673c80..0722770 100644 (file)
@@ -26,6 +26,8 @@ Import-Package: org.eclipse.cdt.debug.core,
  org.eclipse.cdt.debug.internal.core.sourcelookup,
  org.eclipse.cdt.debug.internal.ui.launch,
  org.eclipse.cdt.debug.mi.core,
+ org.eclipse.cdt.debug.mi.core.cdi,
+ org.eclipse.cdt.debug.mi.core.command.factories,
  org.eclipse.cdt.debug.ui,
  org.eclipse.cdt.launch,
  org.eclipse.cdt.launch.internal.ui,
index 0d0dc52..2ce1297 100644 (file)
             sourcepath="/on-demand">
         </tools>
     </extension>
+
+       <extension
+        point="org.eclipse.cdt.debug.mi.core.commandFactories">
+        <commandFactory
+            class="org.tizen.nativeplatform.launch.PlatformCommandFactory"
+            debuggerID="org.tizen.nativecommon.launch.TizenDebugger"
+            id="org.tizen.nativeplatform.launch.PlatformCommandFactory"
+            miVersions="mi,mi1,mi2"
+            name="Tizen Platform Command Set"
+            platforms="*"/>
+       </extension>
     
     <extension point="org.eclipse.core.contenttype.contentTypes">
                <file-association
       </context>
        </extension>
 
+
 <!-- package manager end -->
 </plugin>
index 7e8c610..93ed6d3 100644 (file)
@@ -1,6 +1,9 @@
 package org.tizen.nativeplatform.launch;
 
 public interface ITizenLaunchConfigurationConstants {
+       public static final String DEBUGGER_ID = "org.tizen.nativeplatform.launch.TizenPlatformDebugger";
+       public static final String COMMAND_FACTORY_ID = "org.tizen.nativeplatform.launch.PlatformCommandFactory";
+       
        public static final String PLATFORM_LAUNCH_ID = "org.tizen.platform.launch"; //$NON-NLS-1$
        public static final String ATTR_APP_PROJECT_NAME = PLATFORM_LAUNCH_ID + ".APP_PROJECT_ATTR"; //$NON-NLS-1$
        public static final String ATTR_EXTRA_PACKAGE_LIST = PLATFORM_LAUNCH_ID + ".EXTRA_PACKAGE_LIST_ATTR"; //$NON-NLS-1$
@@ -10,6 +13,8 @@ public interface ITizenLaunchConfigurationConstants {
        public static final String ATTR_PROCESSNAME_OPTION = PLATFORM_LAUNCH_ID + ".PROCESS_NAME_ATTR"; //$NON-NLS-1$
        public static final String ATTR_PROCESSID_OPTION = PLATFORM_LAUNCH_ID + ".PROCESS_ID_ATTR"; //$NON-NLS-1$
        
+       
+       
 
 }
  
\ No newline at end of file
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformCommandFactory.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformCommandFactory.java
new file mode 100644 (file)
index 0000000..be32f1e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+* NativeCommon
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* Yoonki Park <yoonki.park@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.nativeplatform.launch;
+
+import java.io.IOException;
+
+import org.eclipse.cdt.debug.mi.core.MIProcess;
+import org.eclipse.cdt.debug.mi.core.command.factories.StandardCommandFactory;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class PlatformCommandFactory extends StandardCommandFactory {
+       @Override
+       public MIProcess createMIProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
+               return new PlatformMIProcessAdapter(args, launchTimeout, monitor);
+       }
+}
\ No newline at end of file
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformMIProcessAdapter.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformMIProcessAdapter.java
new file mode 100644 (file)
index 0000000..822302e
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+* NativeCommon
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* Yoonki Park <yoonki.park@samsung.com>
+* 
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.nativeplatform.launch;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PushbackInputStream;
+
+import org.eclipse.cdt.debug.mi.core.MIInferior;
+import org.eclipse.cdt.debug.mi.core.MIPlugin;
+import org.eclipse.cdt.debug.mi.core.MIProcessAdapter;
+import org.eclipse.cdt.utils.spawner.Spawner;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.tizen.nativecommon.build.CommonProjectDependentBuilder;
+import org.tizen.nativecommon.build.ProjectTypeManager;
+import org.tizen.nativeplatform.util.CommandLauncher;
+
+
+public class PlatformMIProcessAdapter extends MIProcessAdapter {
+
+       private static final int ONE_SECOND = 1000;
+
+       private Process gdbProcess;
+       InputStream gdbInputStream;
+
+       public PlatformMIProcessAdapter(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
+               super(args, launchTimeout, monitor);
+       }
+
+       public PlatformMIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException {
+               super(args, monitor);
+       }
+       
+       @Override
+       public boolean canInterrupt(MIInferior inferior) {
+               return true;
+       }
+
+       @Override
+       public void interrupt(MIInferior inferior) {
+               if (gdbProcess instanceof Spawner) {
+                       String interruptCmd = CommandLauncher.genDebugginInterruptScript(gdbProcess);
+                       Process shellProcess;
+                       try {
+                               shellProcess = CommandLauncher.createProcess( interruptCmd, null, false );
+                               shellProcess.waitFor();
+                       } catch (InterruptedException e) {                              
+                               e.printStackTrace();
+                               super.interrupt(inferior);
+                               return;
+                       }
+                                               
+                       inferior.setSuspended();
+                       waitForInterrupt(inferior);             
+                       
+                       //super.interrupt(inferior);                    
+               } else {
+                       BufferedWriter bw;
+                       bw = new BufferedWriter(new OutputStreamWriter(gdbProcess.getOutputStream()));
+                       char c = 0x03; //standard code representing "Ctrl-C" sequence
+                       try {
+                               bw.write(c);
+                               bw.newLine();
+                               bw.flush();
+                               inferior.setSuspended();
+                       } catch (IOException e) {
+                               //do nothing.
+                       }
+               }
+       }
+
+       @Override
+       public InputStream getInputStream() {
+               return gdbInputStream;
+       }
+
+       private IProject getProjectName(String[] args) {
+               String projectPathString = null;
+               for (int i = 0; i < args.length; i++) {
+                       if (args[i].contains("--cd")) {
+                               projectPathString = args[i];
+                               break;
+                       }
+               }
+               String[] pathTokens = projectPathString.split("=");
+               projectPathString = pathTokens[pathTokens.length - 1];
+               IPath projectPath = new Path(projectPathString);
+               String projectName = projectPath.lastSegment();
+               IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+               return project;
+       }
+       
+       @Override
+       protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
+           
+               IProject project = getProjectName(args);
+               CommonProjectDependentBuilder builder = ProjectTypeManager.getProjectBuilderInstance(project);
+               
+               String[] newArgs = new String[args.length-1];
+               System.arraycopy(args, 1, newArgs, 0, args.length-1);
+
+               gdbProcess = builder.debug(newArgs);
+               
+//             gdbProcess = createGDBProcess(newArgs);
+               
+               Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$
+                       public void run() {
+                               try {
+                                       PushbackInputStream pb = new PushbackInputStream(gdbProcess.getInputStream());
+                                       gdbInputStream = pb;
+                                       pb.unread(pb.read());  // actually read something, then return it
+                               } catch (Exception e) {
+                                       // Do nothing, ignore the errors
+                               }
+                       }
+               };
+               syncStartup.start();
+
+               int timepass = 0;
+               if (launchTimeout <= 0) {
+                       // Simulate we are waiting forever.
+                       launchTimeout = Integer.MAX_VALUE;
+               }
+
+               // To respect the IProgressMonitor we can not use wait/notify
+               // instead we have to loop and check for the monitor to allow to cancel the thread.
+               // The monitor is check every 1 second delay;
+               for (timepass = 0; timepass < launchTimeout; timepass += ONE_SECOND) {
+                       if (syncStartup.isAlive() && !monitor.isCanceled()) {
+                               try {
+                                       Thread.sleep(ONE_SECOND);
+                               } catch (InterruptedException e) {
+                                       // ignore
+                               }
+                       } else {
+                               break;
+                       }
+               }
+               try {
+                       syncStartup.interrupt();
+                       syncStartup.join(ONE_SECOND);
+               } catch (InterruptedException e) {
+                       // ignore
+               }
+               if (monitor.isCanceled()) {
+                       gdbProcess.destroy();
+                       throw new OperationCanceledException();
+               } else if (timepass >= launchTimeout) {
+                       gdbProcess.destroy();
+                       String message = MIPlugin.getResourceString("src.GDBDebugger.Error_launch_timeout"); //$NON-NLS-1$
+                       throw new IOException(message);
+               }
+
+               return gdbProcess;
+       }
+}
\ No newline at end of file
index 4b41507..91ec68b 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
 import org.eclipse.cdt.debug.core.cdi.ICDISession;
 import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
 import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
+import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants;
 import org.eclipse.cdt.launch.AbstractCLaunchDelegate;
 import org.eclipse.cdt.launch.LaunchUtils;
 import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
@@ -68,6 +69,7 @@ import org.eclipse.debug.core.model.IProcess;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PartInitException;
@@ -85,6 +87,7 @@ import org.tizen.nativecommon.build.ProjectTypeManager;
 import org.tizen.nativecommon.build.SmartBuildInterface;
 import org.tizen.nativecommon.build.exception.SBIException;
 import org.tizen.nativecommon.launch.TizenDebugger;
+import org.tizen.nativecommon.launch.TizenLaunchCommand;
 import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants;
 import org.tizen.nativecommon.launch.TizenLaunchMessages;
 import org.tizen.nativecommon.launch.TizenUIThreadForConfirmMessage;
@@ -107,6 +110,7 @@ public class TizenDebianLaunchDelegate extends AbstractCLaunchDelegate {
     protected static final int defaultTimeOut = 60000;
     protected Shell shell;
     private boolean result;    
+    protected TizenLaunchCommand tizenCommand = null;
 
     protected String getPluginID() {
         return Activator.PLUGIN_ID;
@@ -118,7 +122,9 @@ public class TizenDebianLaunchDelegate extends AbstractCLaunchDelegate {
             monitor = new NullProgressMonitor();
         try {
             monitor.beginTask(TizenLaunchMessages.LAUNCH_APPLICATION, 20);
-            monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION);
+            monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION);            
+
+            tizenCommand = new TizenLaunchCommand(currentDevice, null);          
 
             activateProgressView();
 
@@ -497,8 +503,13 @@ 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);
-            String gdbserverPort = config.getAttribute(TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT, TizenLaunchConfigurationConstants.ATTR_GDBSERVER_PORT_DEFAULT);
+            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);
index d955754..fb4479e 100644 (file)
@@ -36,6 +36,7 @@ import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
 import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.debug.core.ILaunch;
@@ -91,6 +92,10 @@ public class TizenDebianLaunchDelegateForAttach extends TizenDebianLaunchDelegat
         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);
 
             if (pid.equals(Integer.valueOf(-1)) || pid.equals(Integer.valueOf(0))) {
                 newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER + ICDTLaunchConfigurationConstants.ERR_NO_PROCESSID, null);
index 00a71b2..2d4b7e3 100644 (file)
@@ -233,7 +233,7 @@ public class TizenDebianProjectAttachLaunchShortcut extends CApplicationLaunchSh
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, TizenLaunchConfigurationConstants.DEBUGGER_ID);
-                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, TizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
+                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, ITizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, true);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
index f9f594e..821cbad 100644 (file)
@@ -64,6 +64,7 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
 import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants;
 import org.tizen.nativeplatform.Activator;
+import org.tizen.nativeplatform.launch.ITizenLaunchConfigurationConstants;
 import org.tizen.nativeplatform.launch.TizenDebianLaunchMessages;
 
 
@@ -196,7 +197,7 @@ public class TizenDebianProjectCoredumpLaunchShortcut extends CApplicationLaunch
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, TizenLaunchConfigurationConstants.DEBUGGER_ID);
-                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, TizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
+                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, ITizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, true);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
index ad2f854..6b457b7 100644 (file)
@@ -252,7 +252,7 @@ public class TizenDebianProjectLaunchShortcut extends CApplicationLaunchShortcut
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, TizenLaunchConfigurationConstants.DEBUGGER_ID);
-                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, TizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
+                       wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, ITizenLaunchConfigurationConstants.COMMAND_FACTORY_ID);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, true);
                        wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, false);
                        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
index abe6253..220e752 100644 (file)
@@ -11,7 +11,6 @@ import java.util.HashMap;
 import org.eclipse.cdt.core.IProcessInfo;
 import org.eclipse.cdt.core.IProcessList;
 import org.eclipse.cdt.launch.internal.ui.LaunchImages;
-import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
 import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
 import org.eclipse.cdt.managedbuilder.core.IManagedProject;
@@ -27,14 +26,18 @@ import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.console.MessageConsoleStream;
 import org.eclipse.ui.dialogs.TwoPaneElementSelector;
+import org.tizen.common.TizenPlatformConstants;
 import org.tizen.common.ui.view.console.ConsoleManager;
 import org.tizen.common.util.FileUtil;
+import org.tizen.nativecommon.launch.LaunchUtils;
 import org.tizen.nativecommon.launch.TizenDeviceProcessList;
+import org.tizen.nativecommon.launch.TizenLaunchCommand;
 import org.tizen.nativecommon.launch.TizenLaunchMessages;
 import org.tizen.nativeplatform.build.PlatformConfigurationManager;
 import org.tizen.nativeplatform.pkgmgr.PackageManagerOuputReceiver;
@@ -45,8 +48,8 @@ import org.tizen.nativeplatform.preferences.PreferencesManager;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.SdbCommandRejectedException;
 import org.tizen.sdblib.SyncService;
-import org.tizen.sdblib.TimeoutException;
 import org.tizen.sdblib.SyncService.SyncResult;
+import org.tizen.sdblib.TimeoutException;
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -523,5 +526,47 @@ public class PlatformLaunchUtils {
                        return null;
                }               
        }
+       
+       public boolean checkGdbServerInDevice(IDevice device, TizenLaunchCommand command) throws CoreException {
+               String resultCommand = TizenPlatformConstants.GDBSERVER_PLATFORM_CMD + " --version"
+                + TizenPlatformConstants.CMD_RESULT_CHECK;
+        try {
+            command.run(resultCommand, "0");
+        } catch (Exception e) {
+            //LaunchUtils.newCoreException(NLS.bind(TizenLaunchMessages.CANNOT_FIND_GDBSERVER, device.getDeviceName()), e);
+               return false;
+        }
+        
+        return true;
+       }
+       
+       public void readyGdbServer(IDevice device, TizenLaunchCommand command, IPath srcPath) 
+                       throws CoreException, TimeoutException, SdbCommandRejectedException, IOException {
+               File gdbserver = new File(srcPath.toOSString());
+               
+               if (!gdbserver.exists()) {
+                       LaunchUtils.newCoreException(NLS.bind(TizenLaunchMessages.CANNOT_FIND_GDBSERVER, device.getDeviceName()), null);
+               }
+               
+               if (!checkGdbServerInDevice(device, command)) {
+                       copyFileToDevice(device, srcPath.toOSString(), TizenPlatformConstants.GDBSERVER_PLATFORM_CMD);
+                       device.executeShellCommand(String.format("chmod +x %s", TizenPlatformConstants.GDBSERVER_PLATFORM_CMD));                
+               }       
+       }
+       
+       public void copyFileToDevice(IDevice device, String srcPath, String descPath) throws CoreException, TimeoutException, SdbCommandRejectedException, IOException {
+               SyncResult syncSuccess = device.getSyncService().pushFile(srcPath,
+                               descPath, SyncService.getNullProgressMonitor());
 
+        if (syncSuccess.getCode() != SyncService.RESULT_OK) {
+            LaunchUtils.newCoreException(TizenLaunchMessages.CANNOT_TRANSFER_FILE, null);
+        }
+       }
+       
+       public boolean checkGdbServerInBuildSystem(String rootstrapPath) {
+               IPath path = new Path(rootstrapPath).append("usr").append("bin").append("gdbserver");
+               File gdbserver = new File(path.toOSString());
+               
+               return gdbserver.exists();
+       }
 }
index 90df06e..5272b24 100644 (file)
@@ -303,6 +303,44 @@ public class CommandLauncher {
                }
        }
        
+       // generate interrupt script for platform debugging and return script path
+       public static String genDebugginInterruptScript(Process process) {
+               String passwd = SudoPasswdManager.getSudoPassword();
+
+               try {
+                       // get process id
+                       Field f = process.getClass().getDeclaredField("pid");
+                       f.setAccessible(true);
+                       String pid = f.get(process).toString();                                                         
+
+                       // create interrupt script file
+                       File interruptScript = new File("/tmp/interruptProc.sh");
+                       interruptScript.createNewFile();
+                       BufferedWriter bw = new BufferedWriter(new FileWriter(interruptScript));
+                       bw.write("#!/bin/sh");bw.newLine();
+                       bw.write("proctree() {");bw.newLine();
+                       bw.write("  local _pid=$1");bw.newLine();                       
+                       bw.write("  for _child in $(ps -o pid --no-headers --ppid ${_pid}); do");bw.newLine();
+                       bw.write("    proctree ${_child}");bw.newLine();
+                       bw.write("  done");bw.newLine();
+                       bw.write("  user=`ps -o user --no-headers --pid ${_pid}`");bw.newLine();
+                       bw.write("  if [ \"x${user}\" = \"xroot\" ]; then");bw.newLine();
+                       bw.write(String.format("    echo \"%s\" | sudo -S kill -SIGINT ${_pid}", passwd));bw.newLine();
+                       bw.write("    exit 0");bw.newLine();
+                       bw.write("  fi");bw.newLine();                                          
+                       bw.write("}");bw.newLine();
+                       bw.write(String.format("proctree %s", pid));bw.newLine();
+                       bw.write("exit -1");bw.newLine();
+                       bw.close();
+                       interruptScript.setExecutable(true);
+                       
+                       return interruptScript.getPath();
+               }
+               catch (Exception e ) {
+                       return null;
+               }
+       }
+       
        
        static class ProcessMonitorThread extends Thread {
                private Process process;