Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2009-04-13 18:00:32 +0000
committereutarass2009-04-13 18:00:32 +0000
commit9589911df34adc93433ac83af96e5bcc9f9d89b6 (patch)
treee74c2e8751baabe66dfeaa2acf6234b211fb536d
parent44babd128cf9813ab42cf32dea66a7beadb94e8e (diff)
downloadorg.eclipse.tcf-9589911df34adc93433ac83af96e5bcc9f9d89b6.tar.gz
org.eclipse.tcf-9589911df34adc93433ac83af96e5bcc9f9d89b6.tar.xz
org.eclipse.tcf-9589911df34adc93433ac83af96e5bcc9f9d89b6.zip
TCF Debugger: fixed a racing condition during initialization.
-rw-r--r--plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFAnnotationManager.java3
-rw-r--r--plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModel.java58
-rw-r--r--plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModelManager.java37
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/launch/TCFLaunchDelegate.java14
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/model/TCFLaunch.java6
5 files changed, 57 insertions, 61 deletions
diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFAnnotationManager.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFAnnotationManager.java
index b64039107..a475cdc06 100644
--- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFAnnotationManager.java
+++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFAnnotationManager.java
@@ -91,6 +91,9 @@ public class TCFAnnotationManager {
new HashMap<IWorkbenchWindow,WorkbenchWindowInfo>();
private final TCFLaunch.Listener launch_listener = new TCFLaunch.Listener() {
+
+ public void onCreated(TCFLaunch launch) {
+ }
public void onConnected(final TCFLaunch launch) {
updateActiveLaunch();
diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModel.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModel.java
index 65655fb35..0545a5e0c 100644
--- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModel.java
+++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModel.java
@@ -67,7 +67,7 @@ import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Device;
import org.eclipse.tm.internal.tcf.debug.model.TCFLaunch;
import org.eclipse.tm.internal.tcf.debug.model.TCFSourceRef;
import org.eclipse.tm.internal.tcf.debug.ui.Activator;
@@ -107,6 +107,7 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
IModelProxyFactory, IColumnPresentationFactory, ISourceDisplay {
private final TCFLaunch launch;
+ private final Display display;
private final Map<IPresentationContext,TCFModelProxy> model_proxies =
new HashMap<IPresentationContext,TCFModelProxy>();
@@ -147,8 +148,6 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
private static int debug_view_selection_cnt;
private static int display_source_cnt;
- private static Display display;
- private static Color console_colors[];
private final IMemory.MemoryListener mem_listener = new IMemory.MemoryListener() {
@@ -327,24 +326,9 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
}
};
- public static void setDisplay(Display display) {
- assert display.getThread() == Thread.currentThread();
- TCFModel.display = display;
- console_colors = new Color[4];
- for (int i = 0; i < console_colors.length; i++) {
- int id = SWT.COLOR_BLACK;
- switch (i) {
- case 1: id = SWT.COLOR_RED; break;
- case 2: id = SWT.COLOR_BLUE; break;
- case 3: id = SWT.COLOR_GREEN; break;
- }
- console_colors[i] = display.getSystemColor(id);
- }
- }
-
TCFModel(TCFLaunch launch) {
- assert display != null;
this.launch = launch;
+ display = Display.getDefault();
selection_policy = new TCFModelSelectionPolicy(this);
commands.put(ISuspendHandler.class, new SuspendCommand(this));
commands.put(IResumeHandler.class, new ResumeCommand(this));
@@ -414,7 +398,7 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
assert id2node.size() == 0;
}
- void onProcessOutput(String process_id, int stream_id, byte[] data) {
+ void onProcessOutput(String process_id, final int stream_id, byte[] data) {
try {
IProcesses.ProcessContext prs = launch.getProcessContext();
if (prs == null || !process_id.equals(prs.getID())) return;
@@ -427,9 +411,17 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
if (console == null) {
final MessageConsole c = console = new MessageConsole("TCF " + process_id,
ImageCache.getImageDescriptor(ImageCache.IMG_TCF));
+ final MessageConsoleStream s = stream = console.newMessageStream();
display.asyncExec(new Runnable() {
public void run() {
try {
+ int color_id = SWT.COLOR_BLACK;
+ switch (stream_id) {
+ case 1: color_id = SWT.COLOR_RED; break;
+ case 2: color_id = SWT.COLOR_BLUE; break;
+ case 3: color_id = SWT.COLOR_GREEN; break;
+ }
+ s.setColor(display.getSystemColor(color_id));
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
manager.addConsoles(new IConsole[]{ c });
IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
@@ -445,9 +437,6 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
}
});
}
- stream = console.newMessageStream();
- stream.setColor(stream_id >= 0 && stream_id < console_colors.length ?
- console_colors[stream_id] : console_colors[0]);
streams.put(stream_id, stream);
}
stream.print(new String(data, 0, data.length, "UTF-8"));
@@ -891,17 +880,20 @@ public class TCFModel implements IElementContentProvider, IElementLabelProvider,
private void refreshLaunchView() {
final Throwable error = launch.getError();
if (error != null) launch.setError(null);
- display.asyncExec(new Runnable() {
- public void run() {
- IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
- if (windows == null) return;
- for (IWorkbenchWindow window : windows) {
- IDebugView view = (IDebugView)window.getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
- if (view != null) ((StructuredViewer)view.getViewer()).refresh(launch);
+ synchronized (Device.class) {
+ if (display.isDisposed()) return;
+ display.asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ if (windows == null) return;
+ for (IWorkbenchWindow window : windows) {
+ IDebugView view = (IDebugView)window.getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW);
+ if (view != null) ((StructuredViewer)view.getViewer()).refresh(launch);
+ }
}
- }
- });
- if (error != null) showMessageBox("TCF Launch Error", error);
+ });
+ if (error != null) showMessageBox("TCF Launch Error", error);
+ }
}
/*
diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModelManager.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModelManager.java
index 9de7a9fb0..492f60801 100644
--- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModelManager.java
+++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/model/TCFModelManager.java
@@ -17,7 +17,6 @@ import java.util.Map;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchesListener;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.tm.internal.tcf.debug.model.TCFLaunch;
import org.eclipse.tm.tcf.protocol.Protocol;
@@ -27,28 +26,40 @@ public class TCFModelManager {
private final Map<TCFLaunch,TCFModel> models = new HashMap<TCFLaunch,TCFModel>();
private final TCFLaunch.Listener tcf_launch_listener = new TCFLaunch.Listener() {
+
+ public void onCreated(TCFLaunch launch) {
+ assert Protocol.isDispatchThread();
+ assert models.get(launch) == null;
+ TCFModel model = new TCFModel(launch);
+ models.put(launch, model);
+ }
public void onConnected(TCFLaunch launch) {
+ assert Protocol.isDispatchThread();
TCFModel model = models.get(launch);
if (model != null) model.onConnected();
}
public void onDisconnected(TCFLaunch launch) {
+ assert Protocol.isDispatchThread();
TCFModel model = models.get(launch);
if (model != null) model.onDisconnected();
}
public void onContextActionsDone(TCFLaunch launch) {
+ assert Protocol.isDispatchThread();
TCFModel model = models.get(launch);
if (model != null) model.onContextActionsDone();
}
public void onContextActionsStart(TCFLaunch launch) {
+ assert Protocol.isDispatchThread();
TCFModel model = models.get(launch);
if (model != null) model.onContextActionsStart();
}
public void onProcessOutput(TCFLaunch launch, String process_id, int stream_id, byte[] data) {
+ assert Protocol.isDispatchThread();
TCFModel model = models.get(launch);
if (model != null) model.onProcessOutput(process_id, stream_id, data);
}
@@ -56,31 +67,7 @@ public class TCFModelManager {
private final ILaunchesListener debug_launch_listener = new ILaunchesListener() {
- boolean init_done;
-
public void launchesAdded(final ILaunch[] launches) {
- if (!init_done) {
- final Display display = Display.getDefault();
- display.syncExec(new Runnable() {
- public void run() {
- TCFModel.setDisplay(display);
- }
- });
- init_done = true;
- }
- Protocol.invokeAndWait(new Runnable() {
- public void run() {
- for (int i = 0; i < launches.length; i++) {
- if (launches[i] instanceof TCFLaunch) {
- TCFLaunch launch = (TCFLaunch)launches[i];
- assert models.get(launch) == null;
- TCFModel model = new TCFModel(launch);
- models.put(launch, model);
- assert launch.getChannel() == null;
- }
- }
- }
- });
}
public void launchesChanged(final ILaunch[] launches) {
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/launch/TCFLaunchDelegate.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/launch/TCFLaunchDelegate.java
index 431550b6b..14a52e379 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/launch/TCFLaunchDelegate.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/launch/TCFLaunchDelegate.java
@@ -18,6 +18,7 @@ import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.tm.internal.tcf.debug.model.ITCFConstants;
import org.eclipse.tm.internal.tcf.debug.model.TCFLaunch;
import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.tcf.util.TCFTask;
public class TCFLaunchDelegate extends LaunchConfigurationDelegate {
@@ -32,8 +33,17 @@ public class TCFLaunchDelegate extends LaunchConfigurationDelegate {
ATTR_WORKING_DIRECTORY = ITCFConstants.ID_TCF_DEBUG_MODEL + ".WorkingDirectory",
ATTR_USE_TERMINAL = ITCFConstants.ID_TCF_DEBUG_MODEL + ".UseTerminal";
- public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
- return new TCFLaunch(configuration, mode);
+ public ILaunch getLaunch(final ILaunchConfiguration configuration, final String mode) throws CoreException {
+ return new TCFTask<ILaunch>() {
+ int cnt;
+ public void run() {
+ // Need to delay at least one dispatch cycle to work around
+ // a possible racing between thread that calls getLaunch() and
+ // the process of activation of other TCF plug-ins.
+ if (cnt++ < 2) Protocol.invokeLater(this);
+ else done(new TCFLaunch(configuration, mode));
+ }
+ }.getE();
}
public void launch(final ILaunchConfiguration configuration, final String mode,
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/model/TCFLaunch.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/model/TCFLaunch.java
index 0c0f94325..9190c1de2 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/model/TCFLaunch.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/model/TCFLaunch.java
@@ -52,6 +52,8 @@ import org.eclipse.tm.tcf.services.IProcesses.ProcessContext;
public class TCFLaunch extends Launch {
public interface Listener {
+
+ public void onCreated(TCFLaunch launch);
public void onConnected(TCFLaunch launch);
@@ -100,6 +102,7 @@ public class TCFLaunch extends Launch {
public TCFLaunch(ILaunchConfiguration launchConfiguration, String mode) {
super(launchConfiguration, mode, null);
+ for (Listener l : listeners) l.onCreated(TCFLaunch.this);
}
private void onConnected() {
@@ -118,7 +121,7 @@ public class TCFLaunch extends Launch {
for (Iterator<Listener> i = listeners.iterator(); i.hasNext();) {
i.next().onDisconnected(this);
}
- fireChanged();
+ if (DebugPlugin.getDefault() != null) fireChanged();
runShutdownSequence(new Runnable() {
public void run() {
shutdown = true;
@@ -429,6 +432,7 @@ public class TCFLaunch extends Launch {
}
private void disconnectStream(String id) {
+ if (channel.getState() != IChannel.STATE_OPEN) return;
IStreams streams = getService(IStreams.class);
streams.disconnect(id, new IStreams.DoneDisconnect() {
public void doneDisconnect(IToken token, Exception error) {

Back to the top