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 361934 | Differences between
and this patch

Collapse All | Expand All

(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java (+38 lines)
Lines 9-14 Link Here
9
 *     Ericsson - initial API and implementation
9
 *     Ericsson - initial API and implementation
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
11
 *     Sergey Prigogin (Google)
11
 *     Sergey Prigogin (Google)
12
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
14
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
14
15
Lines 189-194 Link Here
189
		// Need to set layout again.
190
		// Need to set layout again.
190
		group2.setLayout(groupLayout);
191
		group2.setLayout(groupLayout);
191
192
193
		final Group groupTimeOut= new Group(parent, SWT.NONE);
194
		groupTimeOut.setText(MessagesForPreferences.GdbDebugPreferencePage_timeout_group_label);
195
		groupLayout= new GridLayout(3, false);
196
		groupTimeOut.setLayout(groupLayout);
197
		groupTimeOut.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
198
199
		final ListenableBooleanFieldEditor enableGdbTimeoutField = new ListenableBooleanFieldEditor(
200
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_ENABLE,
201
				MessagesForPreferences.GdbDebugPreferencePage_enableTimeout_label,
202
				SWT.NONE, groupTimeOut);
203
204
		enableGdbTimeoutField.fillIntoGrid(groupTimeOut, 3);
205
		addField(enableGdbTimeoutField);
206
207
		final IntegerFieldEditor timeoutField = new IntegerFieldEditor(
208
				IGdbDebugPreferenceConstants.PREF_DEFAULT_COMMAND_TIMEOUT_S,
209
				MessagesForPreferences.GdbDebugPreferencePage_timeout_label,
210
				groupTimeOut);
211
212
		// Instead of using Integer.MAX_VALUE which is some obscure number,
213
		// using 100000 sec is nice and readable.
214
		timeoutField.setValidRange(1, 100000);
215
216
		timeoutField.fillIntoGrid(groupTimeOut, 3);
217
		addField(timeoutField);
218
219
		enableGdbTimeoutField.getChangeControl(groupTimeOut).addSelectionListener(new SelectionAdapter() {
220
			@Override
221
			public void widgetSelected(SelectionEvent e) {
222
				boolean enabled = enableGdbTimeoutField.getBooleanValue();
223
				timeoutField.setEnabled(enabled, groupTimeOut);
224
			}
225
		});
226
227
		// Need to set layout again.
228
		groupTimeOut.setLayout(groupLayout);
229
192
		Group group= new Group(parent, SWT.NONE);
230
		Group group= new Group(parent, SWT.NONE);
193
		group.setText(MessagesForPreferences.GdbDebugPreferencePage_termination_label);
231
		group.setText(MessagesForPreferences.GdbDebugPreferencePage_termination_label);
194
		groupLayout= new GridLayout(3, false);
232
		groupLayout= new GridLayout(3, false);
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java (+7 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Ericsson - initial API and implementation
9
 *     Ericsson - initial API and implementation
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
11
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
13
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
13
14
Lines 36-41 Link Here
36
	public static String GdbDebugPreferencePage_initialChildCountLimitForCollections_label;
37
	public static String GdbDebugPreferencePage_initialChildCountLimitForCollections_label;
37
	/** @since 2.2 */
38
	/** @since 2.2 */
38
	public static String GdbDebugPreferencePage_defaults_label;
39
	public static String GdbDebugPreferencePage_defaults_label;
40
	/** @since 2.3 */
41
	public static String GdbDebugPreferencePage_timeout_label;
42
	/** @since 2.3 */
43
	public static String GdbDebugPreferencePage_timeout_group_label;
44
	/** @since 2.3 */
45
	public static String GdbDebugPreferencePage_enableTimeout_label;
39
	static {
46
	static {
40
		// initialize resource bundle
47
		// initialize resource bundle
41
		NLS.initializeMessages(MessagesForPreferences.class.getName(), MessagesForPreferences.class);
48
		NLS.initializeMessages(MessagesForPreferences.class.getName(), MessagesForPreferences.class);
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties (+4 lines)
Lines 27-29 Link Here
27
GdbDebugPreferencePage_initialChildCountLimitForCollections_label=For collections, initially limit child count to
27
GdbDebugPreferencePage_initialChildCountLimitForCollections_label=For collections, initially limit child count to
28
28
29
GdbDebugPreferencePage_defaults_label=Debug Configurations Defaults
29
GdbDebugPreferencePage_defaults_label=Debug Configurations Defaults
30
31
GdbDebugPreferencePage_timeout_group_label=Timeout for gdb commands
32
GdbDebugPreferencePage_timeout_label=Timeout (in seconds)
33
GdbDebugPreferencePage_enableTimeout_label=Enable timeout
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java (-3 / +19 lines)
Lines 9-14 Link Here
9
 *     Ericsson - initial implementation
9
 *     Ericsson - initial implementation
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
11
 *     Sergey Prigogin (Google)
11
 *     Sergey Prigogin (Google)
12
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.cdt.dsf.gdb;
14
package org.eclipse.cdt.dsf.gdb;
14
15
Lines 20-25 Link Here
20
 */
21
 */
21
public interface IGdbDebugPreferenceConstants {
22
public interface IGdbDebugPreferenceConstants {
22
	
23
	
24
	/**
25
     * Help prefixes.
26
     * This should be used for the preference names as well, though it wasn't used from the start.
27
     * We can't change existing ones for backward compatibility, 
28
     * but all new preferences should use {@link #PREFIX}
29
     */
30
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
31
23
	/**
32
	/**
24
	 * Boolean preference whether to enable GDB traces. Default is <code>true</code>. 
33
	 * Boolean preference whether to enable GDB traces. Default is <code>true</code>. 
25
	 */
34
	 */
Lines 86-94 Link Here
86
	 */
95
	 */
87
	public static final String PREF_DEFAULT_NON_STOP = "defaultNonStop"; //$NON-NLS-1$
96
	public static final String PREF_DEFAULT_NON_STOP = "defaultNonStop"; //$NON-NLS-1$
88
97
89
	/**
98
    /**
90
     * Help prefixes.
99
     * Enable timeout for gdb commands.
100
     * @since 4.1
91
     */
101
     */
92
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
102
	public static final String PREF_COMMAND_TIMEOUT_ENABLE = PREFIX + "commandTimeoutEnable"; //$NON-NLS-1$
103
104
	/**
105
	 * Default timeout for gdb commands in seconds.
106
	 * @since 4.1
107
	 */
108
	public static final String PREF_DEFAULT_COMMAND_TIMEOUT_S = PREFIX + "defaultCommandTimeout"; //$NON-NLS-1$
93
}
109
}
94
110
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java (+3 lines)
Lines 10-15 Link Here
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
10
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
11
 *     Sergey Prigogin (Google)
11
 *     Sergey Prigogin (Google)
12
 *     Marc Khouzam (Ericsson) - Move to org.eclipse.cdt.dsf.gdb from UI plugin (bug 348159)
12
 *     Marc Khouzam (Ericsson) - Move to org.eclipse.cdt.dsf.gdb from UI plugin (bug 348159)
13
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.cdt.dsf.gdb.internal;
15
package org.eclipse.cdt.dsf.gdb.internal;
15
16
Lines 38-42 Link Here
38
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT);
39
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT);
39
		node.put(IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT);
40
		node.put(IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT);
40
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP, IGDBLaunchConfigurationConstants.DEBUGGER_NON_STOP_DEFAULT);
41
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP, IGDBLaunchConfigurationConstants.DEBUGGER_NON_STOP_DEFAULT);
42
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_ENABLE, true);
43
		node.putInt(IGdbDebugPreferenceConstants.PREF_DEFAULT_COMMAND_TIMEOUT_S, 30);
