1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 18:25:40 +02:00

Bug 463977 - Exit code not always displayed in console

Change-Id: I6342cd55530eeb1ea9faf52cd26884065f069ebd
Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Marc Khouzam 2015-04-06 14:47:03 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 95bff0bb50
commit db8179004f

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2013 Ericsson and others.
* Copyright (c) 2011, 2015 Ericsson and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -15,7 +15,6 @@ import java.util.Map;
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IProcess;
@ -37,15 +36,34 @@ public class InferiorRuntimeProcess extends RuntimeProcess {
@Override
protected void terminated() {
super.terminated();
// We must set the console label before calling super.terminated()
// This is because super.terminated() will send an event to rename
// the console, and we find ourselves in a race condition
// where we may miss setting the label here (bug 463977)
setConsoleTerminatedLabel();
super.terminated();
}
private void setConsoleTerminatedLabel() {
if (getAttribute(IGdbDebugConstants.INFERIOR_EXITED_ATTR) != null) {
// Add the exit code to the title of the console if the inferior properly exited.
int exitValue = 0;
try {
// We have to explicitly get the exit code from the lower level process
// instead of calling getExitValue() because we have not yet indicated
// that this wrapper process has terminated by calling super.terminated()
// Bug 463977
exitValue = getSystemProcess().exitValue();
} catch (IllegalThreadStateException e) {
// Process not terminated. Should not happen. Use default behavior.
return;
}
// Inspired from org.eclipse.debug.internal.ui.views.console.ProcessConsole#computeName
// We set the IProcess.ATTR_PROCESS_LABEL to modify the console title but not the process label
// of the debug view. Overriding getLabel() affects the element in the debug view also, so
// we don't do that.
private void setConsoleTerminatedLabel() {
String label = getLabel();
String type = null;
@ -63,17 +81,12 @@ public class InferiorRuntimeProcess extends RuntimeProcess {
}
buffer.append(label);
if (getAttribute(IGdbDebugConstants.INFERIOR_EXITED_ATTR) != null) {
// Add the exit code to the label if the inferior properly exited.
try {
// Prefix with exit value
buffer.insert(0, MessageFormat.format(LaunchMessages.getString("InferiorRuntimeProcess_ExitValue"), //$NON-NLS-1$
new Object[] { getExitValue() }));
} catch (DebugException e) {
// Process not terminated. Should not happen. But even so, we should use the plain label.
}
}
new Object[] { exitValue }));
label = buffer.toString();
setAttribute(IProcess.ATTR_PROCESS_LABEL, label);
}
}
}