|
28 | 28 | import java.net.Socket; |
29 | 29 | import java.util.HashMap; |
30 | 30 | import java.util.HashSet; |
31 | | -import java.util.Iterator; |
32 | 31 | import java.util.List; |
33 | 32 | import java.util.Map; |
34 | 33 | import java.util.Set; |
@@ -199,44 +198,95 @@ public synchronized void addBreakpoint(final IRubyBreakpoint breakpoint) { |
199 | 198 | return; |
200 | 199 | } |
201 | 200 | assert breakpoint != null : "breakpoint cannot be null"; |
202 | | - if (breakpoint.isEnabled()) { |
203 | | - try { |
204 | | - if (breakpoint instanceof IRubyLineBreakpoint) { |
205 | | - IRubyLineBreakpoint lineBreakpoint = (IRubyLineBreakpoint) breakpoint; |
206 | | - String command = commandFactory.createAddBreakpoint( |
207 | | - lineBreakpoint.getFilePath(), lineBreakpoint.getLineNumber()); |
208 | | - sendCommand(command); |
209 | | - Integer id = getReadersSupport().readAddedBreakpointNo(); |
210 | | - String condition = lineBreakpoint.getCondition(); |
211 | | - if (condition != null && supportsCondition) { |
212 | | - command = commandFactory.createSetCondition(id, condition); |
213 | | - if (command != null) { |
214 | | - sendCommand(command); |
215 | | - getReadersSupport().readConditionSet(); // read response |
216 | | - } else { |
217 | | - LOGGER.info("conditional breakpoints are not supported by backend"); |
218 | | - } |
219 | | - } |
220 | | - breakpointsIDs.put(id, lineBreakpoint); |
221 | | - } else if (breakpoint instanceof IRubyExceptionBreakpoint) { |
222 | | - IRubyExceptionBreakpoint excBreakpoint = (IRubyExceptionBreakpoint) breakpoint; |
223 | | - // just 're-enable' if contained in removedCatchpoints |
224 | | - if (!removedCatchpoints.remove(excBreakpoint.getException())) { |
225 | | - String command = commandFactory.createCatchOn(excBreakpoint); |
| 201 | + try { |
| 202 | + if (breakpoint instanceof IRubyLineBreakpoint) { |
| 203 | + IRubyLineBreakpoint lineBreakpoint = (IRubyLineBreakpoint) breakpoint; |
| 204 | + String command = commandFactory.createAddBreakpoint( |
| 205 | + lineBreakpoint.getFilePath(), lineBreakpoint.getLineNumber()); |
| 206 | + sendCommand(command); |
| 207 | + Integer id = getReadersSupport().readAddedBreakpointNo(); |
| 208 | + String condition = lineBreakpoint.getCondition(); |
| 209 | + if (condition != null && supportsCondition) { |
| 210 | + command = commandFactory.createSetCondition(id, condition); |
| 211 | + if (command != null) { |
226 | 212 | sendCommand(command); |
227 | | - getReadersSupport().readCatchpointSet(); // read response |
| 213 | + getReadersSupport().readConditionSet(); // read response |
| 214 | + } else { |
| 215 | + LOGGER.info("conditional breakpoints are not supported by backend"); |
228 | 216 | } |
| 217 | + } |
| 218 | + if (!breakpoint.isEnabled()) { |
| 219 | + disableBreakpoint(breakpoint); |
| 220 | + } |
| 221 | + breakpointsIDs.put(id, lineBreakpoint); |
| 222 | + } else if (breakpoint instanceof IRubyExceptionBreakpoint) { |
| 223 | + IRubyExceptionBreakpoint excBreakpoint = (IRubyExceptionBreakpoint) breakpoint; |
| 224 | + // just 're-enable' if contained in removedCatchpoints |
| 225 | + if (!removedCatchpoints.remove(excBreakpoint.getException())) { |
| 226 | + String command = commandFactory.createCatchOn(excBreakpoint); |
| 227 | + sendCommand(command); |
| 228 | + getReadersSupport().readCatchpointSet(); // read response |
| 229 | + } |
| 230 | + } else { |
| 231 | + throw new IllegalArgumentException("Unknown breakpoint type: " + breakpoint); |
| 232 | + } |
| 233 | + } catch (final RubyDebuggerException ex) { |
| 234 | + if (isReady()) { |
| 235 | + LOGGER.log(Level.WARNING, "Cannot add breakpoint to: " + getDebugTarget(), ex); |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + private void disableBreakpoint(final IRubyBreakpoint breakpoint) { |
| 241 | + LOGGER.fine("Disabling breakpoint: " + breakpoint); |
| 242 | + if (!isReady()) { |
| 243 | + LOGGER.fine("Session and/or debuggee is not ready, skipping addition of breakpoint: " + breakpoint); |
| 244 | + return; |
| 245 | + } |
| 246 | + try { |
| 247 | + if (breakpoint instanceof IRubyLineBreakpoint) { |
| 248 | + IRubyLineBreakpoint lineBreakpoint = (IRubyLineBreakpoint) breakpoint; |
| 249 | + Integer id = findBreakpointId(lineBreakpoint); |
| 250 | + String command = commandFactory.createDisableBreakpoint(id); |
| 251 | + if (command != null) { |
| 252 | + sendCommand(command); |
| 253 | + getReadersSupport().readDisabledBreakpointNo(id); |
229 | 254 | } else { |
230 | | - throw new IllegalArgumentException("Unknown breakpoint type: " + breakpoint); |
| 255 | + LOGGER.info("disabling breakpoints is nor supported by backend"); |
231 | 256 | } |
232 | | - } catch (final RubyDebuggerException ex) { |
233 | | - if (isReady()) { |
234 | | - LOGGER.log(Level.WARNING, "Cannot add breakpoint to: " + getDebugTarget(), ex); |
| 257 | + } else { |
| 258 | + removeBreakpoint(breakpoint); |
| 259 | + } |
| 260 | + } catch (RubyDebuggerException e) { |
| 261 | + LOGGER.log(Level.SEVERE, "Exception during disabling breakpoint.", e); |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + private void enableBreakpoint(final IRubyBreakpoint breakpoint) { |
| 266 | + LOGGER.fine("Enabling breakpoint: " + breakpoint); |
| 267 | + if (!isReady()) { |
| 268 | + LOGGER.fine("Session and/or debuggee is not ready, skipping addition of breakpoint: " + breakpoint); |
| 269 | + return; |
| 270 | + } |
| 271 | + try { |
| 272 | + if (breakpoint instanceof IRubyLineBreakpoint) { |
| 273 | + IRubyLineBreakpoint lineBreakpoint = (IRubyLineBreakpoint) breakpoint; |
| 274 | + Integer id = findBreakpointId(lineBreakpoint); |
| 275 | + String command = commandFactory.createEnableBreakpoint(id); |
| 276 | + if (command != null) { |
| 277 | + sendCommand(command); |
| 278 | + getReadersSupport().readEnabledBreakpointNo(id); |
| 279 | + } else { |
| 280 | + LOGGER.info("disabling breakpoints is nor supported by backend"); |
235 | 281 | } |
| 282 | + } else { |
| 283 | + addBreakpoint(breakpoint); |
236 | 284 | } |
| 285 | + } catch (RubyDebuggerException e) { |
| 286 | + LOGGER.log(Level.SEVERE, "Exception during enabling breakpoint.", e); |
237 | 287 | } |
238 | 288 | } |
239 | | - |
| 289 | + |
240 | 290 | public synchronized void removeBreakpoint(final IRubyBreakpoint breakpoint) { |
241 | 291 | removeBreakpoint(breakpoint, false); |
242 | 292 | } |
@@ -285,21 +335,25 @@ public synchronized void removeBreakpoint(final IRubyBreakpoint breakpoint, bool |
285 | 335 | /** |
286 | 336 | * Update the given breakpoint. Use when <em>enabled</em> property has |
287 | 337 | * changed. |
| 338 | + * @param breakpoint breakpoint to be updated |
288 | 339 | */ |
289 | | - public void updateBreakpoint(IRubyBreakpoint breakpoint) throws RubyDebuggerException { |
290 | | - removeBreakpoint(breakpoint, true); |
291 | | - addBreakpoint(breakpoint); |
| 340 | + public void updateBreakpoint(IRubyBreakpoint breakpoint) { |
| 341 | + if (breakpoint.isEnabled()) { |
| 342 | + enableBreakpoint(breakpoint); |
| 343 | + } else { |
| 344 | + disableBreakpoint(breakpoint); |
| 345 | + } |
292 | 346 | } |
293 | 347 |
|
294 | 348 | /** |
295 | 349 | * Find ID under which the given breakpoint is known in the current |
296 | 350 | * debugging session. |
297 | 351 | * |
| 352 | + * @param wantedBP breakpoint to search for |
298 | 353 | * @return found ID; might be <tt>null</tt> if none is found |
299 | 354 | */ |
300 | 355 | private synchronized Integer findBreakpointId(final IRubyLineBreakpoint wantedBP) { |
301 | | - for (Iterator<Map.Entry<Integer, IRubyLineBreakpoint>> it = breakpointsIDs.entrySet().iterator(); it.hasNext();) { |
302 | | - Map.Entry<Integer, IRubyLineBreakpoint> breakpointID = it.next(); |
| 356 | + for (Map.Entry<Integer, IRubyLineBreakpoint> breakpointID : breakpointsIDs.entrySet()) { |
303 | 357 | IRubyLineBreakpoint bp = breakpointID.getValue(); |
304 | 358 | int id = breakpointID.getKey(); |
305 | 359 | if (wantedBP.getFilePath().equals(bp.getFilePath()) && |
|
0 commit comments