2
|
1 |
/*
|
715
|
2 |
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.example.debug.bdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.request.*;
|
|
30 |
|
|
31 |
import java.util.ArrayList;
|
|
32 |
import java.util.List;
|
|
33 |
import java.util.Iterator;
|
|
34 |
|
|
35 |
public class LineBreakpointSpec extends BreakpointSpec {
|
|
36 |
int lineNumber;
|
|
37 |
|
|
38 |
LineBreakpointSpec(EventRequestSpecList specs,
|
|
39 |
ReferenceTypeSpec refSpec, int lineNumber) {
|
|
40 |
super(specs, refSpec);
|
|
41 |
this.lineNumber = lineNumber;
|
|
42 |
}
|
|
43 |
|
|
44 |
/**
|
|
45 |
* The 'refType' is known to match.
|
|
46 |
*/
|
|
47 |
void resolve(ReferenceType refType) throws InvalidTypeException,
|
|
48 |
LineNotFoundException {
|
|
49 |
if (!(refType instanceof ClassType)) {
|
|
50 |
throw new InvalidTypeException();
|
|
51 |
}
|
|
52 |
Location location = location((ClassType)refType);
|
|
53 |
setRequest(refType.virtualMachine().eventRequestManager()
|
|
54 |
.createBreakpointRequest(location));
|
|
55 |
}
|
|
56 |
|
|
57 |
private Location location(ClassType clazz) throws
|
|
58 |
LineNotFoundException {
|
|
59 |
Location location = null;
|
|
60 |
try {
|
51
|
61 |
List<Location> locs = clazz.locationsOfLine(lineNumber());
|
2
|
62 |
if (locs.size() == 0) {
|
|
63 |
throw new LineNotFoundException();
|
|
64 |
}
|
|
65 |
// TODO handle multiple locations
|
51
|
66 |
location = locs.get(0);
|
2
|
67 |
if (location.method() == null) {
|
|
68 |
throw new LineNotFoundException();
|
|
69 |
}
|
|
70 |
} catch (AbsentInformationException e) {
|
|
71 |
/*
|
|
72 |
* TO DO: throw something more specific, or allow
|
|
73 |
* AbsentInfo exception to pass through.
|
|
74 |
*/
|
|
75 |
throw new LineNotFoundException();
|
|
76 |
}
|
|
77 |
return location;
|
|
78 |
}
|
|
79 |
|
|
80 |
public int lineNumber() {
|
|
81 |
return lineNumber;
|
|
82 |
}
|
|
83 |
|
|
84 |
public int hashCode() {
|
|
85 |
return refSpec.hashCode() + lineNumber;
|
|
86 |
}
|
|
87 |
|
|
88 |
public boolean equals(Object obj) {
|
|
89 |
if (obj instanceof LineBreakpointSpec) {
|
|
90 |
LineBreakpointSpec breakpoint = (LineBreakpointSpec)obj;
|
|
91 |
|
|
92 |
return refSpec.equals(breakpoint.refSpec) &&
|
|
93 |
(lineNumber == breakpoint.lineNumber);
|
|
94 |
} else {
|
|
95 |
return false;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
public String errorMessageFor(Exception e) {
|
|
100 |
if (e instanceof LineNotFoundException) {
|
|
101 |
return ("No code at line " + lineNumber() + " in " + refSpec);
|
|
102 |
} else if (e instanceof InvalidTypeException) {
|
|
103 |
return ("Breakpoints can be located only in classes. " +
|
|
104 |
refSpec + " is an interface or array");
|
|
105 |
} else {
|
|
106 |
return super.errorMessageFor( e);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
public String toString() {
|
|
111 |
StringBuffer buffer = new StringBuffer("breakpoint ");
|
|
112 |
buffer.append(refSpec.toString());
|
|
113 |
buffer.append(':');
|
|
114 |
buffer.append(lineNumber);
|
|
115 |
buffer.append(" (");
|
|
116 |
buffer.append(getStatusString());
|
|
117 |
buffer.append(')');
|
|
118 |
return buffer.toString();
|
|
119 |
}
|
|
120 |
}
|