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 / +4 lines)
Lines 34-40 Link Here
34
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
34
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
35
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
35
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
36
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
36
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
37
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess;
37
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess;
38
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
38
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
39
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
39
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
40
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
40
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
Lines 424-430 Link Here
424
							IProcess[] launchProcesses = launch.getProcesses();
424
							IProcess[] launchProcesses = launch.getProcesses();
425
							for (IProcess p : launchProcesses) {
425
							for (IProcess p : launchProcesses) {
426
								// We know there is only one inferior, so just find it.
426
								// We know there is only one inferior, so just find it.
427
								if ((p instanceof GDBProcess) == false) {
427
								if (p instanceof InferiorRuntimeProcess) {
428
									launch.removeProcess(p);
428
									launch.removeProcess(p);
429
									break;
429
									break;
430
								}
430
								}
Lines 432-442 Link Here
432
						}
432
						}
433
433
434
						// Add the inferior
434
						// Add the inferior
435
						IProcess process = DebugPlugin.newProcess(launch, inferior, label);
435
			            InferiorRuntimeProcess runtimeInferior = new InferiorRuntimeProcess(launch, inferior, label, null);
436
			            launch.addProcess(runtimeInferior);
436
437
437
						// Register as an IProcess so that the console is brought to the front
438
						// when the inferior is selected
439
						getSession().registerModelAdapter(IProcess.class, process);
440
						rm.done();
438
						rm.done();
441
					}
439
					}
442
				});
440
				});
(-)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 52-60 Link Here
52
 * @since 4.0
54
 * @since 4.0
53
 */
55
 */
54
public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence {
56
public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence {
55
	
57
		
56
	private static final String GROUP_ATTR = GdbPlugin.PLUGIN_ID + "groupId"; //$NON-NLS-1$
57
	
58
	private IGDBControl fCommandControl;
58
	private IGDBControl fCommandControl;
59
	private CommandFactory fCommandFactory;
59
	private CommandFactory fCommandFactory;
60
	private IGDBProcesses fProcService;
60
	private IGDBProcesses fProcService;
Lines 289-295 Link Here
289
							// For a restart, remove the old inferior
289
							// For a restart, remove the old inferior
290
							IProcess[] launchProcesses = launch.getProcesses();
290
							IProcess[] launchProcesses = launch.getProcesses();
291
							for (IProcess process : launchProcesses) {
291
							for (IProcess process : launchProcesses) {
292
								String groupAttribute = process.getAttribute(GROUP_ATTR);
292
								String groupAttribute = process.getAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR);
293
								if (groupId.equals(groupAttribute)) {
293
								if (groupId.equals(groupAttribute)) {
294
									launch.removeProcess(process);
294
									launch.removeProcess(process);
295
									// Use the exact same label as before
295
									// Use the exact same label as before
Lines 300-311 Link Here
300
						}
300
						}
301
301
302
						// Add the inferior
302
						// Add the inferior
303
						IProcess process = DebugPlugin.newProcess(launch, inferior, label);
303
			            InferiorRuntimeProcess runtimeInferior = new InferiorRuntimeProcess(launch, inferior, label, null);
304
						process.setAttribute(GROUP_ATTR, groupId);
304
			            runtimeInferior.setAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR, groupId);
305
						
305
			            launch.addProcess(runtimeInferior);
306
						// Register as an IProcess so that the console is brought to the front
306
307
						// when the inferior is selected
308
						session.registerModelAdapter(IProcess.class, process);
309
						rm.done();
307
						rm.done();
310
					}
308
					}
311
				});
309
				});
(-)src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsolePageParticipant.java (-3 / +106 lines)
Lines 10-21 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
Lines 24-34 Link Here
24
 * 
36
 * 
25
 * @since 2.1
37
 * @since 2.1
26
 */
38
 */
