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/plugin.xml (+9 lines)
Added Link Here
475
         </enablement>
475
         </enablement>
476
      </toggleTargetFactory>
476
      </toggleTargetFactory>
477
   </extension>
477
   </extension>
478
   <extension
479
         point="org.eclipse.debug.core.statusHandlers">
480
      <statusHandler
481
            class="org.eclipse.cdt.dsf.gdb.internal.ui.GdbStatusHandler"
482
            code="20001"
483
            id="org.eclipse.cdt.dsf.gdb.ui.statusHandler"
484
            plugin="org.eclipse.cdt.dsf.gdb">
485
      </statusHandler>
486
   </extension>
478
</plugin>
487
</plugin>
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbStatusHandler.java (+66 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.internal.ui;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.debug.core.IStatusHandler;
17
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Shell;
20
21
public class GdbStatusHandler implements IStatusHandler {
22
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
25
	 */
26
	@Override
27
	public Object handleStatus( final IStatus status, Object source ) throws CoreException {
28
		Runnable runnable = null;
29
		if ( status.getSeverity() == IStatus.ERROR ) {
30
			runnable = new Runnable() {
31
				
32
				@Override
33
				public void run() {
34
					Shell parent = GdbUIPlugin.getActiveWorkbenchShell();
35
					if ( parent != null )
36
						MessageDialog.openError( parent, Messages.GdbStatusHandler_Error, status.getMessage() );
37
				}
38
			};
39
		}
40
		else if ( status.getSeverity() == IStatus.WARNING ) {
41
			runnable = new Runnable() {
42
				
43
				@Override
44
				public void run() {
45
					Shell parent = GdbUIPlugin.getActiveWorkbenchShell();
46
					if ( parent != null )
47
						MessageDialog.openWarning( parent, Messages.GdbStatusHandler_Warning, status.getMessage() );
48
				}
49
			};
50
		}
51
		else if ( status.getSeverity() == IStatus.INFO ) {
52
			runnable = new Runnable() {
53
				
54
				@Override
55
				public void run() {
56
					Shell parent = GdbUIPlugin.getActiveWorkbenchShell();
57
					if ( parent != null )
58
						MessageDialog.openInformation( parent, Messages.GdbStatusHandler_Information, status.getMessage() );
59
				}
60
			};
61
		}
62
		if ( runnable != null )
63
			Display.getDefault().asyncExec( runnable );
64
		return null;
65
	}
66
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbUIPlugin.java (+31 lines)
Lines 22-27 Link Here
22
import org.eclipse.debug.core.ILaunch;
22
import org.eclipse.debug.core.ILaunch;
23
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.jface.dialogs.ErrorDialog;
24
import org.eclipse.jface.preference.IPreferenceStore;
24
import org.eclipse.jface.preference.IPreferenceStore;
25
import org.eclipse.jface.resource.ImageDescriptor;
26
import org.eclipse.jface.resource.ImageRegistry;
27
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.IWorkbenchPage;
29
import org.eclipse.ui.IWorkbenchPage;
27
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.IWorkbenchWindow;
Lines 227-230 Link Here
227
		}
230
		}
228
	}
231
	}
229
232
233
    /* (non-Javadoc)
234
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
235
	 */
236
	@Override
237
	protected void initializeImageRegistry( ImageRegistry reg ) {
238
		super.initializeImageRegistry( reg );
239
		declareImages( reg );
240
	}
241
242
	/**
243
     * Returns an image descriptor for the image file at the given
244
     * plug-in relative path
245
     *
246
     * @param path the path
247
     * @return the image descriptor
248
     */
249
    public static ImageDescriptor getImageDescriptor(String path) {
250
        return imageDescriptorFromPlugin(PLUGIN_ID, path);
251
    }
252
253
    public static Image getImage( String key ) {
254
    	return getDefault().getImageRegistry().get( key );
255
    }
256
257
    private void declareImages( ImageRegistry reg ) {
258
    	reg.put( IGdbUIConstants.IMG_WIZBAN_ADVANCED_TIMEOUT_SETTINGS, 
259
    			getImageDescriptor( "icons/full/wizban/advtosettings_wiz.png" ) ); //$NON-NLS-1$
260
    }