41
	}
44
	}
42
}
45
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java (+32 lines)
Lines 11-16 Link Here
11
 *     IBM Corporation 
11
 *     IBM Corporation 
12
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
12
 *     Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121)
13
 *     Sergey Prigogin (Google)
13
 *     Sergey Prigogin (Google)
14
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.cdt.dsf.gdb.launching;
16
package org.eclipse.cdt.dsf.gdb.launching;
16
17
Lines 28-33 Link Here
28
import org.eclipse.cdt.dsf.datamodel.DataModelInitializedEvent;
29
import org.eclipse.cdt.dsf.datamodel.DataModelInitializedEvent;
29
import org.eclipse.cdt.dsf.datamodel.IDMContext;
30
import org.eclipse.cdt.dsf.datamodel.IDMContext;
30
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
31
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
32
import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
31
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
33
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
32
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
34
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
33
import org.eclipse.cdt.dsf.gdb.actions.IConnect;
35
import org.eclipse.cdt.dsf.gdb.actions.IConnect;
Lines 38-43 Link Here
38
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
40
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
39
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
41
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
40
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
42
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
43
import org.eclipse.cdt.dsf.mi.service.command.TimeOutCommandListener;
41
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
44
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
42
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
45
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
43
import org.eclipse.cdt.dsf.service.DsfSession;
46
import org.eclipse.cdt.dsf.service.DsfSession;
Lines 59-64 Link Here
59
62
60
	private DsfServicesTracker fTracker;
