Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/dartium/BreakpointManager.java

Issue 126303002: Version 1.1.0-dev.5.3 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, 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.dartium; 15 package com.google.dart.tools.debug.core.dartium;
16 16
17 import com.google.common.annotations.VisibleForTesting;
17 import com.google.dart.tools.core.DartCore; 18 import com.google.dart.tools.core.DartCore;
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 import com.google.dart.tools.debug.core.util.IResourceResolver; 21 import com.google.dart.tools.debug.core.util.IResourceResolver;
21 import com.google.dart.tools.debug.core.webkit.WebkitBreakpoint; 22 import com.google.dart.tools.debug.core.webkit.WebkitBreakpoint;
22 import com.google.dart.tools.debug.core.webkit.WebkitCallback; 23 import com.google.dart.tools.debug.core.webkit.WebkitCallback;
23 import com.google.dart.tools.debug.core.webkit.WebkitLocation; 24 import com.google.dart.tools.debug.core.webkit.WebkitLocation;
24 import com.google.dart.tools.debug.core.webkit.WebkitResult; 25 import com.google.dart.tools.debug.core.webkit.WebkitResult;
25 import com.google.dart.tools.debug.core.webkit.WebkitScript; 26 import com.google.dart.tools.debug.core.webkit.WebkitScript;
26 27
27 import org.eclipse.core.resources.IContainer; 28 import org.eclipse.core.resources.IContainer;
28 import org.eclipse.core.resources.IFile; 29 import org.eclipse.core.resources.IFile;
29 import org.eclipse.core.resources.IMarkerDelta; 30 import org.eclipse.core.resources.IMarkerDelta;
30 import org.eclipse.core.resources.IWorkspaceRoot; 31 import org.eclipse.core.resources.IWorkspaceRoot;
32 import org.eclipse.core.runtime.Path;
31 import org.eclipse.debug.core.DebugPlugin; 33 import org.eclipse.debug.core.DebugPlugin;
32 import org.eclipse.debug.core.IBreakpointListener; 34 import org.eclipse.debug.core.IBreakpointListener;
33 import org.eclipse.debug.core.model.IBreakpoint; 35 import org.eclipse.debug.core.model.IBreakpoint;
34 36
35 import java.io.IOException; 37 import java.io.IOException;
36 import java.util.ArrayList; 38 import java.util.ArrayList;
37 import java.util.HashMap; 39 import java.util.HashMap;
38 import java.util.List; 40 import java.util.List;
39 import java.util.Map; 41 import java.util.Map;
40 42
41 /** 43 /**
42 * Handle adding a removing breakpoints to the WebKit connection for the Dartium DebugTarget class. 44 * Handle adding a removing breakpoints to the WebKit connection for the Dartium DebugTarget class.
43 */ 45 */
44 class BreakpointManager implements IBreakpointListener { 46 public class BreakpointManager implements IBreakpointListener {
45 47
46 private static String PACKAGES_DIRECTORY_PATH = "/packages/"; 48 private static String PACKAGES_DIRECTORY_PATH = "/packages/";
47 private static String LIB_DIRECTORY_PATH = "/lib/"; 49 private static String LIB_DIRECTORY_PATH = "/lib/";
48 50
49 private DartiumDebugTarget debugTarget; 51 private DartiumDebugTarget debugTarget;
50 52
51 private Map<IBreakpoint, List<String>> breakpointToIdMap = new HashMap<IBreakp oint, List<String>>(); 53 private Map<IBreakpoint, List<String>>
52 private Map<String, DartBreakpoint> breakpointsToUpdateMap = new HashMap<Strin g, DartBreakpoint>(); 54 breakpointToIdMap = new HashMap<IBreakpoint, List<String>>();
55 private Map<String, DartBreakpoint>
56 breakpointsToUpdateMap = new HashMap<String, DartBreakpoint>();
53 57
54 private List<IBreakpoint> ignoredBreakpoints = new ArrayList<IBreakpoint>(); 58 private List<IBreakpoint> ignoredBreakpoints = new ArrayList<IBreakpoint>();
55 59
56 public BreakpointManager(DartiumDebugTarget debugTarget) { 60 public BreakpointManager(DartiumDebugTarget debugTarget) {
57 this.debugTarget = debugTarget; 61 this.debugTarget = debugTarget;
58 } 62 }
59 63
60 @Override 64 @Override
61 public void breakpointAdded(IBreakpoint breakpoint) { 65 public void breakpointAdded(IBreakpoint breakpoint) {
62 if (debugTarget.supportsBreakpoint(breakpoint)) { 66 if (debugTarget.supportsBreakpoint(breakpoint)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (!debugTarget.isTerminated()) { 104 if (!debugTarget.isTerminated()) {
101 DartDebugCorePlugin.logError(exception); 105 DartDebugCorePlugin.logError(exception);
102 } 106 }
103 } 107 }
104 } 108 }
105 } 109 }
106 } 110 }
107 } 111 }
108 112
109 public void connect() throws IOException { 113 public void connect() throws IOException {
110 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager(). getBreakpoints( 114 IBreakpoint[] breakpoints = DebugPlugin.getDefault()
111 DartDebugCorePlugin.DEBUG_MODEL_ID); 115 .getBreakpointManager().getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_I D);
112 116
113 for (IBreakpoint breakpoint : breakpoints) { 117 for (IBreakpoint breakpoint : breakpoints) {
114 if (debugTarget.supportsBreakpoint(breakpoint)) { 118 if (debugTarget.supportsBreakpoint(breakpoint)) {
115 addBreakpoint((DartBreakpoint) breakpoint); 119 addBreakpoint((DartBreakpoint) breakpoint);
116 } 120 }
117 } 121 }
118 122
119 DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); 123 DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
120 } 124 }
121 125
(...skipping 14 matching lines...) Expand all
136 DartDebugCorePlugin.logError(exception); 140 DartDebugCorePlugin.logError(exception);
137 } 141 }
138 } 142 }
139 } 143 }
140 144
141 DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(t his); 145 DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(t his);
142 } 146 }
143 } 147 }
144 148
145 public DartBreakpoint getBreakpointFor(WebkitLocation location) { 149 public DartBreakpoint getBreakpointFor(WebkitLocation location) {
146 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager(). getBreakpoints( 150 IBreakpoint[] breakpoints = DebugPlugin.getDefault()
147 DartDebugCorePlugin.DEBUG_MODEL_ID); 151 .getBreakpointManager().getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_I D);
148 152
149 WebkitScript script = debugTarget.getWebkitConnection().getDebugger().getScr ipt( 153 WebkitScript script = debugTarget.getWebkitConnection()
150 location.getScriptId()); 154 .getDebugger().getScript(location.getScriptId());
151 155
152 if (script == null) { 156 if (script == null) {
153 return null; 157 return null;
154 } 158 }
155 159
156 String url = script.getUrl(); 160 String url = script.getUrl();
157 int line = WebkitLocation.webkitToElipseLine(location.getLineNumber()); 161 int line = WebkitLocation.webkitToElipseLine(location.getLineNumber());
158 162
159 for (IBreakpoint bp : breakpoints) { 163 for (IBreakpoint bp : breakpoints) {
160 if (debugTarget.supportsBreakpoint(bp)) { 164 if (debugTarget.supportsBreakpoint(bp)) {
161 DartBreakpoint breakpoint = (DartBreakpoint) bp; 165 DartBreakpoint breakpoint = (DartBreakpoint) bp;
162 166
163 if (breakpoint.getLine() == line) { 167 if (breakpoint.getLine() == line) {
164 String bpUrl = getResourceResolver().getUrlForResource(breakpoint.getF ile()); 168 String bpUrl = getResourceResolver().getUrlForResource(breakpoint.getF ile());
165 169
166 if (bpUrl != null && bpUrl.equals(url)) { 170 if (bpUrl != null && bpUrl.equals(url)) {
167 return breakpoint; 171 return breakpoint;
168 } 172 }
169 } 173 }
170 } 174 }
171 } 175 }
172 176
173 return null; 177 return null;
174 } 178 }
175 179
180 @VisibleForTesting
181 public String getPackagePath(String regex, IFile resource) {
182 Path path = new Path(regex);
183 int i = 0;
184 if (regex.indexOf(LIB_DIRECTORY_PATH) != -1) {
185 // remove all segments after "lib", they show path in the package
186 while (i < path.segmentCount() && !path.segment(i).equals("lib")) {
187 i++;
188 }
189 } else {
190 i = 1;
191 }
192 String filePath = new Path(regex).removeLastSegments(path.segmentCount() - ( i + 1)).toString();
193
194 String packagePath = resolvePathToPackage(resource, filePath);
195 if (packagePath != null) {
196 packagePath += "/" + path.removeFirstSegments(i + 1);
197 }
198 return packagePath;
199 }
200
201 @VisibleForTesting
202 protected String resolvePathToPackage(IFile resource, String filePath) {
203 return DartCore.getProjectManager().resolvePathToPackage(resource, filePath) ;
204 }
205
176 void addToBreakpointMap(IBreakpoint breakpoint, String id, boolean trackChange s) { 206 void addToBreakpointMap(IBreakpoint breakpoint, String id, boolean trackChange s) {
177 synchronized (breakpointToIdMap) { 207 synchronized (breakpointToIdMap) {
178 if (breakpointToIdMap.get(breakpoint) == null) { 208 if (breakpointToIdMap.get(breakpoint) == null) {
179 breakpointToIdMap.put(breakpoint, new ArrayList<String>()); 209 breakpointToIdMap.put(breakpoint, new ArrayList<String>());
180 } 210 }
181 211
182 breakpointToIdMap.get(breakpoint).add(id); 212 breakpointToIdMap.get(breakpoint).add(id);
183 213
184 if (trackChanges) { 214 if (trackChanges) {
185 breakpointsToUpdateMap.put(id, (DartBreakpoint) breakpoint); 215 breakpointsToUpdateMap.put(id, (DartBreakpoint) breakpoint);
186 } 216 }
187 } 217 }
188 } 218 }
189 219
190 void handleBreakpointResolved(WebkitBreakpoint webkitBreakpoint) { 220 void handleBreakpointResolved(WebkitBreakpoint webkitBreakpoint) {
191 DartBreakpoint breakpoint = breakpointsToUpdateMap.get(webkitBreakpoint.getB reakpointId()); 221 DartBreakpoint breakpoint = breakpointsToUpdateMap.get(webkitBreakpoint.getB reakpointId());
192 222
193 if (breakpoint != null) { 223 if (breakpoint != null) {
194 int eclipseLine = WebkitLocation.webkitToElipseLine(webkitBreakpoint.getLo cation().getLineNumber()); 224 int eclipseLine = WebkitLocation.webkitToElipseLine(
225 webkitBreakpoint.getLocation().getLineNumber());
195 226
196 if (breakpoint.getLine() != eclipseLine) { 227 if (breakpoint.getLine() != eclipseLine) {
197 ignoredBreakpoints.add(breakpoint); 228 ignoredBreakpoints.add(breakpoint);
198 229
199 String message = "[breakpoint in " + breakpoint.getFile().getName() + " moved from line " 230 String message = "[breakpoint in " + breakpoint.getFile().getName() + " moved from line "
200 + breakpoint.getLine() + " to " + eclipseLine + "]"; 231 + breakpoint.getLine() + " to " + eclipseLine + "]";
201 debugTarget.writeToStdout(message); 232 debugTarget.writeToStdout(message);
202 233
203 breakpoint.updateLineNumber(eclipseLine); 234 breakpoint.updateLineNumber(eclipseLine);
204 } 235 }
(...skipping 23 matching lines...) Expand all
228 // Check if source is located in the "lib" directory; if there is a link to it from the 259 // Check if source is located in the "lib" directory; if there is a link to it from the
229 // packages directory breakpoint should be /packages/... 260 // packages directory breakpoint should be /packages/...
230 String packageName = DartCore.getSelfLinkedPackageName(breakpoint.getFil e()); 261 String packageName = DartCore.getSelfLinkedPackageName(breakpoint.getFil e());
231 262
232 if (packageName != null) { 263 if (packageName != null) {
233 // Create a breakpoint for self-links. 264 // Create a breakpoint for self-links.
234 int libIndex = regex.lastIndexOf(LIB_DIRECTORY_PATH); 265 int libIndex = regex.lastIndexOf(LIB_DIRECTORY_PATH);
235 String packageRegex = packageName + "/" 266 String packageRegex = packageName + "/"
236 + regex.substring(libIndex + LIB_DIRECTORY_PATH.length()); 267 + regex.substring(libIndex + LIB_DIRECTORY_PATH.length());
237 268
238 debugTarget.getWebkitConnection().getDebugger().setBreakpointByUrl( 269 debugTarget.getWebkitConnection().getDebugger()
239 null, 270 .setBreakpointByUrl(null, packageRegex, line, -1, new WebkitCallba ck<String>() {
240 packageRegex,
241 line,
242 -1,
243 new WebkitCallback<String>() {
244 @Override 271 @Override
245 public void handleResult(WebkitResult<String> result) { 272 public void handleResult(WebkitResult<String> result) {
246 if (!result.isError()) { 273 if (!result.isError()) {
247 addToBreakpointMap(breakpoint, result.getResult(), false); 274 addToBreakpointMap(breakpoint, result.getResult(), false);
248 } 275 }
249 } 276 }
250 }); 277 });
251 } 278 }
252 } 279 }
253 280
254 debugTarget.getWebkitConnection().getDebugger().setBreakpointByUrl( 281 // check if it is a file in a package, if so replace regex with package ur i path
255 null, 282 // TODO(keertip): revisit when moved to calling pub for package info
256 regex, 283 String packagePath = getPackagePath(regex, breakpoint.getFile());
257 line, 284 if (packagePath != null) {
258 -1, 285 regex = packagePath;
259 new WebkitCallback<String>() { 286 }
287
288 debugTarget.getWebkitConnection()
289 .getDebugger().setBreakpointByUrl(null, regex, line, -1, new WebkitCal lback<String>() {
260 @Override 290 @Override
261 public void handleResult(WebkitResult<String> result) { 291 public void handleResult(WebkitResult<String> result) {
262 if (!result.isError()) { 292 if (!result.isError()) {
263 addToBreakpointMap(breakpoint, result.getResult(), true); 293 addToBreakpointMap(breakpoint, result.getResult(), true);
264 } 294 }
265 } 295 }
266 }); 296 });
267 297
268 // Handle source mapped breakpoints - set an additional breakpoint if the file is under 298 // Handle source mapped breakpoints - set an additional breakpoint if the file is under
269 // source mapping. 299 // source mapping.
270 SourceMapManager sourceMapManager = debugTarget.getSourceMapManager(); 300 SourceMapManager sourceMapManager = debugTarget.getSourceMapManager();
271 301
272 if (sourceMapManager.isMapTarget(breakpoint.getFile())) { 302 if (sourceMapManager.isMapTarget(breakpoint.getFile())) {
273 List<SourceMapManager.SourceLocation> locations = sourceMapManager.getRe verseMappingsFor( 303 List<SourceMapManager.SourceLocation> locations = sourceMapManager.getRe verseMappingsFor(
274 breakpoint.getFile(), 304 breakpoint.getFile(),
275 line); 305 line);
276 306
277 for (SourceMapManager.SourceLocation location : locations) { 307 for (SourceMapManager.SourceLocation location : locations) {
278 String mappedRegex = getResourceResolver().getUrlRegexForResource(loca tion.getFile()); 308 String mappedRegex = getResourceResolver().getUrlRegexForResource(loca tion.getFile());
279 309
280 if (mappedRegex != null) { 310 if (mappedRegex != null) {
281 if (DartDebugCorePlugin.LOGGING) { 311 if (DartDebugCorePlugin.LOGGING) {
282 System.out.println("breakpoint [" + regex + "," + breakpoint.getLi ne() 312 System.out.println(
283 + ",-1] ==> mapped to [" + mappedRegex + "," + location.getLin e() + "," 313 "breakpoint [" + regex + "," + breakpoint.getLine() + ",-1] == > mapped to ["
284 + location.getColumn() + "]"); 314 + mappedRegex + "," + location.getLine() + "," + location. getColumn() + "]");
285 } 315 }
286 316
287 debugTarget.getWebkitConnection().getDebugger().setBreakpointByUrl( 317 debugTarget.getWebkitConnection().getDebugger().setBreakpointByUrl(
288 null, 318 null,
289 mappedRegex, 319 mappedRegex,
290 location.getLine(), 320 location.getLine(),
291 location.getColumn(), 321 location.getColumn(),
292 new WebkitCallback<String>() { 322 new WebkitCallback<String>() {
293 @Override 323 @Override
294 public void handleResult(WebkitResult<String> result) { 324 public void handleResult(WebkitResult<String> result) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 357 }
328 358
329 if (container.getParent() instanceof IWorkspaceRoot) { 359 if (container.getParent() instanceof IWorkspaceRoot) {
330 return false; 360 return false;
331 } 361 }
332 362
333 return isPubLib(container.getParent()); 363 return isPubLib(container.getParent());
334 } 364 }
335 365
336 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698