Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 338136 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/dsf/gdb/IGdbDebugConstants.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Ericsson and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Ericsson - initial implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.dsf.gdb;
12
13
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
14
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
15
16
17
18
/**
19
 * @noimplement This interface is not intended to be implemented by clients.
20
 * @since 4.0
21
 */
22
public interface IGdbDebugConstants {
23
	
24
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
25
26
    /**
27
     * Attribute key to be added to the IProcess associated with an IMIContainerDMContext.
28
     * The value should be the groupId as returned by {@link IMIContainerDMContext#getGroupId()}
29
     */
30
    public static final String INFERIOR_GROUPID_ATTR = PREFIX + "inferiorGroupId"; //$NON-NLS-1$
31
32
33
}
34
(-)src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java (-13 lines)
Lines 52-58 Link Here
52
import org.eclipse.debug.core.ILaunchConfiguration;
52
import org.eclipse.debug.core.ILaunchConfiguration;
53
import org.eclipse.debug.core.model.IDisconnect;
53
import org.eclipse.debug.core.model.IDisconnect;
54
import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
54
import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
55
import org.eclipse.debug.core.model.IProcess;
56
import org.eclipse.debug.core.model.ISourceLocator;
55
import org.eclipse.debug.core.model.ISourceLocator;
57
import org.eclipse.debug.core.model.ITerminate;
56
import org.eclipse.debug.core.model.ITerminate;
58
57
Lines 171-188 Link Here
171
170
172
            GDBProcess gdbProcess = new GDBProcess(this, cliProc, label, null);
171
            GDBProcess gdbProcess = new GDBProcess(this, cliProc, label, null);
173
            addProcess(gdbProcess);
172
            addProcess(gdbProcess);
174
            
175
            Object existingAdapter = getSession().getModelAdapter(IProcess.class);
176
            if (existingAdapter == null) {
177
            	// Register the model adapter to the gdbProcess only if there is no other one
178
            	// registered already; if there is already one, it is from our inferior process
179
            	// and it takes precedence because we want the inferior console to show
180
            	// when we select a debug context of this debug session.
181
            	// If the inferior process is added later, it will properly overwrite this model adapter.
182
            	// Note that we don't always have an inferior console, so it is important to register
183
            	// this adapter for those cases.
184
                getSession().registerModelAdapter(IProcess.class, gdbProcess);
185
            }
186
        } catch (InterruptedException e) {
173
        } catch (InterruptedException e) {
187
            throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$
174
            throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$
188
        } catch (ExecutionException e) {
175
        } catch (ExecutionException e) {
(-)src/org/eclipse/cdt/dsf/gdb/launching/InferiorRuntimeProcess.java (+30 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Ericsson and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * 	Ericsson - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.dsf.gdb.launching;
12
13
import java.util.Map;
14
15
import org.eclipse.debug.core.ILaunch;
16
import org.eclipse.debug.core.model.RuntimeProcess;
17
18
/**
19
 * A process for the inferior to know it belongs to a DSF-GDB session
20
 * 
21
 * @since 4.0
22
 */
23
public class InferiorRuntimeProcess extends RuntimeProcess {
24
25
	public InferiorRuntimeProcess(ILaunch launch, Process process, String name,
26
			Map<String, String> attributes) {
27
		super(launch, process, name, attributes);
28
	}
29
30
}
(-)src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses.java (-6 / +6 lines)
Lines 34-42 Link Here
34
import org.eclipse.cdt.dsf.debug.service.IRunControl.IStartedDMEvent;
34
import org.eclipse.cdt.dsf.debug.service.IRunControl.IStartedDMEvent;
35
import org.eclipse.cdt.dsf.debug.service.command.ICommand;
35
import org.eclipse.cdt.dsf.debug.service.command.ICommand;
36
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
36
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
37
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
37
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
38
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
38
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
39
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
39
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess;
40
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess;
40
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
41
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
41
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
42
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
42
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
43
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
Lines 463-469 Link Here
463
							IProcess[] launchProcesses = launch.getProcesses();
464
							IProcess[] launchProcesses = launch.getProcesses();
464
							for (IProcess p : launchProcesses) {
465
							for (IProcess p : launchProcesses) {
465
								// We know there is only one inferior, so just find it.
466
								// We know there is only one inferior, so just find it.
466
								if ((p instanceof GDBProcess) == false) {
467
								if (p instanceof InferiorRuntimeProcess) {
467
									launch.removeProcess(p);
468
									launch.removeProcess(p);
468
									break;
469
									break;
469
								}
470
								}
Lines 471-481 Link Here
471
						}
472
						}
472
473
473
						// Add the inferior
474
						// Add the inferior
474
						IProcess process = DebugPlugin.newProcess(launch, inferior, label);
475
						InferiorRuntimeProcess runtimeInferior = new InferiorRuntimeProcess(launch, inferior, label, null);
476
			            runtimeInferior.setAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR, MIProcesses.UNIQUE_GROUP_ID);
477
						launch.addProcess(runtimeInferior);
475
478
476
						// Register as an IProcess so that the console is brought to the front
477
						// when the inferior is selected
478
						getSession().registerModelAdapter(IProcess.class, process);
479
						rm.done();
479
						rm.done();
480
					}