63
	private DsfServicesTracker fTracker;
61
	private DsfSession fSession;
64
	private DsfSession fSession;
65
	private ICommandListener fCommandListener;
62
66
63
	/**
67
	/**
64
	 * @since 4.0
68
	 * @since 4.0
Lines 75-80 Link Here
75
			return new String[] {
79
			return new String[] {
76
					"stepInitializeFinalLaunchSequence",   //$NON-NLS-1$
80
					"stepInitializeFinalLaunchSequence",   //$NON-NLS-1$
77
					// Global GDB settings
81
					// Global GDB settings
82
					"stepSetCommandTimeout",   //$NON-NLS-1$
78
					"stepSetEnvironmentDirectory",   //$NON-NLS-1$
83
					"stepSetEnvironmentDirectory",   //$NON-NLS-1$
79
					"stepSetBreakpointPending",    //$NON-NLS-1$
84
					"stepSetBreakpointPending",    //$NON-NLS-1$
80
					"stepEnablePrettyPrinting",    //$NON-NLS-1$
85
					"stepEnablePrettyPrinting",    //$NON-NLS-1$
Lines 151-156 Link Here
151
	}
156
	}
152
157
153
	/**
158
	/**
159
	 * Sets gdb command timeout if the {@link IGdbDebugPreferenceConstants#PREF_COMMAND_TIMEOUT_ENABLE} is enabled.
160
	 * @since 4.1
161
	 */
162
	@Execute
163
	public void stepSetCommandTimeout(RequestMonitor requestMonitor) {
164
		if (Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID,
165
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_ENABLE, true, null)) {
166
			fCommandListener = new TimeOutCommandListener(fCommandControl, requestMonitor);
167
			fCommandControl.addCommandListener(fCommandListener);
168
		}
169
		requestMonitor.done();
170
	}
171
172
	/**
173
	 * Removes the timeout listener.
174
	 * @since 4.1
175
	 */
176
	@RollBack("stepSetCommandTimeout")
177
	public void rollBackSetCommandTimeout(RequestMonitor requestMonitor) {
178
		if (fCommandListener != null) {
179
			fCommandControl.removeCommandListener(fCommandListener);
180
			fCommandListener = null;
181
		}
182
		requestMonitor.done();
183
	}
184
185
	/**
154
	 * Specify GDB's working directory. 
186
	 * Specify GDB's working directory. 
155
	 * @since 4.0 
187
	 * @since 4.0 
156
	 */
188
	 */
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java (-1 / +8 lines)
Lines 10-15 Link Here
10
 *     Ericsson 		  - Modified for handling of multiple stacks and threads
10
 *     Ericsson 		  - Modified for handling of multiple stacks and threads
11
 *     Nokia - create and use backend service.
11
 *     Nokia - create and use backend service.
12
 *     Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306)
12
 *     Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306)
13
 *     Mohamed Hussein (Mentor Graphics) - Add timeout for gdb commands (Bug 361934)
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.cdt.dsf.mi.service.command;
15
package org.eclipse.cdt.dsf.mi.service.command;
15
16
Lines 72-77 Link Here
72
public abstract class AbstractMIControl extends AbstractDsfService
73
public abstract class AbstractMIControl extends AbstractDsfService
73
    implements IMICommandControl
