Java Code Examples for com.sun.jdi.StackFrame

The following are top voted examples for showing how to use com.sun.jdi.StackFrame. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: eclipse.jdt.core   File: JDIStackFrame.java View source code 7 votes vote down vote up
public char[] declaringTypeName() {
	if (this.breakpointLine != Integer.MAX_VALUE) { // if not in a code snippet
		StackFrame frame = getStackFrame();
		return frame.location().declaringType().name().toCharArray();
	}
	return null;
}
 
Example 2
Project: ikvm-openjdk   File: ThreadInfo.java View source code 7 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 3
Project: droolsjbpm   File: DroolsThread.java View source code 6 votes vote down vote up
public final static synchronized DroolsStackFrame createCustomFrame(DroolsThread thread,
                                                                    int depth,
                                                                    StackFrame currentFrame) {
    DroolsStackFrame customFrame;
    Location loc = currentFrame.location();
    if ( loc.declaringType().name().equals( "org.drools.base.mvel.MVELDebugHandler" ) && loc.method().name().equals( "onBreak" ) ) {
        customFrame = new MVELStackFrame( thread,
                                          currentFrame,
                                          depth );
    } else {
        customFrame = new DroolsStackFrame( thread,
                                            currentFrame,
                                            depth );
    }
    return customFrame;
}
 
Example 4
Project: droolsjbpm-tools   File: DroolsThread.java View source code 6 votes vote down vote up
public final static synchronized DroolsStackFrame createCustomFrame(DroolsThread thread,
                                                                    int depth,
                                                                    StackFrame currentFrame) {
    DroolsStackFrame customFrame;
    Location loc = currentFrame.location();
    if ( loc.declaringType().name().equals( "org.drools.core.base.mvel.MVELDebugHandler" ) && loc.method().name().equals( "onBreak" ) ) {
        customFrame = new MVELStackFrame( thread,
                                          currentFrame,
                                          depth );
    } else {
        customFrame = new DroolsStackFrame( thread,
                                            currentFrame,
                                            depth );
    }
    return customFrame;
}
 
Example 5
Project: damp.ekeko.snippets   File: JPDAVariable.java View source code 6 votes vote down vote up
/**
* Creates local variable. Called from thread.
*/
JPDAVariable (
    JPDADebugger  debugger,
    String        name,
    Value         value,
    String        type,
    StackFrame    stackFrame
) {
    this (debugger, true);
    update (name, value, type, stackFrame);
    //S ystem.out.println("new JPDAVariable " + getVariableName ());
}
 
