mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 13:55:39 +02:00
Bug 463975 - Show exit code in console when doing a Run
Change-Id: I97fe993e33f1774133aa7cfd488e6e549dae2e0a Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
parent
c4f5c35620
commit
1ac11fc4bf
2 changed files with 47 additions and 2 deletions
|
@ -23,7 +23,10 @@ import org.eclipse.debug.core.model.RuntimeProcess;
|
||||||
import com.ibm.icu.text.MessageFormat;
|
import com.ibm.icu.text.MessageFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A process for the inferior to know it belongs to a DSF-GDB session
|
* A process for the inferior to know it belongs to a DSF-GDB session.
|
||||||
|
* This class also adds the exit code of the inferior to the console.
|
||||||
|
*
|
||||||
|
* Note that this class is also used in Run mode.
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* Marc Khouzam (Ericsson) - Modified to only handle Run mode and modernized (Bug 464636)
|
* Marc Khouzam (Ericsson) - Modified to only handle Run mode and modernized (Bug 464636)
|
||||||
|
* Marc Khouzam (Ericsson) - Show exit code in console when doing a Run (Bug 463975)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.launch.internal;
|
package org.eclipse.cdt.launch.internal;
|
||||||
|
|
||||||
|
@ -16,6 +17,8 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||||
|
@ -33,6 +36,7 @@ import org.eclipse.core.variables.VariablesPlugin;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.ILaunch;
|
import org.eclipse.debug.core.ILaunch;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.debug.core.ILaunchManager;
|
import org.eclipse.debug.core.ILaunchManager;
|
||||||
|
|
||||||
import com.ibm.icu.text.DateFormat;
|
import com.ibm.icu.text.DateFormat;
|
||||||
|
@ -92,12 +96,28 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2
|
||||||
|
|
||||||
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
||||||
String processLabel = String.format("%s (%s)", commandArray[0], timestamp); //$NON-NLS-1$
|
String processLabel = String.format("%s (%s)", commandArray[0], timestamp); //$NON-NLS-1$
|
||||||
DebugPlugin.newProcess(launch, process, processLabel);
|
|
||||||
|
DebugPlugin.newProcess(launch, process, processLabel, createProcessAttributes());
|
||||||
} finally {
|
} finally {
|
||||||
monitor.done();
|
monitor.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Map<String, String> createProcessAttributes() {
|
||||||
|
Map<String, String> attributes = new HashMap<>();
|
||||||
|
|
||||||
|
// Specify that the process factory (GdbProcessFactory) should use InferiorRuntimeProcess to wrap
|
||||||
|
// the process that we are about to run.
|
||||||
|
// Note that GdbProcessFactory is only used for launches created using DSF-GDB not CDI
|
||||||
|
attributes.put("org.eclipse.cdt.dsf.gdb.createProcessType" /* IGdbDebugConstants.PROCESS_TYPE_CREATION_ATTR */, //$NON-NLS-1$
|
||||||
|
"org.eclipse.cdt.dsf.gdb.inferiorProcess" /* IGdbDebugConstants.INFERIOR_PROCESS_CREATION_VALUE */); //$NON-NLS-1$
|
||||||
|
|
||||||
|
// Show the exit code of the process in the console title once it has terminated
|
||||||
|
attributes.put("org.eclipse.cdt.dsf.gdb.inferiorExited" /* IGdbDebugConstants.INFERIOR_EXITED_ATTR */, //$NON-NLS-1$
|
||||||
|
""); //$NON-NLS-1$
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used to check that the project and program are correct.
|
* Method used to check that the project and program are correct.
|
||||||
* Can be overridden to avoid checking certain things.
|
* Can be overridden to avoid checking certain things.
|
||||||
|
@ -139,9 +159,31 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preLaunchCheck(ILaunchConfiguration config, String mode, IProgressMonitor monitor) throws CoreException {
|
public boolean preLaunchCheck(ILaunchConfiguration config, String mode, IProgressMonitor monitor) throws CoreException {
|
||||||
|
// Setup default Process Factory
|
||||||
|
setDefaultProcessFactory(config);
|
||||||
|
|
||||||
return super.preLaunchCheck(config, mode, monitor);
|
return super.preLaunchCheck(config, mode, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the ILaunchConfiguration to set the DebugPlugin.ATTR_PROCESS_FACTORY_ID attribute,
|
||||||
|
* so as to specify the process factory to use.
|
||||||
|
*
|
||||||
|
* This attribute should only be set if it is not part of the configuration already, to allow
|
||||||
|
* other code to set it to something else.
|
||||||
|
*/
|
||||||
|
protected void setDefaultProcessFactory(ILaunchConfiguration config) throws CoreException {
|
||||||
|
if (!config.hasAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID)) {
|
||||||
|
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
|
||||||
|
// Use the debug process factory as it provides extra features for the program
|
||||||
|
// that is being debugged or in this case run.
|
||||||
|
// Effectively, we want to use InferiorRuntimeProcess when doing this Run launch.
|
||||||
|
wc.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID,
|
||||||
|
"org.eclipse.cdt.dsf.gdb.GdbProcessFactory"); //$NON-NLS-1$
|
||||||
|
wc.doSave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPluginID() {
|
protected String getPluginID() {
|
||||||
return LaunchUIPlugin.getUniqueIdentifier();
|
return LaunchUIPlugin.getUniqueIdentifier();
|
||||||
|
|
Loading…
Add table
Reference in a new issue