230
}
261
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/IGdbUIConstants.java (+28 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.internal.ui;
13
14
/**
15
 * @noimplement This interface is not intended to be implemented by clients.
16
 * 
17
 * @since 4.1
18
 */
19
public interface IGdbUIConstants {
20
21
	/**
22
	 * Plug-in identifier (value <code>"org.eclipse.cdt.dsf.gdb.ui"</code>).
23
	 */
24
	public static final String PLUGIN_ID = GdbUIPlugin.PLUGIN_ID; 
25
	
26
	/**  image identifier. */
27
	public static final String IMG_WIZBAN_ADVANCED_TIMEOUT_SETTINGS = PLUGIN_ID + ".imageAdvancedTimeoutSettings"; //$NON-NLS-1$
28
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/Messages.java (+31 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.internal.ui;
13
14
import org.eclipse.osgi.util.NLS;
15
16
public class Messages extends NLS {
17
	private static final String BUNDLE_NAME = "org.eclipse.cdt.dsf.gdb.internal.ui.Messages"; //$NON-NLS-1$
18
19
	public static String GdbStatusHandler_Error;
20
21
	public static String GdbStatusHandler_Information;
22
23
	public static String GdbStatusHandler_Warning;
24
	static {
25
		// initialize resource bundle
26
		NLS.initializeMessages( BUNDLE_NAME, Messages.class );
27
	}
28
29
	private Messages() {
30
	}
31
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/Messages.properties (+3 lines)
Added Link Here
1
GdbStatusHandler_Error=Error
2
GdbStatusHandler_Information=Information
3
GdbStatusHandler_Warning=Warning
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java (-10 / +515 lines)
Lines 13-37 Link Here
13
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
13
package org.eclipse.cdt.dsf.gdb.internal.ui.preferences;
14
14
15
import java.io.File;
15
import java.io.File;
16
import java.util.LinkedList;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Set;
16
20
21
import org.eclipse.cdt.dsf.debug.internal.ui.preferences.IntegerWithBooleanFieldEditor;
17
import org.eclipse.cdt.dsf.debug.internal.ui.preferences.StringWithBooleanFieldEditor;
22
import org.eclipse.cdt.dsf.debug.internal.ui.preferences.StringWithBooleanFieldEditor;
18
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
23
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
19
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
24
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
20
import org.eclipse.cdt.dsf.gdb.internal.ui.launching.LaunchUIMessages;
25
import org.eclipse.cdt.dsf.gdb.internal.ui.IGdbUIConstants;
26
import org.eclipse.cdt.dsf.gdb.service.command.CustomTimeoutsMap;
27
import org.eclipse.jface.dialogs.IDialogConstants;
28
import org.eclipse.jface.dialogs.TitleAreaDialog;
21
import org.eclipse.jface.preference.BooleanFieldEditor;
29
import org.eclipse.jface.preference.BooleanFieldEditor;
22
import org.eclipse.jface.preference.FieldEditorPreferencePage;
30
import org.eclipse.jface.preference.FieldEditorPreferencePage;
23
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.jface.preference.IPreferenceStore;
24
import org.eclipse.jface.preference.IntegerFieldEditor;
32
import org.eclipse.jface.preference.IntegerFieldEditor;
25
import org.eclipse.jface.preference.StringFieldEditor;
33
import org.eclipse.jface.preference.StringFieldEditor;
34
import org.eclipse.jface.resource.JFaceResources;
35
import org.eclipse.jface.util.PropertyChangeEvent;
36
import org.eclipse.jface.viewers.CellEditor;
37
import org.eclipse.jface.viewers.ColumnLabelProvider;
38
import org.eclipse.jface.viewers.ColumnViewer;
39
import org.eclipse.jface.viewers.DoubleClickEvent;
40
import org.eclipse.jface.viewers.EditingSupport;
41
import org.eclipse.jface.viewers.ICellEditorListener;
42
import org.eclipse.jface.viewers.ICellEditorValidator;
43
import org.eclipse.jface.viewers.IDoubleClickListener;
44
import org.eclipse.jface.viewers.ISelectionChangedListener;
45
import org.eclipse.jface.viewers.IStructuredContentProvider;
46
import org.eclipse.jface.viewers.IStructuredSelection;
47
import org.eclipse.jface.viewers.SelectionChangedEvent;
48
import org.eclipse.jface.viewers.StructuredSelection;
49
import org.eclipse.jface.viewers.TableViewer;
50
import org.eclipse.jface.viewers.TableViewerColumn;
51
import org.eclipse.jface.viewers.TextCellEditor;
52
import org.eclipse.jface.viewers.Viewer;
53
import org.eclipse.jface.window.Window;
26
import org.eclipse.swt.SWT;
54
import org.eclipse.swt.SWT;
55
import org.eclipse.swt.events.ControlAdapter;
56
import org.eclipse.swt.events.ControlEvent;
27
import org.eclipse.swt.events.SelectionAdapter;
57
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionEvent;
58
import org.eclipse.swt.events.SelectionEvent;
59
import org.eclipse.swt.graphics.Rectangle;
29
import org.eclipse.swt.layout.GridData;
60
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
61
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
62
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Composite;
63
import org.eclipse.swt.widgets.Composite;
64
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.FileDialog;
65
import org.eclipse.swt.widgets.FileDialog;
34
import org.eclipse.swt.widgets.Group;
66
import org.eclipse.swt.widgets.Group;
67
import org.eclipse.swt.widgets.Shell;
68
import org.eclipse.swt.widgets.Table;
69
import org.eclipse.swt.widgets.TableColumn;
35
import org.eclipse.ui.IWorkbench;
70
import org.eclipse.ui.IWorkbench;
36
import org.eclipse.ui.IWorkbenchPreferencePage;
71
import org.eclipse.ui.IWorkbenchPreferencePage;
37
import org.eclipse.ui.PlatformUI;
72
import org.eclipse.ui.PlatformUI;
Lines 41-46 Link Here
41
 */
76
 */
42
@SuppressWarnings("restriction")
77
@SuppressWarnings("restriction")
43
public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
78
public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
79
	
44
	/**
80
	/**
45
	 * A vehicle in order to be able to register a selection listener with
81
	 * A vehicle in order to be able to register a selection listener with
46
	 * a {@link BooleanFieldEditor}.
82
	 * a {@link BooleanFieldEditor}.
Lines 58-68 Link Here
58
		}
94
		}
59
	}
95
	}
60
96
97
	class AdvancedTimeoutSettingsDialog extends TitleAreaDialog {
98
99
		class CommandTimeoutEntry {
100
			
101
			String fCommand;
102
			Integer fTimeout;
103
			
104
			CommandTimeoutEntry( String command, Integer timeout ) {
105
				fCommand = command;
106
				fTimeout = timeout;
107
			}
108
		}
109
110
		class CellEditorListener implements ICellEditorListener {
111
			
112
			CellEditor fEditor;
113
			
114
			public CellEditorListener( CellEditor editor ) {
115
				super();
116
				fEditor = editor;
117
			}
118
119
			@Override
120
			public void editorValueChanged( boolean oldValidState, boolean newValidState ) {
121
				if ( newValidState ) {
122
					setErrorMessage( null );
123
				}
124
				else {
125
					setErrorMessage( fEditor.getErrorMessage() );
126
				}
127
				updateDialogButtons();
128
			}
129
			
130
			@Override
131
			public void cancelEditor() {
132
			}
133
			
134
			@Override
135
			public void applyEditorValue() {
136
				validate();
137
				updateDialogButtons();
138
			}
139
		};
140
		
141
		abstract class AbstractEditingSupport extends EditingSupport {
142
143
			public AbstractEditingSupport( ColumnViewer viewer ) {
144
				super( viewer );
145
			}
146
147
			@Override
148
			protected void setValue( Object element, Object value ) {
149
				if ( element instanceof CommandTimeoutEntry && value instanceof String ) {
150
					if ( processValue( (CommandTimeoutEntry)element, (String)value ) ) {
151
						fViewer.refresh( element );
152
						validate();
153
						updateDialogButtons();
154
					}
155
				}
156
			}
157
			
158
			@Override
159
			protected Object getValue( Object element ) {
160
				if ( element instanceof CommandTimeoutEntry ) {
161
					return doGetValue( (CommandTimeoutEntry)element );
162
				}
163
				return null;
164
			}
165
			
166
			@Override
167
			protected CellEditor getCellEditor( Object element ) {
168
				final CellEditor editor = new TextCellEditor( (Composite)getViewer().getControl() );
169
				editor.setValidator( getValidator() );
170
				editor.addListener( new CellEditorListener( editor ) );
171
				return editor;
172
			}
173
			
174
			@Override
175
			protected boolean canEdit( Object element ) {
176
				return ( element instanceof CommandTimeoutEntry );
177
			}
178
			
179
			abstract boolean processValue( CommandTimeoutEntry entry, String value );
180
181
			abstract Object doGetValue( CommandTimeoutEntry entry );
182
183
			abstract ICellEditorValidator getValidator();
184
		};
185
186
		private TableViewer fViewer;
187
		private Button fAddButton;
188
		private Button fDeleteButton;
189
		
190
		private List<CommandTimeoutEntry> fEntries;
191
		
192
		final private ICellEditorValidator fCommandValidator = new ICellEditorValidator() {
193
			
194
			@Override
195
			public String isValid( Object value ) {
196
				if ( value instanceof String && ((String)value).trim().length() == 0 ) {
197
					return MessagesForPreferences.GdbDebugPreferencePage_Command_field_can_not_be_empty;
198
				}
199
				return null;
200
			}
201
		};
202
203
		final private ICellEditorValidator fTimeoutValidator = new ICellEditorValidator() {
204
			
205
			@Override
206
			public String isValid( Object value ) {
207
				if ( value instanceof String ) {
208
					try {
209
						int intValue = Integer.decode( (String)value ).intValue();
210
						if ( intValue < 0 )
211
							return MessagesForPreferences.GdbDebugPreferencePage_Timeout_value_can_not_be_negative;
212
					}
213
					catch( NumberFormatException e ) {
214
						return MessagesForPreferences.GdbDebugPreferencePage_Invalid_timeout_value;
215
					}
216
				}
217
				return null;
218
			}
219
		};
220
221
		AdvancedTimeoutSettingsDialog( Shell parentShell, Set<Map.Entry<String, Integer>> entries ) {
222
			super( parentShell );
223
			setShellStyle(getShellStyle() | SWT.RESIZE);
224
			fEntries = new LinkedList<CommandTimeoutEntry>();
225
			for ( Map.Entry<String, Integer> entry : entries ) {
226
				fEntries.add( new CommandTimeoutEntry( entry.getKey(), entry.getValue() ) );
227
			}
228
		}
229
230
		/* (non-Javadoc)
231
		 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
232
		 */
233
		@Override
234
		protected Control createDialogArea( Composite parent ) {
235
			getShell().setText( MessagesForPreferences.GdbDebugPreferencePage_Anvanced_Timeout_Settings ); 
236
			setTitle( MessagesForPreferences.GdbDebugPreferencePage_Advanced_timeout_dialog_title ); 
237
			setTitleImage( GdbUIPlugin.getImage( IGdbUIConstants.IMG_WIZBAN_ADVANCED_TIMEOUT_SETTINGS ) );
238
			setMessage( MessagesForPreferences.GdbDebugPreferencePage_Advanced_timeout_dialog_message );
239
240
			Composite control = (Composite)super.createDialogArea( parent );
241
			Composite comp = new Composite( control, SWT.NONE );
242
			GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
243
			comp.setLayout( new GridLayout( 2, false ) );
244
			comp.setLayoutData( gd );
245
			
246
			fViewer = new TableViewer( comp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
247
			final Table table = fViewer.getTable();
248
			gd = new GridData( SWT.FILL, SWT.FILL, true, true );
249
			table.setLayoutData( gd );
250
251
			fViewer.addDoubleClickListener( new IDoubleClickListener() {
252
				@Override
253
				public void doubleClick( DoubleClickEvent event ) {
254
					okPressed();
255
				}
256
			} );
257
258
			fViewer.addSelectionChangedListener( new ISelectionChangedListener() {
259
				
260
				@Override
261
				public void selectionChanged( SelectionChangedEvent event ) {
262
					updateDialogButtons();
263
				}
264
			} );
265
266
			Composite btnComp = new Composite( comp, SWT.NONE );
267
			btnComp.setLayout( new GridLayout() );
268
			btnComp.setLayoutData( new GridData( SWT.RIGHT, SWT.TOP, false, false ) );
269
			
270
			fAddButton = new Button( btnComp, SWT.PUSH );
271
			fAddButton.setText( MessagesForPreferences.GdbDebugPreferencePage_Add_button );
272
			fAddButton.setFont( JFaceResources.getDialogFont() );
273
			setButtonLayoutData( fAddButton );
274
			fAddButton.addSelectionListener( new SelectionAdapter() {
275
276
				@Override
277
				public void widgetSelected( SelectionEvent e ) {
278
					addNewEntry();
279
				}
280
			} );
281
			
282
			fDeleteButton = new Button( btnComp, SWT.PUSH );
283
			fDeleteButton.setText( MessagesForPreferences.GdbDebugPreferencePage_Delete_button );
284
			fDeleteButton.setFont( JFaceResources.getDialogFont() );
285
			setButtonLayoutData( fDeleteButton );
286
			fDeleteButton.addSelectionListener( new SelectionAdapter() {
287
288
				@Override
289
				public void widgetSelected( SelectionEvent e ) {
290
					deleteEntries();
291
				}
292
			} );
293
294
			table.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
295
			table.setHeaderVisible( true );
296
			table.setLinesVisible( true );
297
			
298
			TableViewerColumn commandColumn = new TableViewerColumn( fViewer, SWT.LEFT );
299
			commandColumn.getColumn().setText( MessagesForPreferences.GdbDebugPreferencePage_Command_column_name );
300
			commandColumn.setLabelProvider( createCommandLabelProvider() );
301
			commandColumn.setEditingSupport( createCommandEditingSupport( fViewer ) );
302
303
			TableViewerColumn timeoutColumn = new TableViewerColumn( fViewer, SWT.LEFT );
304
			timeoutColumn.getColumn().setText( MessagesForPreferences.GdbDebugPreferencePage_Timeout_column_name );
305
			timeoutColumn.setLabelProvider( createTimeoutLabelProvider() );
306
			timeoutColumn.setEditingSupport( createTimeoutEditingSupport( fViewer ) );
307
308
			fViewer.setContentProvider( createCustomTimeoutsContentProvider() );
309
			
310
			table.addControlListener( new ControlAdapter() {
311
				
312
				@Override
313
				public void controlResized( ControlEvent e ) {
314
					Rectangle area = table.getClientArea();
315
					if ( area.width > 0 ) {
316
						TableColumn[] cols = table.getColumns();
317
						cols[0].setWidth( area.width * 50 / 100 );
318
						cols[1].setWidth( area.width * 50 / 100 );
319
						table.removeControlListener( this );
320
					}
321
				}
322
			} );
323
324
			fViewer.setInput( fEntries );
325
326
			updateDialogButtons();
327
328
			return control;
329
		}
330
331
		void updateDialogButtons() {
332
			if ( fViewer != null && fDeleteButton != null ) {
333
				fDeleteButton.setEnabled( !fViewer.getSelection().isEmpty() );
334
			}
335
			Button okButton = getButton( IDialogConstants.OK_ID );
336
			if ( okButton != null )
337
				okButton.setEnabled( getErrorMessage() == null );
338
		}
339
340
		void addNewEntry() {
341
			CommandTimeoutEntry newEntry = new CommandTimeoutEntry( "", Integer.valueOf( 0 ) ); //$NON-NLS-1$
342
			fEntries.add( newEntry );
343
			fViewer.refresh();
344
			fViewer.setSelection( new StructuredSelection( newEntry ) );
345
			validateEntry( newEntry );
346
			updateDialogButtons();
347
			fViewer.editElement( newEntry, 0 );
348
		}
349
350
		void deleteEntries() {
351
			IStructuredSelection sel = (IStructuredSelection)fViewer.getSelection();
352
			if ( !sel.isEmpty() )
353
				fEntries.removeAll( sel.toList() );
354
			fViewer.refresh();
355
			validate();
356
			updateDialogButtons();
357
		}
358
359
		CustomTimeoutsMap getResult() {
360
			CustomTimeoutsMap map = new CustomTimeoutsMap();
361
			for ( CommandTimeoutEntry entry : fEntries ) {
362
				map.put( entry.fCommand, entry.fTimeout );
363
			}
364
			return map;
365
		}
366
367
		void validate() {
368
			for ( CommandTimeoutEntry entry : fEntries ) {
369
				validateEntry( entry );
370
			}
371
		}
372
373
		void validateEntry( CommandTimeoutEntry entry ) {
374
			String errorMessage = fCommandValidator.isValid( entry.fCommand );
375
			setErrorMessage( ( errorMessage != null ) ? 
376
					errorMessage : fTimeoutValidator.isValid( entry.fTimeout.toString() ) );
377
		}
378
379
		IStructuredContentProvider createCustomTimeoutsContentProvider() {
380
			return new IStructuredContentProvider() {
381
				
382
				@Override
383
				public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) {
384
				}
385
				
386
				@Override
387
				public void dispose() {
388
				}
389
				
390
				@Override
391
				public Object[] getElements( Object inputElement ) {
392
					if ( inputElement instanceof List<?> ) {
393
						@SuppressWarnings( "unchecked" )
394
						List<CommandTimeoutEntry> list = (List<CommandTimeoutEntry>)inputElement;
395
						return list.toArray( new Object[list.size()] );
396
					}
397
					return null;
398
				}
399
			};
400
		}
401
402
		ColumnLabelProvider createCommandLabelProvider() {
403
			return new ColumnLabelProvider() {
404
405
				/* (non-Javadoc)
406
				 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
407
				 */
408
				@Override
409
				public String getText( Object element ) {
410
					if ( element instanceof CommandTimeoutEntry ) {
411
						return ((CommandTimeoutEntry)element).fCommand;
412
					}
413
					return super.getText( element );
414
				}
415
			};
416
		}
417
418
		ColumnLabelProvider createTimeoutLabelProvider() {
419
			return new ColumnLabelProvider() {
420
421
				/* (non-Javadoc)
422
				 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
423
				 */
424
				@Override
425
				public String getText( Object element ) {
426
					if ( element instanceof CommandTimeoutEntry ) {
427
						return ((CommandTimeoutEntry)element).fTimeout.toString();
428
					}
429
					return super.getText( element );
430
				}
431
			};
432
		}
433
434
		EditingSupport createCommandEditingSupport( ColumnViewer viewer ) {
435
			return new AbstractEditingSupport( viewer ) {
436
				
437
				@Override
438
				boolean processValue( CommandTimeoutEntry entry, String value ) {
439
					entry.fCommand = value;
440
					return true;
441
				}
442
443
				@Override
444
				Object doGetValue( CommandTimeoutEntry entry ) {
445
					return entry.fCommand;
446
				}
447
448
				@Override
449
				ICellEditorValidator getValidator() {
450
					return fCommandValidator;
451
				}
452
			};
453
		}
454
455
		EditingSupport createTimeoutEditingSupport( ColumnViewer viewer ) {
456
			return new AbstractEditingSupport( viewer ) {
457
458
				@Override
459
				boolean processValue( CommandTimeoutEntry entry, String value ) {
460
					try {
461
						entry.fTimeout = Integer.decode( value );
462
						return true;
463
					}
464
					catch( NumberFormatException e ) {
465
						// Shouldn't happen, validator takes care of this case.
466
					}
467
					return false;
468
				}
469
470
				@Override
471
				Object doGetValue( CommandTimeoutEntry entry ) {
472
					return entry.fTimeout.toString();
473
				}
474
475
				@Override
476
				ICellEditorValidator getValidator() {
477
					return fTimeoutValidator;
478
				}
479
			};
480
		}
481
	}
482
483
	private IntegerWithBooleanFieldEditor fCommandTimeoutField;
484
	private Button fTimeoutAdvancedButton;
485
486
	private CustomTimeoutsMap fCustomTimeouts;
487
	
61
	public GdbDebugPreferencePage() {
488
	public GdbDebugPreferencePage() {
62
		super(FLAT);
489
		super(FLAT);
63
		IPreferenceStore store= GdbUIPlugin.getDefault().getPreferenceStore();
490
		IPreferenceStore store= GdbUIPlugin.getDefault().getPreferenceStore();
64
		setPreferenceStore(store);
491
		setPreferenceStore(store);
65
		setDescription(MessagesForPreferences.GdbDebugPreferencePage_description);
492
		setDescription(MessagesForPreferences.GdbDebugPreferencePage_description);
493
		fCustomTimeouts = new CustomTimeoutsMap();
66
	}
494
	}
67
495
68
    @Override
496
    @Override
Lines 70-77 Link Here
70
	}
498
	}
71
499
72
	@Override
500
	@Override
501
	protected void initialize() {
502
		super.initialize();
503
		initializeCustomTimeouts();
504
	}
505
506
	@Override
73
	public void createControl(Composite parent) {
507
	public void createControl(Composite parent) {
74
		super.createControl(parent);
508
		super.createControl(parent);
509
		updateTimeoutButtons();
75
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
510
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
76
				GdbUIPlugin.PLUGIN_ID + ".dsfgdb_preference_page"); //$NON-NLS-1$
511
				GdbUIPlugin.PLUGIN_ID + ".dsfgdb_preference_page"); //$NON-NLS-1$
77
	}