Example 6
Project: ManagedRuntimeInitiative   File: ThreadInfo.java View source code 6 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 7
Project: openjdk   File: ThreadInfo.java View source code 6 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 8
Project: plugin-java   File: Evaluator.java View source code 6 votes vote down vote up
public ExpressionValue getLocalVariable(String text) {
    ExpressionValue value = null;
    try {
        StackFrame frame = thread.frame(0);
        LocalVariable var = frame.visibleVariableByName(text);
        if (var != null) {
            value = new LocalValue(thread, var);
        }
    } catch (IncompatibleThreadStateException | AbsentInformationException | InvalidStackFrameException | NativeMethodException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
    LOG.debug("GET local variable {} {} ", text, value);
    return value;
}
 
Example 9
Project: eclipse.jdt.debug   File: HotCodeReplacementTest.java View source code 6 votes vote down vote up
private void reenterOnExit(ThreadReference thread) {
	// Get top frame's location
	Location location = null;
	try {
		StackFrame frame = thread.frames(0, 1).get(0);
		location = frame.location();
	} catch (IncompatibleThreadStateException e) {
		assertTrue("reenterOnExit.1", false);
	}

	// Create and install reenter step request
	org.eclipse.jdi.hcr.EventRequestManager eventRequestManager =
		(org.eclipse.jdi.hcr.EventRequestManager) fVM.eventRequestManager();
	org.eclipse.jdi.hcr.ReenterStepRequest request =
		eventRequestManager.createReenterStepRequest(thread);
	request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
	request.enable();

	// Prepare to receive the step event
	EventWaiter waiter = new EventWaiter(request, false);
	fEventReader.addEventListener(waiter);

	// Resume thread with a doReturn so that the frame is reentered right away
	 ((org.eclipse.jdi.hcr.ThreadReference) thread).doReturn(null, false);

	// Wait for the step event to come in
	StepEvent event = (StepEvent) waitForEvent(waiter, 10000); // Wait 10s max
	assertTrue("reenterOnExit.2", event != null);
	fEventReader.removeEventListener(waiter);
	fVM.eventRequestManager().deleteEventRequest(request);

	// Check that the top frame location is as expected
	Location newLocation = null;
	try {
		StackFrame frame = thread.frames(0, 1).get(0);
		newLocation = frame.location();
	} catch (IncompatibleThreadStateException e) {
		assertTrue("reenterOnExit.3", false);
	}
	assertTrue("reenterOnExit.4", !newLocation.equals(location));
	assertTrue("reenterOnExit.5", newLocation.codeIndex() <= location.codeIndex());

}
 
Example 10
Project: openjdk8-jdk   File: ThreadInfo.java View source code 6 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 11
Project: nbscala   File: SourcePath.java View source code 6 votes vote down vote up
public String getURL (
    StackFrame sf,
    String stratumn
) {
    try {
        return getURL (
            convertSlash (sf.location ().sourcePath (stratumn)), 
            true
        );
    } catch (AbsentInformationException e) {
        return getURL (
            convertClassNameToRelativePath (
                sf.location ().declaringType ().name ()
            ),
            true
        );
    }
}
 
Example 12
Project: jdk7-jdk   File: ThreadInfo.java View source code 6 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 13
Project: old-gosu-repo   File: GosuExpressionEvaluatorImpl.java View source code 6 votes vote down vote up
private Value findThisObjectFromCtx( EvaluationContext context ) {
  List<LocalVariable> localVariables = null;
  StackFrame frame;
  try {
    frame = context.getFrameProxy().getStackFrame();
  }
  catch( EvaluateException e ) {
    throw new RuntimeException( e );
  }
  try {
    localVariables = frame.visibleVariables();
  }
  catch( AbsentInformationException e ) {
    return context.getThisObject();
  }
  for( LocalVariable localVar : localVariables ) {
    if( localVar.name().equals( "$that$" ) ) {
      // Use the enhanced object for the 'this' ref in enhancements
      return frame.getValue( localVar );
    }
  }
  return context.getThisObject();
}
 
Example 14
Project: gravel   File: VMTargetRemoteTest.java View source code 6 votes vote down vote up
private void printStack(ThreadReference thread)
		throws IncompatibleThreadStateException {
	List<StackFrame> frames = thread.frames();
	for (StackFrame stackFrame : frames) {
		System.out.println("-Stack: "+ stackFrame+" location:  "+stackFrame.location().method());
		
	}
}
 
Example 15
Project: jmseq   File: DefaultEventHandler.java View source code 6 votes vote down vote up
@Override
public Execution<?> handleEvent(ExceptionEvent event, ExecutionTraceOracle executionTraceOracle) {
	try {
		ObjectReference exception = event.exception();
		String className = exception.type().name();
		StackFrame frame = event.thread().frame(0);
		ObjectReference object = frame.thisObject();
		Long oid = object.uniqueID();
		ExceptionExecution exExec = executionTraceOracle.addException(event, className, object, oid);
		return exExec;
	} catch (Exception e) {
		logger.error("Error in fetching exception event data: " + e.getMessage());
	}
	return null;
}
 
Example 16
Project: j   File: Jdb.java View source code 6 votes vote down vote up
private String getStringValueOfObject(ObjectReference objRef,
    ThreadReference threadRef)
{
    try {
        // Get index of current stack frame so we can restore it later.
        List frames = threadRef.frames();
        int index = -1;
        if (frames.size() > 0) {
            for (int i = 0; i < frames.size(); i++) {
                StackFrame frame = (StackFrame) frames.get(i);
                if (frame != null && frame.equals(currentStackFrame)) {
                    index = i;
                    break;
                }
            }
        }

        ReferenceType refType = objRef.referenceType();
        List methods =
            refType.methodsByName("toString", "()Ljava/lang/String;");
        Method method = (Method) methods.get(0);
        Value value = objRef.invokeMethod(threadRef, method,
            new ArrayList(), ObjectReference.INVOKE_SINGLE_THREADED);

        // Restore current stack frame if possible.
        frames = threadRef.frames();
        if (frames != null && index >= 0 && index < frames.size())
            currentStackFrame = (StackFrame) frames.get(index);

        if (value != null)
            return value.toString();
    }
    catch (Exception e) {
        Log.error(e);
    }
    return null;
}
 
Example 17
Project: ceylon-ide-eclipse   File: CeylonJDIThread.java View source code 6 votes vote down vote up
protected boolean shouldDoStepReturn() throws DebugException {
    boolean shouldDoStepReturn = super.shouldDoStepReturn();
    if (shouldDoStepReturn) {
        try {
            StackFrame previousFrame = getUnderlyingThread().frame(1);
            if (DebugUtils.isMethodToStepThrough(previousFrame.location().method())) {
                return false;
            }
        } catch (IncompatibleThreadStateException e) {
            e.printStackTrace();
        }
        return true;
    }
    return false;
}
 
Example 18
Project: visage-compiler   File: ThreadInfo.java View source code 6 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example 19
Project: fiji   File: StartDebugging.java View source code 5 votes vote down vote up
public Process startDebugging() throws IOException, InterruptedException, AbsentInformationException {

		vm = launchVirtualMachine();
		vm.resume();
		if (plugInName.endsWith(".java")) {
			String fileName = plugInName.substring(plugInName.lastIndexOf(File.separator) + 1);
			className = fileName.substring(0, fileName.length() - 5);
		}
		addClassWatch(vm);
		Process process = vm.process();
		final InputStream inputStream = process.getErrorStream();
		new Thread() {
			public void run() {
				byte[] buffer = new byte[16384];
				for (;;) {
					try {
						int count = inputStream.read(buffer);
						if (count < 0)
							return; // EOF
						System.out.println(new String(buffer, 0, count));
					} catch (IOException e) {}
				}
			}
		} .start();
		EventQueue eventQueue = vm.eventQueue();

		while (true) {
			EventSet eventSet = eventQueue.remove();
			for (Event event : eventSet) {
				if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
					return process;
				} else if (event instanceof ClassPrepareEvent) {
					System.out.println("It comes in the class prepare event");
					// watch field on loaded class
					ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
					refType = (ClassType)classPrepEvent.referenceType();
					System.out.println("The class loaded is " + refType.name());
					fields = refType.allFields();
					toKnow = refType.fieldByName(fieldName);
					System.out.println("The number of elements in the linenumber list is" + lineNumbers.size());
					Iterator iterator = lineNumbers.iterator();
					while (true) {
						if (iterator.hasNext()) {
							Integer k = (Integer)iterator.next();
							System.out.println("The line number is " + k.intValue());
							addBreakPointRequest(vm, refType, k.intValue() + 1);
						} else
							break;
					}
				} else if (event instanceof BreakpointEvent) {

					BreakpointEvent breakEvent = (BreakpointEvent)event;
					List<ThreadReference> threads = vm.allThreads();
					for (ThreadReference thread: threads) {
						if (thread.isSuspended()) {
							try {
								System.out.println(thread.name());
								List<StackFrame> frames = thread.frames();
								if (frames.size() > 0) {
									StackFrame frame = frames.get(0);
									List<LocalVariable> variables = null;
									try {
										variables = frame.visibleVariables();
									} catch (AbsentInformationException e) {}
									if (variables != null) {
										System.out.println(frame.toString());
										for (LocalVariable variable: variables) {
											System.out.println("The name of variable " + variable.name() + " is " + frame.getValue(variable));
										}
									}
								}

							} catch (IncompatibleThreadStateException e) {
								System.out.println("Imcompatible thread state");
							}

						}
					}
					for (Field f: fields) {
						System.out.println("The value of " + f.name() + " is " + refType.getValue(f));
					}
					System.out.println(refType.getValue(toKnow));
				} else if (event instanceof VMStartEvent) {
					System.out.println("Virtual machine started");
				}

			}
			eventSet.resume();
		}
	}
 
