2
|
1 |
/*
|
715
|
2 |
* Copyright 1998-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.tty;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.request.EventRequest;
|
|
30 |
import com.sun.jdi.event.ClassPrepareEvent;
|
|
31 |
|
|
32 |
import java.util.ArrayList;
|
|
33 |
import java.util.Collections;
|
|
34 |
import java.util.Iterator;
|
|
35 |
import java.util.List;
|
|
36 |
import java.util.StringTokenizer;
|
|
37 |
|
|
38 |
class EventRequestSpecList {
|
|
39 |
|
|
40 |
private static final int statusResolved = 1;
|
|
41 |
private static final int statusUnresolved = 2;
|
|
42 |
private static final int statusError = 3;
|
|
43 |
|
|
44 |
// all specs
|
|
45 |
private List<EventRequestSpec> eventRequestSpecs = Collections.synchronizedList(
|
|
46 |
new ArrayList<EventRequestSpec>());
|
|
47 |
|
|
48 |
EventRequestSpecList() {
|
|
49 |
}
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Resolve all deferred eventRequests waiting for 'refType'.
|
|
53 |
* @return true if it completes successfully, false on error.
|
|
54 |
*/
|
|
55 |
boolean resolve(ClassPrepareEvent event) {
|
|
56 |
boolean failure = false;
|
|
57 |
synchronized(eventRequestSpecs) {
|
51
|
58 |
for (EventRequestSpec spec : eventRequestSpecs) {
|
2
|
59 |
if (!spec.isResolved()) {
|
|
60 |
try {
|
|
61 |
EventRequest eventRequest = spec.resolve(event);
|
|
62 |
if (eventRequest != null) {
|
|
63 |
MessageOutput.println("Set deferred", spec.toString());
|
|
64 |
}
|
|
65 |
} catch (Exception e) {
|
|
66 |
MessageOutput.println("Unable to set deferred",
|
|
67 |
new Object [] {spec.toString(),
|
|
68 |
spec.errorMessageFor(e)});
|
|
69 |
failure = true;
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}
|
|
73 |
}
|
|
74 |
return !failure;
|
|
75 |
}
|
|
76 |
|
|
77 |
void resolveAll() {
|
51
|
78 |
for (EventRequestSpec spec : eventRequestSpecs) {
|
2
|
79 |
try {
|
|
80 |
EventRequest eventRequest = spec.resolveEagerly();
|
|
81 |
if (eventRequest != null) {
|
|
82 |
MessageOutput.println("Set deferred", spec.toString());
|
|
83 |
}
|
|
84 |
} catch (Exception e) {
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
boolean addEagerlyResolve(EventRequestSpec spec) {
|
|
90 |
try {
|
|
91 |
eventRequestSpecs.add(spec);
|
|
92 |
EventRequest eventRequest = spec.resolveEagerly();
|
|
93 |
if (eventRequest != null) {
|
|
94 |
MessageOutput.println("Set", spec.toString());
|
|
95 |
}
|
|
96 |
return true;
|
|
97 |
} catch (Exception exc) {
|
|
98 |
MessageOutput.println("Unable to set",
|
|
99 |
new Object [] {spec.toString(),
|
|
100 |
spec.errorMessageFor(exc)});
|
|
101 |
return false;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
51
|
105 |
BreakpointSpec createBreakpoint(String classPattern, int line)
|
|
106 |
throws ClassNotFoundException {
|
2
|
107 |
ReferenceTypeSpec refSpec =
|
|
108 |
new PatternReferenceTypeSpec(classPattern);
|
|
109 |
return new BreakpointSpec(refSpec, line);
|
|
110 |
}
|
|
111 |
|
51
|
112 |
BreakpointSpec createBreakpoint(String classPattern,
|
2
|
113 |
String methodId,
|
51
|
114 |
List<String> methodArgs)
|
2
|
115 |
throws MalformedMemberNameException,
|
|
116 |
ClassNotFoundException {
|
|
117 |
ReferenceTypeSpec refSpec =
|
|
118 |
new PatternReferenceTypeSpec(classPattern);
|
|
119 |
return new BreakpointSpec(refSpec, methodId, methodArgs);
|
|
120 |
}
|
|
121 |
|
|
122 |
EventRequestSpec createExceptionCatch(String classPattern,
|
|
123 |
boolean notifyCaught,
|
|
124 |
boolean notifyUncaught)
|
|
125 |
throws ClassNotFoundException {
|
|
126 |
ReferenceTypeSpec refSpec =
|
|
127 |
new PatternReferenceTypeSpec(classPattern);
|
|
128 |
return new ExceptionSpec(refSpec, notifyCaught, notifyUncaught);
|
|
129 |
}
|
|
130 |
|
51
|
131 |
WatchpointSpec createAccessWatchpoint(String classPattern,
|
2
|
132 |
String fieldId)
|
|
133 |
throws MalformedMemberNameException,
|
|
134 |
ClassNotFoundException {
|
|
135 |
ReferenceTypeSpec refSpec =
|
|
136 |
new PatternReferenceTypeSpec(classPattern);
|
|
137 |
return new AccessWatchpointSpec(refSpec, fieldId);
|
|
138 |
}
|
|
139 |
|
51
|
140 |
WatchpointSpec createModificationWatchpoint(String classPattern,
|
2
|
141 |
String fieldId)
|
|
142 |
throws MalformedMemberNameException,
|
|
143 |
ClassNotFoundException {
|
|
144 |
ReferenceTypeSpec refSpec =
|
|
145 |
new PatternReferenceTypeSpec(classPattern);
|
|
146 |
return new ModificationWatchpointSpec(refSpec, fieldId);
|
|
147 |
}
|
|
148 |
|
|
149 |
boolean delete(EventRequestSpec proto) {
|
|
150 |
synchronized (eventRequestSpecs) {
|
|
151 |
int inx = eventRequestSpecs.indexOf(proto);
|
|
152 |
if (inx != -1) {
|
51
|
153 |
EventRequestSpec spec = eventRequestSpecs.get(inx);
|
2
|
154 |
spec.remove();
|
|
155 |
eventRequestSpecs.remove(inx);
|
|
156 |
return true;
|
|
157 |
} else {
|
|
158 |
return false;
|
|
159 |
}
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
List<EventRequestSpec> eventRequestSpecs() {
|
|
164 |
// We need to make a copy to avoid synchronization problems
|
|
165 |
synchronized (eventRequestSpecs) {
|
|
166 |
return new ArrayList<EventRequestSpec>(eventRequestSpecs);
|
|
167 |
}
|
|
168 |
}
|
|
169 |
}
|