1010 *******************************************************************************/
1111package org .eclipse .linuxtools .internal .valgrind .memcheck ;
1212
13+ import java .util .Arrays ;
14+
1315import org .eclipse .core .runtime .CoreException ;
1416import org .eclipse .debug .core .ILaunchConfiguration ;
1517import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
1618import 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 ;
1722import org .eclipse .linuxtools .valgrind .launch .IValgrindToolPage ;
1823import org .eclipse .osgi .util .NLS ;
1924import org .eclipse .swt .SWT ;
2227import org .eclipse .swt .events .SelectionAdapter ;
2328import org .eclipse .swt .events .SelectionEvent ;
2429import org .eclipse .swt .events .SelectionListener ;
30+ import org .eclipse .swt .graphics .FontMetrics ;
2531import org .eclipse .swt .layout .GridData ;
2632import org .eclipse .swt .layout .GridLayout ;
2733import org .eclipse .swt .widgets .Button ;
2834import org .eclipse .swt .widgets .Combo ;
2935import org .eclipse .swt .widgets .Composite ;
3036import org .eclipse .swt .widgets .Label ;
37+ import org .eclipse .swt .widgets .List ;
3138import org .eclipse .swt .widgets .Spinner ;
39+ import org .eclipse .swt .widgets .Text ;
3240import org .osgi .framework .Version ;
3341
3442public class MemcheckToolPage extends AbstractLaunchConfigurationTab implements IValgrindToolPage {
@@ -50,6 +58,13 @@ public class MemcheckToolPage extends AbstractLaunchConfigurationTab implements
5058 // VG >= 3.4.0
5159 protected Button trackOriginsButton ;
5260
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+
5368 protected boolean isInitializing = false ;
5469 protected Version valgrindVersion ;
5570 protected CoreException ex = null ;
@@ -144,16 +159,126 @@ public void widgetSelected(SelectionEvent e) {
144159 alignmentSpinner .setMinimum (0 );
145160 alignmentSpinner .setMaximum (4096 );
146161 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 );
147263 }
148264
149265 private void checkAlignmentEnablement () {
150266 alignmentSpinner .setEnabled (alignmentButton .getSelection ());
151267 }
152268
269+ private void checkMallocFillEnablement () {
270+ mallocFillText .setEnabled (mallocFillButton .getSelection ());
271+ }
272+
273+ private void checkFreeFillEnablement () {
274+ freeFillText .setEnabled (freeFillButton .getSelection ());
275+ }
276+
153277 public String getName () {
154278 return Messages .getString ("MemcheckToolPage.Memcheck_Options" ); //$NON-NLS-1$
155279 }
156280
281+ @ SuppressWarnings ("unchecked" )
157282 public void initializeFrom (ILaunchConfiguration configuration ) {
158283 isInitializing = true ;
159284 try {
@@ -172,6 +297,18 @@ public void initializeFrom(ILaunchConfiguration configuration) {
172297 if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
173298 trackOriginsButton .setSelection (configuration .getAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , MemcheckLaunchConstants .DEFAULT_MEMCHECK_TRACKORIGINS ));
174299 }
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+
175312 } catch (CoreException e ) {
176313 ex = e ;
177314 }
@@ -192,6 +329,13 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
192329 if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
193330 configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , trackOriginsButton .getSelection ());
194331 }
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 ()));
195339 }
196340
197341 @ Override
@@ -244,6 +388,9 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
244388 if (valgrindVersion == null || valgrindVersion .compareTo (VER_3_4_0 ) >= 0 ) {
245389 configuration .setAttribute (MemcheckLaunchConstants .ATTR_MEMCHECK_TRACKORIGINS , MemcheckLaunchConstants .DEFAULT_MEMCHECK_TRACKORIGINS );
246390 }
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 );
247394 }
248395
249396 public void setValgrindVersion (Version ver ) {
@@ -314,4 +461,19 @@ public Button getTrackOriginsButton() {
314461 return trackOriginsButton ;
315462 }
316463
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+ }
317479}
0 commit comments