Example 20
Project: Sorbet   File: StepEventHandler.java View source code 5 votes vote down vote up
private String getValue(ThreadReference thread, Location location,
		String variableName) {
	
	StackFrame stackFrame;
	try {
		stackFrame = thread.frame(0);
	} catch (IncompatibleThreadStateException e1) {
		// TODO Auto-generated catch block

		return "null";
	}

	LocalVariable variable;
	try {
		variable = stackFrame.visibleVariableByName(variableName);
	} catch (AbsentInformationException e) {
		// TODO Auto-generated catch block

		return "null";
	}

	if (variable != null) {
		// The variable was on the stack

		return stackFrame.getValue(variable).toString();
	} else {
		// The variable was not on the stack

		String varName = variableName;
		// this may need to get fixed up a bit later, but it should work
		// takes care of our fully qualified fields.
		if (variableName.indexOf('.') != -1) {
			varName = variableName.substring(variableName.lastIndexOf('.') + 1);
		}

		Value value = null;

		ObjectReference objectReference = stackFrame.thisObject();
		if (objectReference != null) {
			ReferenceType referenceType = objectReference.referenceType();
			Field field = referenceType.fieldByName(varName);
			if (field != null) {
				value = objectReference.getValue(field);
			}
		}

		// handle static fields
		if (value == null) {
			ReferenceType referenceType = location.declaringType();
			Field field = referenceType.fieldByName(varName);
			if (field != null) {
				value = referenceType.getValue(field);
			}
		}

		if (value != null) {
			return value.toString();
		} else {
			return "null"; // TODO: This returns null for static fields
			// outside the current class as well...
		}
	}
}