480
					}
481
				});
481
				});
(-)src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java (-10 / +8 lines)
Lines 26-32 Link Here
26
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
26
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
27
import org.eclipse.cdt.dsf.debug.service.command.ICommand;
27
import org.eclipse.cdt.dsf.debug.service.command.ICommand;
28
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
28
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
29
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
29
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
30
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
31
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess;
30
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
32
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
31
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
33
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
32
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
34
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
Lines 53-61 Link Here
53
 * @since 4.0
55
 * @since 4.0
54
 */
56
 */
55
public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence {
57
public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence {
56
	
58
		
57
	private static final String GROUP_ATTR = GdbPlugin.PLUGIN_ID + "groupId"; //$NON-NLS-1$
58
	
59
	private IGDBControl fCommandControl;
59
	private IGDBControl fCommandControl;
60
	private CommandFactory fCommandFactory;
60
	private CommandFactory fCommandFactory;
61
	private IGDBProcesses fProcService;
61
	private IGDBProcesses fProcService;
Lines 290-296 Link Here
290
							// For a restart, remove the old inferior
290
							// For a restart, remove the old inferior
291
							IProcess[] launchProcesses = launch.getProcesses();
291
							IProcess[] launchProcesses = launch.getProcesses();
292
							for (IProcess process : launchProcesses) {
292
							for (IProcess process : launchProcesses) {
293
								String groupAttribute = process.getAttribute(GROUP_ATTR);
293
								String groupAttribute = process.getAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR);
294
								if (groupId.equals(groupAttribute)) {
294
								if (groupId.equals(groupAttribute)) {
295
									launch.removeProcess(process);
295
									launch.removeProcess(process);
296
									// Use the exact same label as before
296
									// Use the exact same label as before
Lines 301-312 Link Here
301
						}
301
						}
302
302
303
						// Add the inferior
303
						// Add the inferior
304
						IProcess process = DebugPlugin.newProcess(launch, inferior, label);
304
			            InferiorRuntimeProcess runtimeInferior = new InferiorRuntimeProcess(launch, inferior, label, null);
305
						process.setAttribute(GROUP_ATTR, groupId);
305
			            runtimeInferior.setAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR, groupId);
306
						
306
			            launch.addProcess(runtimeInferior);
307
						// Register as an IProcess so that the console is brought to the front
307
308
						// when the inferior is selected
309
						session.registerModelAdapter(IProcess.class, process);
310
						rm.done();
308
						rm.done();
311
					}
309
					}
312
				});
310
				});
