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,
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.
106
	 * @since 4.1
107
	 */
108
	public static final String PREF_DEFAULT_COMMAND_TIMEOUT = 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, 30);
41
	}
44
	}
42
}
45
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java (-2 / +77 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 25-35 Link Here
25
import java.util.List;
26
import java.util.List;
26
import java.util.Map;
27
import java.util.Map;
27
import java.util.concurrent.BlockingQueue;
28
import java.util.concurrent.BlockingQueue;
29
import java.util.concurrent.Callable;
30
import java.util.concurrent.Executors;
28
import java.util.concurrent.LinkedBlockingQueue;
31
import java.util.concurrent.LinkedBlockingQueue;
29
import java.util.concurrent.RejectedExecutionException;
32
import java.util.concurrent.RejectedExecutionException;
33
import java.util.concurrent.ScheduledExecutorService;
34
import java.util.concurrent.ScheduledFuture;
35
import java.util.concurrent.TimeUnit;
30
36
31
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
37
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
32
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
38
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
39
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
33
import org.eclipse.cdt.dsf.datamodel.DMContexts;
40
import org.eclipse.cdt.dsf.datamodel.DMContexts;
34
import org.eclipse.cdt.dsf.datamodel.IDMContext;
41
import org.eclipse.cdt.dsf.datamodel.IDMContext;
35
import org.eclipse.cdt.dsf.debug.service.IRunControl;
42
import org.eclipse.cdt.dsf.debug.service.IRunControl;
Lines 39-44 Link Here
39
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
46
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
40
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
47
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
41
import org.eclipse.cdt.dsf.debug.service.command.IEventListener;
48
import org.eclipse.cdt.dsf.debug.service.command.IEventListener;
49
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
42
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
50
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
43
import org.eclipse.cdt.dsf.gdb.service.GDBBackend;
51
import org.eclipse.cdt.dsf.gdb.service.GDBBackend;
44
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
52
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
Lines 59-64 Link Here
59
import org.eclipse.cdt.dsf.service.AbstractDsfService;
67
import org.eclipse.cdt.dsf.service.AbstractDsfService;
60
import org.eclipse.cdt.dsf.service.DsfSession;
68
import org.eclipse.cdt.dsf.service.DsfSession;
61
import org.eclipse.core.runtime.IStatus;
69
import org.eclipse.core.runtime.IStatus;
70
import org.eclipse.core.runtime.Platform;
62
import org.eclipse.core.runtime.Status;
71
import org.eclipse.core.runtime.Status;
63
72
64
import com.ibm.icu.text.MessageFormat;
73
import com.ibm.icu.text.MessageFormat;
Lines 72-77 Link Here
72
public abstract class AbstractMIControl extends AbstractDsfService
81
public abstract class AbstractMIControl extends AbstractDsfService
73
    implements IMICommandControl
82
    implements IMICommandControl
74
{
83
{
84
	/**
85
	 * Maximum number of gdb commands allowed to be on the wire at the same time.
86
	 * @since 4.1
87
	 */
88
	protected static final int NUM_OF_PARALLEL_COMMANDS = 3;
89
75
	private static final String MI_TRACE_IDENTIFIER = " [MI]  "; //$NON-NLS-1$
90
	private static final String MI_TRACE_IDENTIFIER = " [MI]  "; //$NON-NLS-1$
76
	
91
	
77
    /*
92
    /*
Lines 160-166 Link Here
160
        fCommandFactory = factory;
175
        fCommandFactory = factory;
161
    }
176
    }
162
177
163
    /**
178
	@Override
179
	public void initialize(RequestMonitor rm) {
180
		super.initialize(rm);
181
        addTimeOutCommandListener(rm);
182
	}
183
184
	/**
185
	 * Adds a timeout listener for gdb commands if the preference requires it.
186
	 * @see IGdbDebugPreferenceConstants#PREF_COMMAND_TIMEOUT_ENABLE
187
	 * @since 4.1
188
	 */
189
	protected void addTimeOutCommandListener(final RequestMonitor requestMonitor) {
190
		if (Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID,
191
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_ENABLE, true, null)) {
192
			addCommandListener(new TimeOutCommandListener(requestMonitor));
193
		}
194
	}
195
196
	/**
197
	 * A Timeout command listener that will shutdown the gdb connection if any of the gdb commands timed out.
198
	 * @see IGdbDebugPreferenceConstants#PREF_DEFAULT_COMMAND_TIMEOUT 
199
	 * @author mhussein
200
	 */
201
	private class TimeOutCommandListener implements ICommandListener {
202
		private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(NUM_OF_PARALLEL_COMMANDS); 
203
204
		private Map<ICommandToken, ScheduledFuture<?>> commands = new HashMap<ICommandToken, ScheduledFuture<?>>(NUM_OF_PARALLEL_COMMANDS);
205
		private int timeout;
206
		private final RequestMonitor rm;
207
208
		public TimeOutCommandListener(RequestMonitor rm) {
209
			this.rm = rm;
210
			timeout  = Platform.getPreferencesService().getInt(GdbPlugin.PLUGIN_ID, IGdbDebugPreferenceConstants.PREF_DEFAULT_COMMAND_TIMEOUT, 30, null);
211
		}
212
		@Override
213
		public void commandQueued(ICommandToken token) {}
214
		@Override
215
		public void commandRemoved(ICommandToken token) {}
216
217
		@Override
218
		public void commandSent(final ICommandToken token) {
219
			ScheduledFuture<?> task = scheduler.schedule(new Callable<Object>() {
220
				@Override
221
				public Object call() {
222
					shutdown(rm);
223
					return null;
224
				}
225
			}, timeout, TimeUnit.SECONDS);
226
			commands.put(token, task);
227
		}
228
229
		@Override
230
		public void commandDone(ICommandToken token, ICommandResult result) {
231
			if (commands.containsKey(token)) {
232
				ScheduledFuture<?> task = commands.remove(token);
233
				task.cancel(true);
234
			}
235
		}
236
	}
237
238
	/**
164
     * Set the tracing stream for the MI communication.  If this method is never
239
     * Set the tracing stream for the MI communication.  If this method is never
165
     * called, tracing will be off, by default.
240
     * called, tracing will be off, by default.
166
     * 
241
     * 
Lines 319-325 Link Here
319
        	fCommandQueue.add(handle);
394
        	fCommandQueue.add(handle);
320
            processCommandQueued(handle);
395
            processCommandQueued(handle);
321
            
396
            
322
            if (fRxCommands.size() < 3) {
397
            if (fRxCommands.size() < NUM_OF_PARALLEL_COMMANDS) {
323
                // In a separate dispatch cycle.  This allows command listeners 
398
                // In a separate dispatch cycle.  This allows command listeners 
324
            	// to respond to the command queued event.  
399
            	// to respond to the command queued event.  
325
                getExecutor().execute(new DsfRunnable() {
400
                getExecutor().execute(new DsfRunnable() {

Return to bug 361934