1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Bug 264895: Allow the visible console to match the currently selected debug context for a DSF-GDB session.

This commit is contained in:
Marc Khouzam 2010-05-10 18:48:38 +00:00
parent d913b26d1f
commit 0be25d015f
2 changed files with 21 additions and 55 deletions

View file

@ -51,6 +51,7 @@ import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IDisconnect;
import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.ISourceLocator;
import org.eclipse.debug.core.model.ITerminate;
@ -153,7 +154,10 @@ public class GdbLaunch extends DsfLaunch
}
}).get();
DebugPlugin.newProcess(this, inferiorProc, label);
IProcess inferior = DebugPlugin.newProcess(this, inferiorProc, label);
// Register the model adapter so that the inferior console becomes visible
// when we select a debug context for this debug session.
getSession().registerModelAdapter(IProcess.class, inferior);
} catch (InterruptedException e) {
throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$
} catch (ExecutionException e) {
@ -180,6 +184,18 @@ public class GdbLaunch extends DsfLaunch
GDBProcess gdbProcess = new GDBProcess(this, cliProc, label, null);
addProcess(gdbProcess);
Object existingAdapter = getSession().getModelAdapter(IProcess.class);
if (existingAdapter == null) {
// Register the model adapter to the gdbProcess only if there is no other one
// registered already; if there is already one, it is from our inferior process
// and it takes precedence because we want the inferior console to show
// when we select a debug context of this debug session.
// If the inferior process is added later, it will properly overwrite this model adapter.
// Note that we don't always have an inferior console, so it is important to register
// this adapter for those cases.
getSession().registerModelAdapter(IProcess.class, gdbProcess);
}
} catch (InterruptedException e) {
throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$
} catch (ExecutionException e) {
@ -283,7 +299,7 @@ public class GdbLaunch extends DsfLaunch
fExecutor.execute(shutdownSeq);
}
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
// Must force adapters to be loaded.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems and others.
* Copyright (c) 2006, 2010 Wind River Systems 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
@ -11,17 +11,13 @@
package org.eclipse.cdt.dsf.debug.ui.viewmodel.launch;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMNode;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
@ -39,52 +35,6 @@ import org.eclipse.jface.viewers.TreePath;
@SuppressWarnings("restriction")
public class StandardProcessVMNode extends AbstractVMNode {
/**
* VMC element implementation, it is a proxy for the IProcess class, to
* allow the standard label adapter to be used with this object.
*/
private class VMC extends AbstractVMContext
implements IProcess
{
private final IProcess fProcess;
VMC(IProcess process) {
super(StandardProcessVMNode.this);
fProcess = process;
}
@Override
public IVMNode getVMNode() { return StandardProcessVMNode.this; }
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
Object vmcAdapter = super.getAdapter(adapter);
if (vmcAdapter != null) {
return vmcAdapter;
}
return fProcess.getAdapter(adapter);
}
@Override
public String toString() { return "IProcess " + fProcess.toString(); } //$NON-NLS-1$
public String getAttribute(String key) { return fProcess.getAttribute(key); }
public int getExitValue() throws DebugException { return fProcess.getExitValue(); }
public String getLabel() { return fProcess.getLabel(); }
public ILaunch getLaunch() { return fProcess.getLaunch(); }
public IStreamsProxy getStreamsProxy() { return fProcess.getStreamsProxy(); }
public void setAttribute(String key, String value) { fProcess.setAttribute(key, value); }
public boolean canTerminate() { return fProcess.canTerminate(); }
public boolean isTerminated() { return fProcess.isTerminated(); }
public void terminate() throws DebugException { fProcess.terminate(); }
@Override
public boolean equals(Object other) {
return other instanceof VMC && fProcess.equals(((VMC)other).fProcess);
}
@Override
public int hashCode() { return fProcess.hashCode(); }
}
public StandardProcessVMNode(AbstractVMProvider provider) {
super(provider);
}
@ -111,7 +61,7 @@ public class StandardProcessVMNode extends AbstractVMNode {
*/
IProcess[] processes = launch.getProcesses();
for (int i = 0; i < processes.length; i++) {
update.setChild(new VMC(processes[i]), i);
update.setChild(processes[i], i);
}
update.done();
}
@ -209,7 +159,7 @@ public class StandardProcessVMNode extends AbstractVMNode {
}
protected void handleChange(DebugEvent event, ModelDelta parent) {
parent.addNode(new VMC((IProcess)event.getSource()), IModelDelta.STATE);
parent.addNode(event.getSource(), IModelDelta.STATE);
}
protected void handleCreate(DebugEvent event, ModelDelta parent) {