10
10
*******************************************************************************/
11
11
package org .eclipse .linuxtools .internal .valgrind .memcheck ;
12
12
13
+ import java .util .Arrays ;
14
+
13
15
import org .eclipse .core .runtime .CoreException ;
14
16
import org .eclipse .debug .core .ILaunchConfiguration ;
15
17
import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
16
18
import org .eclipse .debug .ui .AbstractLaunchConfigurationTab ;
19
+ import org .eclipse .jface .dialogs .Dialog ;
20
+ import org .eclipse .jface .dialogs .InputDialog ;
21
+ import org .eclipse .jface .window .Window ;
17
22
import org .eclipse .linuxtools .valgrind .launch .IValgrindToolPage ;
18
23
import org .eclipse .osgi .util .NLS ;
19
24
import org .eclipse .swt .SWT ;
22
27
import org .eclipse .swt .events .SelectionAdapter ;
23
28
import org .eclipse .swt .events .SelectionEvent ;
24
29
import org .eclipse .swt .events .SelectionListener ;
30
+ import org .eclipse .swt .graphics .FontMetrics ;
25
31
import org .eclipse .swt .layout .GridData ;
26
32
import org .eclipse .swt .layout .GridLayout ;
27
33
import org .eclipse .swt .widgets .Button ;
28
34
import org .eclipse .swt .widgets .Combo ;
29
35
import org .eclipse .swt .widgets .Composite ;
30
36
import org .eclipse .swt .widgets .Label ;
37
+ import org .eclipse .swt .widgets .List ;
31
38
import org .eclipse .swt .widgets .Spinner ;
39
+ import org .eclipse .swt .widgets .Text ;
32
40
import org .osgi .framework .Version ;
33
41
34
42
public class MemcheckToolPage extends AbstractLaunchConfigurationTab implements IValgrindToolPage {
@@ -50,6 +58,13 @@ public class MemcheckToolPage extends AbstractLaunchConfigurationTab implements
50
58
// VG >= 3.4.0
51
59
protected Button trackOriginsButton ;
52
60
61
+ protected Button showPossiblyLostButton ;
62
+ protected Button mallocFillButton ;
63
+ protected Text mallocFillText ;
64
+ protected Button freeFillButton ;
65
+ protected Text freeFillText ;
66
+ protected List ignoreRangesList ;
67
+
53
68
protected boolean isInitializing = false ;
54
69
protected Version valgrindVersion ;
55
70
protected CoreException ex = null ;
@@ -144,16 +159,126 @@ public void widgetSelected(SelectionEvent e) {
144
159
alignmentSpinner .setMinimum (0 );
145
160
alignmentSpinner .setMaximum (4096 );
146
161
alignmentSpinner .addModifyListener (modifyListener );
162
+
163
+ showPossiblyLostButton = new Button (top , SWT .CHECK );
164
+ showPossiblyLostButton .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
165
+ showPossiblyLostButton .setText (Messages .getString ("MemcheckToolPage.Show_Possibly_Lost" )); //$NON-NLS-1$
166
+ showPossiblyLostButton .addSelectionListener (selectListener );
167
+
168
+ Composite mallocFillTop = new Composite (top , SWT .NONE );
169
+ GridLayout mallocFillLayout = new GridLayout (2 , false );
170
+ mallocFillTop .setLayout (mallocFillLayout );
171
+ mallocFillTop .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
172
+
173
+ mallocFillButton = new Button (mallocFillTop , SWT .CHECK );
174
+ mallocFillButton .setText (Messages .getString ("MemcheckToolPage.Malloc_Fill" )); //$NON-NLS-1$
175
+ mallocFillButton .addSelectionListener (new SelectionAdapter () {
176
+ @ Override
177
+ public void widgetSelected (SelectionEvent e ) {
178
+ checkMallocFillEnablement ();
179
+ updateLaunchConfigurationDialog ();
180
+ }
181
+ });
182
+ mallocFillText = new Text (mallocFillTop , SWT .BORDER );
183
+ mallocFillText .setTextLimit (8 );
184
+ mallocFillText .addModifyListener (modifyListener );
185
+
186
+
187
+ Composite freeFillTop = new Composite (top , SWT .NONE );
188
+ GridLayout freeFillLayout = new GridLayout (2 , false );
189
+ freeFillTop .setLayout (freeFillLayout );
190
+ freeFillTop .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
191
+
192
+ freeFillButton = new Button (freeFillTop , SWT .CHECK );
193
+ freeFillButton .setText (Messages .getString ("MemcheckToolPage.Free_Fill" )); //$NON-NLS-1$
194
+ freeFillButton .addSelectionListener (new SelectionAdapter () {
195
+ @ Override
196
+ public void widgetSelected (SelectionEvent e ) {
197
+ checkFreeFillEnablement ();
198
+ updateLaunchConfigurationDialog ();
199
+ }
200
+ });
201
+ freeFillText = new Text (freeFillTop , SWT .BORDER );
202
+ mallocFillText .setTextLimit (8 );
203
+ freeFillText .addModifyListener (modifyListener );
204
+
205
+ Composite ignoreRangesTop = new Composite (top , SWT .NONE );
206
+ ignoreRangesTop .setLayout (new GridLayout (3 , false ));
207
+ ignoreRangesTop .setLayoutData (new GridData (SWT .BEGINNING , SWT .BEGINNING , false , false , 2 , 1 ));
208
+
209
+ Label ignoreRangesLabel = new Label (ignoreRangesTop , SWT .NONE );
210
+ ignoreRangesLabel .setText (Messages .getString ("MemcheckToolPage.Ignore_Ranges" )); //$NON-NLS-1$
211
+ ignoreRangesLabel .setLayoutData (new GridData (SWT .BEGINNING , SWT .BEGINNING , false , false ));
212
+
213
+ createIgnoreRangesControls (ignoreRangesTop );
214
+ }
215
+
216
+ private void createIgnoreRangesControls (Composite top ) {
217
+
218
+ ignoreRangesList = new List (top , SWT .BORDER | SWT .MULTI | SWT .H_SCROLL | SWT .V_SCROLL );
219
+ FontMetrics fm = MemcheckPlugin .getFontMetrics (ignoreRangesList );
220
+ ignoreRangesList .setLayoutData (new GridData (Dialog .convertWidthInCharsToPixels (fm , 50 ), Dialog .convertHeightInCharsToPixels (fm , 5 )));
221
+
222
+ Composite ignoreButtons = new Composite (top , SWT .NONE );
223
+ GridLayout ignoreButtonsLayout = new GridLayout ();
224
+ ignoreButtonsLayout .marginWidth = ignoreButtonsLayout .marginHeight = 0 ;
225
+ ignoreButtons .setLayout (ignoreButtonsLayout );
226
+ ignoreButtons .setLayoutData (new GridData (SWT .BEGINNING , SWT .BEGINNING , false , false ));
227
+
228
+ Button newButton = new Button (ignoreButtons , SWT .PUSH );
229
+ newButton .setText (Messages .getString ("MemcheckToolPage.New" )); //$NON-NLS-1$
230
+ newButton .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
231
+ newButton .addSelectionListener (new SelectionAdapter () {
232
+ public void widgetSelected (SelectionEvent e ) {
233
+ handleIgnoreNewButtonPressed ();
234
+ updateLaunchConfigurationDialog ();
235
+ }
236
+ });
237
+
238
+ Button removeButton = new Button (ignoreButtons , SWT .PUSH );
239
+ removeButton .setText (Messages .getString ("MemcheckToolPage.Remove" )); //$NON-NLS-1$
240
+ removeButton .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
241
+ removeButton .addSelectionListener (new SelectionAdapter () {
242
+ public void widgetSelected (SelectionEvent e ) {
243
+ handleIgnoreRemoveButtonPressed ();
244
+ updateLaunchConfigurationDialog ();
245
+ }
246
+ });
247
+
248
+ }
249
+
250
+ protected void handleIgnoreNewButtonPressed () {
251
+ InputDialog dialog = new InputDialog (getShell (), Messages .getString ("MemcheckToolPage.Ignore_Ranges" ), Messages .getString ("MemcheckToolPage.Range" ), "" , null ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
252
+ if (dialog .open () == Window .OK ) {
253
+ String function = dialog .getValue ();
254
+ if (!function .equals ("" )) { //$NON-NLS-1$
255
+ ignoreRangesList .add (function );
256
+ }
257
+ }
258
+ }
259
+
260
+ protected void handleIgnoreRemoveButtonPressed () {
261
+ int [] selections = ignoreRangesList .getSelectionIndices ();
262
+ ignoreRangesList .remove (selections );
147
263
}
148
264
149
265
private void checkAlignmentEnablement () {
150
266
alignmentSpinner .setEnabled (alignmentButton .getSelection ());
151
267
}
152
268
269
+ private void checkMallocFillEnablement () {
270
+ mallocFillText .setEnabled (mallocFillButton .getSelection ());
271
+ }
272
+
273
+ private void checkFreeFillEnablement () {
274
+ freeFillText .setEnabled (freeFillButton .getSelection ());
275
+ }
276
+
153
277
public String getName () {
154
278
return Messages .getString ("MemcheckToolPage.Memcheck_Options" ); //$NON-NLS-1$
155
279
}
156
280
281
+ @ SuppressWarnings ("unchecked" )
157
282
public void initializeFrom (ILaunchConfiguration configuration ) {
158
283
isInitializing = true ;
159
284
try {
@@ -172,6 +297,18 @@ public void initializeFrom(ILaunchConfiguration configuration) {
172
297
if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
173
298
trackOriginsButton .setSelection (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , MemcheckLaunchConstants .DEFAULT_MEMCHECK_TRACKORIGINS ));
174
299
}
300
+
301
+ showPossiblyLostButton .setSelection (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_POSSIBLY_LOST_BOOL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_POSSIBLY_LOST_BOOL ));
302
+ mallocFillButton .setSelection (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_MALLOCFILL_BOOL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_MALLOCFILL_BOOL ));
303
+ checkMallocFillEnablement ();
304
+ mallocFillText .setText (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_MALLOCFILL_VAL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_MALLOCFILL_VAL ));
305
+ freeFillButton .setSelection (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_FREEFILL_BOOL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_FREEFILL_BOOL ));
306
+ checkFreeFillEnablement ();
307
+ freeFillText .setText (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_FREEFILL_VAL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_FREEFILL_VAL ));
308
+ java .util .List <String > ignoreFns = configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_IGNORE_RANGES , MemcheckLaunchConstants .DEFAULT_MEMCHECK_IGNORE_RANGES );
309
+ ignoreRangesList .setItems (ignoreFns .toArray (new String [ignoreFns .size ()]));
310
+
311
+
175
312
} catch (CoreException e ) {
176
313
ex = e ;
177
314
}
@@ -192,6 +329,13 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
192
329
if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
193
330
configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , trackOriginsButton .getSelection ());
194
331
}
332
+
333
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_POSSIBLY_LOST_BOOL , showPossiblyLostButton .getSelection ());
334
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_MALLOCFILL_BOOL , mallocFillButton .getSelection ());
335
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_MALLOCFILL_VAL , mallocFillText .getText ());
336
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_FREEFILL_BOOL , freeFillButton .getSelection ());
337
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_FREEFILL_VAL , freeFillText .getText ());
338
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_IGNORE_RANGES , Arrays .asList (ignoreRangesList .getItems ()));
195
339
}
196
340
197
341
@ Override
@@ -244,6 +388,9 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
244
388
if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
245
389
configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , MemcheckLaunchConstants .DEFAULT_MEMCHECK_TRACKORIGINS );
246
390
}
391
+
392
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_POSSIBLY_LOST_BOOL , MemcheckLaunchConstants .DEFAULT_MEMCHECK_POSSIBLY_LOST_BOOL );
393
+ configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_IGNORE_RANGES , MemcheckLaunchConstants .DEFAULT_MEMCHECK_IGNORE_RANGES );
247
394
}
248
395
249
396
public void setValgrindVersion (Version ver ) {
@@ -314,4 +461,19 @@ public Button getTrackOriginsButton() {
314
461
return trackOriginsButton ;
315
462
}
316
463
464
+ public Button getShowPossiblyLostButton () {
465
+ return showPossiblyLostButton ;
466
+ }
467
+
468
+ public Text getMallocFillText () {
469
+ return mallocFillText ;
470
+ }
471
+
472
+ public Text getFreeFillText () {
473
+ return freeFillText ;
474
+ }
475
+
476
+ public List getIgnoreRangesList () {
477
+ return ignoreRangesList ;
478
+ }
317
479
}
0 commit comments