512
	}
Lines 91-134 Link Here
91
526
92
		final StringFieldEditor stringFieldEditorCommand = new StringFieldEditor(
527
		final StringFieldEditor stringFieldEditorCommand = new StringFieldEditor(
93
				IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND,
528
				IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND,
94
				LaunchUIMessages.getString("GDBDebuggerPage.gdb_debugger"), //$NON-NLS-1$
529
				"GDB debugger:", //$NON-NLS-1$
95
				group1);
530
				group1);
96
531
97
		stringFieldEditorCommand.fillIntoGrid(group1, 2);
532
		stringFieldEditorCommand.fillIntoGrid(group1, 2);
98
		addField(stringFieldEditorCommand);
533
		addField(stringFieldEditorCommand);
99
		Button browsebutton = new Button(group1, SWT.PUSH);
534
		Button browsebutton = new Button(group1, SWT.PUSH);
100
		browsebutton.setText(LaunchUIMessages.getString("GDBDebuggerPage.gdb_browse")); //$NON-NLS-1$
535
		browsebutton.setText("&Browse..."); //$NON-NLS-1$
101
		browsebutton.addSelectionListener(new SelectionAdapter() {
536
		browsebutton.addSelectionListener(new SelectionAdapter() {
102
			@Override
537
			@Override
103
			public void widgetSelected(SelectionEvent e) {
538
			public void widgetSelected(SelectionEvent e) {
104
				handleBrowseButtonSelected(LaunchUIMessages.getString("GDBDebuggerPage.gdb_browse_dlg_title"),  //$NON-NLS-1$
539
				handleBrowseButtonSelected("GDB Debugger",  //$NON-NLS-1$
105
						stringFieldEditorCommand);
540
						stringFieldEditorCommand);
106
			}
541
			}
107
		});
542
		});
543
		setButtonLayoutData( browsebutton );
108
544
109
		final StringFieldEditor stringFieldEditorGdbInit = new StringFieldEditor(
545
		final StringFieldEditor stringFieldEditorGdbInit = new StringFieldEditor(
110
				IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_INIT,
546
				IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_INIT,
111
				LaunchUIMessages.getString("GDBDebuggerPage.gdb_command_file"), //$NON-NLS-1$
547
				"GDB command file:", //$NON-NLS-1$
112
				group1);
548
				group1);
113
549
114
		stringFieldEditorGdbInit.fillIntoGrid(group1, 2);
550
		stringFieldEditorGdbInit.fillIntoGrid(group1, 2);
115
		addField(stringFieldEditorGdbInit);
551
		addField(stringFieldEditorGdbInit);
116
		browsebutton = new Button(group1, SWT.PUSH);
552
		browsebutton = new Button(group1, SWT.PUSH);
117
		browsebutton.setText(LaunchUIMessages.getString("GDBDebuggerPage.gdb_browse")); //$NON-NLS-1$
553
		browsebutton.setText("&Browse..."); //$NON-NLS-1$
118
		browsebutton.addSelectionListener(new SelectionAdapter() {
554
		browsebutton.addSelectionListener(new SelectionAdapter() {
119
			@Override
555
			@Override
120
			public void widgetSelected(SelectionEvent e) {
556
			public void widgetSelected(SelectionEvent e) {
121
				handleBrowseButtonSelected(LaunchUIMessages.getString("GDBDebuggerPage.gdb_cmdfile_dlg_title"), //$NON-NLS-1$
557
				handleBrowseButtonSelected("GDB Command File", //$NON-NLS-1$
122
						stringFieldEditorGdbInit);
558
						stringFieldEditorGdbInit);
123
			}
559
			}
124
		});
560
		});
561
		setButtonLayoutData( browsebutton );
125
562
126
		final StringWithBooleanFieldEditor enableStopAtMain = new StringWithBooleanFieldEditor(
563
		final StringWithBooleanFieldEditor enableStopAtMain = new StringWithBooleanFieldEditor(
127
				IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN,
564
				IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN,
128
				IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN_SYMBOL,
565
				IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN_SYMBOL,
129
				LaunchUIMessages.getString("CDebuggerTab.Stop_at_main_on_startup"), //$NON-NLS-1$
566
				"Stop on startup at:", //$NON-NLS-1$
130
				group1);
567
				group1);
131
		enableStopAtMain.fillIntoGrid(group1, 2);
568
		enableStopAtMain.fillIntoGrid(group1, 3);
132
		addField(enableStopAtMain);
569
		addField(enableStopAtMain);
133
570
134
//		final StringFieldEditor stopAtMainSymbol = new StringFieldEditor(
571
//		final StringFieldEditor stopAtMainSymbol = new StringFieldEditor(
Lines 145-153 Link Here
145
//			}
582
//			}
146
//		});
583
//		});
147
584
585
		fCommandTimeoutField = new IntegerWithBooleanFieldEditor( 
586
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT, 
587
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_VALUE, 
588
				MessagesForPreferences.GdbDebugPreferencePage_Command_timeout,
589
				group1);
590
		fCommandTimeoutField.setValidRange(1, Integer.MAX_VALUE);
591
		fCommandTimeoutField.fillIntoGrid(group1, 2);
592
		addField(fCommandTimeoutField);
593
		
594
		fTimeoutAdvancedButton = new Button(group1, SWT.PUSH);
595
		fTimeoutAdvancedButton.setText(MessagesForPreferences.GdbDebugPreferencePage_Advanced_button);
596
		fTimeoutAdvancedButton.addSelectionListener(new SelectionAdapter() {
597
			@Override
598
			public void widgetSelected(SelectionEvent e) {
599
				handleAdvancedButtonSelected(
600
						"GDB Debugger");  //$NON-NLS-1$
601
			}
602
		});
603
		setButtonLayoutData( fTimeoutAdvancedButton );
604
148
		final ListenableBooleanFieldEditor enableNonStop= new ListenableBooleanFieldEditor(
605
		final ListenableBooleanFieldEditor enableNonStop= new ListenableBooleanFieldEditor(
149
				IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP,
606
				IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP,
150
				LaunchUIMessages.getString("GDBDebuggerPage.nonstop_mode"), //$NON-NLS-1$
607
				"Non-stop mode (Note: Requires non-stop GDB)", //$NON-NLS-1$
151
				SWT.NONE, group1);
608
				SWT.NONE, group1);
