import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.IProcess;
import org.eclipse.linuxtools.valgrind.core.ValgrindCommand;
import org.eclipse.linuxtools.valgrind.core.utils.LaunchConfigurationConstants;
import org.eclipse.linuxtools.valgrind.ui.ValgrindUIPlugin;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.tizen.common.TizenPlatformConstants;
protected static final String PACKAGE_FILENAME_ARM = "valgrind_armel.deb";
protected String toolID;
+ protected int confirmMsg = 0;
@Override
public void launch(ILaunchConfiguration config, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException
{
-
if (monitor == null)
monitor = new NullProgressMonitor();
+
try {
IDevice device = ConnectionPlugin.getDefault().getCurrentDevice();
if(!device.isEmulator())
verifyCProjectConfigurationSettings(config);
verifyDeviceReachability(ProjectUtil.getProject(config),
new SubProgressMonitor(monitor, 9));
- verifyBuildConfiguration(config, mode, new SubProgressMonitor(
- monitor, 11));
+ verifyBuildConfiguration(config, mode, new SubProgressMonitor(monitor, 11));
// getLaunchSession(config, new SubProgressMonitor(monitor, 1));
}
}
- protected void launchApplicationWithValgrind(ILaunch launch,
- ILaunchConfiguration config, IProgressMonitor monitor)
- throws CoreException {
+ protected void launchApplicationWithValgrind(ILaunch launch, ILaunchConfiguration config,
+ IProgressMonitor monitor) throws CoreException
+ {
// Process remoteShellProcess = null;
try {
- // find Valgrind
+ // find Valgrind executable
String valgrindCmd = "/home/developer/sdk_tools/valgrind/usr/bin/valgrind";
String cmd = "ls " + valgrindCmd + TizenPlatformConstants.CMD_SUFFIX;
- // String resultRsp = session.run(cmd, null);
String[] resultRsp = CommandManager.runCommandReturningResult(cmd);
if (!CommandManager.isRunSeccessfuly(resultRsp)) {
- // if (CommandManager.isEmulator()) {
- newCoreException(
- TizenLaunchMessages.CANNOT_LAUNCH,
- new Exception(
- "No valgrind in this target (/home/developer/sdk_tools/valgrind/usr/bin/valgrind). "));
- // } else {
- // transferProfilingToolPackage(monitor);
- // installProfilingToolPackage(monitor);
- // }
+ newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, new Exception(
+ "No valgrind in this target (/home/developer/sdk_tools/valgrind/usr/bin/valgrind)."));
}
+
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+
+ // verify target app path
IProjectLaunchCommand manifest = ProjectUtil.getProjectManifest(ProjectUtil.getProject(config));
String remoteExePath = TizenPlatformConstants.APP_INSTALL_PATH + "/" + manifest.getPackageName() + "/bin/";
-// cmd = "cd " + remoteExePath + CMD_RESULT_CHECK;
-// // resultRsp = session.run(cmd, null);
-// resultRsp = CommandManager.runCommandReturningResult(cmd);
-// if (!CommandManager.isRunSeccessfuly(resultRsp))
-// newCoreException(TizenLaunchMessages.CANNOT_LAUNCH,
-// new Exception("Cannot change to run-directory : "
-// + ". (Return Code: " + resultRsp
-// + ", exepath: " + remoteExePath + ")"));
IPath exeFile = CDebugUtils.verifyProgramPath(config);
remoteExePath += exeFile.toFile().getName();
+
// for bada application
- // execute not .exe file instead of .exe file
+ // execute non-exe file instead of .exe file
if(remoteExePath.endsWith(BADA_EXT))
{
remoteExePath = remoteExePath.substring(0, remoteExePath.length() - BADA_EXT.length());
}
cmd = "ls " + remoteExePath + TizenPlatformConstants.CMD_SUFFIX;
- // resultRsp = session.run(cmd, null);
resultRsp = CommandManager.runCommandReturningResult(cmd);
if (!CommandManager.isRunSeccessfuly(resultRsp))
- newCoreException(
- TizenLaunchMessages.CANNOT_LAUNCH,
- new Exception(
- "Executable does not exist on a valid path. You must install your application before running it."));
-
+ {
+ newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, new Exception(
+ "Executable does not exist on a valid path. You must install your application before running it."));
+ }
+
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+
monitor.worked(3);
// remove and remake valgrind result directory
cmd = "rm -rf" + " " + ValgrindLaunchPlugin.RESULT_DIR;
- // session.run(cmd, null);
CommandManager.runShell(cmd);
cmd = "mkdir -p" + " " + ValgrindLaunchPlugin.RESULT_DIR;
- // session.run(cmd, null);
CommandManager.runShell(cmd);
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+
monitor.worked(1);
// ask tool (that was launched) extension for arguments
toolID = getTool(config);
- dynamicDelegate = ValgrindLaunchPlugin.getDefault()
- .getToolDelegate(toolID);
+ dynamicDelegate = ValgrindLaunchPlugin.getDefault().getToolDelegate(toolID);
String[] opts = getValgrindArgumentsArray(config);
String[] arguments = getProgramArgumentsArray(config);
- ArrayList<String> cmdLine = new ArrayList<String>(
- 1 + arguments.length);
+ ArrayList<String> cmdLine = new ArrayList<String>(1 + arguments.length);
cmdLine.add(valgrindCmd);
cmdLine.addAll(Arrays.asList(opts));
cmdLine.add(remoteExePath.toString());
cmdLine.addAll(Arrays.asList(arguments));
- String[] commandArray = (String[]) cmdLine
- .toArray(new String[cmdLine.size()]);
+ String[] commandArray = (String[]) cmdLine.toArray(new String[cmdLine.size()]);
// compose full command of valgrind
String fullcommand = "";
fullcommand += commandArray[i] + " ";
}
- // if (CommandManager.isEmulator()
- // && Platform.getOS().equals(Platform.OS_WIN32)) {
- // Exception te;
- // te = new Exception(
- // "Can not use valgrind, because the host doesn't support Intel VT");
- // throw (te);
- // }
-
- config.getAttribute(
- ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL,
- ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT); // what
- // is
- // this?
- // remoteShellProcess = session.launch(fullcommand, null);
- // CommandManager.runShell(fullcommand);
- runApplication(config, launch, fullcommand);
+ config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL,
+ ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
+
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+
+ // run application with valgrind
+ runApplication(config, launch, fullcommand, monitor);
monitor.worked(2);
- // process = DebugPlugin.newProcess(launch, remoteShellProcess,
- // "valgrind");
+ // process = DebugPlugin.newProcess(launch, remoteShellProcess, "valgrind");
// create launch summary string to distinguish this launch
String launchStr = createLaunchStr(config);
// create view
ValgrindUIPlugin.getDefault().createView(launchStr, toolID);
+ monitor.worked(1);
+
// pass off control to extender
- command = new ValgrindCommand(new File(
- ValgrindLaunchPlugin.RESULT_DIR));
- dynamicDelegate.launch(command, config, launch,
- new SubProgressMonitor(monitor, 15));
+ command = new ValgrindCommand(new File(ValgrindLaunchPlugin.RESULT_DIR));
+ dynamicDelegate.launch(command, config, launch, new SubProgressMonitor(monitor, 15));
+ monitor.worked(1);
+
// refresh view
ValgrindUIPlugin.getDefault().refreshView();
+ monitor.worked(2);
+
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage()
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView(ValgrindUIPlugin.VIEW_ID);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
-
+ } catch (ValgrindCanceledException e) {
+ // do nothing
+ } catch (OperationCanceledException e) {
+ newCoreException("Operation canceled by user.", null);
} catch (CoreException e) {
throw e;
} catch (Exception e) {
newCoreException(TizenLaunchMessages.CANNOT_LAUNCH, e);
} finally {
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- } else {
- monitor.done();
- }
+ monitor.done();
}
}
private void runApplication(ILaunchConfiguration config, ILaunch launch,
- String command) {
- SdbShellProcess oprofileProc = CommandManager.runApplication(command);
+ String command, IProgressMonitor monitor) throws ValgrindCanceledException
+ {
+ SdbShellProcess valgrindProc = CommandManager.runApplication(command);
IPath exeFile = null;
try {
exeFile = CDebugUtils.verifyProgramPath(config);
- ValgrindDebugPlugin.newProcess(launch, oprofileProc, exeFile
- .toFile().getName());
- BufferedReader br = new BufferedReader(new InputStreamReader(
- oprofileProc.getInputStream()));
- while (null != br.readLine()) {
+ IProcess vproc = ValgrindDebugPlugin.newProcess(launch, valgrindProc, exeFile.toFile().getName());
+// BufferedReader br = new BufferedReader(new InputStreamReader(valgrindProc.getInputStream()));
+
+ while (true)
+ {
+ if (monitor.isCanceled())
+ {
+ valgrindProc.destroy();
+
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow wbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ MessageBox confirm = new MessageBox(wbench.getShell(), SWT.ICON_WARNING | SWT.OK);
+ confirm.setMessage(Messages.getString("ValgrindLaunchPlugin.Confirm_cancel"));
+ confirm.open();
+ }
+ });
+
+ throw new ValgrindCanceledException();
+ }
+ else if(vproc.isTerminated())
+ {
+ monitor.worked(2);
+ break;
+ }
+
+ Thread.sleep(250);
}
} catch (CoreException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
+ } catch (InterruptedException e) {
e.printStackTrace();
}
-
}
- private String[] getValgrindArgumentsArray(ILaunchConfiguration config)
- throws IOException, CoreException {
+ private String[] getValgrindArgumentsArray(ILaunchConfiguration config) throws IOException, CoreException
+ {
ArrayList<String> opts = new ArrayList<String>();
- opts.add(ValgrindCommand.OPT_TOOL + EQUALS
- + ValgrindLaunchPlugin.getDefault().getToolName(toolID));
-
- // opts.add(ValgrindCommand.OPT_LOGFILE + EQUALS +
- // ValgrindLaunchPlugin.RESULT_DIR + LOG_FILE);
- opts.add(ValgrindCommand.OPT_XMLFILE + EQUALS
- + ValgrindLaunchPlugin.RESULT_DIR + LOG_FILE);
- // opts.add(ValgrindCommand.OPT_LOGFILE + EQUALS + "/home" +
- // File.separator + LOG_FILE);
-
- opts.add(ValgrindCommand.OPT_TRACECHILD
- + EQUALS
- + (config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD,
- false) ? YES : NO));
- opts.add(ValgrindCommand.OPT_CHILDSILENT + EQUALS + YES);// (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_CHILDSILENT,
- // false) ?
- // YES :
- // NO));
+ opts.add(ValgrindCommand.OPT_TOOL + EQUALS + ValgrindLaunchPlugin.getDefault().getToolName(toolID));
+
+ // opts.add(ValgrindCommand.OPT_LOGFILE + EQUALS + ValgrindLaunchPlugin.RESULT_DIR + LOG_FILE);
+ opts.add(ValgrindCommand.OPT_XMLFILE + EQUALS + ValgrindLaunchPlugin.RESULT_DIR + LOG_FILE);
+ // opts.add(ValgrindCommand.OPT_LOGFILE + EQUALS + "/home" + File.separator + LOG_FILE);
+
+ opts.add(ValgrindCommand.OPT_TRACECHILD + EQUALS +
+ (config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD, false) ? YES : NO));
+ opts.add(ValgrindCommand.OPT_CHILDSILENT + EQUALS + YES);
+ // (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_CHILDSILENT, false) ? YES : NO));
+
// opts.add(ValgrindCommand.OPT_TRACKFDS + EQUALS +
- // (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_TRACKFDS,
- // false) ? YES : NO));
+ // (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_TRACKFDS, false) ? YES : NO));
// opts.add(ValgrindCommand.OPT_TIMESTAMP + EQUALS +
- // (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_TIMESTAMP,
- // false) ? YES : NO));
- opts.add(ValgrindCommand.OPT_FREERES
- + EQUALS
- + (config
- .getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_FREERES,
- true) ? YES : NO));
-
- opts.add(ValgrindCommand.OPT_DEMANGLE
- + EQUALS
- + (config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_DEMANGLE,
- true) ? YES : NO));
- opts.add(ValgrindCommand.OPT_NUMCALLERS
- + EQUALS
- + config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_NUMCALLERS,
- 12));
- opts.add(ValgrindCommand.OPT_ERRLIMIT
- + EQUALS
- + (config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_ERRLIMIT,
- true) ? YES : NO));
- opts.add(ValgrindCommand.OPT_BELOWMAIN
- + EQUALS
- + (config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_BELOWMAIN,
- false) ? YES : NO));
- opts.add(ValgrindCommand.OPT_MAXFRAME
- + EQUALS
- + config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_MAXFRAME,
- 2000000));
-
- String strpath = config.getAttribute(
- LaunchConfigurationConstants.ATTR_GENERAL_SUPPFILE,
- EMPTY_STRING);
+ // (config.getAttribute(ValgrindLaunchPlugin.ATTR_GENERAL_TIMESTAMP, false) ? YES : NO));
+ opts.add(ValgrindCommand.OPT_FREERES + EQUALS +
+ (config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_FREERES, true) ? YES : NO));
+
+ opts.add(ValgrindCommand.OPT_DEMANGLE + EQUALS +
+ (config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_DEMANGLE, true) ? YES : NO));
+ opts.add(ValgrindCommand.OPT_NUMCALLERS + EQUALS +
+ config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_NUMCALLERS, 12));
+ opts.add(ValgrindCommand.OPT_ERRLIMIT + EQUALS +
+ (config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_ERRLIMIT, true) ? YES : NO));
+ opts.add(ValgrindCommand.OPT_BELOWMAIN + EQUALS +
+ (config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_BELOWMAIN, false) ? YES : NO));
+ opts.add(ValgrindCommand.OPT_MAXFRAME + EQUALS +
+ config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_MAXFRAME, 2000000));
+
+ String strpath = config.getAttribute(LaunchConfigurationConstants.ATTR_GENERAL_SUPPFILE, EMPTY_STRING);
if (!strpath.equals(EMPTY_STRING)) {
- File suppfile = ValgrindLaunchPlugin.getDefault().parseWSPath(
- strpath);
+ File suppfile = ValgrindLaunchPlugin.getDefault().parseWSPath(strpath);
if (suppfile != null) {
String escapedPath = null;
try {
- escapedPath = ValgrindLaunchPlugin.getDefault()
- .escapeAndQuote(suppfile.getCanonicalPath());
+ escapedPath = ValgrindLaunchPlugin.getDefault().escapeAndQuote(suppfile.getCanonicalPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}
- opts.addAll(Arrays.asList(dynamicDelegate.getCommandArray(command,
- config)));
+ opts.addAll(Arrays.asList(dynamicDelegate.getCommandArray(command, config)));
String[] ret = new String[opts.size()];
return opts.toArray(ret);
}
- protected String getTool(ILaunchConfiguration config) throws CoreException {
+ protected String getTool(ILaunchConfiguration config) throws CoreException
+ {
return config.getAttribute(LaunchConfigurationConstants.ATTR_TOOL,
ValgrindLaunchPlugin.TOOL_EXT_DEFAULT);
}
- protected String getPluginID() {
+ protected String getPluginID()
+ {
return ValgrindLaunchPlugin.PLUGIN_ID;
}
- public String[] getProgramArgumentsArray(ILaunchConfiguration config)
- throws CoreException {
+ public String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException
+ {
return LaunchUtils.getProgramArgumentsArray(config);
}
- protected String createLaunchStr(ILaunchConfiguration config)
- throws CoreException {
- return config.getName() + " ["
- + ValgrindLaunchPlugin.getDefault().getToolName(toolID) + "] ";
+ protected String createLaunchStr(ILaunchConfiguration config) throws CoreException
+ {
+ return config.getName() + " [" + ValgrindLaunchPlugin.getDefault().getToolName(toolID) + "] ";
+ }
+
+
+ class ValgrindCanceledException extends Exception
+ {
+ private static final long serialVersionUID = 1L;
+
+ public ValgrindCanceledException() {
+ super();
+ }
}
}