27
public class ConsolePageParticipant implements IConsolePageParticipant{
39
public class ConsolePageParticipant implements IConsolePageParticipant, IDebugContextListener {
28
	
40
	
41
    private IConsole fConsole;
42
    private IPageBookViewPage fPage;
43
    private IConsoleView fView;
44
29
	public void init(IPageBookViewPage page, IConsole console) {
45
	public void init(IPageBookViewPage page, IConsole console) {
30
		if(console instanceof TracingConsole || isConsoleGdbCli(console))
46
        fPage = page;
31
		{
47
        fConsole = console;
48
        fView = (IConsoleView)fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
49
50
        if (isConsoleInferior(console) || isConsoleGdbCli(console)) {
51
        	// This console participant will affect all consoles, even those not for DSF-GDB.
52
        	// Only consoles for GDBProcess or InferiorRuntimeProcess are what we care about for DSF-GDB 
53
        	DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this);
54
        }
55
56
		if(console instanceof TracingConsole || isConsoleGdbCli(console)) {
32
			TextConsole textConsole = (TextConsole) console;
57
			TextConsole textConsole = (TextConsole) console;
33
58
34
			// Add the save console action
59
			// Add the save console action
Lines 55-66 Link Here
55
		return false;
80
		return false;
56
	}
81
	}
57
82
83
	/**
84
	 * Checks if the the console is for an inferior.
85
	 * 
86
	 * @param console The console to check
87
	 * @return true if the the console is for an inferior
88
	 */
89
	private boolean isConsoleInferior(IConsole console) {
90
		if(console instanceof org.eclipse.debug.ui.console.IConsole) {
91
			org.eclipse.debug.ui.console.IConsole debugConsole  = (org.eclipse.debug.ui.console.IConsole)console;
92
			return (debugConsole.getProcess() instanceof InferiorRuntimeProcess);
93
		}
94
		return false;
95
	}
96
	
58
	@SuppressWarnings("rawtypes")
97
	@SuppressWarnings("rawtypes")
59
	public Object getAdapter(Class adapter) {
98
	public Object getAdapter(Class adapter) {
60
		return null;
99
		return null;
61
	}
100
	}
62
	
101
	
63
	public void dispose() {
102
	public void dispose() {
103
        if (isConsoleInferior(fConsole) || isConsoleGdbCli(fConsole)) {
104
			DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this);
105
		}
106
		fConsole = null;
64
	}
107
	}
65
108
66
	public void activated() {
109
	public void activated() {
Lines 69-72 Link Here
69
	public void deactivated() {
112
	public void deactivated() {
70
	}
113
	}
71
114
115
    protected IProcess getConsoleProcess() {
116
    	if (fConsole instanceof org.eclipse.debug.ui.console.IConsole) {
117
    		return ((org.eclipse.debug.ui.console.IConsole)fConsole).getProcess();
118
    	}
119
    	return null;
120
    }
121
    
122
	protected IProcess getCurrentProcess() {
123
		IAdaptable context = DebugUITools.getDebugContext();
124
		
125
		// If the launch is selected, we should choose the first inferior being debugged
126
        if (context instanceof ILaunch) {
127
        	ILaunch launch = (ILaunch)context;
128
        	for (IProcess process : launch.getProcesses()) {
129
        		if (process instanceof InferiorRuntimeProcess) {
130
        			return process;
131
        		}
132
        	}
133
        	
134
        	// No inferior?  return the gdb process
135
        	// We have to check that the process is actually from a DSF-GDB session,
136
        	// since the current context could be for any debug session
137
        	if (launch.getProcesses()[0] instanceof GDBProcess) {
138
        		return launch.getProcesses()[0];
139
        	}
140
        	
141
        	return null;
142
        }
143
144
		if (context != null) {
145
			// Look for the process that this context refers to, so we can select its console
146
			IDMContext dmc = (IDMContext)context.getAdapter(IDMContext.class);
147
			IMIContainerDMContext container = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class);
148
			if (container != null) {
149
				ILaunch launch = (ILaunch)context.getAdapter(ILaunch.class);
150
				if (launch != null) {
151
					for (IProcess process : launch.getProcesses()) {
152
						String groupId = process.getAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR);
153
						if (container.getGroupId().equals(groupId)) {
154
							return process;
155
						}
156
					}
157
				}
158
			}
159
		}
160
161
		return null;
162
	}
163
	
164
	/* (non-Javadoc)
165
	 * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener#contextEvent(org.eclipse.debug.internal.ui.contexts.provisional.DebugContextEvent)
166
	 */
167
	public void debugContextChanged(DebugContextEvent event) {
168
		if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
169
			IProcess consoleProcess = getConsoleProcess();
170
			if (fView != null && consoleProcess != null && consoleProcess.equals(getCurrentProcess())) {
171
	            fView.display(fConsole);
172
	        }
173
		}
174
	}
72
}
175
}

Return to bug 338136