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;
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;
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;
monitor.done();
} catch (InterruptedException e) {
- e.printStackTrace();
+ // This exception is occurred if device is not root on or failed to install
+ newCoreException(TizenDebianLaunchMessages.FAILED_INSTALL_PKGS, e);
}
}
monitor.subTask(TizenLaunchMessages.PREPARE_TO_LAUNCH);
currentDevice = ConnectionPlugin.getDefault().getCurrentDevice();
- if (currentDevice == null)
+ if (currentDevice == null) {
newCoreException(TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE, null);
- if (currentDevice.isOffline())
+ }
+ if (currentDevice.isOffline()) {
newCoreException(TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE, null);
+ }
} finally {
monitor.done();
}
}
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();
}
monitor.subTask(TizenLaunchMessages.LAUNCH_APPLICATION_WITH_GDBCLIENT);
TizenDebugger debugger = new TizenDebugger();
- debugSession = ((ICDIDebugger2)debugger).createSession(launch, exeFile.getPath().toFile(), new SubProgressMonitor(monitor, 1));
+ debugSession = ((ICDIDebugger2)debugger).createSession(launch,
+ getGDBClientArgument(exeFile), new SubProgressMonitor(monitor, 1));
if(debugSession == null)
newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBCLIENT, null);
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();
return result;
}
+
+ protected File getGDBClientArgument(IBinaryObject exeFile) {
+ return exeFile.getPath().toFile();
+ }
}
package org.tizen.nativeplatform.launch;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import org.eclipse.cdt.core.IProcessInfo;
+import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
+import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.utils.PathUtil;
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.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
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.ProjectUtil;
import org.tizen.nativecommon.build.SmartBuildInterface;
import org.tizen.nativecommon.build.exception.SBIException;
import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants;
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;
@Override
protected void setDebugConfigAttributes(ILaunchConfiguration config) throws CoreException {
+
+ setSharedlibrarySearchPath(config);
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
pid = wc.getAttribute(ITizenLaunchConfigurationConstants.ATTR_PROCESSID_OPTION, -1);
newCoreException(TizenLaunchMessages.CANNOT_CREATE_FORWARD, null);
currentDevice.createForward(localDebugPort, Integer.parseInt(gdbserverPort));
String localPort = Integer.valueOf(localDebugPort).toString();
- wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, localPort);
+ wc.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, localPort);
wc.doSave();
} catch (TimeoutException e) {
newCoreException(TizenLaunchMessages.CANNOT_CREATE_FORWARD, e);
newCoreException(TizenLaunchMessages.CANNOT_CREATE_FORWARD, e);
} catch (IOException e) {
newCoreException(TizenLaunchMessages.CANNOT_CREATE_FORWARD, e);
+ }
+ }
+
+ private void setSharedlibrarySearchPath(ILaunchConfiguration config) throws CoreException {
+
+ // Attach debugging should add the "Debug" directory to its [Shared Libraries] path.
+ List<String> values = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, new ArrayList(1));
+ ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+ IProject proj = ProjectUtil.getProject(config);
+ String appPath = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
+ if (!appPath.isEmpty()) {
+ appPath = new Path(appPath).removeLastSegments(1).toOSString();
+ } else {
+ newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+ }
+ IConfiguration buildConfig = ProjectUtil.getDefaultConfiguration(proj);
+ String targetID = "";
+ String rootstrapPath = "";
+ try {
+ targetID = PlatformConfigurationManager.getDefaultBuildTargetName(buildConfig);
+ String path = SmartBuildInterface.getInstance().getRootstrapPath(targetID);
+ rootstrapPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(path);
+ } catch (SBIException e) {
+ newCoreException(TizenLaunchMessages.CANNOT_LAUNCH_APPLICATION_WITH_GDBSERVER, null);
+ }
+
+ IPath debugProjPath = new Path(rootstrapPath + File.separatorChar
+ + "usr" + File.separatorChar
+ + "lib" + File.separatorChar
+ + "debug" + File.separatorChar
+ + appPath);
+
+ if (canAddLibrarySearchPath(config, debugProjPath)) {
+ values.add(debugProjPath.toOSString());
+ }
+
+ IPath debugBinPath = new Path(rootstrapPath + File.separatorChar
+ + "usr" + File.separatorChar
+ + "lib" + File.separatorChar
+ + "debug" + File.separatorChar
+ + "usr" + File.separatorChar
+ + "bin");
+
+ if (canAddLibrarySearchPath(config, debugBinPath)) {
+ values.add(debugBinPath.toOSString());
}
+
+ IPath debugLibPath = new Path(rootstrapPath + File.separatorChar
+ + "usr" + File.separatorChar
+ + "lib" + File.separatorChar
+ + "debug" + File.separatorChar
+ + "usr" + File.separatorChar
+ + "lib");
+
+ if (canAddLibrarySearchPath(config, debugLibPath)) {
+ values.add(debugLibPath.toOSString());
+ }
+
+ // set shared library search path
+ if (values.size() > 0) {
+ wc.setAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, values);
+ }
+ wc.doSave();
}
+ protected boolean canAddLibrarySearchPath(ILaunchConfiguration config, IPath searchPath) throws CoreException {
+ List values = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, Collections.EMPTY_LIST);
+ Iterator it = values.iterator();
+ boolean ret = true;
+
+ while (it.hasNext()) {
+ IPath oldPath = new Path((String) it.next());
+ if (PathUtil.equalPath(oldPath, searchPath)) {
+ ret = false;
+ break;
+ }
+ }
+ return ret;
+ }
+
+
@Override
protected void setConfigIfNotFromShortcut(ILaunchConfiguration config, String mode, IProgressMonitor monitor)
throws CoreException {
}
@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, "");
} catch (InterruptedException e) {
e.printStackTrace();
}
- }
+ }
+
+ @Override
+ protected File getGDBClientArgument(IBinaryObject exeFile) {
+ // It should be null. If <binary_path> is passed as an gdb argument, breakpoint address is corrupted.
+ // 1) gdb
+ // 2) target remote :<port>
+ // 3) set solib-search-path <binary_path>
+ return null;
+ }
}
\ No newline at end of file