152
		enableNonStop.fillIntoGrid(group1, 3);
609
		enableNonStop.fillIntoGrid(group1, 3);
153
		addField(enableNonStop);
610
		addField(enableNonStop);
Lines 286-293 Link Here
286
		stringFieldEditor.setStringValue(res);
743
		stringFieldEditor.setStringValue(res);
287
	}
744
	}
288
745
746
	private void handleAdvancedButtonSelected(String dialogTitle) {
747
		AdvancedTimeoutSettingsDialog dialog = 
748
			new AdvancedTimeoutSettingsDialog( getShell(), fCustomTimeouts.entrySet() );
749
		if ( dialog.open() == Window.OK ) {
750
			fCustomTimeouts = dialog.getResult();
751
		}
752
	}
753
289
	@Override
754
	@Override
290
	protected void adjustGridLayout() {
755
	protected void adjustGridLayout() {
291
		// do nothing
756
		// do nothing
292
	}
757
	}
758
759
	@Override
760
	public void propertyChange( PropertyChangeEvent event ) {
761
		if ( event.getSource().equals( fCommandTimeoutField ) && event.getNewValue() instanceof Boolean ) {
762
			fTimeoutAdvancedButton.setEnabled( ((Boolean)event.getNewValue()).booleanValue() );
763
		}
764
		super.propertyChange( event );
765
	}
766
767
	@Override
768
	protected void performDefaults() {
769
		IPreferenceStore store = getPreferenceStore();
770
		if ( store != null ) {
771
			String memento = store.getDefaultString( IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS );
772
			fCustomTimeouts.initializeFromMemento( memento );
773
		}
774
		super.performDefaults();
775
		updateTimeoutButtons();
776
	}
777
778
	/* (non-Javadoc)
779
	 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk()
780
	 */
781
	@Override
782
	public boolean performOk() {
783
		getPreferenceStore().setValue( IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS, fCustomTimeouts.getMemento() );
784
		return super.performOk();
785
	}
786
787
	private void updateTimeoutButtons() {
788
		fTimeoutAdvancedButton.setEnabled( fCommandTimeoutField.getBooleanValue() );
789
	}
790
791
	private void initializeCustomTimeouts() {
792
		IPreferenceStore store = getPreferenceStore();
793
		if ( store != null ) {
794
			String memento = store.getString( IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS );
795
			fCustomTimeouts.initializeFromMemento( memento );
796
		}
797
	}
293
}
798
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java (+12 lines)
Lines 17-22 Link Here
17
 * Preference strings.
17
 * Preference strings.
18
 */
18
 */
19
class MessagesForPreferences extends NLS {
19
class MessagesForPreferences extends NLS {
20
	public static String GdbDebugPreferencePage_Add_button;
21
	public static String GdbDebugPreferencePage_Advanced_button;
22
	public static String GdbDebugPreferencePage_Advanced_timeout_dialog_message;
23
	public static String GdbDebugPreferencePage_Advanced_timeout_dialog_title;
24
	public static String GdbDebugPreferencePage_Anvanced_Timeout_Settings;
20
	public static String GdbDebugPreferencePage_description;
25
	public static String GdbDebugPreferencePage_description;
21
	public static String GdbDebugPreferencePage_traces_label;
26
	public static String GdbDebugPreferencePage_traces_label;
22
	public static String GdbDebugPreferencePage_enableTraces_label;
27
	public static String GdbDebugPreferencePage_enableTraces_label;
Lines 24-29 Link Here
24
	public static String GdbDebugPreferencePage_maxGdbTraces_label;
29
	public static String GdbDebugPreferencePage_maxGdbTraces_label;
25
	public static String GdbDebugPreferencePage_termination_label;
30
	public static String GdbDebugPreferencePage_termination_label;
26
	public static String GdbDebugPreferencePage_autoTerminateGdb_label;
31
	public static String GdbDebugPreferencePage_autoTerminateGdb_label;
32
	public static String GdbDebugPreferencePage_Command_column_name;
33
	public static String GdbDebugPreferencePage_Command_field_can_not_be_empty;
34
	public static String GdbDebugPreferencePage_Command_timeout;
27
	public static String GdbDebugPreferencePage_hover_label;
35
	public static String GdbDebugPreferencePage_hover_label;
28
	public static String GdbDebugPreferencePage_useInspectorHover_label;
36
	public static String GdbDebugPreferencePage_useInspectorHover_label;
29
	/** @since 2.2 */
37
	/** @since 2.2 */
Lines 36-41 Link Here
36
	public static String GdbDebugPreferencePage_initialChildCountLimitForCollections_label;
44
	public static String GdbDebugPreferencePage_initialChildCountLimitForCollections_label;
37
	/** @since 2.2 */
45
	/** @since 2.2 */
38
	public static String GdbDebugPreferencePage_defaults_label;
46
	public static String GdbDebugPreferencePage_defaults_label;
47
	public static String GdbDebugPreferencePage_Delete_button;
48
	public static String GdbDebugPreferencePage_Invalid_timeout_value;
49
	public static String GdbDebugPreferencePage_Timeout_column_name;
50
	public static String GdbDebugPreferencePage_Timeout_value_can_not_be_negative;
39
	static {
51
	static {
40
		// initialize resource bundle
52
		// initialize resource bundle
41
		NLS.initializeMessages(MessagesForPreferences.class.getName(), MessagesForPreferences.class);
53
		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 (+13 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
###############################################################################
11
###############################################################################
12
12
13
GdbDebugPreferencePage_Add_button=Add
13
GdbDebugPreferencePage_description=General settings for GDB Debugging
14
GdbDebugPreferencePage_description=General settings for GDB Debugging
14
15
15
GdbDebugPreferencePage_traces_label=Traces
16
GdbDebugPreferencePage_traces_label=Traces
Lines 17-22 Link Here
17
GdbDebugPreferencePage_maxGdbTraces_label=Limit GDB traces output (number of characters):
18
GdbDebugPreferencePage_maxGdbTraces_label=Limit GDB traces output (number of characters):
18
GdbDebugPreferencePage_termination_label=Termination
19
GdbDebugPreferencePage_termination_label=Termination
19
GdbDebugPreferencePage_autoTerminateGdb_label=Terminate GDB when last process exits
20
GdbDebugPreferencePage_autoTerminateGdb_label=Terminate GDB when last process exits
21
GdbDebugPreferencePage_Command_column_name=GDB/MI Command
22
GdbDebugPreferencePage_Command_field_can_not_be_empty='Command' field can not be empty
23
GdbDebugPreferencePage_Command_timeout=Command timeout (ms):
20
24
21
GdbDebugPreferencePage_hover_label=Debug Text Hover
25
GdbDebugPreferencePage_hover_label=Debug Text Hover
22
GdbDebugPreferencePage_useInspectorHover_label=Use enhanced debug hover
26
GdbDebugPreferencePage_useInspectorHover_label=Use enhanced debug hover
Lines 27-29 Link Here
27
GdbDebugPreferencePage_initialChildCountLimitForCollections_label=For collections, initially limit child count to
31
GdbDebugPreferencePage_initialChildCountLimitForCollections_label=For collections, initially limit child count to
28
32
29
GdbDebugPreferencePage_defaults_label=Debug Configurations Defaults
33
GdbDebugPreferencePage_defaults_label=Debug Configurations Defaults
34
GdbDebugPreferencePage_Delete_button=Delete
35
GdbDebugPreferencePage_Invalid_timeout_value=Invalid timeout value
36
GdbDebugPreferencePage_Timeout_column_name=Timeout(ms)
37
GdbDebugPreferencePage_Timeout_value_can_not_be_negative=Timeout value can not be negative
38
39
GdbDebugPreferencePage_Advanced_button=&Advanced...
40
GdbDebugPreferencePage_Advanced_timeout_dialog_message=Specify commands and corresponding timeout values, '0' for 'no timeout'.\nAll commands that are not mentioned here will get the default timeout value.
41
GdbDebugPreferencePage_Advanced_timeout_dialog_title=Add/delete/modify custom timeouts for GDB/MI commands
42
GdbDebugPreferencePage_Anvanced_Timeout_Settings=Advanced Timeout Settings
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/.options (+1 lines)
Line 1 Link Here
1
org.eclipse.cdt.dsf.gdb/debug = false
1
org.eclipse.cdt.dsf.gdb/debug = false
2
org.eclipse.cdt.dsf.gdb/debug/timeouts = false
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugConstants.java (-2 / +6 lines)
Lines 16-22 Link Here
16
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
16
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
17
17
18
18
19
20
/**
19
/**
21
 * @noimplement This interface is not intended to be implemented by clients.
20
 * @noimplement This interface is not intended to be implemented by clients.
22
 * @since 4.0
21
 * @since 4.0
Lines 24-29 Link Here
24
public interface IGdbDebugConstants {
23
public interface IGdbDebugConstants {
25
	
24
	
26
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
25
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
26
27
	/**
28
	 * Status code for which a UI handler is registered.
29
	 * @since 4.1
30
	 */
31
	public static final int STATUS_HANDLER_CODE = 20001;
27
32
28
    /**
33
    /**
29
     * Attribute key to be added to the IProcess associated with an IMIContainerDMContext.
34
     * Attribute key to be added to the IProcess associated with an IMIContainerDMContext.
Lines 54-59 Link Here
54
     */
59
     */
55
    public static final String GDB_PROCESS_CREATION_VALUE = PREFIX + "gdbProcess"; //$NON-NLS-1$
60
    public static final String GDB_PROCESS_CREATION_VALUE = PREFIX + "gdbProcess"; //$NON-NLS-1$
56
    
61
    
57
58
}
62
}
59
63
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java (+24 lines)
Lines 87-92 Link Here
87
	public static final String PREF_DEFAULT_NON_STOP = "defaultNonStop"; //$NON-NLS-1$
87
	public static final String PREF_DEFAULT_NON_STOP = "defaultNonStop"; //$NON-NLS-1$
88
88
89
	/**
89
	/**
90
	 * The value is an boolean specifying whether the timeout is used for GDB commands.
91
	 * @since 4.1
92
	 */
93
	public static final String PREF_COMMAND_TIMEOUT = "commandTimeout"; //$NON-NLS-1$
94
95
	/**
96
	 * The value is an integer specifying the timeout value (milliseconds) for GDB commands.
97
	 * @since 4.1
98
	 */
99
	public static final String PREF_COMMAND_TIMEOUT_VALUE = "commandTimeoutValue"; //$NON-NLS-1$
100
101
	/**
102
	 * The value is a string specifying the list of GDB/MI commands with custom timeout values.
103
	 * @since 4.1
104
	 */
105
	public static final String PREF_COMMAND_CUSTOM_TIMEOUTS = "commandTimeoutSpecials"; //$NON-NLS-1$
106
107
	/**
108
	 * Default default value for <code>PREF_COMMAND_TIMEOUT</code>;
109
	 * @since 4.1
110
	 */
111
	public static final int COMMAND_TIMEOUT_VALUE_DEFAULT = 10000;
112
113
	/**
90
     * Help prefixes.
114
     * Help prefixes.
91
     */
115
     */
92
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
116
    public static final String PREFIX = GdbPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java (+2 lines)
Lines 38-42 Link Here
38
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_STOP_AT_MAIN, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT);
38
		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);
39
		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);
