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

Collapse All | Expand All

(-)plugin.xml (-14 / +13 lines)
Lines 724-729 Link Here
724
         </action>
724
         </action>
725
      </objectContribution>
725
      </objectContribution>
726
      <objectContribution
726
      <objectContribution
727
            objectClass="org.eclipse.cdt.debug.internal.core.IWatchpointTarget"
728
            id="org.eclipse.cdt.debug.ui.WatchpointActions">
729
         <action
730
               class="org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointOnVariableActionDelegate"
731
               enablesFor="1"
732
               icon="icons/elcl16/watchpoint_co.gif"
733
               id="org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointOnVariableActionDelegate"
734
               label="%AddWatchpoint.label"
735
               menubarPath="additions"
736
               tooltip="%AddWatchpoint.tooltip">
737
         </action>
738
      </objectContribution>
739
      <objectContribution
727
            objectClass="org.eclipse.cdt.core.model.IVariable"
740
            objectClass="org.eclipse.cdt.core.model.IVariable"
728
            id="org.eclipse.cdt.debug.ui.WatchpointActions">
741
            id="org.eclipse.cdt.debug.ui.WatchpointActions">
729
         <action
742
         <action
Lines 808-827 Link Here
808
                  class="org.eclipse.cdt.debug.core.model.ICVariable">
821
                  class="org.eclipse.cdt.debug.core.model.ICVariable">
809
            </selection>
822
            </selection>
810
         </action>
823
         </action>
811
         <action
812
               class="org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointOnVariableActionDelegate"
813
               enablesFor="1"
814
               icon="icons/elcl16/watchpoint_co.gif"
815
               id="org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointOnVariableActionDelegate"
816
               label="%AddWatchpoint.label"
817
               menubarPath="additions"
818
               tooltip="%AddWatchpoint.tooltip">
819
               <enablement>
820
                  <pluginState
821
                     value="activated"
822
                     id="org.eclipse.cdt.debug.ui"/>
823
               </enablement>
824
         </action>
825
      </viewerContribution>
824
      </viewerContribution>
826
      <viewerContribution
825
      <viewerContribution
827
            targetID="org.eclipse.debug.ui.RegisterView"
826
            targetID="org.eclipse.debug.ui.RegisterView"
(-)src/org/eclipse/cdt/debug/internal/ui/actions/AddWatchpointOnVariableActionDelegate.java (-44 / +74 lines)
Lines 11-76 Link Here
11
package org.eclipse.cdt.debug.internal.ui.actions;
11
package org.eclipse.cdt.debug.internal.ui.actions;
12
12
13
13
14
import org.eclipse.cdt.debug.internal.core.model.CVariable;
14
import org.eclipse.cdt.debug.internal.core.IWatchpointTarget;
15
import org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointDialog;
16
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
15
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
17
import org.eclipse.debug.core.DebugException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.TreeSelection;
22
import org.eclipse.jface.viewers.TreeSelection;
22
import org.eclipse.jface.window.Window;
23
import org.eclipse.jface.window.Window;
23
import org.eclipse.ui.IActionDelegate;
24
import org.eclipse.ui.IObjectActionDelegate;
24
import org.eclipse.ui.IObjectActionDelegate;
25
import org.eclipse.ui.IWorkbenchPart;
25
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.progress.WorkbenchJob;
26
27
27
28
/**
28
public class AddWatchpointOnVariableActionDelegate extends AddWatchpointActionDelegate {
29
 * Invoked when user right clicks on an element in the Variables or Expressions
30
 * view and selects 'Add Watchpoint (C/C++)'
31
 */
32
public class AddWatchpointOnVariableActionDelegate extends AddWatchpointActionDelegate implements IObjectActionDelegate {
29
33
30
	/**
34
	/**
31
	 * Constructor for Action1.
35
	 * The target variable/expression
36
	 */
37
	private IWatchpointTarget fVar;
38
	
39
	/**
40
	 * Constructor
32
	 */
41
	 */
33
	public AddWatchpointOnVariableActionDelegate() {
42
	public AddWatchpointOnVariableActionDelegate() {
34
		super();
43
		super();
35
	}
44
	}
36
45
37
	/**
46
	/* (non-Javadoc)
38
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
47
	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
39
	 */
48
	 */
40
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {}
49
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
50
		// Don't care. Our logic is agnostic to the view we're invoked from.
51
	}
41
52
42
	/**
53
	/* (non-Javadoc)
43
	 * @see IActionDelegate#run(IAction)
54
	 * @see org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointActionDelegate#run(org.eclipse.jface.action.IAction)
44
	 */
55
	 */