74
    implements IMICommandControl
74
{
75
{
76
	/**
77
	 * Maximum number of gdb commands allowed to be on the wire at the same time.
78
	 * @since 4.1
79
	 */
80
	protected static final int NUM_OF_PARALLEL_COMMANDS = 3;
81
75
	private static final String MI_TRACE_IDENTIFIER = " [MI]  "; //$NON-NLS-1$
82
	private static final String MI_TRACE_IDENTIFIER = " [MI]  "; //$NON-NLS-1$
76
	
83
	
77
    /*
84
    /*
Lines 319-325 Link Here
319
        	fCommandQueue.add(handle);
326
        	fCommandQueue.add(handle);
320
            processCommandQueued(handle);
327
            processCommandQueued(handle);
321
            
328
            
322
            if (fRxCommands.size() < 3) {
329
            if (fRxCommands.size() < NUM_OF_PARALLEL_COMMANDS) {
323
                // In a separate dispatch cycle.  This allows command listeners 
330
                // In a separate dispatch cycle.  This allows command listeners 
324
            	// to respond to the command queued event.  
331
            	// to respond to the command queued event.  
325
                getExecutor().execute(new DsfRunnable() {
332
                getExecutor().execute(new DsfRunnable() {
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/TimeOutCommandListener.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 Mentor Graphics 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
 * Mentor Graphics - Initial API and implementation (Bug 361934)
10
 *******************************************************************************/
11
package org.eclipse.cdt.dsf.mi.service.command;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.concurrent.Callable;
16
import java.util.concurrent.Executors;
17
import java.util.concurrent.ScheduledExecutorService;
18
import java.util.concurrent.ScheduledFuture;
19
import java.util.concurrent.TimeUnit;
20
21
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
22
import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
23
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
24
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
25
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
26
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
27
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
28
import org.eclipse.core.runtime.Platform;
29
30
/**
31
 * A Timeout command listener that will shutdown the gdb connection if any of the gdb commands timed out.
32
 * @see IGdbDebugPreferenceConstants#PREF_DEFAULT_COMMAND_TIMEOUT_S 
33
 * @since 4.1
34
 */
35
public class TimeOutCommandListener implements ICommandListener {
36
	private final IGDBControl connectionControl;
37
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(AbstractMIControl.NUM_OF_PARALLEL_COMMANDS); 
38
	private final Map<ICommandToken, ScheduledFuture<?>> commands = new HashMap<ICommandToken, ScheduledFuture<?>>(AbstractMIControl.NUM_OF_PARALLEL_COMMANDS);
39
	private final int timeout;
40
	private final RequestMonitor rm;
41
42
	public TimeOutCommandListener(IGDBControl igdbControl, RequestMonitor rm) {
43
		this.connectionControl = igdbControl;
44
		this.rm = rm;
45
		timeout  = Platform.getPreferencesService().getInt(GdbPlugin.PLUGIN_ID, IGdbDebugPreferenceConstants.PREF_DEFAULT_COMMAND_TIMEOUT_S, 30, null);
46
	}
47
	@Override
48
	public void commandQueued(ICommandToken token) {}
49
	@Override
50
	public void commandRemoved(ICommandToken token) {}
51
52
	/**
53
	 * Start timeout check for the sent command.
54
	 */
55
	@Override
56
	public void commandSent(final ICommandToken token) {
57
		ScheduledFuture<?> task = scheduler.schedule(new Callable<Object>() {
58
			@Override
59
			public Object call() {
60
				connectionControl.shutdown(rm);
61
				return null;
62
			}
63
		}, timeout, TimeUnit.SECONDS);
64
		commands.put(token, task);
65
	}
66
67
	/**
68
	 * Cancels timeout check for the command after its result is returned.
69
	 */
70
	@Override
71
	public void commandDone(ICommandToken token, ICommandResult result) {
72
		if (commands.containsKey(token)) {
73
			ScheduledFuture<?> task = commands.remove(token);
74
			task.cancel(true);
75
		}
76
	}
77
}

Return to bug 361934