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

(-)src/org/eclipse/cdt/debug/internal/core/CRequest.java (+48 lines)
Added Link Here
1
package org.eclipse.cdt.debug.internal.core;
2
3
import org.eclipse.core.runtime.IStatus;
4
import org.eclipse.debug.core.IRequest;
5
6
/**
7
 * Base class for request objects used in asynchronous calls in base CDT
8
 * (non-DSF). This is used in base features that delegate a task to a backend
9
 * that is either DSF or CDI. Since DSF is highly asynchronous, the base logic
10
 * has to use asynchronous APIs.
11
 */
12
public class CRequest implements IRequest {
13
	private IStatus fStatus;
14
	private boolean fCanceled;
15
	/*
16
	 * @see org.eclipse.debug.core.IRequest#cancel()
17
	 */
18
	public void cancel() {
19
		fCanceled= true;
20
	}
21
22
	/*
23
	 * @see org.eclipse.debug.core.IRequest#done()
24
	 */
25
	public void done() {
26
	}
27
28
	/*
29
	 * @see org.eclipse.debug.core.IRequest#getStatus()
30
	 */
31
	public IStatus getStatus() {
32
		return fStatus;
33
	}
34
35
	/*
36
	 * @see org.eclipse.debug.core.IRequest#isCanceled()
37
	 */
38
	public boolean isCanceled() {
39
		return fCanceled;
40
	}
41
42
	/*
43
	 * @see org.eclipse.debug.core.IRequest#setStatus(org.eclipse.core.runtime.IStatus)
44
	 */
45
	public void setStatus(IStatus status) {
46
		fStatus= status;
47
	}
48
}
(-)src/org/eclipse/cdt/debug/internal/core/IWatchpointTarget.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Freescale Semiconductor 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
 *     Freescale Semiconductor - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.cdt.debug.internal.core;
12
13
/**
14
 * View model types for which the "Add Watchpoint (C/C++)" action is applicable
15
 * should implement this interface. The action is a popupMenu/objectContribution
16
 * that targets this type.
17
 */
18
public interface IWatchpointTarget {
19
20
	/** IRequest object used in the asynchronous method {@link IWatchpointTarget#getSize()} */
21
	static class GetSizeRequest extends CRequest {
22
		int fSize;
23
24
		public int getSize() {
25
			return fSize;
26
		}
27
28
		public void setSize(int size) {
29
			fSize = size;
30
		}
31
	};
32
	
33
	/**
34
	 * Get the expression or the name of the variable
35
	 */
36
	String getExpression();
37
38
	/**
39
	 * Asynchronous method to retrieve the size of the variable/expression, in
40
	 * bytes.
41
	 * 
42
	 * @param request
43
	 *            the async request object
44
	 */
45
	void getSize(GetSizeRequest request);
46
}
(-)src/org/eclipse/cdt/debug/internal/core/model/CVariable.java (-1 / +22 lines)
Lines 33-38 Link Here
33
import org.eclipse.cdt.debug.core.model.ICType;
33
import org.eclipse.cdt.debug.core.model.ICType;
34
import org.eclipse.cdt.debug.core.model.ICValue;
34
import org.eclipse.cdt.debug.core.model.ICValue;
35
import org.eclipse.cdt.debug.internal.core.CSettingsManager;
35
import org.eclipse.cdt.debug.internal.core.CSettingsManager;
36
import org.eclipse.cdt.debug.internal.core.IWatchpointTarget;
36
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.debug.core.DebugEvent;
38
import org.eclipse.debug.core.DebugEvent;
38
import org.eclipse.debug.core.DebugException;
39
import org.eclipse.debug.core.DebugException;
Lines 72-78 Link Here
72
/**
73
/**
73
 * Represents a variable in the CDI model.
74
 * Represents a variable in the CDI model.
74
 */
75
 */
75
public abstract class CVariable extends AbstractCVariable implements ICDIEventListener {
76
public abstract class CVariable extends AbstractCVariable implements ICDIEventListener, IWatchpointTarget {
76
77
77
	interface IInternalVariable {
78
	interface IInternalVariable {
78
		IInternalVariable createShadow( int start, int length ) throws DebugException;
79
		IInternalVariable createShadow( int start, int length ) throws DebugException;
Lines 878-881 Link Here
878
			// even if the initial setup fails, we still want the complete creation to be successful
879
			// even if the initial setup fails, we still want the complete creation to be successful
879
		}
880
		}
880
	}
881
	}
882
	
883
	/* (non-Javadoc)
884
	 * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getExpression()
885
	 */
886
	public String getExpression() {
887
		try {
888
			return getExpressionString();
889
		} catch (DebugException e) {
890
			return ""; //$NON-NLS-1$
891
		}
892
	}
893
	
894
	/* (non-Javadoc)
895
	 * @see org.eclipse.cdt.debug.internal.core.IWatchpointTarget#getSize()
896
	 */
897
	public void getSize(IWatchpointTarget.GetSizeRequest request) {
898
		// CDI has synchronous APIs, so this is easy...
899
		request.setSize(sizeof());
900
		request.done();
901
	}
881
}
902
}
(-)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
		/**

Return to bug 248606