ReferenceType classType = ((ClassPrepareEvent)
event).referenceType();
for (Integer line : lineList) {
List<Location> locations = classType.locationsOfLine(line);
if (!locations.isEmpty()) {
Location loc = locations.get(0);
BreakpointRequest breakpointRequest =
jdb.eventRequestManager.
createBreakpointRequest(loc);
breakpointRequest.setSuspendPolicy(
EventRequest.SUSPEND_ALL);
breakpointRequest.enable();
jdb.breakpointRegisterMap.put(
loc.toString(), breakpointRequest);
System.out.println(
String.format("Breakpoint set: " + loc));
}
}
}
// set the possible deferred method breakpoints
List<String> methodStrList = deferringMethodBreakpoint.get(className);
if (methodStrList != null) {
ReferenceType classType = ((ClassPrepareEvent)
event).referenceType();
for (String methodStr : methodStrList) {
String[] params = methodStr.split("|");
// Generate the target argument type string list
String[] argTypeNames;
if (params.length > 1) {
argTypeNames = params[1].split(",");
} else {
argTypeNames = new String[0];
}
// Get all methods of the class
List<Method> methodList = classType.methodsByName(params[0]);
Method matchedMethod = null;
/*
* As the jdb command argument doesn't supply the result
* value type, it's impossible to generate a jni signature
* for the specified method. I just have to search...
*/
for (Method m : methodList) {
List<String> types = m.argumentTypeNames();
if (types.size() != argTypeNames.length) {
continue;
} else {
boolean matched = true;
for (int i = 0; i < argTypeNames.length; i++) {
if (!types.get(i).equals(argTypeNames[i])) {
matched = false;
break;
}
}
if (matched) {
matchedMethod = m;
break;
}
}
}
if (null != matchedMethod) {
Location loc = matchedMethod.location();
if (null != loc) {
BreakpointRequest breakpointRequest =
jdb.eventRequestManager.
createBreakpointRequest(loc);
breakpointRequest.setSuspendPolicy(
EventRequest.SUSPEND_ALL);
breakpointRequest.enable();
jdb.breakpointRegisterMap.put(
loc.toString(), breakpointRequest);
System.out.println(
String.format("Breakpoint set: " + loc));
}
}
}