use of com.sun.jdi.Method in project che by eclipse.
the class Evaluator method invokeMethod.
public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
if (!(value instanceof ObjectReference)) {
throw new ExpressionException("Value is not object. Cannot invoke method " + name);
}
ObjectReference object = (ObjectReference) value;
ReferenceType type = object.referenceType();
List<Method> methods = type.methodsByName(name);
Method method = findMethod(methods, arguments);
if (method == null) {
throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
}
try {
return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
} catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
throw new ExpressionException(e.getMessage(), e);
}
}
use of com.sun.jdi.Method 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.Method in project jdk8u_jdk by JetBrains.
the class OomDebugTest method test1.
/*
* Test case: Object reference as method parameter.
*/
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
System.out.println("DEBUG: ------------> Running test1");
try {
Field field = targetClass.fieldByName("fooCls");
ClassType clsType = (ClassType) field.type();
Method constructor = getConstructorForClass(clsType);
for (int i = 0; i < 15; i++) {
@SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
if (objRef.isCollected()) {
System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
continue;
}
invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
}
} catch (InvocationException e) {
handleFailure(e);
}
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class WildcardMethodBreakpoint method getEventMessage.
public String getEventMessage(LocatableEvent event) {
final Location location = event.location();
final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
String locationFileName;
try {
locationFileName = location.sourceName();
} catch (AbsentInformationException e) {
locationFileName = "";
}
final int locationLine = location.lineNumber();
if (event instanceof MethodEntryEvent) {
MethodEntryEvent entryEvent = (MethodEntryEvent) event;
final Method method = entryEvent.method();
return DebuggerBundle.message("status.method.entry.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
if (event instanceof MethodExitEvent) {
MethodExitEvent exitEvent = (MethodExitEvent) event;
final Method method = exitEvent.method();
return DebuggerBundle.message("status.method.exit.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
return "";
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class ValueHint method getSelectedExpression.
private static Trinity<PsiElement, TextRange, Value> getSelectedExpression(final Project project, final Editor editor, final Point point, final ValueHintType type) {
final Ref<PsiElement> selectedExpression = Ref.create(null);
final Ref<TextRange> currentRange = Ref.create(null);
final Ref<Value> preCalculatedValue = Ref.create(null);
PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
// Point -> offset
final int offset = calculateOffset(editor, point);
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null || !psiFile.isValid()) {
return;
}
int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
if ((type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT) && (selectionStart <= offset && offset <= selectionEnd)) {
PsiElement ctx = (selectionStart > 0) ? psiFile.findElementAt(selectionStart - 1) : psiFile.findElementAt(selectionStart);
try {
String text = editor.getSelectionModel().getSelectedText();
if (text != null && ctx != null) {
final JVMElementFactory factory = JVMElementFactories.getFactory(ctx.getLanguage(), project);
if (factory == null) {
return;
}
selectedExpression.set(factory.createExpressionFromText(text, ctx));
currentRange.set(new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()));
}
} catch (IncorrectOperationException ignored) {
}
}
if (currentRange.get() == null) {
PsiElement elementAtCursor = psiFile.findElementAt(offset);
if (elementAtCursor == null) {
return;
}
Pair<PsiElement, TextRange> pair = findExpression(elementAtCursor, type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT);
if (pair == null) {
if (type == ValueHintType.MOUSE_OVER_HINT) {
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(project).getContext().getDebuggerSession();
if (debuggerSession != null && debuggerSession.isPaused()) {
final Pair<Method, Value> lastExecuted = debuggerSession.getProcess().getLastExecutedMethod();
if (lastExecuted != null) {
final Method method = lastExecuted.getFirst();
if (method != null) {
final Pair<PsiElement, TextRange> expressionPair = findExpression(elementAtCursor, true);
if (expressionPair != null && expressionPair.getFirst() instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expressionPair.getFirst();
final PsiMethod psiMethod = methodCallExpression.resolveMethod();
if (psiMethod != null) {
final JVMName jvmSignature = JVMNameUtil.getJVMSignature(psiMethod);
try {
if (method.name().equals(psiMethod.getName()) && method.signature().equals(jvmSignature.getName(debuggerSession.getProcess()))) {
pair = expressionPair;
preCalculatedValue.set(lastExecuted.getSecond());
}
} catch (EvaluateException ignored) {
}
}
}
}
}
}
}
}
if (pair == null) {
return;
}
selectedExpression.set(pair.getFirst());
currentRange.set(pair.getSecond());
}
});
return Trinity.create(selectedExpression.get(), currentRange.get(), preCalculatedValue.get());
}
Aggregations