|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model.debug.jpda; |
|
38 |
| |
|
39 |
| import edu.rice.cs.drjava.model.OrderedDocumentRegion; |
|
40 |
| import edu.rice.cs.drjava.model.IDocumentRegion; |
|
41 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
42 |
| import edu.rice.cs.drjava.model.debug.Breakpoint; |
|
43 |
| import edu.rice.cs.drjava.model.debug.DebugException; |
|
44 |
| import edu.rice.cs.util.UnexpectedException; |
|
45 |
| |
|
46 |
| import java.awt.EventQueue; |
|
47 |
| import java.util.List; |
|
48 |
| import java.util.Vector; |
|
49 |
| import javax.swing.text.BadLocationException; |
|
50 |
| import javax.swing.text.Position; |
|
51 |
| |
|
52 |
| import com.sun.jdi.*; |
|
53 |
| import com.sun.jdi.request.*; |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| public class JPDABreakpoint extends DocumentDebugAction<BreakpointRequest> implements Breakpoint { |
|
59 |
| |
|
60 |
| private volatile Position _position; |
|
61 |
| private volatile Position _startPos; |
|
62 |
| private volatile Position _endPos; |
|
63 |
| |
|
64 |
| |
|
65 |
| private volatile OpenDefinitionsDocument _doc; |
|
66 |
| |
|
67 |
| |
|
68 |
0
| public JPDABreakpoint(OpenDefinitionsDocument doc, int offset, boolean isEnabled, JPDADebugger manager)
|
|
69 |
| throws DebugException { |
|
70 |
| |
|
71 |
0
| super(manager, doc, offset);
|
|
72 |
| |
|
73 |
0
| assert EventQueue.isDispatchThread();
|
|
74 |
0
| _doc = doc;
|
|
75 |
0
| try { _position = doc.createPosition(offset); }
|
|
76 |
0
| catch(BadLocationException e) { throw new UnexpectedException(e); }
|
|
77 |
| |
|
78 |
0
| _suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
|
|
79 |
0
| _isEnabled = isEnabled;
|
|
80 |
0
| update();
|
|
81 |
| |
|
82 |
0
| if (_manager != null && _manager.isReady()) {
|
|
83 |
| |
|
84 |
| |
|
85 |
0
| Vector<ReferenceType> refTypes = _manager.getReferenceTypes(_className, _manager.LLBreakpointLineNum(this));
|
|
86 |
0
| _initializeRequests(refTypes);
|
|
87 |
0
| setEnabled(isEnabled);
|
|
88 |
| } |
|
89 |
| } |
|
90 |
| |
|
91 |
| |
|
92 |
0
| public String getString() {
|
|
93 |
0
| try {
|
|
94 |
0
| int start = _startPos.getOffset();
|
|
95 |
0
| int end = _endPos.getOffset();
|
|
96 |
0
| int length = end - start;
|
|
97 |
0
| if (length <= 120) return _doc.getText(start, length);
|
|
98 |
0
| StringBuilder sb = new StringBuilder(124);
|
|
99 |
0
| sb.append(_doc.getText(start, 120)).append(" ...");
|
|
100 |
0
| return sb.toString();
|
|
101 |
| } |
|
102 |
0
| catch(BadLocationException e) { throw new UnexpectedException(e); }
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
0
| protected void _createRequests(Vector<ReferenceType> refTypes) throws DebugException {
|
|
119 |
0
| try {
|
|
120 |
0
| for (int i = 0; i < refTypes.size(); i++) {
|
|
121 |
0
| ReferenceType rt = refTypes.get(i);
|
|
122 |
| |
|
123 |
0
| if (! rt.isPrepared()) {
|
|
124 |
| |
|
125 |
0
| continue;
|
|
126 |
| } |
|
127 |
| |
|
128 |
| |
|
129 |
0
| List<Location> lines = rt.locationsOfLine(_manager.LLBreakpointLineNum(this));
|
|
130 |
0
| if (lines.size() == 0) {
|
|
131 |
| |
|
132 |
0
| setEnabled(false);
|
|
133 |
0
| throw new DebugException("Could not find line number: " + _lineNumber);
|
|
134 |
| } |
|
135 |
0
| Location loc = lines.get(0);
|
|
136 |
| |
|
137 |
0
| BreakpointRequest request = _manager.getEventRequestManager().createBreakpointRequest(loc);
|
|
138 |
0
| request.setEnabled(_isEnabled);
|
|
139 |
0
| _requests.add(request);
|
|
140 |
| } |
|
141 |
| } |
|
142 |
0
| catch (AbsentInformationException aie) { throw new DebugException("Could not find line number: " + aie); }
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
0
| public int getStartOffset() { return _startPos.getOffset(); }
|
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
0
| public int getEndOffset() { return _endPos.getOffset(); }
|
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
0
| public int getLineStartOffset() { return _startPos.getOffset(); }
|
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
0
| public int getLineEndOffset() { return _endPos.getOffset(); }
|
|
164 |
| |
|
165 |
| |
|
166 |
0
| public void update() {
|
|
167 |
0
| try {
|
|
168 |
0
| int offset = _position.getOffset();
|
|
169 |
0
| _startPos = _doc.createPosition(_doc._getLineStartPos(offset));
|
|
170 |
0
| _endPos = _doc.createPosition(_doc._getLineEndPos(offset));
|
|
171 |
0
| _lineNumber = _doc.getLineOfOffset(offset)+1;
|
|
172 |
| } |
|
173 |
0
| catch (BadLocationException ble) { throw new UnexpectedException(ble); }
|
|
174 |
| } |
|
175 |
| |
|
176 |
0
| public boolean isEmpty() { update(); return getStartOffset() == getEndOffset(); }
|
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
0
| public final boolean equals(Object o) {
|
|
193 |
0
| if (o == null || ! (o instanceof IDocumentRegion)) return false;
|
|
194 |
0
| update();
|
|
195 |
0
| IDocumentRegion r = (IDocumentRegion) o;
|
|
196 |
0
| return getDocument() == r.getDocument() && getStartOffset() == r.getStartOffset() && getEndOffset() == r.getEndOffset();
|
|
197 |
| } |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
0
| public int compareTo(OrderedDocumentRegion r) {
|
|
203 |
0
| int docRel = getDocument().compareTo(r.getDocument());
|
|
204 |
0
| if (docRel != 0) return docRel;
|
|
205 |
| |
|
206 |
| |
|
207 |
0
| assert getDocument() == r.getDocument();
|
|
208 |
0
| int end1 = getEndOffset();
|
|
209 |
0
| int end2 = r.getEndOffset();
|
|
210 |
0
| int endDiff = end1 - end2;
|
|
211 |
0
| if (endDiff != 0) return endDiff;
|
|
212 |
| |
|
213 |
0
| int start1 = getStartOffset();
|
|
214 |
0
| int start2 = r.getStartOffset();
|
|
215 |
0
| return start1 - start2;
|
|
216 |
| } |
|
217 |
| |
|
218 |
| |
|
219 |
0
| public int getLineNumber() {
|
|
220 |
0
| update();
|
|
221 |
0
| return _lineNumber;
|
|
222 |
| } |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
| |
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
0
| public void setEnabled(boolean isEnabled) {
|
|
232 |
0
| assert EventQueue.isDispatchThread();
|
|
233 |
0
| boolean old = _isEnabled;
|
|
234 |
0
| super.setEnabled(isEnabled);
|
|
235 |
0
| try {
|
|
236 |
0
| for(BreakpointRequest bpr: _requests) {
|
|
237 |
0
| bpr.setEnabled(isEnabled);
|
|
238 |
| } |
|
239 |
| } |
|
240 |
| catch(VMDisconnectedException vmde) { } |
|
241 |
0
| if (_isEnabled!=old) _manager.notifyBreakpointChange(this);
|
|
242 |
| } |
|
243 |
| |
|
244 |
0
| public String toString() {
|
|
245 |
0
| String cn = getClassName();
|
|
246 |
0
| if (_exactClassName != null) { cn = _exactClassName.replace('$', '.'); }
|
|
247 |
0
| if (_requests.size() > 0) {
|
|
248 |
| |
|
249 |
| |
|
250 |
0
| return "Breakpoint[class: " + cn +
|
|
251 |
| ", lineNumber: " + getLineNumber() + |
|
252 |
| ", method: " + _requests.get(0).location().method() + |
|
253 |
| ", codeIndex: " + _requests.get(0).location().codeIndex() + |
|
254 |
| ", numRefTypes: " + _requests.size() + "]"; |
|
255 |
| } |
|
256 |
| else { |
|
257 |
0
| return "Breakpoint[class: " + cn +
|
|
258 |
| ", lineNumber: " + getLineNumber() + "]"; |
|
259 |
| } |
|
260 |
| } |
|
261 |
| } |