@SuppressWarnings("unused") // called via reflection 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); } }
public boolean isLeaf (Object node) throws UnknownTypeException { if (node == ROOT) return false; if (node instanceof JPDAWatchEvaluating) { JPDAWatchEvaluating jwe = (JPDAWatchEvaluating) node; if (!jwe.getWatch().isEnabled()) { return true; } if (!jwe.isCurrent()) { return false; // When not yet evaluated, suppose that it's not leaf } JPDAWatch jw = jwe.getEvaluatedWatch(); if (jw instanceof AbstractVariable) { return !(((AbstractVariable) jw).getInnerValue() instanceof ObjectReference); } } if (node == EMPTY_WATCH) return true; return getLocalsTreeModel ().isLeaf (node); }
private boolean ungrabWindowAWT(ThreadReference tr, ObjectReference grabbedWindow) { // Call XBaseWindow.ungrabInput() try { VirtualMachine vm = MirrorWrapper.virtualMachine(grabbedWindow); List<ReferenceType> xbaseWindowClassesByName = VirtualMachineWrapper.classesByName(vm, "sun.awt.X11.XBaseWindow"); if (xbaseWindowClassesByName.isEmpty()) { logger.info("Unable to release X grab, no XBaseWindow class in target VM "+VirtualMachineWrapper.description(vm)); return false; } ClassType XBaseWindowClass = (ClassType) xbaseWindowClassesByName.get(0); Method ungrabInput = XBaseWindowClass.concreteMethodByName("ungrabInput", "()V"); if (ungrabInput == null) { logger.info("Unable to release X grab, method ungrabInput not found in target VM "+VirtualMachineWrapper.description(vm)); return false; } XBaseWindowClass.invokeMethod(tr, ungrabInput, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); } catch (VMDisconnectedExceptionWrapper vmdex) { return true; // Disconnected, all is good. } catch (Exception ex) { logger.log(Level.INFO, "Unable to release X grab.", ex); return false; } return true; }
@Test public void testAcceptType() throws Exception { LocalVariable i = this.getLocalVariable("i"); assertFalse("NumericFormatter should accept null.", formatter.acceptType(null, new HashMap<>())); assertTrue("NumericFormatter should accept int type.", formatter.acceptType(i.type(), new HashMap<>())); ObjectReference integer = this.getObjectReference("java.lang.Integer"); assertFalse("NumericFormatter should not accept Integer type.", formatter.acceptType(integer.type(), new HashMap<>())); assertFalse("NumericFormatter should not accept Object type.", formatter.acceptType(this.getLocalVariable("obj").type(), new HashMap<>())); assertFalse("NumericFormatter should not accept array type.", formatter.acceptType(this.getLocalVariable("arrays").type(), new HashMap<>())); assertFalse("NumericFormatter should not accept String type.", formatter.acceptType(this.getLocalVariable("str").type(), new HashMap<>())); VirtualMachine vm = getVM(); assertFalse("NumericFormatter should not accept boolean type.", formatter.acceptType(vm.mirrorOf(true).type(), new HashMap<>())); assertFalse("NumericFormatter should not accept char type.", formatter.acceptType(vm.mirrorOf('c').type(), new HashMap<>())); assertTrue("NumericFormatter should accept long type.", formatter.acceptType(vm.mirrorOf(1L).type(), new HashMap<>())); assertTrue("NumericFormatter should accept float type.", formatter.acceptType(vm.mirrorOf(1.2f).type(), new HashMap<>())); assertTrue("NumericFormatter should accept double type.", formatter.acceptType(vm.mirrorOf(1.2).type(), new HashMap<>())); assertTrue("NumericFormatter should accept byte type.", formatter.acceptType(vm.mirrorOf((byte)12).type(), new HashMap<>())); assertTrue("NumericFormatter should accept short type.", formatter.acceptType(vm.mirrorOf((short)12121).type(), new HashMap<>())); }
public List<ObjectReference> referringObjects(long maxReferrers) { if (!vm.canGetInstanceInfo()) { throw new UnsupportedOperationException( "target does not support getting referring objects"); } if (maxReferrers < 0) { throw new IllegalArgumentException("maxReferrers is less than zero: " + maxReferrers); } int intMax = (maxReferrers > Integer.MAX_VALUE)? Integer.MAX_VALUE: (int)maxReferrers; // JDWP can't currently handle more than this (in mustang) try { return Arrays.asList((ObjectReference[])JDWP.ObjectReference.ReferringObjects. process(vm, this, intMax).referringObjects); } catch (JDWPException exc) { throw exc.toJDIException(); } }
@Override public Action[] getActions(boolean context) { FieldInfo fieldInfo = getField(); ObjectReference component = getComponent(); ComponentBreakpoint b = ComponentBreakpointActionProvider.findBreakpoint(component); List<Action> actions = new ArrayList<Action>(); if (fieldInfo != null) { actions.add(GoToFieldDeclarationAction.get(GoToFieldDeclarationAction.class)); } actions.add(GoToSourceAction.get(GoToSourceAction.class)); if (getAddCallStack() != null) { actions.add(GoToAddIntoHierarchyAction.get(GoToAddIntoHierarchyAction.class)); } // actions.add(null); // actions.add(ShowListenersAction.get(ShowListenersAction.class)); actions.add(null); actions.add(ToggleComponentBreakpointAction.get(ToggleComponentBreakpointAction.class)); if (b != null) { actions.add(CBP_CUSTOMIZE_ACTION); } return actions.toArray(new Action[] {}); }
private static ObjectReference getQuantumTookitClassLoader(VirtualMachine vm) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { ClassType classQuantumToolkit = getClass(vm, "com.sun.javafx.tk.quantum.QuantumToolkit"); if (classQuantumToolkit == null) { return null; } ClassLoaderReference cl = ReferenceTypeWrapper.classLoader(classQuantumToolkit); return cl; }
private synchronized boolean remove(ObjectReference component, ClassObjectReference listenerClass, LoggingListenerCallBack listener) { Map<ClassObjectReference, Set<LoggingListenerCallBack>> listeners = componentListeners.get(component); if (listeners == null) { return false; } Set<LoggingListenerCallBack> lcb = listeners.get(listenerClass); if (lcb == null) { return false; } boolean removed = lcb.remove(listener); if (removed) { if (lcb.isEmpty()) { listeners.remove(listenerClass); if (listeners.isEmpty()) { componentListeners.remove(component); } } } return removed; }
private Value handleSetValueForObject(String name, String belongToClass, String valueString, ObjectReference container, Map<String, Object> options) throws InvalidTypeException, ClassNotLoadedException { Value newValue; if (container instanceof ArrayReference) { ArrayReference array = (ArrayReference) container; Type eleType = ((ArrayType) array.referenceType()).componentType(); newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); } else { if (StringUtils.isBlank(belongToClass)) { Field field = container.referenceType().fieldByName(name); if (field != null) { if (field.isStatic()) { newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); } else { newValue = this.setObjectFieldValue(container, field, name, valueString, options); } } else { throw new IllegalArgumentException( String.format("SetVariableRequest: Variable %s cannot be found.", name)); } } else { newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); } } return newValue; }
static void doAction(Node[] activatedNodes) { for (Node n : activatedNodes) { JavaComponentInfo ci = n.getLookup().lookup(JavaComponentInfo.class); if (ci != null) { ObjectReference component = ci.getComponent(); ComponentBreakpoint b = findBreakpoint(component); if (b == null) { JPDADebugger debugger = ci.getThread().getDebugger(); b = (ci instanceof AWTComponentInfo) ? new AWTComponentBreakpoint( new ComponentBreakpoint.ComponentDescription(ci, debugger, component) ) : new FXComponentBreakpoint( new ComponentBreakpoint.ComponentDescription(ci, debugger, component) ); DebuggerManager.getDebuggerManager().addBreakpoint(b); } else { DebuggerManager.getDebuggerManager().removeBreakpoint(b); } } } }
private String getBundleLocation(ObjectReference permissions) { List<String> walker; if (hasBundlePerms(permissions)) { walker = BUNDLE_PERM_WALKER; } else if (hasBlueprintProtectionDomain(permissions)) { walker = BLUEPRINT_PERM_WALKER; } else { walker = BUNDLE_PROTDOMAIN_WALKER; } ObjectReference revList = getReference(permissions, walker); ArrayReference revArray = (ArrayReference) revList.getValue(revList.referenceType().fieldByName("elementData")); ObjectReference moduleRev = (ObjectReference) revArray.getValue(0); return getValue( moduleRev, ImmutableList.of("symbolicName"), currRef -> ((StringReference) currRef).value()); }
public void stop(ObjectReference throwable) throws InvalidTypeException { validateMirrorOrNull(throwable); // Verify that the given object is a Throwable instance List<ReferenceType> list = vm.classesByName("java.lang.Throwable"); ClassTypeImpl throwableClass = (ClassTypeImpl)list.get(0); if ((throwable == null) || !throwableClass.isAssignableFrom(throwable)) { throw new InvalidTypeException("Not an instance of Throwable"); } try { JDWP.ThreadReference.Stop.process(vm, this, (ObjectReferenceImpl)throwable); } catch (JDWPException exc) { throw exc.toJDIException(); } }
private void checkConditions(ThreadReference threadRef, Field contextField) throws Exception { ArrayReference contextArray = getContextArray(contextField, threadRef); int size = contextArray.getValues().size(); for (int i = 0; i < size; i++) { ObjectReference context = (ObjectReference) contextArray.getValues().get(i); if (context != null && (hasBundlePerms(context) || hasBundleProtectionDomain(context) || hasBlueprintProtectionDomain(context))) { missingPerms.put(getBundleLocation(context), getPermissionString(threadRef)); } } if (missingPerms.isEmpty()) { System.out.println("this is wrong"); } }
private ObjectLocalVariable ( JPDADebuggerImpl debugger, ObjectReference value, String className, LocalVariable local, String genericSignature, String id, CallStackFrameImpl frame ) { super (debugger, value, genericSignature, id); this.local = local; if (frame != null) { this.thread = frame.getThread(); this.depth = frame.getFrameDepth(); } this.className = className; }
private ObjectFieldVariable ( JPDADebuggerImpl debugger, ObjectReference value, //String className, Field field, String parentID, ObjectReference objectReference ) { super ( debugger, value, getID(parentID, field) ); this.field = field; //this.className = className; this.objectReference = objectReference; }
protected ObjectFieldVariable ( JPDADebuggerImpl debugger, ObjectReference value, //String className, Field field, String parentID, String genericSignature, ObjectReference objectReference ) { this ( debugger, value, field, parentID, objectReference ); this.genericSignature = genericSignature; }
public ObjectFieldVariable ( JPDADebuggerImpl debugger, Field field, String parentID, String genericSignature, ObjectReference objectReference ) { this ( debugger, null, field, parentID, genericSignature, objectReference ); this.valueSet = false; }
@Override public List<ObjectVariable> getInstances(long maxInstances) { //assert !java.awt.EventQueue.isDispatchThread() : "Instances retrieving in AWT Event Queue!"; final List<ObjectReference> instances; try { instances = ReferenceTypeWrapper.instances(classType, maxInstances); } catch (ObjectCollectedExceptionWrapper | VMDisconnectedExceptionWrapper | InternalExceptionWrapper ex) { return Collections.emptyList(); } return new AbstractList<ObjectVariable>() { @Override public ObjectVariable get(int i) { ObjectReference obj = instances.get(i); return new AbstractObjectVariable(debugger, obj, classType.name()+" instance "+i); } @Override public int size() { return instances.size(); } }; }
private void submitCheckForMonitorEntered(ObjectReference waitingMonitor) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, IllegalThreadStateExceptionWrapper { try { ThreadReferenceWrapper.suspend(threadReference); logger.fine("submitCheckForMonitorEntered(): suspending "+threadName); ObjectReference monitor = ThreadReferenceWrapper.currentContendedMonitor(threadReference); if (monitor == null) return ; Location loc = StackFrameWrapper.location(ThreadReferenceWrapper.frame(threadReference, 0)); loc = MethodWrapper.locationOfCodeIndex(LocationWrapper.method(loc), LocationWrapper.codeIndex(loc) + 1); if (loc == null) return; BreakpointRequest br = EventRequestManagerWrapper.createBreakpointRequest( VirtualMachineWrapper.eventRequestManager(MirrorWrapper.virtualMachine(threadReference)), loc); BreakpointRequestWrapper.addThreadFilter(br, threadReference); submitMonitorEnteredRequest(br); } catch (IncompatibleThreadStateException itex) { Exceptions.printStackTrace(itex); } catch (InvalidStackFrameExceptionWrapper isex) { Exceptions.printStackTrace(isex); } finally { logger.fine("submitCheckForMonitorEntered(): resuming "+threadName); ThreadReferenceWrapper.resume(threadReference); } }
@Test public void testToString() throws Exception { Value string = this.getLocalValue("str"); Map<String, Object> options = formatter.getDefaultOptions(); options.put(MAX_STRING_LENGTH_OPTION, 4); assertEquals("Should be able to format string type.", String.format("\"s...\" (id=%d)", ((ObjectReference) string).uniqueID()), formatter.toString(string, options)); options.put(MAX_STRING_LENGTH_OPTION, 5); assertEquals("Should be able to format string type.", String.format("\"st...\" (id=%d)", ((ObjectReference) string).uniqueID()), formatter.toString(string, options)); assertTrue("Should not trim long string by default", formatter.toString(string, new HashMap<>()).contains(((StringReference) string).value())); }
public FieldVariable ( JPDADebuggerImpl debugger, PrimitiveValue value, // String className, Field field, String parentID, ObjectReference objectReference // instance or null for static fields ) { super ( debugger, value, getID(parentID, field) ); this.field = field; //this.className = className; this.objectReference = objectReference; }
ObjectArrayFieldVariable ( JPDADebuggerImpl debugger, ObjectReference value, String declaredType, ObjectVariable array, int index, int maxIndex, String parentID ) { super ( debugger, value, parentID + '.' + index + "^" ); this.index = index; this.maxIndexLog = ArrayFieldVariable.log10(maxIndex); this.declaredType = declaredType; this.parent = array; this.array = (ArrayReference) ((JDIVariable) array).getJDIValue(); }
private Value setFieldValueWithConflict(ObjectReference obj, List<Field> fields, String name, String belongToClass, String value, Map<String, Object> options) throws ClassNotLoadedException, InvalidTypeException { Field field; // first try to resolve field by fully qualified name List<Field> narrowedFields = fields.stream().filter(TypeComponent::isStatic) .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) .collect(Collectors.toList()); if (narrowedFields.isEmpty()) { // second try to resolve field by formatted name narrowedFields = fields.stream().filter(TypeComponent::isStatic) .filter(t -> t.name().equals(name) && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) .collect(Collectors.toList()); } if (narrowedFields.size() == 1) { field = narrowedFields.get(0); } else { throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); } return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) : this.setObjectFieldValue(obj, field, name, value, options); }
@Test public void testAcceptType() throws Exception { ObjectReference or = this.getObjectReference("Foo"); assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>())); assertTrue("Should accept Foo type.", formatter.acceptType(or.referenceType(), new HashMap<>())); ObjectReference str = this.getObjectReference("java.lang.String"); assertTrue("Should accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>())); ObjectReference clz = this.getObjectReference("java.lang.Class"); assertTrue("Should accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>())); LocalVariable list = this.getLocalVariable("strList"); assertTrue("Should accept List type.", formatter.acceptType(list.type(), new HashMap<>())); LocalVariable arrays = this.getLocalVariable("arrays"); assertTrue("Should accept array type.", formatter.acceptType(arrays.type(), new HashMap<>())); }
private ObjectReference findEnclosingObject(Tree arg0, ObjectReference object, ReferenceType type, String fieldName, String methodName) { if (instanceOf(object.referenceType(), type)) { return object; } if (((ReferenceType) object.type()).isStatic()) { // instance fields/methods can not be accessed from static context. if (fieldName != null) { Assert.error(arg0, "accessInstanceVariableFromStaticContext", fieldName); } if (methodName != null) { Assert.error(arg0, "invokeInstanceMethodAsStatic", methodName); } return null; } object = findOuterObject(object); if (object == null) { return null; } return findEnclosingObject(arg0, object, type, fieldName, methodName); }
@Override public Mirror visitInstanceOf(InstanceOfTree arg0, EvaluationContext evaluationContext) { Mirror expr = arg0.getExpression().accept(this, evaluationContext); VirtualMachine vm = evaluationContext.getDebugger().getVirtualMachine(); if (vm == null) { return null; } if (expr == null) { return mirrorOf(vm, false); } Assert.assertAssignable(expr, ObjectReference.class, arg0, "instanceOfLeftOperandNotAReference", expr); ReferenceType expressionType = ((ObjectReference) expr).referenceType(); Type type = (Type) arg0.getType().accept(this, evaluationContext); return mirrorOf(vm, instanceOf(expressionType, type)); }
private boolean ungrabWindowFX(ThreadReference tr) { // javafx.stage.Window.impl_getWindows() - Iterator<Window> // while (iterator.hasNext()) { // Window w = iterator.next(); // ungrabWindowFX(w); // } try { VirtualMachine vm = MirrorWrapper.virtualMachine(tr); List<ReferenceType> windowClassesByName = VirtualMachineWrapper.classesByName(vm, "javafx.stage.Window"); if (windowClassesByName.isEmpty()) { logger.info("Unable to release FX X grab, no javafx.stage.Window class in target VM "+VirtualMachineWrapper.description(vm)); return true; // We do not know whether there was any grab } ClassType WindowClass = (ClassType) windowClassesByName.get(0); Method getWindowsMethod = WindowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;"); if (getWindowsMethod == null) { logger.info("Unable to release FX X grab, no impl_getWindows() method in "+WindowClass); return true; // We do not know whether there was any grab } ObjectReference windowsIterator = (ObjectReference) WindowClass.invokeMethod(tr, getWindowsMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (windowsIterator == null) { return true; // We do not know whether there was any grab } InterfaceType IteratorClass = (InterfaceType) VirtualMachineWrapper.classesByName(vm, Iterator.class.getName()).get(0); Method hasNext = IteratorClass.methodsByName("hasNext", "()Z").get(0); Method next = IteratorClass.methodsByName("next", "()Ljava/lang/Object;").get(0); while (hasNext(hasNext, tr, windowsIterator)) { ObjectReference w = next(next, tr, windowsIterator); ungrabWindowFX(WindowClass, w, tr); } } catch (VMDisconnectedExceptionWrapper vmdex) { return true; // Disconnected, all is good. } catch (Exception ex) { logger.log(Level.INFO, "Unable to release FX X grab (if any).", ex); return true; // We do not know whether there was any grab } return true; }
private void ungrabWindowFX(ClassType WindowClass, ObjectReference w, ThreadReference tr) throws Exception { // javafx.stage.Window w // w.focusGrabCounter // while (focusGrabCounter-- > 0) { // w.impl_getPeer().ungrabFocus(); OR: w.impl_peer.ungrabFocus(); // } Field focusGrabCounterField = WindowClass.fieldByName("focusGrabCounter"); if (focusGrabCounterField == null) { logger.info("Unable to release FX X grab, no focusGrabCounter field in "+w); return ; } Value focusGrabCounterValue = w.getValue(focusGrabCounterField); if (!(focusGrabCounterValue instanceof IntegerValue)) { logger.info("Unable to release FX X grab, focusGrabCounter does not have an integer value in "+w); return ; } int focusGrabCounter = ((IntegerValue) focusGrabCounterValue).intValue(); if (logger.isLoggable(Level.FINE)) { logger.fine("Focus grab counter of "+w+" is: "+focusGrabCounter); } while (focusGrabCounter-- > 0) { //Method impl_getPeerMethod = WindowClass.concreteMethodByName("impl_getPeer", ""); Field impl_peerField = WindowClass.fieldByName("impl_peer"); if (impl_peerField == null) { logger.info("Unable to release FX X grab, no impl_peer field in "+w); return ; } ObjectReference impl_peer = (ObjectReference) w.getValue(impl_peerField); if (impl_peer == null) { continue; } InterfaceType TKStageClass = (InterfaceType) w.virtualMachine().classesByName("com.sun.javafx.tk.TKStage").get(0); Method ungrabFocusMethod = TKStageClass.methodsByName("ungrabFocus", "()V").get(0); impl_peer.invokeMethod(tr, ungrabFocusMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (logger.isLoggable(Level.FINE)) { logger.fine("FX Window "+w+" was successfully ungrabbed."); } } }
private static boolean hasBundlePerms(ObjectReference context) { String permissionType = getValue( context, ImmutableList.of("permissions"), currRef -> (currRef != null) ? currRef.type().name() : ""); return permissionType.endsWith("BundlePermissions"); }
private static void pauseMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException { final ClassType audioClipClass = getClass(vm, tr, "com.sun.media.jfxmedia.AudioClip"); final ClassType mediaManagerClass = getClass(vm, tr, "com.sun.media.jfxmedia.MediaManager"); final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer"); final ClassType playerStateEnum = getClass(vm, tr, "com.sun.media.jfxmedia.events.PlayerStateEvent$PlayerState"); if (audioClipClass != null) { Method stopAllClips = audioClipClass.concreteMethodByName("stopAllClips", "()V"); audioClipClass.invokeMethod(tr, stopAllClips, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); } if (mediaManagerClass != null && mediaPlayerClass != null && playerStateEnum != null) { Method getAllPlayers = mediaManagerClass.concreteMethodByName("getAllMediaPlayers", "()Ljava/util/List;"); ObjectReference plList = (ObjectReference)mediaManagerClass.invokeMethod(tr, getAllPlayers, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (plList != null) { ClassType listType = (ClassType)plList.referenceType(); Method iterator = listType.concreteMethodByName("iterator", "()Ljava/util/Iterator;"); ObjectReference plIter = (ObjectReference)plList.invokeMethod(tr, iterator, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); ClassType iterType = (ClassType)plIter.referenceType(); Method hasNext = iterType.concreteMethodByName("hasNext", "()Z"); Method next = iterType.concreteMethodByName("next", "()Ljava/lang/Object;"); Field playingState = playerStateEnum.fieldByName("PLAYING"); Method getState = mediaPlayerClass.methodsByName("getState", "()Lcom/sun/media/jfxmedia/events/PlayerStateEvent$PlayerState;").get(0); Method pausePlayer = mediaPlayerClass.methodsByName("pause", "()V").get(0); boolean hasNextFlag = false; do { BooleanValue v = (BooleanValue)plIter.invokeMethod(tr, hasNext, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); hasNextFlag = v.booleanValue(); if (hasNextFlag) { ObjectReference player = (ObjectReference)plIter.invokeMethod(tr, next, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); ObjectReference curState = (ObjectReference)player.invokeMethod(tr, getState, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (playingState.equals(curState)) { player.invokeMethod(tr, pausePlayer, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); pausedPlayers.add(player); } } } while (hasNextFlag); } } }
private static void resumeMedia(ThreadReference tr, VirtualMachine vm) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException { if (!pausedPlayers.isEmpty()) { final InterfaceType mediaPlayerClass = getInterface(vm, tr, "com.sun.media.jfxmedia.MediaPlayer"); List<Method> play = mediaPlayerClass.methodsByName("play", "()V"); if (play.isEmpty()) { return; } Method p = play.iterator().next(); for(ObjectReference pR : pausedPlayers) { pR.invokeMethod(tr, p, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); } } }
@Test public void testAcceptType() throws Exception { Value boolVar = getVM().mirrorOf(true); assertTrue("Should accept any type.", formatter.acceptType(boolVar.type(), new HashMap<>())); ObjectReference or = this.getObjectReference("Foo"); assertTrue("Should accept any type.", formatter.acceptType(null, new HashMap<>())); assertTrue("Should accept any type.", formatter.acceptType(or.type(), new HashMap<>())); ObjectReference str = this.getObjectReference("java.lang.String"); assertTrue("Should accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>())); }
public static List<RemoteListener> getAttachedListeners(final JavaComponentInfo ci, final boolean combineAllTypes) throws PropertyVetoException { final List<RemoteListener> rlisteners = new ArrayList<RemoteListener>(); final JPDAThreadImpl thread = ci.getThread(); final ObjectReference component = ci.getComponent(); Pair<ClassType, Field> setPreferredEQThreadField; try { setPreferredEQThreadField = setPreferredEQThread(thread, ServiceType.AWT); } catch (InternalExceptionWrapper | VMDisconnectedExceptionWrapper ex) { return rlisteners; } try { runOnStoppedThread(thread, new Runnable() { @Override public void run() { if (ci instanceof RemoteAWTScreenshot.AWTComponentInfo) { retrieveAttachedListeners(thread, component, rlisteners, combineAllTypes); } else { retrieveAttachedFXListeners(thread, component, rlisteners); } } }, (ci instanceof RemoteAWTScreenshot.AWTComponentInfo) ? ServiceType.AWT : ServiceType.FX); } finally { clearPreferredEQThread(thread.getDebugger(), setPreferredEQThreadField); } return rlisteners; }
public synchronized void enableCollection() { gcDisableCount--; if (gcDisableCount == 0) { try { JDWP.ObjectReference.EnableCollection.process(vm, this); } catch (JDWPException exc) { // If already collected, no harm done, no exception if (exc.errorCode() != JDWP.Error.INVALID_OBJECT) { throw exc.toJDIException(); } return; } } }
/** * Get the variables of the object with pagination. * * @param obj * the object * @param start * the start of the pagination * @param count * the number of variables needed * @return the variable list * @throws AbsentInformationException * when there is any error in retrieving information */ public static List<Variable> listFieldVariables(ObjectReference obj, int start, int count) throws AbsentInformationException { List<Variable> res = new ArrayList<>(); Type type = obj.type(); if (type instanceof ArrayType) { int arrayIndex = start; for (Value elementValue : ((ArrayReference) obj).getValues(start, count)) { res.add(new Variable(String.valueOf(arrayIndex++), elementValue)); } return res; } throw new UnsupportedOperationException("Only Array type is supported."); }
public static Stack getStackOf(JPDADebugger debugger, ObjectReference component) { synchronized(componentsAndStackTraces) { Map<ObjectReference, Stack> cs = componentsAndStackTraces.get(debugger); if (cs != null) { return cs.get(component); } else { return null; } } }
private void addProperties() { addPropertySet(new PropertySet("main", NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropMain"), NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropMainDescr")) { @Override public Property<?>[] getProperties() { return new Property[] { new ReadOnly("name", String.class, NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropName"), NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropNameDescr")) { @Override public Object getValue() throws IllegalAccessException, InvocationTargetException { return JavaComponentInfo.this.getName(); } }, new ReadOnly("type", String.class, NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropType"), NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropTypeDescr")) { @Override public Object getValue() throws IllegalAccessException, InvocationTargetException { return JavaComponentInfo.this.getType(); } }, new ReadOnly("bounds", String.class, NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropBounds"), NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropBoundsDescr")) { @Override public Object getValue() throws IllegalAccessException, InvocationTargetException { Rectangle r = JavaComponentInfo.this.getWindowBounds(); return "[x=" + r.x + ",y=" + r.y + ",width=" + r.width + ",height=" + r.height + "]"; } }, }; } }); final LazyProperties lazyProperties = new LazyProperties(); addPropertySet( new PropertySet("Properties", NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentProps"), NbBundle.getMessage(JavaComponentInfo.class, "MSG_ComponentPropsDescr")) { @Override public Property<?>[] getProperties() { //System.err.println("JavaComponentInfo.Properties PropertySet.getProperties()"); // To fix https://netbeans.org/bugzilla/show_bug.cgi?id=243065 // https://netbeans.org/bugzilla/show_bug.cgi?id=241154 // Do not compute properties above, compute them on demand in a separate thread now. // When done, fire Node.PROP_PROPERTY_SETS, null, null. Property<?>[] props = lazyProperties.getProperties(); //System.err.println("\nprops = "+props.length+"\n"); return props; } }); try { Method getTextMethod = ClassTypeWrapper.concreteMethodByName( (ClassType) ObjectReferenceWrapper.referenceType(component), "getText", "()Ljava/lang/String;"); //Method getTextMethod = methodsByName.get("getText"); // NOI18N if (getTextMethod != null) { try { Value theText = ObjectReferenceWrapper.invokeMethod(component, getThread().getThreadReference(), getTextMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); if (theText instanceof StringReference) { setComponentText(StringReferenceWrapper.value((StringReference) theText)); } } catch (VMDisconnectedExceptionWrapper vmdex) { return; } catch (Exception ex) { Exceptions.printStackTrace(ex); } } } catch (ClassNotPreparedExceptionWrapper | InternalExceptionWrapper | ObjectCollectedExceptionWrapper | VMDisconnectedExceptionWrapper cnpe) { } }
ComponentProperty(String propertyName, Method getter, Method setter, JavaComponentInfo ci, ObjectReference component, JPDAThreadImpl t, JPDADebuggerImpl debugger, RemoteServices.ServiceType sType) { super(String.class); this.propertyName = propertyName; this.getter = getter; this.setter = setter; this.ci = ci; this.component = component; this.t = t; this.tawt = t.getThreadReference(); this.debugger = debugger; this.sType = sType; }
@Test public void testToString() throws Exception { Value clazzValue = this.getLocalValue("b"); assertEquals("Should be able to format clazz type.", String.format("java.lang.Class (A) (id=%d)", ((ObjectReference)clazzValue).uniqueID()), formatter.toString(clazzValue, new HashMap<>())); }
private ComponentInfo findComponentInfo(ComponentInfo ci, ObjectReference oc) { if (ci instanceof JavaComponentInfo) { ObjectReference or = ((JavaComponentInfo) ci).getComponent(); if (oc.equals(or)) { return ci; } } for (ComponentInfo sci : ci.getSubComponents()) { ComponentInfo fci = findComponentInfo(sci, oc); if (fci != null) { return fci; } } return null; }