40
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_DEFAULT_NON_STOP, IGDBLaunchConfigurationConstants.DEBUGGER_NON_STOP_DEFAULT);
41
		node.putBoolean(IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT, false);
42
		node.putInt(IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_VALUE, IGdbDebugPreferenceConstants.COMMAND_TIMEOUT_VALUE_DEFAULT);
41
	}
43
	}
42
}
44
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/Messages.java (+27 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.internal;
13
14
import org.eclipse.osgi.util.NLS;
15
16
public class Messages extends NLS {
17
	private static final String BUNDLE_NAME = "org.eclipse.cdt.dsf.gdb.internal.Messages"; //$NON-NLS-1$
18
19
	public static String DefaultGdbCommandTimeoutPolicy_Session_is_terminated;
20
	static {
21
		// initialize resource bundle
22
		NLS.initializeMessages( BUNDLE_NAME, Messages.class );
23
	}
24
25
	private Messages() {
26
	}
27
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/Messages.properties (+12 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
10
#######################################################################################
11
12
DefaultGdbCommandTimeoutPolicy_Session_is_terminated=Session is terminated.\nReason: %s
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java (+9 lines)
Lines 40-45 Link Here
40
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
40
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
41
import org.eclipse.cdt.dsf.gdb.internal.memory.GdbMemoryBlockRetrieval;
41
import org.eclipse.cdt.dsf.gdb.internal.memory.GdbMemoryBlockRetrieval;
42
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
42
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
43
import org.eclipse.cdt.dsf.gdb.service.command.IGdbCommandTimeoutService.ICommandTimedOutDMEvent;
43
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
44
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
44
import org.eclipse.cdt.dsf.mi.service.MIProcesses;
45
import org.eclipse.cdt.dsf.mi.service.MIProcesses;
45
import org.eclipse.cdt.dsf.mi.service.command.AbstractCLIProcess;
46
import org.eclipse.cdt.dsf.mi.service.command.AbstractCLIProcess;
Lines 313-316 Link Here
313
    	}
314
    	}
314
    	super.launchRemoved(launch);
315
    	super.launchRemoved(launch);
315
    }
316
    }
317
318
    /**
319
	 * @since 4.1
320
	 */
321
    @DsfServiceEventHandler 
322
    public void eventDispatched(ICommandTimedOutDMEvent event) {
323
        shutdownSession(new RequestMonitor(ImmediateExecutor.getInstance(), null));
324
    }
316
}
325
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/ServicesLaunchSequence.java (-1 / +12 lines)
Lines 25-34 Link Here
25
import org.eclipse.cdt.dsf.debug.service.IRegisters;
25
import org.eclipse.cdt.dsf.debug.service.IRegisters;
26
import org.eclipse.cdt.dsf.debug.service.IRunControl;
26
import org.eclipse.cdt.dsf.debug.service.IRunControl;
27
import org.eclipse.cdt.dsf.debug.service.ISourceLookup;
27
import org.eclipse.cdt.dsf.debug.service.ISourceLookup;
28
import org.eclipse.cdt.dsf.debug.service.IStack;
29
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
28
import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext;
29
import org.eclipse.cdt.dsf.debug.service.IStack;
30
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
30
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
31
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl;
31
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl;
32
import org.eclipse.cdt.dsf.gdb.service.command.IGdbCommandTimeoutService;
32
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
33
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
33
import org.eclipse.cdt.dsf.mi.service.IMIBackend;
34
import org.eclipse.cdt.dsf.mi.service.IMIBackend;
34
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
35
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
Lines 123-128 Link Here
123
           		requestMonitor.done();
124
           		requestMonitor.done();
124
           	}
125
           	}
125
        }},
126
        }},
127
        new Step() { @Override
128
        public void execute(RequestMonitor requestMonitor) {
129
           	IGdbCommandTimeoutService timeoutService = fLaunch.getServiceFactory().createService(IGdbCommandTimeoutService.class, fSession);
130
           	// Note that for older versions of GDB, we don't support tracing, so there is no trace service.
131
           	if (timeoutService != null) {
132
           		timeoutService.initialize(requestMonitor);
133
           	} else {
134
           		requestMonitor.done();
135
           	}
136
        }},
126
    };
137
    };
127
138
128
    DsfSession fSession;
139
    DsfSession fSession;
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java (-1 / +14 lines)
Lines 31-36 Link Here
31
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_0;
31
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_0;
32
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_2;
32
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_2;
33
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_4;
33
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_4;
34
import org.eclipse.cdt.dsf.gdb.service.command.GdbCommandTimeoutService;
35
import org.eclipse.cdt.dsf.gdb.service.command.IGdbCommandTimeoutService;
34
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
36
import org.eclipse.cdt.dsf.mi.service.CSourceLookup;
35
import org.eclipse.cdt.dsf.mi.service.IMIBackend;
37
import org.eclipse.cdt.dsf.mi.service.IMIBackend;
36
import org.eclipse.cdt.dsf.mi.service.MIBreakpoints;
38
import org.eclipse.cdt.dsf.mi.service.MIBreakpoints;
Lines 89-100 Link Here
89
					return (V)createBackendGDBService(session, (ILaunchConfiguration)arg);
91
					return (V)createBackendGDBService(session, (ILaunchConfiguration)arg);
90
				}
92
				}
91
			}
93
			}
92
		} else if (IGDBTraceControl.class.isAssignableFrom(clazz)) {
94
		} 
95
		else if (IGDBTraceControl.class.isAssignableFrom(clazz)) {
93
			for (Object arg : optionalArguments) {
96
			for (Object arg : optionalArguments) {
94
				if (arg instanceof ILaunchConfiguration) {
97
				if (arg instanceof ILaunchConfiguration) {
95
					return (V)createTraceControlService(session, (ILaunchConfiguration)arg);
98
					return (V)createTraceControlService(session, (ILaunchConfiguration)arg);
96
				}
99
				}
97
			}
100
			}
101
		}
102
		else if (IGdbCommandTimeoutService.class.isAssignableFrom(clazz)) {
103
			return (V)createCommandTimeoutService(session);
98
		}
104
		}
99
105
100
        return super.createService(clazz, session);
106
        return super.createService(clazz, session);
Lines 214-217 Link Here
214
		// in those older GDB versions.  Also, gdbserver only supports tracing starting with 7.2
220
		// in those older GDB versions.  Also, gdbserver only supports tracing starting with 7.2
215
		return null;		
221
		return null;		
216
	}
222
	}
223
224
	/**
225
	 * @since 4.1
226
	 */
227
	protected IGdbCommandTimeoutService createCommandTimeoutService(DsfSession session) {
228
		return new GdbCommandTimeoutService(session);
229
	}
