use of com.sun.jdi.event.BreakpointEvent in project otertool by wuntee.
the class Testing method main.
/**
* @param args
* @throws IllegalConnectorArgumentsException
* @throws IOException
* @throws InterruptedException
* @throws IncompatibleThreadStateException
* @throws AbsentInformationException
*/
@SuppressWarnings("restriction")
public static void main(String[] args) throws IOException, IllegalConnectorArgumentsException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException {
SocketAttachingConnector c = (SocketAttachingConnector) getConnector();
Map<String, Connector.Argument> arguments = c.defaultArguments();
Connector.Argument hostnameArgument = arguments.get("hostname");
hostnameArgument.setValue("127.0.0.1");
Connector.Argument portArgument = arguments.get("port");
portArgument.setValue("8603");
arguments.put("hostname", hostnameArgument);
arguments.put("port", portArgument);
VirtualMachine vm = c.attach(arguments);
EventRequestManager mgr = vm.eventRequestManager();
for (com.sun.jdi.ReferenceType rt : vm.allClasses()) {
if (rt.name().toLowerCase().contains("wuntee")) {
System.out.println(rt.name());
for (Method m : rt.allMethods()) {
System.out.println(" -" + m.name());
if (m.name().contains("cache")) {
addBreakpointToMethod(m, mgr);
}
}
}
}
/* for(Method m : vm.classesByName("android.content.Intent").get(0).methodsByName("<init>")){
System.out.println("Breakpoint: " + m.toString());
Location location = m.location();
BreakpointRequest bpr = mgr.createBreakpointRequest(location);
bpr.enable();
}*/
//addIntentBreakpoints(vm);
com.sun.jdi.event.EventQueue q = vm.eventQueue();
while (true) {
EventSet es = q.remove();
Iterator<com.sun.jdi.event.Event> it = es.iterator();
while (it.hasNext()) {
com.sun.jdi.event.Event e = it.next();
BreakpointEvent bpe = (BreakpointEvent) e;
try {
System.out.println("Method: " + bpe.location().method().toString());
for (StackFrame sf : bpe.thread().frames()) {
System.out.println("Stackframe Method: " + sf.location().method().toString());
System.out.println("Arguments: ");
for (Value lv : sf.getArgumentValues()) {
System.out.println("\t--");
System.out.println("\t" + lv.toString());
}
}
} catch (Exception ex) {
System.out.println("Error: ");
ex.printStackTrace();
}
System.out.println();
vm.resume();
}
}
}
use of com.sun.jdi.event.BreakpointEvent in project jdk8u_jdk by JetBrains.
the class LambdaBreakpointTest method runTests.
/********** test core **********/
protected void runTests() throws Exception {
startToMain("LambdaBreakpointTestTarg");
// Put a breakpoint on each location in the order they should happen
for (int line : LambdaBreakpointTestTarg.breakpointLines) {
System.out.println("Running to line: " + line);
BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line);
int stoppedAt = be.location().lineNumber();
System.out.println("Stopped at line: " + stoppedAt);
if (stoppedAt != line) {
throw new Exception("Stopped on the wrong line: " + stoppedAt + " != " + line);
}
}
/*
* resume the target listening for events
*/
listenUntilVMDisconnect();
}
use of com.sun.jdi.event.BreakpointEvent in project jdk8u_jdk by JetBrains.
the class LambdaStepTest method runTests.
/********** test core **********/
protected void runTests() throws Exception {
// ## Normal instance method
BreakpointEvent bpe = startTo("LambdaStepTestTarg", "instanceTest", "()V");
ThreadReference thread = bpe.thread();
// step over allocation
StepEvent se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into test();
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
StackFrame frame = se.thread().frame(0);
LocalVariable lv = frame.visibleVariableByName("from");
System.out.println(lv);
StringReference sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("test")) {
throw new Exception("Unexpected variable value in instanceTest: " + sr.value());
}
// ## Lambda method
bpe = resumeTo("LambdaStepTestTarg", "lambdaTest", "()V");
thread = bpe.thread();
// step over allocation
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into run() of the lambda
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
frame = se.thread().frame(0);
lv = frame.visibleVariableByName("from");
System.out.println(lv);
sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("lambda")) {
throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
}
// ## Default method
bpe = resumeTo("LambdaStepTestTarg", "defaultTest", "()V");
thread = bpe.thread();
// step over allocation
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// step into defaultMethod()
se = stepIntoLine(thread);
System.out.println(se.thread().frame(0));
// step over variable initialization
se = stepOverLine(thread);
System.out.println(se.thread().frame(0));
// get value of variable "from"
frame = se.thread().frame(0);
lv = frame.visibleVariableByName("from");
System.out.println(lv);
sr = (StringReference) frame.getValue(lv);
if (!sr.value().equals("default")) {
throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
}
/*
* resume the target listening for events
*/
listenUntilVMDisconnect();
}
use of com.sun.jdi.event.BreakpointEvent in project jdk8u_jdk by JetBrains.
the class GetUninitializedStringValue method runTests.
/********** test core **********/
protected void runTests() throws Exception {
/*
* Run to String.<init>
*/
startUp("GetUninitializedStringValueTarg");
BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");
/*
* We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
*/
StackFrame frame = bpe.thread().frame(0);
StringReference sr = (StringReference) frame.thisObject();
if (!sr.value().equals("")) {
throw new Exception("Unexpected value for the uninitialized String");
}
/*
* resume the target listening for events
*/
listenUntilVMDisconnect();
}
use of com.sun.jdi.event.BreakpointEvent in project gravel by gravel-st.
the class VMTargetStarter method createJVM.
public VMRemoteTarget createJVM() throws IOException, InterruptedException, IncompatibleThreadStateException {
Process process = startSecondJVM(VMLocalTarget.class);
sleep(90);
// connect
VirtualMachine vm = new VMAcquirer().connect(debugPort);
ClassPrepareRequest createClassPrepareRequest = vm.eventRequestManager().createClassPrepareRequest();
createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
createClassPrepareRequest.enable();
vm.resume();
List<ThreadReference> allThreads = vm.allThreads();
for (ThreadReference threadReference : allThreads) {
System.out.println(threadReference + " isSuspended: " + threadReference.isSuspended() + " suspendCount: " + threadReference.suspendCount());
}
// process events
EventQueue eventQueue = vm.eventQueue();
while (true) {
EventSet eventSet = eventQueue.remove();
for (Event event : eventSet) {
if (event instanceof ClassPrepareEvent) {
event.request().disable();
installHaltPoint(vm);
}
if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
return null;
}
if (event instanceof BreakpointEvent) {
event.request().disable();
ThreadReference thread = ((BreakpointEvent) event).thread();
return new VMRemoteTarget(process, vm, thread, debugPort);
}
}
eventSet.resume();
}
}
Aggregations