45
	public void run(IAction action) {
56
	public void run(IAction action) {
46
		IStructuredSelection selection = getSelection();
57
		if (fVar == null) {
47
		
48
		if (selection == null || selection.isEmpty()) {
49
			return;
58
			return;
50
		}
59
		}
51
		
60
		
52
		Object obj = ((TreeSelection)selection).getFirstElement();
61
		final String expr = fVar.getExpression();
53
		if (obj != null && obj instanceof CVariable) {
62
		if (expr == null) {
54
			CVariable var = (CVariable)obj;
63
			assert false : "how are we getting an empty expression?"; //$NON-NLS-1$
55
64
			return;
56
			String expr = "";
57
			 
58
			try {
59
				expr = var.getExpressionString();
60
			} catch (DebugException e) {}
61
			 
62
			AddWatchpointDialog dlg = new AddWatchpointDialog(CDebugUIPlugin.getActiveWorkbenchShell(), 
63
					getMemorySpaceManagement()); //$NON-NLS-1$
64
			dlg.setExpression(expr);
65
			dlg.initializeRange(false, Integer.toString(var.sizeof()));
66
			if (dlg.open() == Window.OK) {
67
				addWatchpoint(dlg.getWriteAccess(), dlg.getReadAccess(), dlg.getExpression(), dlg.getMemorySpace(), dlg.getRange());
68
			}
69
		}
65
		}
66
67
		// Getting the size of the variable/expression is an asynchronous
68
		// operation...or at least the API is (the CDI implementation reacts
69
		// synchronously)
70
		final IWatchpointTarget.GetSizeRequest request = new IWatchpointTarget.GetSizeRequest() {
71
			public void done() {
72
				// Now that we have the size, put up a dialog to create the watchpoint
73
				final int size = getSize();
74
				assert size > 0 : "unexpected variale/expression size"; //$NON-NLS-1$
75
				WorkbenchJob job = new WorkbenchJob("open watchpoint dialog") { //$NON-NLS-1$
76
					@Override
77
					public IStatus runInUIThread(IProgressMonitor monitor) {
78
						AddWatchpointDialog dlg = new AddWatchpointDialog(CDebugUIPlugin.getActiveWorkbenchShell(), 
79
								getMemorySpaceManagement());
80
						dlg.setExpression(expr);
81
						dlg.initializeRange(false, Integer.toString(size));
82
						if (dlg.open() == Window.OK) {
83
							addWatchpoint(dlg.getWriteAccess(), dlg.getReadAccess(), dlg.getExpression(), dlg.getMemorySpace(), dlg.getRange());
84
						}
85
						return Status.OK_STATUS;
86
					}
87
				};
88
				job.setSystem(true);
89
				job.schedule();
90
			}
91
		};
92
		fVar.getSize(request);
70
	}
93
	}
71
	
94
72
	/**
95
	/**
73
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
96
	 * Record the target variable/expression.
97
	 * 
98
	 * @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
99
	 *      org.eclipse.jface.viewers.ISelection)
74
	 */
100
	 */
75
	public void selectionChanged(IAction action, ISelection selection) {
101
	public void selectionChanged(IAction action, ISelection selection) {
76
		if (selection == null || selection.isEmpty()) {
102
		if (selection == null || selection.isEmpty()) {
Lines 79-94 Link Here
79
		}
105
		}
80
		if (selection instanceof TreeSelection) {
106
		if (selection instanceof TreeSelection) {
81
			Object obj = ((TreeSelection)selection).getFirstElement();
107
			Object obj = ((TreeSelection)selection).getFirstElement();
82
			if (obj != null && obj instanceof CVariable) {
108
			action.setEnabled(obj instanceof IWatchpointTarget);
83
				action.setEnabled(true);
109
			if (obj instanceof IWatchpointTarget) {
84
			} else {
110
				fVar = (IWatchpointTarget)obj;
85
				action.setEnabled(false);
111
				return;
86
			}
112
			}
113
			assert false : "action installed in unexpected type of object"; //$NON-NLS-1$
87
		}
114
		}
115
		else if (selection instanceof StructuredSelection) {
116
			// Not sure why, but sometimes we get an extraneous empty StructuredSelection. Seems harmless enough
117
			assert ((StructuredSelection)selection).getFirstElement() == null : "action installed in unexpected type of view/part"; //$NON-NLS-1$
118
		}
119
		else {
120
			assert false : "action installed in unexpected type of view/part"; //$NON-NLS-1$
121
		}
122
		action.setEnabled(false);
88
	}
123
	}
89
90
	private IStructuredSelection getSelection() {
91
		return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection();
92
	}
93
94
}
124
}
(-)src/org/eclipse/cdt/debug/internal/ui/disassembly/dsf/IDisassemblyRetrieval.java (-44 / +3 lines)
Lines 14-70 Link Here
14
import java.math.BigInteger;
14
import java.math.BigInteger;
15
15
16
import org.eclipse.cdt.debug.core.model.IDisassemblyBlock;
16
import org.eclipse.cdt.debug.core.model.IDisassemblyBlock;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.cdt.debug.internal.core.CRequest;
18
import org.eclipse.debug.core.IRequest;
19
import org.eclipse.debug.core.model.IStackFrame;
18
import org.eclipse.debug.core.model.IStackFrame;
20
19
21
/**
20
/**
22
 */
21
 */
