| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. | 12 * the License. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 package com.google.dart.tools.debug.core.server; | 15 package com.google.dart.tools.debug.core.server; |
| 16 | 16 |
| 17 import com.google.dart.tools.core.DartCore; | 17 import com.google.dart.tools.core.DartCore; |
| 18 import com.google.dart.tools.core.internal.util.ResourceUtil; |
| 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; | 19 import com.google.dart.tools.debug.core.DartDebugCorePlugin; |
| 19 import com.google.dart.tools.debug.core.breakpoints.DartBreakpoint; | 20 import com.google.dart.tools.debug.core.breakpoints.DartBreakpoint; |
| 20 | 21 |
| 21 import org.eclipse.core.resources.IFile; | 22 import org.eclipse.core.resources.IFile; |
| 22 import org.eclipse.core.resources.IMarkerDelta; | 23 import org.eclipse.core.resources.IMarkerDelta; |
| 23 import org.eclipse.debug.core.DebugPlugin; | 24 import org.eclipse.debug.core.DebugPlugin; |
| 24 import org.eclipse.debug.core.IBreakpointListener; | 25 import org.eclipse.debug.core.IBreakpointListener; |
| 25 import org.eclipse.debug.core.model.IBreakpoint; | 26 import org.eclipse.debug.core.model.IBreakpoint; |
| 26 | 27 |
| 27 import java.io.File; | 28 import java.io.File; |
| 28 import java.io.IOException; | 29 import java.io.IOException; |
| 29 import java.net.URI; | 30 import java.net.URI; |
| 30 import java.util.ArrayList; | 31 import java.util.ArrayList; |
| 31 import java.util.Arrays; | 32 import java.util.Arrays; |
| 32 import java.util.HashMap; | 33 import java.util.HashMap; |
| 33 import java.util.Iterator; | 34 import java.util.Iterator; |
| 34 import java.util.List; | 35 import java.util.List; |
| 35 import java.util.Map; | 36 import java.util.Map; |
| 36 import java.util.Map.Entry; | 37 import java.util.Map.Entry; |
| 38 import java.util.concurrent.atomic.AtomicInteger; |
| 37 | 39 |
| 38 // TODO: handle removing deleted breakpoints | 40 // TODO: handle removing deleted breakpoints |
| 39 | 41 |
| 40 /** | 42 /** |
| 41 * This breakpoint manager serves to off-load some of the breakpoint logic from
ServerDebugTarget. | 43 * This breakpoint manager serves to off-load some of the breakpoint logic from
ServerDebugTarget. |
| 42 */ | 44 */ |
| 43 class ServerBreakpointManager implements IBreakpointListener { | 45 class ServerBreakpointManager implements IBreakpointListener { |
| 46 private class SetBreakpointHelper { |
| 47 final int NUM_URLS = 2; |
| 48 |
| 49 final VmIsolate isolate; |
| 50 final DartBreakpoint breakpoint; |
| 51 final int line; |
| 52 final AtomicInteger numErrors = new AtomicInteger(); |
| 53 |
| 54 public SetBreakpointHelper(VmIsolate isolate, DartBreakpoint breakpoint, int
line) { |
| 55 this.isolate = isolate; |
| 56 this.breakpoint = breakpoint; |
| 57 this.line = line; |
| 58 } |
| 59 |
| 60 void setBreakpoint(String url) throws IOException { |
| 61 // fail if no URL |
| 62 if (url == null) { |
| 63 if (numErrors.incrementAndGet() == NUM_URLS) { |
| 64 target.writeToStdout("No valid URL for: " + breakpoint); |
| 65 } |
| 66 return; |
| 67 } |
| 68 // try to set |
| 69 getConnection().setBreakpoint(isolate, url, line, new VmCallback<VmBreakpo
int>() { |
| 70 @Override |
| 71 public void handleResult(VmResult<VmBreakpoint> result) { |
| 72 if (result.isError()) { |
| 73 if (numErrors.incrementAndGet() == NUM_URLS) { |
| 74 String error = result.getError(); |
| 75 target.writeToStdout(error); |
| 76 } |
| 77 } else { |
| 78 addCreatedBreakpoint(breakpoint, result.getResult()); |
| 79 } |
| 80 } |
| 81 }); |
| 82 } |
| 83 } |
| 84 |
| 44 private ServerDebugTarget target; | 85 private ServerDebugTarget target; |
| 45 | 86 |
| 46 private VmIsolate mainIsolate; | 87 private VmIsolate mainIsolate; |
| 47 | 88 |
| 48 private List<IBreakpoint> ignoredBreakpoints = new ArrayList<IBreakpoint>(); | 89 private List<IBreakpoint> ignoredBreakpoints = new ArrayList<IBreakpoint>(); |
| 49 | 90 |
| 50 Map<IBreakpoint, List<VmBreakpoint>> createdBreakpoints = new HashMap<IBreakpo
int, List<VmBreakpoint>>(); | 91 Map<IBreakpoint, List<VmBreakpoint>> createdBreakpoints = new HashMap<IBreakpo
int, List<VmBreakpoint>>(); |
| 51 | 92 |
| 52 List<VmIsolate> liveIsolates = new ArrayList<VmIsolate>(); | 93 List<VmIsolate> liveIsolates = new ArrayList<VmIsolate>(); |
| 53 | 94 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 264 } |
| 224 | 265 |
| 225 if (!enabled) { | 266 if (!enabled) { |
| 226 return; | 267 return; |
| 227 } | 268 } |
| 228 | 269 |
| 229 try { | 270 try { |
| 230 VmInterruptResult interruptResult = pause ? getConnection().interruptCondi
tionally(isolate) | 271 VmInterruptResult interruptResult = pause ? getConnection().interruptCondi
tionally(isolate) |
| 231 : VmInterruptResult.createNoopResult(getConnection()); | 272 : VmInterruptResult.createNoopResult(getConnection()); |
| 232 | 273 |
| 233 for (final DartBreakpoint breakpoint : breakpoints) { | 274 for (DartBreakpoint breakpoint : breakpoints) { |
| 234 if (breakpoint.isBreakpointEnabled()) { | 275 if (breakpoint.isBreakpointEnabled()) { |
| 235 IFile file = breakpoint.getFile(); | 276 int line = breakpoint.getLine(); |
| 236 String url = null; | 277 SetBreakpointHelper helper = new SetBreakpointHelper(isolate, breakpoi
nt, line); |
| 237 | 278 // file path |
| 238 if (file != null) { | 279 String filePath = breakpoint.getActualFilePath(); |
| 239 url = getAbsoluteUrlForResource(file); | 280 if (filePath == null) { |
| 281 continue; |
| 240 } | 282 } |
| 241 | 283 // try package: URL |
| 242 int line = breakpoint.getLine(); | 284 { |
| 243 | 285 String url = getPackagesUrlForFilePath(filePath); |
| 244 if (url != null) { | 286 helper.setBreakpoint(url); |
| 245 getConnection().setBreakpoint(isolate, url, line, new VmCallback<VmB
reakpoint>() { | |
| 246 @Override | |
| 247 public void handleResult(VmResult<VmBreakpoint> result) { | |
| 248 if (!result.isError()) { | |
| 249 addCreatedBreakpoint(breakpoint, result.getResult()); | |
| 250 } | |
| 251 } | |
| 252 }); | |
| 253 } | 287 } |
| 254 | 288 // try file:// URL |
| 255 if (file != null) { | 289 { |
| 256 url = getPackagesUrlForResource(file); | 290 String url = getAbsoluteUrlForFilePath(filePath); |
| 257 } | 291 helper.setBreakpoint(url); |
| 258 | |
| 259 if (url != null) { | |
| 260 getConnection().setBreakpoint(isolate, url, line, new VmCallback<VmB
reakpoint>() { | |
| 261 @Override | |
| 262 public void handleResult(VmResult<VmBreakpoint> result) { | |
| 263 if (!result.isError()) { | |
| 264 addCreatedBreakpoint(breakpoint, result.getResult()); | |
| 265 } | |
| 266 } | |
| 267 }); | |
| 268 } | 292 } |
| 269 } | 293 } |
| 270 } | 294 } |
| 271 | 295 |
| 272 interruptResult.resume(); | 296 interruptResult.resume(); |
| 273 } catch (IOException exception) { | 297 } catch (IOException exception) { |
| 274 DartDebugCorePlugin.logError(exception); | 298 DartDebugCorePlugin.logError(exception); |
| 275 } | 299 } |
| 276 } | 300 } |
| 277 | 301 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 295 List<VmBreakpoint> breakpoints = entry.getValue(); | 319 List<VmBreakpoint> breakpoints = entry.getValue(); |
| 296 for (Iterator<VmBreakpoint> bpIter = breakpoints.iterator(); bpIter.hasNex
t();) { | 320 for (Iterator<VmBreakpoint> bpIter = breakpoints.iterator(); bpIter.hasNex
t();) { |
| 297 VmBreakpoint breakpoint = bpIter.next(); | 321 VmBreakpoint breakpoint = bpIter.next(); |
| 298 if (breakpoint.getIsolate() == isolate) { | 322 if (breakpoint.getIsolate() == isolate) { |
| 299 bpIter.remove(); | 323 bpIter.remove(); |
| 300 } | 324 } |
| 301 } | 325 } |
| 302 } | 326 } |
| 303 } | 327 } |
| 304 | 328 |
| 305 private String getAbsoluteUrlForResource(IFile file) { | 329 private String getAbsoluteUrlForFilePath(String filePath) { |
| 306 return file.getLocation().toFile().toURI().toString(); | 330 return new File(filePath).toURI().toString(); |
| 307 } | 331 } |
| 308 | 332 |
| 309 private VmConnection getConnection() { | 333 private VmConnection getConnection() { |
| 310 return target.getConnection(); | 334 return target.getConnection(); |
| 311 } | 335 } |
| 312 | 336 |
| 313 private String getPackagesUrlForResource(IFile file) { | 337 private String getPackagesUrlForFilePath(String filePath) { |
| 314 String locationUrl = file.getLocation().toFile().toURI().toString(); | 338 File javaFile = new File(filePath); |
| 339 IFile resourceFile = ResourceUtil.getFile(javaFile); |
| 340 if (resourceFile == null) { |
| 341 return null; |
| 342 } |
| 343 String locationUrl = resourceFile.getLocation().toFile().toURI().toString(); |
| 315 | 344 |
| 316 int index = locationUrl.indexOf(DartCore.PACKAGES_DIRECTORY_URL); | 345 int index = locationUrl.indexOf(DartCore.PACKAGES_DIRECTORY_URL); |
| 317 | 346 |
| 318 if (index != -1) { | 347 if (index != -1) { |
| 319 locationUrl = DartCore.PACKAGE_SCHEME_SPEC | 348 locationUrl = DartCore.PACKAGE_SCHEME_SPEC |
| 320 + locationUrl.substring(index + DartCore.PACKAGES_DIRECTORY_URL.length
()); | 349 + locationUrl.substring(index + DartCore.PACKAGES_DIRECTORY_URL.length
()); |
| 321 | 350 |
| 322 return locationUrl; | 351 return locationUrl; |
| 323 } | 352 } |
| 324 | 353 |
| 325 index = locationUrl.lastIndexOf(DartCore.LIB_URL_PATH); | 354 index = locationUrl.lastIndexOf(DartCore.LIB_URL_PATH); |
| 326 | 355 |
| 327 if (index != -1) { | 356 if (index != -1) { |
| 328 String path = file.getLocation().toString(); | 357 String path = resourceFile.getLocation().toString(); |
| 329 path = path.substring(0, path.lastIndexOf(DartCore.LIB_URL_PATH)); | 358 path = path.substring(0, path.lastIndexOf(DartCore.LIB_URL_PATH)); |
| 330 File packagesDir = new File(path, DartCore.PACKAGES_DIRECTORY_NAME); | 359 File packagesDir = new File(path, DartCore.PACKAGES_DIRECTORY_NAME); |
| 331 | 360 |
| 332 if (packagesDir.exists()) { | 361 if (packagesDir.exists()) { |
| 333 String packageName = DartCore.getSelfLinkedPackageName(file); | 362 String packageName = DartCore.getSelfLinkedPackageName(resourceFile); |
| 334 | 363 |
| 335 if (packageName != null) { | 364 if (packageName != null) { |
| 336 locationUrl = DartCore.PACKAGE_SCHEME_SPEC + packageName + "/" | 365 locationUrl = DartCore.PACKAGE_SCHEME_SPEC + packageName + "/" |
| 337 + locationUrl.substring(index + DartCore.LIB_URL_PATH.length()); | 366 + locationUrl.substring(index + DartCore.LIB_URL_PATH.length()); |
| 338 | 367 |
| 339 return locationUrl; | 368 return locationUrl; |
| 340 } | 369 } |
| 341 } | 370 } |
| 342 } | 371 } |
| 343 | 372 |
| 344 return null; | 373 return null; |
| 345 } | 374 } |
| 346 | 375 |
| 347 private boolean supportsBreakpoint(IBreakpoint breakpoint) { | 376 private boolean supportsBreakpoint(IBreakpoint breakpoint) { |
| 348 return target.supportsBreakpoint(breakpoint); | 377 return target.supportsBreakpoint(breakpoint); |
| 349 } | 378 } |
| 350 | |
| 351 } | 379 } |
| OLD | NEW |