(-)src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsolePageParticipant.java (-5 / +114 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 Marc-Andre Laperle and others.
2
 * Copyright (c) 2010, 2011 Marc-Andre Laperle and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-34 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
11
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
12
12
13
import org.eclipse.cdt.dsf.datamodel.DMContexts;
14
import org.eclipse.cdt.dsf.datamodel.IDMContext;
15
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
13
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess;
16
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess;
17
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess;
18
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.debug.core.ILaunch;
21
import org.eclipse.debug.core.model.IProcess;
22
import org.eclipse.debug.ui.DebugUITools;
23
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.debug.ui.contexts.IDebugContextListener;
14
import org.eclipse.jface.action.IToolBarManager;
25
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.action.Separator;
26
import org.eclipse.jface.action.Separator;
16
import org.eclipse.ui.console.IConsole;
27
import org.eclipse.ui.console.IConsole;
17
import org.eclipse.ui.console.IConsoleConstants;
28
import org.eclipse.ui.console.IConsoleConstants;
18
import org.eclipse.ui.console.IConsolePageParticipant;
29
import org.eclipse.ui.console.IConsolePageParticipant;
30
import org.eclipse.ui.console.IConsoleView;
19
import org.eclipse.ui.console.TextConsole;
31
import org.eclipse.ui.console.TextConsole;
20
import org.eclipse.ui.part.IPageBookViewPage;
32
import org.eclipse.ui.part.IPageBookViewPage;
21
33
22
/**
34
/**
23
 * A console page participant for both the gdb tracing console and the gdb CLI console
35
 * A console page participant for DSF-GDB.
36
 * It adds a save button to both the gdb tracing console and the gdb CLI console.
37
 * It also brings to the front the proper inferior console when a container is selected.
24
 * 
38
 * 
25
 * @since 2.1
39
 * @since 2.1
26
 */
40
 */
27
public class ConsolePageParticipant implements IConsolePageParticipant{
41
public class ConsolePageParticipant implements IConsolePageParticipant, IDebugContextListener {
28
	
42
	
43
    private IConsole fConsole;
44
    private IPageBookViewPage fPage;
45
    private IConsoleView fView;
46
29
	public void init(IPageBookViewPage page, IConsole console) {
47
	public void init(IPageBookViewPage page, IConsole console) {
30
		if(console instanceof TracingConsole || isConsoleGdbCli(console))
48
        fPage = page;
31
		{
49
        fConsole = console;
50
        fView = (IConsoleView)fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
51
52
        if (isConsoleInferior(console) || isConsoleGdbCli(console)) {
53
        	// This console participant will affect all consoles, even those not for DSF-GDB.
54
        	// Only consoles for GDBProcess or InferiorRuntimeProcess are what we care about for DSF-GDB 
55
        	DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this);
56
        }
57
58
		if(console instanceof TracingConsole || isConsoleGdbCli(console)) {
32
			TextConsole textConsole = (TextConsole) console;
59
			TextConsole textConsole = (TextConsole) console;
33
60
34
			// Add the save console action
61
			// Add the save console action
Lines 55-66 Link Here
55
		return false;
82
		return false;
56
	}
83
	}
57
84
85
	/**
86
	 * Checks if the the console is for an inferior.
87
	 * 
88
	 * @param console The console to check
89
	 * @return true if the the console is for an inferior
90
	 */
91
	private boolean isConsoleInferior(IConsole console) {
92
		if(console instanceof org.eclipse.debug.ui.console.IConsole) {
93
			org.eclipse.debug.ui.console.IConsole debugConsole  = (org.eclipse.debug.ui.console.IConsole)console;
94
			return (debugConsole.getProcess() instanceof InferiorRuntimeProcess);
95
		}
96
		return false;
97
	}
98
	
58
	@SuppressWarnings("rawtypes")
99
	@SuppressWarnings("rawtypes")
59
	public Object getAdapter(Class adapter) {
100
	public Object getAdapter(Class adapter) {
60
		return null;
101
		return null;
61
	}
102
	}
62
	
103
	
63
	public void dispose() {
104
	public void dispose() {
105
        if (isConsoleInferior(fConsole) || isConsoleGdbCli(fConsole)) {
106
			DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this);
107
		}
108
		fConsole = null;
64
	}
109
	}
65
110
66
	public void activated() {
111
	public void activated() {
Lines 69-72 Link Here
69
	public void deactivated() {
114
	public void deactivated() {
70
	}
115
	}
71
116
117
    protected IProcess getConsoleProcess() {
118
    	if (fConsole instanceof org.eclipse.debug.ui.console.IConsole) {
119
    		return ((org.eclipse.debug.ui.console.IConsole)fConsole).getProcess();
120
    	}
121
    	return null;
122
    }
123
    
124
	protected IProcess getCurrentProcess() {
125
		IAdaptable context = DebugUITools.getDebugContext();
126
		
127
		// If the launch is selected, we should choose the first inferior being debugged
128
        if (context instanceof ILaunch) {
129
        	ILaunch launch = (ILaunch)context;
130
        	
131
        	IProcess[] processes = launch.getProcesses();
132
        	if (processes != null && processes.length > 0) {
133
        		for (IProcess process : processes) {
134
        			if (process instanceof InferiorRuntimeProcess) {
135
        				return process;
136
        			}
137
        		}
138
139
        		// No inferior?  return the gdb process
140
        		// We have to check that the process is actually from a DSF-GDB session,
141
        		// since the current context could be for any debug session
142
        		if (processes[0] instanceof GDBProcess) {
143
        			return launch.getProcesses()[0];
144
        		}
145
        	}
146
        	
147
        	return null;
148
        }
149
150
		if (context != null) {
151
			// Look for the process that this context refers to, so we can select its console
152
			IDMContext dmc = (IDMContext)context.getAdapter(IDMContext.class);
153
			IMIContainerDMContext container = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class);
154
			if (container != null) {
155
				ILaunch launch = (ILaunch)context.getAdapter(ILaunch.class);
156
				if (launch != null) {
157
					for (IProcess process : launch.getProcesses()) {
158
						String groupId = process.getAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR);
159
						if (container.getGroupId().equals(groupId)) {
160
							return process;
161
						}
162
					}
163
				}
164
			}
165
		}
166
167
		return null;
168
	}
169
	
170
	/* (non-Javadoc)
171
	 * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener#contextEvent(org.eclipse.debug.internal.ui.contexts.provisional.DebugContextEvent)
172
	 */
173
	public void debugContextChanged(DebugContextEvent event) {
174
		if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
175
			IProcess consoleProcess = getConsoleProcess();
176
			if (fView != null && consoleProcess != null && consoleProcess.equals(getCurrentProcess())) {
177
	            fView.display(fConsole);
178
	        }
179
		}
180
	}
72
}
181
}

Return to bug 338136