217
}
230
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CustomTimeoutsMap.java (+78 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.StringTokenizer;
17
18
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.Status;
22
23
/**
24
 * @since 4.1
25
 */
26
public class CustomTimeoutsMap extends HashMap<String, Integer> {
27
28
	public CustomTimeoutsMap() {
29
		super();
30
	}
31
32
	public CustomTimeoutsMap( CustomTimeoutsMap map ) {
33
		super( map );
34
	}
35
36
	private static final long serialVersionUID = -8281280275781904870L;
37
38
	public String getMemento() {
39
		StringBuilder sb = new StringBuilder();
40
		for ( Map.Entry<String, Integer> entry : entrySet() ) {
41
			sb.append( entry.getKey() );
42
			sb.append( ',' );
43
			sb.append( entry.getValue().intValue() );
44
			sb.append( ';' );
45
		}
46
		return sb.toString();
47
	}
48
	
49
	public void initializeFromMemento( String memento ) {
50
		clear();
51
		StringTokenizer st = new StringTokenizer( memento, ";" ); //$NON-NLS-1$
52
		MultiStatus ms = new MultiStatus( GdbPlugin.PLUGIN_ID, 0, "Error initializing custom timeouts", null );
53
		while( st.hasMoreTokens() ) {
54
			String token = st.nextToken();
55
			String[] tokenParts = token.split( "," ); //$NON-NLS-1$
56
			if ( tokenParts.length == 2 && tokenParts[0].length() > 0 && tokenParts[0].length() > 0 ) {
57
				try {
58
					put( tokenParts[0], Integer.valueOf( tokenParts[1] ) );
59
				}
60
				catch( NumberFormatException e ) {
61
					ms.add( new Status(
62
							IStatus.ERROR, 
63
							GdbPlugin.PLUGIN_ID, 
64
							String.format( "Invalid custom timeout value for '%s'.", tokenParts[0] ) ) );
65
				}
66
			}
67
			else {
68
				ms.add( new Status(
69
						IStatus.ERROR, 
70
						GdbPlugin.PLUGIN_ID, 
71
						"Invalid custom timeout data." ) );
72
			}
73
		}
74
		if ( !ms.isOK() ) {
75
			GdbPlugin.getDefault().getLog().log( ms );
76
		}
77
	}
78
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/DefaultGdbCommandTimeoutPolicy.java (+115 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
15
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
16
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
17
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
18
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
19
import org.eclipse.cdt.dsf.gdb.internal.Messages;
20
import org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl;
21
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
22
import org.eclipse.cdt.dsf.service.DsfSession;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.IStatusHandler;
28
29
/**
30
 * Default implementation of the command timeout policy.
31
 * If a command is timed out it sets the command's status to 
32
 * 'error' and terminate the session.
33
 *  
34
 * @since 4.1
35
 */
36
public class DefaultGdbCommandTimeoutPolicy implements ICommandTimeoutPolicy {
37
38
	private DsfSession fSession;
39
	private AbstractMIControl fCommandControl;
40
41
	public DefaultGdbCommandTimeoutPolicy( DsfSession session, AbstractMIControl commandControl ) {
42
		super();
43
		fSession = session;
44
		fCommandControl = commandControl;
45
	}
46
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.cdt.dsf.gdb.service.command.ICommandTimeoutPolicy#commandTimedOut(org.eclipse.cdt.dsf.debug.service.command.ICommandToken)
49
	 */
50
	@Override
51
	public void commandTimedOut( ICommandToken token ) {
52
		String commandText = token.getCommand().toString();
53
		if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
54
			commandText = commandText.substring( 0, commandText.length() - 1 );
55
		final String errorMessage = String.format( "Command '%s' is timed out", commandText ); //$NON-NLS-1$
56
		fCommandControl.commandFailed( token, errorMessage );
57
		
58
		fSession.getExecutor().execute( new DsfRunnable() {
59
			
60
			@Override
61
			public void run() {
62
				DsfServicesTracker tracker = new DsfServicesTracker( GdbPlugin.getBundleContext(), fSession.getId() );
63
				IGDBControl gdbControl = tracker.getService( IGDBControl.class );
64
				tracker.dispose();
65
				
66
				if ( gdbControl != null ) {
67
					gdbControl.terminate( new RequestMonitor( fSession.getExecutor(), null ) {
68
						
69
						@Override
70
						protected void handleErrorOrWarning() {
71
							GdbPlugin.getDefault().getLog().log( getStatus() );
72
							super.handleErrorOrWarning();
73
						};
74
					} );
75
76
					// If the timeout occurs while the launch sequence is being executed the error 
77
					// will be reported using the launcher's error reporting mechanism.
78
					if ( fCommandControl instanceof IGDBControlExtension 
79
							&& ((IGDBControlExtension)fCommandControl).isInitialized() ) {
80
						IStatus status = new Status( 
81
								IStatus.ERROR, 
82
								GdbPlugin.PLUGIN_ID, 
83
								IGdbDebugConstants.STATUS_HANDLER_CODE, 
84
								String.format( Messages.DefaultGdbCommandTimeoutPolicy_Session_is_terminated, errorMessage ), 
85
								null );
86
						IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler( status );
87
						if ( statusHandler != null ) {
88
							try {
89
								statusHandler.handleStatus( status, null );
90
							}
91
							catch( CoreException e ) {
92
								GdbPlugin.getDefault().getLog().log( e.getStatus() );
93
							}
94
						}
95
					}
96
				}
97
			}
98
		} );
99
	}
100
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.cdt.dsf.gdb.service.command.ICommandTimeoutPolicy#dispose()
103
	 */
104
	@Override
105
	public void dispose() {
106
	}
107
108
	protected DsfSession getSession() {
109
		return fSession;
110
	}
111
112
	protected AbstractMIControl getCommandControl() {
113
		return fCommandControl;
114
	}
115
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java (-14 / +29 lines)
Lines 58-63 Link Here
58
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
58
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
59
import org.eclipse.cdt.dsf.service.DsfSession;
59
import org.eclipse.cdt.dsf.service.DsfSession;
60
import org.eclipse.core.runtime.CoreException;
60
import org.eclipse.core.runtime.CoreException;
61
import org.eclipse.core.runtime.IProgressMonitor;
61
import org.eclipse.core.runtime.IStatus;
62
import org.eclipse.core.runtime.IStatus;
62
import org.eclipse.core.runtime.NullProgressMonitor;
63
import org.eclipse.core.runtime.NullProgressMonitor;
63
import org.eclipse.core.runtime.Status;
64
import org.eclipse.core.runtime.Status;
Lines 72-78 Link Here
72
 * - CLI console support,<br>
73
 * - CLI console support,<br>
73
 * - inferior process status tracking.<br>
74
 * - inferior process status tracking.<br>
74
 */
75
 */
75
public class GDBControl extends AbstractMIControl implements IGDBControl {
76
public class GDBControl extends AbstractMIControl implements IGDBControl, IGDBControlExtension {
76
77
77
    /**
78
    /**
78
     * Event indicating that the back end process has started.
79
     * Event indicating that the back end process has started.
Lines 105-110 Link Here
105
    private AbstractCLIProcess fCLIProcess;
106
    private AbstractCLIProcess fCLIProcess;
106
107
107
    private boolean fTerminated;
108
    private boolean fTerminated;
109
    
110
    private Sequence fInitializationSequence;
111
    
112
    private boolean fInitialized = false;
108
113
109
    /**
114
    /**
110
     * @since 3.0
115
     * @since 3.0
Lines 290-309 Link Here
290
		} catch (CoreException e) {}
295
		} catch (CoreException e) {}
291
296
292
		// We need a RequestMonitorWithProgress, if we don't have one, we create one.
297
		// We need a RequestMonitorWithProgress, if we don't have one, we create one.
293
		RequestMonitorWithProgress progressRm;
298
		IProgressMonitor monitor = (rm instanceof RequestMonitorWithProgress) ?				
294
		if (rm instanceof RequestMonitorWithProgress) {
299
			((RequestMonitorWithProgress)rm).getProgressMonitor() : new NullProgressMonitor();
295
			progressRm = (RequestMonitorWithProgress)rm;
300
		RequestMonitorWithProgress progressRm = new RequestMonitorWithProgress(getExecutor(), monitor) {
296
		} else {
301
		
297
			progressRm = new RequestMonitorWithProgress(getExecutor(), new NullProgressMonitor()) {
302
			@Override
298
				@Override
303
			protected void handleCompleted() {
299
				protected void handleCompleted() {
304
    			fInitializationSequence = null;
300
       				rm.setStatus(getStatus());
305
    			fInitialized = true;
301
        			rm.done();
306
   				rm.setStatus(getStatus());
302
				}
307
    			rm.done();
303
			};
308
			}
304
		}
309
		};
305
310
306
		ImmediateExecutor.getInstance().execute(getCompleteInitializationSequence(attributes, progressRm));
311
		fInitializationSequence = getCompleteInitializationSequence(attributes, progressRm); 
312
313
		ImmediateExecutor.getInstance().execute(fInitializationSequence);
307
	}
314
	}
308
	
315
	
309
	/**
316
	/**
Lines 471-474 Link Here
471
	public void setPrintPythonErrors(boolean enabled, RequestMonitor rm) {
478
	public void setPrintPythonErrors(boolean enabled, RequestMonitor rm) {
472
		rm.done();
479
		rm.done();
473
	}
480
	}
481
482
	/**
483
	 * @since 4.1
484
	 */
485
	@Override
486
	public boolean isInitialized() {
487
		return fInitialized;
488
	}
474
}
489
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java (-14 / +29 lines)
Lines 57-62 Link Here
57
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
57
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
58
import org.eclipse.cdt.dsf.service.DsfSession;
58
import org.eclipse.cdt.dsf.service.DsfSession;
59
import org.eclipse.core.runtime.CoreException;
59
import org.eclipse.core.runtime.CoreException;
60
import org.eclipse.core.runtime.IProgressMonitor;
60
import org.eclipse.core.runtime.IStatus;
61
import org.eclipse.core.runtime.IStatus;
61
import org.eclipse.core.runtime.NullProgressMonitor;
62
import org.eclipse.core.runtime.NullProgressMonitor;
62
import org.eclipse.core.runtime.Status;
63
import org.eclipse.core.runtime.Status;
Lines 71-77 Link Here
71
 * - CLI console support,<br>
72
 * - CLI console support,<br>
72
 * - inferior process status tracking.<br>
73
 * - inferior process status tracking.<br>
73
 */
74
 */
74
public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl {
75
public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl, IGDBControlExtension {
75
76
76
    /**
77
    /**
77
     * Event indicating that the back end process has started.
78
     * Event indicating that the back end process has started.
Lines 106-111 Link Here
106
    private List<String> fFeatures = new ArrayList<String>();
107
    private List<String> fFeatures = new ArrayList<String>();
107
108
108
    private boolean fTerminated;
109
    private boolean fTerminated;
110
    
111
    private Sequence fInitializationSequence;
112
    
113
    private boolean fInitialized = false;
109
    
114
    
110
    /**
115
    /**
111
     * @since 3.0
116
     * @since 3.0
Lines 304-323 Link Here
304
		} catch (CoreException e) {}
309
		} catch (CoreException e) {}
305
310
306
		// We need a RequestMonitorWithProgress, if we don't have one, we create one.
311
		// We need a RequestMonitorWithProgress, if we don't have one, we create one.
307
		RequestMonitorWithProgress progressRm;
312
		IProgressMonitor monitor = (rm instanceof RequestMonitorWithProgress) ?				
308
		if (rm instanceof RequestMonitorWithProgress) {
313
			((RequestMonitorWithProgress)rm).getProgressMonitor() : new NullProgressMonitor();
309
			progressRm = (RequestMonitorWithProgress)rm;
314
		RequestMonitorWithProgress progressRm = new RequestMonitorWithProgress(getExecutor(), monitor) {
310
		} else {
315
		
311
			progressRm = new RequestMonitorWithProgress(getExecutor(), new NullProgressMonitor()) {
316
			@Override
312
				@Override
317
			protected void handleCompleted() {
313
				protected void handleCompleted() {
318
    			fInitializationSequence = null;
314
       				rm.setStatus(getStatus());
319
    			fInitialized = true;
315
        			rm.done();
320
   				rm.setStatus(getStatus());
316
				}
321
    			rm.done();
317
			};
322
			}
318
		}
323
		};
319
324
320
		ImmediateExecutor.getInstance().execute(getCompleteInitializationSequence(attributes, progressRm));
325
		fInitializationSequence = getCompleteInitializationSequence(attributes, progressRm); 
326
327
		ImmediateExecutor.getInstance().execute(fInitializationSequence);
321
	}
328
	}
322
	
329
	
323
	/**
330
	/**
Lines 497-500 Link Here
497
				getCommandFactory().createCLIMaintenance(fControlDmc, subCommand),
504
				getCommandFactory().createCLIMaintenance(fControlDmc, subCommand),
498
				new DataRequestMonitor<MIInfo>(getExecutor(), rm));
505
				new DataRequestMonitor<MIInfo>(getExecutor(), rm));
499
	}
506
	}
507
508
	/**
509
	 * @since 4.1
510
	 */
511
	@Override
512
	public boolean isInitialized() {
513
		return fInitialized;
514
	}
500
}
515
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GdbCommandTimeoutService.java (+472 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
import java.util.Hashtable;
15
import java.util.concurrent.BlockingQueue;
16
import java.util.concurrent.LinkedBlockingQueue;
17
18
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
19
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
20
import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent;
21
import org.eclipse.cdt.dsf.debug.service.command.ICommand;
22
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
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.mi.service.command.AbstractMIControl;
28
import org.eclipse.cdt.dsf.mi.service.command.commands.MICommand;
29
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
30
import org.eclipse.cdt.dsf.service.AbstractDsfService;
31
import org.eclipse.cdt.dsf.service.DsfSession;
32
import org.eclipse.core.runtime.IStatus;
33
import org.eclipse.core.runtime.Platform;
34
import org.eclipse.core.runtime.Status;
35
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
38
import org.eclipse.core.runtime.preferences.InstanceScope;
39
import org.osgi.framework.BundleContext;
40
41
/**
42
 * Command timeout service. Registers itself as a command listener and monitors 
43
 * the execution time. If the execution of a command takes more time than expected 
44
 * the service activates the timeout policy {@link ICommandTimeoutPolicy}.
45
 *    
46
 * @since 4.1
47
 */
48
public class GdbCommandTimeoutService extends AbstractDsfService implements IGdbCommandTimeoutService, IPreferenceChangeListener {
49
50
	public final static boolean DEBUG = "true".equals( Platform.getDebugOption( "org.eclipse.cdt.dsf.gdb/debug/timeouts" ) ); //$NON-NLS-1$//$NON-NLS-2$
51
	
52
	class CommandTimedOutDMEvent extends AbstractDMEvent<ICommandControlDMContext> implements ICommandTimedOutDMEvent {
53
54
		private ICommandToken fCommandToken;
55
56
		CommandTimedOutDMEvent( ICommandControlDMContext context, ICommandToken commandToken ) {
57
			super( context );
58
			fCommandToken = commandToken;
59
		}
60
61
		/* (non-Javadoc)
62
		 * @see org.eclipse.cdt.dsf.gdb.service.command.IGdbCommandTimeoutService.ICommandTimedOutDMEvent#getCommand()
63
		 */
64
		@Override
65
		public ICommandToken getCommand() {
66
			return fCommandToken;
67
		}
68
	}
69
70
	class QueueEntry {
71
		long fTimestamp;
72
		ICommandToken fCommandToken;
73
		
74
		QueueEntry( long timestamp, ICommandToken commandToken ) {
75
			super();
76
			fTimestamp = timestamp;
77
			fCommandToken = commandToken;
78
		}
79
80
		/* (non-Javadoc)
81
		 * @see java.lang.Object#equals(java.lang.Object)
82
		 */
83
		@Override
84
		public boolean equals( Object obj ) {
85
			// We purposely ignore the timestamp here to make the removing 
86
			// of a command token from the queue simple.
87
			// See org.eclipse.cdt.dsf.gdb.service.command.GdbCommandTimeoutService#commandRemoved()
88
			// and org.eclipse.cdt.dsf.gdb.service.command.GdbCommandTimeoutService#commandDone().
89
			if ( obj instanceof QueueEntry ) {
90
				return fCommandToken.equals( ((QueueEntry)obj).fCommandToken );
91
			}
92
			return false;
93
		}
94
	}
95
96
	enum TimerThreadState {
97
		INITIALIZING,
98
		RUNNING,
99
		HALTED,
100
		SHUTDOWN
101
	}
102
103
	/**
104
	 *
105
	 */
106
	class TimerThread extends Thread {
107
108
		private BlockingQueue<QueueEntry> fQueue;
109
		private int fWaitTimeout = IGdbDebugPreferenceConstants.COMMAND_TIMEOUT_VALUE_DEFAULT;
110
		private TimerThreadState fState = TimerThreadState.INITIALIZING;
111
112
		TimerThread( BlockingQueue<QueueEntry> queue, int timeout ) {
113
			super();
114
			fQueue = queue;
115
			setWaitTimout( timeout );
116
		}
117
118
		/* (non-Javadoc)
119
		 * @see java.lang.Thread#run()
120
		 */
121
		@Override
122
		public void run() {
123
			setState( ( getWaitTimeout() > 0 ) ? 
124
					TimerThreadState.RUNNING : TimerThreadState.HALTED );
125
			doRun();
126
		}
127
128
		private void doRun() {
129
			if ( fState == TimerThreadState.HALTED ) {
130
				halted();
131
			}
132
			else {
133
				running();
134
			}
135
		}
136
137
		private void halted() {
138
			try {
139
				synchronized( TimerThread.this ) {
140
					wait();
141
				}
142
			}
143
			catch( InterruptedException e ) {
144
				doRun();
145
			}
146
		}
147
148
		private void running() {
149
			try {
150
				while( fState == TimerThreadState.RUNNING ) {
151
					long timeout = getWaitTimeout();
152
					QueueEntry entry = fQueue.peek();
153
					if ( entry != null ) {
154
						// Calculate the time elapsed since the execution of this command started 
155
						// and compare it with the command's timeout value.
156
						// If the elapsed time is greater or equal than the timeout value the command 
157
						// is marked as timed out. Otherwise, schedule the next check when the timeout 
158
						// expires.
159
						long commandTimeout = getTimeoutForCommand( entry.fCommandToken.getCommand() );
160
						
161
						if ( DEBUG ) {
162
							String commandText = entry.fCommandToken.getCommand().toString();
163
							if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
164
								commandText = commandText.substring( 0, commandText.length() - 1 );
165
							printDebugMessage( String.format( "Processing command '%s', command timeout is %d", //$NON-NLS-1$ 
166
									commandText, Long.valueOf( commandTimeout ) ) );
167
						}
168
						
169
						long elapsedTime = System.currentTimeMillis() - entry.fTimestamp;
170
						if ( commandTimeout <= elapsedTime ) {
171
							processTimedOutCommand( entry.fCommandToken );
172
							fQueue.remove( entry );
173
						}
174
						else {
175
							timeout = Math.min( timeout, commandTimeout - elapsedTime );
176
						
177
							if ( DEBUG ) {
178
								String commandText = entry.fCommandToken.getCommand().toString();
179
								if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
180
									commandText = commandText.substring( 0, commandText.length() - 1 );
181
								printDebugMessage( String.format( "Setting timeout %d for command '%s'", Long.valueOf( timeout ), commandText ) ); //$NON-NLS-1$
182
							}
183
						}
184
					}
185
					synchronized( TimerThread.this ) {
186
						wait( timeout );
187
					}
188
					if ( isInterrupted() ) {
189
						doRun();
190
					}
191
				}
192
			}
193
			catch( InterruptedException e ) {
194
				doRun();
195
			}
196
		}
197
198
		void shutdown() {
199
			setState( TimerThreadState.SHUTDOWN );
200
			interrupt();
201
		}
202
		
203
		void haltProcessing() {
204
			setState( TimerThreadState.HALTED );
205
			interrupt();
206
		}
207
		
208
		void resumeProcessing() {
209
			setState( TimerThreadState.RUNNING );
210
			interrupt();
211
		}
212
		
213
		void setWaitTimout( int waitTimeout ) {
214
			fWaitTimeout = waitTimeout;
215
			if ( DEBUG )
216
				printDebugMessage( String.format( "Wait timeout is set to %d", Integer.valueOf( fWaitTimeout ) ) ); //$NON-NLS-1$
217
		}
218
		
219
		int getWaitTimeout() {
220
			return fWaitTimeout;
221
		}
222
		
223
		void setState( TimerThreadState state ) {
224
			fState = state;
225
		}
226
	}
227
228
	private AbstractMIControl fCommandControl;
229
	private ICommandTimeoutPolicy fTimeoutPolicy;
230
	private int fTimeout = 30;
231
	private TimerThread fTimerThread;
232
	private BlockingQueue<QueueEntry> fCommandQueue = new LinkedBlockingQueue<QueueEntry>();
233
	private CustomTimeoutsMap fCustomTimeouts = new CustomTimeoutsMap();
234
235
	public GdbCommandTimeoutService( DsfSession session ) {
236
		super( session );
237
	}
238
239
	/* (non-Javadoc)
240
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#initialize(org.eclipse.cdt.dsf.concurrent.RequestMonitor)
241
	 */
242
	@Override
243
	public void initialize( final RequestMonitor requestMonitor ) {
244
		super.initialize( new RequestMonitor( ImmediateExecutor.getInstance(), requestMonitor ) {
245
			@Override
246
			protected void handleSuccess() {
247
				doInitialize( requestMonitor );
248
			}
249
		} );
250
	}
251
252
	private void doInitialize( final RequestMonitor requestMonitor ) {
253
		fCommandControl = getServicesTracker().getService( AbstractMIControl.class );
254
		if ( fCommandControl != null ) {
255
			IEclipsePreferences node = InstanceScope.INSTANCE.getNode( GdbPlugin.PLUGIN_ID );
256
257
			fTimeout = Platform.getPreferencesService().getInt( 
258
					GdbPlugin.PLUGIN_ID,
259
					IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_VALUE, 
260
					IGdbDebugPreferenceConstants.COMMAND_TIMEOUT_VALUE_DEFAULT,
261
					null );
262
			
263
			fCustomTimeouts.initializeFromMemento( Platform.getPreferencesService().getString( 
264
					GdbPlugin.PLUGIN_ID,
265
					IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS, 
266
					"", //$NON-NLS-1$
267
					null ) );
268
			
269
			node.addPreferenceChangeListener( this );
270
			
271
			fCommandControl.addCommandListener( this );
272
			
273
			fTimeoutPolicy = getTimeoutPolicy();
274
275
			fTimerThread = new TimerThread( fCommandQueue, calculateWaitTimeout() );
276
			fTimerThread.start();
277
		}
278
		
279
		register( 
280
			new String[] { 
281
				IGdbCommandTimeoutService.class.getName(),
282
				GdbCommandTimeoutService.class.getName(),
283
			},
284
			new Hashtable<String, String>() );
285
286
		requestMonitor.done();
287
	}
288
289
	/* (non-Javadoc)
290
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#shutdown(org.eclipse.cdt.dsf.concurrent.RequestMonitor)
291
	 */
292
	@Override
293
	public void shutdown( RequestMonitor rm ) {
294
		if ( fCommandControl != null ) {
295
			fTimerThread.shutdown();
296
			InstanceScope.INSTANCE.getNode( GdbPlugin.PLUGIN_ID ).removePreferenceChangeListener( this );
297
			fCommandControl.removeCommandListener( this );
298
			fCommandQueue.clear();
299
			fCustomTimeouts.clear();
300
			if ( fTimeoutPolicy != null ) {
301
				fTimeoutPolicy.dispose();
302
			}
303
		}
304
		super.shutdown( rm );
305
	}
306
307
	/* (non-Javadoc)
308
	 * @see org.eclipse.cdt.dsf.debug.service.command.ICommandListener#commandQueued(org.eclipse.cdt.dsf.debug.service.command.ICommandToken)
309
	 */
310
	@Override
311
	public void commandQueued( ICommandToken token ) {
312
	}
313
314
	/* (non-Javadoc)
315
	 * @see org.eclipse.cdt.dsf.debug.service.command.ICommandListener#commandSent(org.eclipse.cdt.dsf.debug.service.command.ICommandToken)
316
	 */
317
	@Override
318
	public void commandSent( ICommandToken token ) {
319
		int commandTimeout = getTimeoutForCommand( token.getCommand() );
320
		if ( DEBUG ) {
321
			String commandText = token.getCommand().toString();
322
			if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
323
				commandText = commandText.substring( 0, commandText.length() - 1 );
324
			printDebugMessage( String.format( "Command '%s' sent, timeout = %d", commandText, Integer.valueOf( commandTimeout ) ) ); //$NON-NLS-1$
325
		}
326
		if ( commandTimeout == 0 )
327
			// Skip commands with no timeout 
328
			return;
329
		try {
330
			fCommandQueue.put( new QueueEntry( System.currentTimeMillis(), token ) );
331
		}
332
		catch( InterruptedException e ) {
333
			// ignore
334
		}
335
	}
336
337
	/* (non-Javadoc)
338
	 * @see org.eclipse.cdt.dsf.debug.service.command.ICommandListener#commandRemoved(org.eclipse.cdt.dsf.debug.service.command.ICommandToken)
339
	 */
340
	@Override
341
	public void commandRemoved( ICommandToken token ) {
342
		fCommandQueue.remove( new QueueEntry( 0, token ) );
343
		if ( DEBUG ) {
344
			String commandText = token.getCommand().toString();
345
			if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
346
				commandText = commandText.substring( 0, commandText.length() - 1 );
347
			printDebugMessage( String.format( "Command '%s' removed", commandText ) ); //$NON-NLS-1$
348
		}
349
	}
350
351
	/* (non-Javadoc)
352
	 * @see org.eclipse.cdt.dsf.debug.service.command.ICommandListener#commandDone(org.eclipse.cdt.dsf.debug.service.command.ICommandToken, org.eclipse.cdt.dsf.debug.service.command.ICommandResult)
353
	 */
354
	@Override
355
	public void commandDone( ICommandToken token, ICommandResult result ) {
356
		fCommandQueue.remove( new QueueEntry( 0, token ) );
357
		if ( DEBUG ) {
358
			String commandText = token.getCommand().toString();
359
			if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
360
				commandText = commandText.substring( 0, commandText.length() - 1 );
361
			printDebugMessage( String.format( "Command '%s' done", commandText ) ); //$NON-NLS-1$
362
		}
363
	}
364
365
	/* (non-Javadoc)
366
	 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
367
	 */
368
	@Override
369
	public void preferenceChange( PreferenceChangeEvent event ) {
370
		String property = event.getKey();
371
		if ( IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT.equals( property ) ) {
372
			if ( event.getNewValue() == null || !event.getNewValue().equals( event.getOldValue() ) ) {
373
				updateWaitTimeout();
374
				fTimerThread.setState( ( fTimerThread.getWaitTimeout() > 0 ) ? 
375
						TimerThreadState.RUNNING : TimerThreadState.HALTED );
376
				fTimerThread.interrupt();
377
			}
378
		}
379
		else if ( IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_VALUE.equals( property ) ) {
380
			if ( !event.getNewValue().equals( event.getOldValue() ) ) {
381
				try {
382
					fTimeout = Integer.parseInt( event.getNewValue().toString() );
383
					updateWaitTimeout();
384
					fTimerThread.setState( ( fTimerThread.getWaitTimeout() > 0 ) ? 
385
							TimerThreadState.RUNNING : TimerThreadState.HALTED );
386
					fTimerThread.interrupt();
387
				}
388
				catch( NumberFormatException e ) {
389
					GdbPlugin.getDefault().getLog().log( new Status( IStatus.ERROR, GdbPlugin.PLUGIN_ID, "Invlaid timeout value" ) ); //$NON-NLS-1$
390
				}
391
			}
392
		}
393
		else if ( IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS.equals( property ) ) {
394
			if ( event.getNewValue() instanceof String ) {
395
				fCustomTimeouts.initializeFromMemento( (String)event.getNewValue() );
396
			}
397
			else if ( event.getNewValue() == null ) {
398
				fCustomTimeouts.clear();
399
			}
400
			updateWaitTimeout();
401
			fTimerThread.setState( ( fTimerThread.getWaitTimeout() > 0 ) ? 
402
					TimerThreadState.RUNNING : TimerThreadState.HALTED );
403
			fTimerThread.interrupt();
404
		}
405
	}
406
407
	/* (non-Javadoc)
408
	 * @see org.eclipse.cdt.dsf.service.AbstractDsfService#getBundleContext()
409
	 */
410
	@Override
411
	protected BundleContext getBundleContext() {
412
        return GdbPlugin.getBundleContext();
413
	}
414
415
	protected int getTimeoutForCommand( ICommand<? extends ICommandResult> command ) {
416
		if ( !(command instanceof MICommand<?>) )
417
			return 0;
418
		@SuppressWarnings( "unchecked" )
419
		Integer timeout = fCustomTimeouts.get( ((MICommand<? extends MIInfo>)command).getOperation() );
420
		return ( timeout != null ) ? timeout.intValue() : fTimeout;
421
	}
422
423
	protected void processTimedOutCommand( ICommandToken token ) {
424
		if ( DEBUG ) {
425
			String commandText = token.getCommand().toString();
426
			if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
427
				commandText = commandText.substring( 0, commandText.length() - 1 );
428
			printDebugMessage( String.format( "Command '%s' is timed out", commandText ) ); //$NON-NLS-1$
429
		}
430
431
		if ( fTimeoutPolicy != null ) {
432
			fTimeoutPolicy.commandTimedOut( token );
433
		}
434
435
		getSession().dispatchEvent( 
436
				new CommandTimedOutDMEvent( fCommandControl.getContext(), token ), 
437
				getProperties() );
438
	}
439
440
	private void updateWaitTimeout() {
441
		fTimerThread.setWaitTimout( calculateWaitTimeout() );
442
	}
443
444
	private boolean isTimeoutEnabled() {
445
		return Platform.getPreferencesService().getBoolean( 
446
				GdbPlugin.PLUGIN_ID,
447
				IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT, 
448
				false,
449
				null );
450
	}
451
452
	protected ICommandTimeoutPolicy getTimeoutPolicy() {
453
		return new DefaultGdbCommandTimeoutPolicy( getSession(), fCommandControl );
454
	}
455
456
	private void printDebugMessage( String message ) {
457
		System.out.println( String.format( "[%s] %s", GdbPlugin.getDebugTime(), message ) ); //$NON-NLS-1$		
458
	}
459
460
	private int calculateWaitTimeout() {
461
		int waitTimeout = 0;
462
		if ( isTimeoutEnabled() ) {
463
			waitTimeout = fTimeout;
464
			for ( Integer t : fCustomTimeouts.values() ) {
465
				if ( t.intValue() > 0 ) {
466
					waitTimeout = Math.min( waitTimeout, t.intValue() );
467
				}
468
			}
469
		}
470
		return waitTimeout;
471
	}
472
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/ICommandTimeoutPolicy.java (+24 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
15
16
/**
17
 * @since 4.1
18
 */
19
public interface ICommandTimeoutPolicy {
20
	
21
	public void commandTimedOut( ICommandToken token );
22
	
23
	public void dispose();
24
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGDBControlExtension.java (+20 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
/**
15
 * @since 4.1
16
 */
17
public interface IGDBControlExtension extends IGDBControl {
18
19
	boolean isInitialized();
20
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGdbCommandTimeoutService.java (+35 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
10
 *******************************************************************************/
11
12
package org.eclipse.cdt.dsf.gdb.service.command;
13
14
import org.eclipse.cdt.dsf.datamodel.IDMEvent;
15
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
16
import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
17
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
18
import org.eclipse.cdt.dsf.service.IDsfService;
19
20
/**
21
 * @since 4.1
22
 */
23
public interface IGdbCommandTimeoutService extends IDsfService, ICommandListener {
24
25
    /**
26
     * Indicates that a command in the given command control is timed out.
27
     */
28
    public interface ICommandTimedOutDMEvent extends IDMEvent<ICommandControlDMContext> {
29
    	
30
        /**
31
         * Returns the command that is timed out.
32
         */
33
        ICommandToken getCommand();
34
    }
35
}
(-)a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java (+53 lines)
Lines 1080-1083 Link Here
1080
    	fCurrentStackLevel = -1; 
1080
    	fCurrentStackLevel = -1; 
1081
    }
1081
    }
1082
1082
1083
    /**
1084
	 * @since 4.1
1085
	 */
1086
    public void commandFailed(ICommandToken token, String errorMessage) {
1087
    	if ( !(token instanceof CommandHandle && token.getCommand() instanceof MICommand<?>) )
1088
    		return;
1089
		final CommandHandle commandHandle = (CommandHandle)token;
1090
		Integer tokenId = commandHandle.getTokenId();
1091
1092
		MIConst value = new MIConst();
1093
		value.setCString( errorMessage );
1094
		MIResult result = new MIResult();
1095
		result.setVariable( "msg" ); //$NON-NLS-1$
1096
		result.setMIValue( value );
1097
		MIResultRecord resultRecord = new MIResultRecord();
1098
		resultRecord.setToken( tokenId.intValue() );
1099
		resultRecord.setResultClass( MIResultRecord.ERROR );
1100
		resultRecord.setMIResults( new MIResult[] { result } );
1101
		MIOutput miOutput = new MIOutput( resultRecord, new MIOOBRecord[0] );
1102
1103
		final MIInfo info = commandHandle.getCommand().getResult(miOutput);
1104
		DataRequestMonitor<MIInfo> rm = commandHandle.getRequestMonitor();
1105
		
1106
		if ( rm != null ) {
1107
			rm.setData(info);			
1108
			rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, errorMessage)); 
1109
			
1110
			/*
1111
			 *  We need to complete the command on the DSF thread for data security.
1112
			 */
1113
			getExecutor().execute(new DsfRunnable() {
1114
                @Override
1115
				public void run() {
1116
                	/*
1117
                	 *  Complete the specific command.
1118
                	 */
1119
                    if (commandHandle.getRequestMonitor() != null) {
1120
                        commandHandle.getRequestMonitor().done();
1121
                    }
1122
                    
1123
                    /*
1124
                     *  Now tell the generic listeners about it.
1125
                     */
1126
                    processCommandDone(commandHandle, info);
1127
                }
1128
1129
                @Override
1130
                public String toString() {
1131
                    return "MI command output received for: " + commandHandle.getCommand(); //$NON-NLS-1$
1132
                }
1133
            });
1134
		}
1135
    }
1083
}
1136
}

Return to bug 361934