23
public interface IDisassemblyRetrieval {
22
public interface IDisassemblyRetrieval {
24
	/**
25
	 */
26
	public static class Request implements IRequest {
27
		private IStatus fStatus;
28
		private boolean fCanceled;
29
		/*
30
		 * @see org.eclipse.debug.core.IRequest#cancel()
31
		 */
32
		public void cancel() {
33
			fCanceled= true;
34
		}
35
36
		/*
37
		 * @see org.eclipse.debug.core.IRequest#done()
38
		 */
39
		public void done() {
40
		}
41
42
		/*
43
		 * @see org.eclipse.debug.core.IRequest#getStatus()
44
		 */
45
		public IStatus getStatus() {
46
			return fStatus;
47
		}
48
49
		/*
50
		 * @see org.eclipse.debug.core.IRequest#isCanceled()
51
		 */
52
		public boolean isCanceled() {
53
			return fCanceled;
54
		}
55
56
		/*
57
		 * @see org.eclipse.debug.core.IRequest#setStatus(org.eclipse.core.runtime.IStatus)
58
		 */
59
		public void setStatus(IStatus status) {
60
			fStatus= status;
61
		}
62
63
	}
64
23
65
	/**
24
	/**
66
	 */
25
	 */
67
	public static class AddressRequest extends Request {
26
	public static class AddressRequest extends CRequest {
68
		private BigInteger fAddress;
27
		private BigInteger fAddress;
69
		/**
28
		/**
70
		 * @return the address
29
		 * @return the address
Lines 81-87 Link Here
81
		}
40
		}
82
	}
41
	}
83
42
84
	public static class DisassemblyRequest extends Request {
43
	public static class DisassemblyRequest extends CRequest {
85
		IDisassemblyBlock fDisassemblyBlock;
44
		IDisassemblyBlock fDisassemblyBlock;
86
45
87
		/**
46
		/**
(-)src/org/eclipse/cdt/dsf/debug/ui/viewmodel/variable/VariableVMNode.java (-3 / +45 lines)
Lines 17-22 Link Here
17
import java.util.Map;
17
import java.util.Map;
18
import java.util.concurrent.RejectedExecutionException;
18
import java.util.concurrent.RejectedExecutionException;
19
19
20
import org.eclipse.cdt.debug.internal.core.IWatchpointTarget;
20
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
21
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
21
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
22
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor;
22
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
23
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
Lines 134-140 Link Here
134
     */    
135
     */    
135
    private final IElementLabelProvider fLabelProvider;
136
    private final IElementLabelProvider fLabelProvider;
136
137
137
    public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext  {
138
    public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext, IWatchpointTarget  {
138
        
139
        
139
        private IExpression fExpression;
140
        private IExpression fExpression;
140
        
141
        
Lines 146-153 Link Here
146
            fExpression = expression;
147
            fExpression = expression;
147
        }
148
        }
148
        
149
        
149
        @Override
150
        @SuppressWarnings("rawtypes")
150
        @SuppressWarnings("rawtype") 
151
		@Override
151
        public Object getAdapter(Class adapter) {
152
        public Object getAdapter(Class adapter) {
152
            if (fExpression != null && adapter.isAssignableFrom(fExpression.getClass())) {
153
            if (fExpression != null && adapter.isAssignableFrom(fExpression.getClass())) {
153
                return fExpression;
154
                return fExpression;
Lines 172-177 Link Here
172
        public int hashCode() {
173
        public int hashCode() {
173
            return super.hashCode() + (fExpression != null ? fExpression.hashCode() : 0);
174
            return super.hashCode() + (fExpression != null ? fExpression.hashCode() : 0);
174
        }
175
        }
176
177
		/* (non-Javadoc)
178
		 * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getExpression()
179
		 */
180
		public String getExpression() {
181
			final IExpressionDMContext exprDmc = DMContexts.getAncestorOfType(getDMContext(), IExpressionDMContext.class);
182
			if (exprDmc != null) {
183
				return exprDmc.getExpression();
184
			}
185
								
186
			return ""; //$NON-NLS-1$
187
		}
188
189
		/* (non-Javadoc)
190
		 * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getSize()
191
		 */
192
		public void getSize(final IWatchpointTarget.GetSizeRequest request) {
193
			final IExpressionDMContext exprDmc = DMContexts.getAncestorOfType(getDMContext(), IExpressionDMContext.class);
194
			if (exprDmc != null) {
195
	            getSession().getExecutor().execute(new Runnable() {
196
	                public void run() {
197
	                    final IExpressions expressionService = getServicesTracker().getService(IExpressions.class);
198
	                    if (expressionService != null) {
199
	                    	final DataRequestMonitor<IExpressionDMAddress> drm = new DataRequestMonitor<IExpressionDMAddress>(getSession().getExecutor(), null) {
200
                                @Override
201
								public void handleSuccess() {
202
                                    request.setSize(getData().getSize());
203
                                    request.done();
204
                                }
205
	                    	};
206
	                    	
207
	                        expressionService.getExpressionAddressData(exprDmc, drm);
208
	                    }
209
	                }
210
	            });
211
			}
212
			else {
213
				request.setSize(-1);
214
				request.done();
215
			}
216
		}
175
    }
217
    }
176
    
218
    
177
    protected class VariableExpressionFactory implements IWatchExpressionFactoryAdapter2 {
219
    protected class VariableExpressionFactory implements IWatchExpressionFactoryAdapter2 {

Return to bug 248606