com.sun.jdi.ThreadReference Java Examples
The following examples show how to use
com.sun.jdi.ThreadReference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VisualDebuggerListener.java From netbeans with Apache License 2.0 | 6 votes |
/** * JavaFX runtime is boobietrapped with various checks for {@linkplain com.sun.javafx.runtime.SystemProperties#isDebug() } * which lead to spurious NPEs. Need to make it happy and force the runtime into debug mode */ private static void setFxDebug(VirtualMachine vm, ThreadReference tr) { ClassType sysPropClass = getClass(vm, tr, "com.sun.javafx.runtime.SystemProperties"); if(sysPropClass == null) { // openjfx doesn't have runtime.SystemProperties.isDebug return; } try { Field debugFld = ReferenceTypeWrapper.fieldByName(sysPropClass, "isDebug"); // NOI18N sysPropClass.setValue(debugFld, VirtualMachineWrapper.mirrorOf(vm, true)); } catch (VMDisconnectedExceptionWrapper vmdex) { } catch (InternalExceptionWrapper iex) { } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
Example #2
Source File: ThreadsRequestHandler.java From java-debug with Eclipse Public License 1.0 | 6 votes |
private CompletableFuture<Response> resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) { boolean allThreadsContinued = true; ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); /** * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(), * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended. */ if (thread != null) { context.getExceptionManager().removeException(arguments.threadId); allThreadsContinued = false; DebugUtility.resumeThread(thread); checkThreadRunningAndRecycleIds(thread, context); } else { context.getExceptionManager().removeAllExceptions(); context.getDebugSession().resume(); context.getRecyclableIdPool().removeAllObjects(); } response.body = new Responses.ContinueResponseBody(allThreadsContinued); return CompletableFuture.completedFuture(response); }
Example #3
Source File: JPDADebuggerImpl.java From netbeans with Apache License 2.0 | 6 votes |
public void popFrames (ThreadReference thread, StackFrame frame) { PropertyChangeEvent evt = null; accessLock.readLock().lock(); try { JPDAThreadImpl threadImpl = getThread(thread); setState (STATE_RUNNING); try { threadImpl.popFrames(frame); evt = updateCurrentCallStackFrameNoFire(threadImpl); } catch (IncompatibleThreadStateException ex) { Exceptions.printStackTrace(ex); } finally { setState (STATE_STOPPED); } } finally { accessLock.readLock().unlock(); } if (evt != null) { firePropertyChange(evt); } }
Example #4
Source File: DebugJUnitRunner.java From astor with GNU General Public License v2.0 | 6 votes |
public static boolean loadClass(String className, VirtualMachine vm) { boolean result = false; ClassType classReference = (ClassType) vm.classesByName("java.lang.Class").get(0); for (int i = 0; i < vm.allThreads().size(); i++) { ThreadReference thread = vm.allThreads().get(i); try { classReference.invokeMethod(thread, classReference.methodsByName("forName").get(0), Arrays.asList(vm.mirrorOf(className)), ObjectReference.INVOKE_SINGLE_THREADED); } catch (Exception e) { continue; } result = true; break; } return result; }
Example #5
Source File: ThreadInfo.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static void removeThread(ThreadReference thread) { if (thread.equals(ThreadInfo.current)) { // Current thread has died. // Be careful getting the thread name. If its death happens // as part of VM termination, it may be too late to get the // information, and an exception will be thrown. String currentThreadName; try { currentThreadName = "\"" + thread.name() + "\""; } catch (Exception e) { currentThreadName = ""; } setCurrentThread(null); MessageOutput.println(); MessageOutput.println("Current thread died. Execution continuing...", currentThreadName); } threads.remove(getThreadInfo(thread)); }
Example #6
Source File: ThreadInfo.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void removeThread(ThreadReference thread) { if (thread.equals(ThreadInfo.current)) { // Current thread has died. // Be careful getting the thread name. If its death happens // as part of VM termination, it may be too late to get the // information, and an exception will be thrown. String currentThreadName; try { currentThreadName = "\"" + thread.name() + "\""; } catch (Exception e) { currentThreadName = ""; } setCurrentThread(null); MessageOutput.println(); MessageOutput.println("Current thread died. Execution continuing...", currentThreadName); } threads.remove(getThreadInfo(thread)); }
Example #7
Source File: Operator.java From netbeans with Apache License 2.0 | 6 votes |
public void notifyMethodInvokeDone(ThreadReference tr) { if (logger.isLoggable(Level.FINE)) { logger.fine(" notifyMethodInvokeDone("+tr+")"); } if (Thread.currentThread() == thread) { HandlerTask task = eventHandlers.remove(tr); if (task != null) { task.cancel(); } } boolean done; synchronized (methodInvokingThreads) { methodInvokingThreads.remove(tr); done = methodInvokingThreads.isEmpty(); } if (done) { loopControl.setInMethodInvoke(false); } }
Example #8
Source File: DebugSession.java From java-debug with Eclipse Public License 1.0 | 6 votes |
@Override public void resume() { /** * To ensure that all threads are fully resumed when the VM is resumed, make sure the suspend count * of each thread is no larger than 1. * Notes: Decrementing the thread' suspend count to 1 is on purpose, because it doesn't break the * the thread's suspend state, and also make sure the next instruction vm.resume() is able to resume * all threads fully. */ for (ThreadReference tr : DebugUtility.getAllThreadsSafely(this)) { while (!tr.isCollected() && tr.suspendCount() > 1) { tr.resume(); } } vm.resume(); }
Example #9
Source File: JPDAThreadImpl.java From netbeans with Apache License 2.0 | 6 votes |
public void resumeBlockingThreads() { List<JPDAThread> blockingThreads; synchronized (lockerThreadsLock) { if (lockerThreadsList == null) { return ;//false; } blockingThreads = new ArrayList<>(lockerThreadsList); } List<ThreadReference> resumedThreads = new ArrayList<ThreadReference>(blockingThreads.size()); for (JPDAThread t : blockingThreads) { if (t.isSuspended()) { t.resume(); resumedThreads.add(((JPDAThreadImpl) t).getThreadReference()); } } synchronized (lockerThreadsLock) { this.resumedBlockingThreads = resumedThreads; } return ;//true; }
Example #10
Source File: JPDADebuggerImpl.java From netbeans with Apache License 2.0 | 6 votes |
public void notifyToBeResumedAllNoFire(Set<ThreadReference> ignoredThreads) { Collection threads = threadsTranslation.getTranslated(); for (Iterator it = threads.iterator(); it.hasNext(); ) { Object threadOrGroup = it.next(); if (threadOrGroup instanceof JPDAThreadImpl && (ignoredThreads == null || !ignoredThreads.contains(threadOrGroup))) { int status = ((JPDAThreadImpl) threadOrGroup).getState(); boolean invalid = (status == JPDAThread.STATE_NOT_STARTED || status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE); if (!invalid) { ((JPDAThreadImpl) threadOrGroup).notifyToBeResumedNoFire(); } else if (status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE) { threadsTranslation.remove(((JPDAThreadImpl) threadOrGroup).getThreadReference()); } } } }
Example #11
Source File: JPDADebuggerImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void run() { List<ThreadReference> allThreads = vm.allThreads(); System.err.println("All Threads:"); for (ThreadReference tr : allThreads) { String name = tr.name(); boolean suspended = tr.isSuspended(); int suspendCount = tr.suspendCount(); int status = tr.status(); System.err.println(name+"\t SUSP = "+suspended+", COUNT = "+suspendCount+", STATUS = "+status); } System.err.println(""); if (!finish) { rp.post(this, INTERVAL); } }
Example #12
Source File: ThreadInfo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static void addThread(ThreadReference thread) { synchronized (threads) { initThreads(); ThreadInfo ti = new ThreadInfo(thread); // Guard against duplicates. Duplicates can happen during // initialization when a particular thread might be added both // by a thread start event and by the initial call to threads() if (getThreadInfo(thread) == null) { threads.add(ti); } } }
Example #13
Source File: ExceptionInfoRequestHandler.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { ExceptionInfoArguments exceptionInfoArgs = (ExceptionInfoArguments) arguments; ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), exceptionInfoArgs.threadId); if (thread == null) { throw AdapterUtils.createCompletionException("Thread " + exceptionInfoArgs.threadId + " doesn't exist.", ErrorCode.EXCEPTION_INFO_FAILURE); } JdiExceptionReference jdiException = context.getExceptionManager().getException(exceptionInfoArgs.threadId); if (jdiException == null) { throw AdapterUtils.createCompletionException("No exception exists in thread " + exceptionInfoArgs.threadId, ErrorCode.EXCEPTION_INFO_FAILURE); } Method toStringMethod = null; for (Method method : jdiException.exception.referenceType().allMethods()) { if (Objects.equals("toString", method.name()) && Objects.equals("()Ljava/lang/String;", method.signature())) { toStringMethod = method; break; } } String typeName = jdiException.exception.type().name(); String exceptionToString = typeName; if (toStringMethod != null) { try { Value returnValue = jdiException.exception.invokeMethod(thread, toStringMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED); exceptionToString = returnValue.toString(); } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) { logger.log(Level.SEVERE, String.format("Failed to get the return value of the method Exception.toString(): %s", e.toString(), e)); } } response.body = new Responses.ExceptionInfoResponse(typeName, exceptionToString, jdiException.isUncaught ? ExceptionBreakMode.USERUNHANDLED : ExceptionBreakMode.ALWAYS); return CompletableFuture.completedFuture(response); }
Example #14
Source File: EvaluatableBreakpoint.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public CompletableFuture<IBreakpoint> install() { Disposable subscription = eventHub.events() .filter(debugEvent -> debugEvent.event instanceof ThreadDeathEvent) .subscribe(debugEvent -> { ThreadReference deathThread = ((ThreadDeathEvent) debugEvent.event).thread(); compiledExpressions.remove(deathThread.uniqueID()); }); super.subscriptions().add(subscription); return super.install(); }
Example #15
Source File: ProcessAttachDebugger.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String main_args[]) throws Exception { String pid = main_args[0]; // find ProcessAttachingConnector List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors(); AttachingConnector ac = null; for (AttachingConnector c: l) { if (c.name().equals("com.sun.jdi.ProcessAttach")) { ac = c; break; } } if (ac == null) { throw new RuntimeException("Unable to locate ProcessAttachingConnector"); } Map<String,Connector.Argument> args = ac.defaultArguments(); Connector.StringArgument arg = (Connector.StringArgument)args.get("pid"); arg.setValue(pid); System.out.println("Debugger is attaching to: " + pid + " ..."); VirtualMachine vm = ac.attach(args); System.out.println("Attached! Now listing threads ..."); // list all threads for (ThreadReference thr: vm.allThreads()) { System.out.println(thr); } System.out.println("Debugger done."); }
Example #16
Source File: ThreadInfo.java From hottub with GNU General Public License v2.0 | 5 votes |
static void setCurrentThread(ThreadReference tr) { if (tr == null) { setCurrentThreadInfo(null); } else { ThreadInfo tinfo = getThreadInfo(tr); setCurrentThreadInfo(tinfo); } }
Example #17
Source File: ThreadInfo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void initThreads() { if (!gotInitialThreads) { for (ThreadReference thread : Env.vm().allThreads()) { threads.add(new ThreadInfo(thread)); } gotInitialThreads = true; } }
Example #18
Source File: ThreadsCache.java From netbeans with Apache License 2.0 | 5 votes |
private void filterThreads(List<ThreadReference> threads) { for (int i = 0; i < threads.size(); i++) { ThreadReference tr = threads.get(i); try { if (ThreadReferenceWrapper.name(tr).contains(THREAD_NAME_FILTER_PATTERN)) { threads.remove(i); i--; } } catch (Exception ex) { // continue } } }
Example #19
Source File: VMTargetRemoteTest.java From gravel with Apache License 2.0 | 5 votes |
@Test public void testDNU() throws Throwable { ObjectReference promise = remote.evaluateForked("3 fromage"); ThreadReference thread = ((ThreadReference) remote.invokeMethod( promise, "thread")); remote.invokeMethod(thread, "start"); ObjectReference state = (ObjectReference) remote.invokeMethod(thread, "getState"); StringReference str = (StringReference) remote.invokeMethod(state, "toString"); System.out.println(str.value()); printStack(thread); // assertFalse(thread.isSuspended()); printThreadState(); System.out.println("VMTargetStarter.sleep(1000)"); VMTargetStarter.sleep(1000); printStack(thread); printThreadState(); boolean isFinished = ((BooleanValue) remote.invokeMethod(promise, "isFinished")).booleanValue(); assertFalse(isFinished); printThreadState(); printStack(thread); assertTrue(thread.isAtBreakpoint()); }
Example #20
Source File: VariableMirrorTranslator.java From netbeans with Apache License 2.0 | 5 votes |
private static void setValueToFinalField(ObjectReference obj, String name, ClassType clazz, Value fv, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException, InvalidObjectException { ObjectReference fieldRef = getDeclaredOrInheritedField(clazz, name, vm, thread); if (fieldRef == null) { InvalidObjectException ioex = new InvalidObjectException("No field "+name+" of class "+clazz); throw ioex; } // field.setAccessible(true); ClassType fieldClassType = (ClassType) ValueWrapper.type(fieldRef); com.sun.jdi.Method setAccessibleMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "setAccessible", "(Z)V"); try { ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setAccessibleMethod, Collections.singletonList(vm.mirrorOf(true)), ClassType.INVOKE_SINGLE_THREADED); // field.set(newInstance, fv); com.sun.jdi.Method setMethod = ClassTypeWrapper.concreteMethodByName( fieldClassType, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V"); if (fv instanceof PrimitiveValue) { PrimitiveType pt = (PrimitiveType) ValueWrapper.type(fv); ReferenceType fieldBoxingClass = EvaluatorVisitor.adjustBoxingType(clazz, pt, null); fv = EvaluatorVisitor.box((PrimitiveValue) fv, fieldBoxingClass, thread, null); } List<Value> args = Arrays.asList(new Value[] { obj, fv }); ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setMethod, args, ClassType.INVOKE_SINGLE_THREADED); } catch (InvocationException iex) { throw new InvalidObjectException( "Problem setting value "+fv+" to field "+name+" of class "+clazz+ " : "+iex.exception()); } }
Example #21
Source File: JPDAStepImpl.java From netbeans with Apache License 2.0 | 5 votes |
private boolean setUpBoundaryStepRequest(EventRequestManager erm, ThreadReference trRef, boolean isNextOperationFromDifferentExpression) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { boundaryStepRequest = EventRequestManagerWrapper.createStepRequest( erm, trRef, StepRequest.STEP_LINE, StepRequest.STEP_OVER ); if (isNextOperationFromDifferentExpression) { EventRequestWrapper.addCountFilter(boundaryStepRequest, 2); } else { EventRequestWrapper.addCountFilter(boundaryStepRequest, 1); } ((JPDADebuggerImpl) debugger).getOperator().register(boundaryStepRequest, this); EventRequestWrapper.setSuspendPolicy(boundaryStepRequest, debugger.getSuspend()); try { EventRequestWrapper.enable (boundaryStepRequest); requestsToCancel.add(boundaryStepRequest); } catch (IllegalThreadStateException itsex) { // the thread named in the request has died. ((JPDADebuggerImpl) debugger).getOperator().unregister(boundaryStepRequest); boundaryStepRequest = null; return false; } catch (InvalidRequestStateExceptionWrapper ex) { Exceptions.printStackTrace(ex); ((JPDADebuggerImpl) debugger).getOperator().unregister(boundaryStepRequest); boundaryStepRequest = null; return false; } return true; }
Example #22
Source File: AWTGrabHandler.java From netbeans with Apache License 2.0 | 5 votes |
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.<Value>emptyList(), 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; }
Example #23
Source File: ThreadInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static void addThread(ThreadReference thread) { synchronized (threads) { initThreads(); ThreadInfo ti = new ThreadInfo(thread); // Guard against duplicates. Duplicates can happen during // initialization when a particular thread might be added both // by a thread start event and by the initial call to threads() if (getThreadInfo(thread) == null) { threads.add(ti); } } }
Example #24
Source File: ProcessAttachDebugger.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String main_args[]) throws Exception { String pid = main_args[0]; // find ProcessAttachingConnector List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors(); AttachingConnector ac = null; for (AttachingConnector c: l) { if (c.name().equals("com.sun.jdi.ProcessAttach")) { ac = c; break; } } if (ac == null) { throw new RuntimeException("Unable to locate ProcessAttachingConnector"); } Map<String,Connector.Argument> args = ac.defaultArguments(); Connector.StringArgument arg = (Connector.StringArgument)args.get("pid"); arg.setValue(pid); System.out.println("Debugger is attaching to: " + pid + " ..."); VirtualMachine vm = ac.attach(args); System.out.println("Attached! Now listing threads ..."); // list all threads for (ThreadReference thr: vm.allThreads()) { System.out.println(thr); } System.out.println("Debugger done."); }
Example #25
Source File: TreeEvaluator.java From netbeans with Apache License 2.0 | 5 votes |
public static Value invokeVirtual ( ClassType classType, Method method, ThreadReference evaluationThread, List<Value> args, JPDADebuggerImpl debugger, InvocationExceptionTranslated existingInvocationException ) throws InvalidExpressionException { return invokeVirtual(null, classType, method, evaluationThread, args, debugger, existingInvocationException); }
Example #26
Source File: ThreadsRequestHandler.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private CompletableFuture<Response> pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) { ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); if (thread != null) { thread.suspend(); context.getProtocolServer().sendEvent(new Events.StoppedEvent("pause", arguments.threadId)); } else { context.getDebugSession().suspend(); context.getProtocolServer().sendEvent(new Events.StoppedEvent("pause", arguments.threadId, true)); } return CompletableFuture.completedFuture(response); }
Example #27
Source File: ThreadInfo.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static void setCurrentThread(ThreadReference tr) { if (tr == null) { setCurrentThreadInfo(null); } else { ThreadInfo tinfo = getThreadInfo(tr); setCurrentThreadInfo(tinfo); } }
Example #28
Source File: JdtEvaluationProvider.java From java-debug with Eclipse Public License 1.0 | 5 votes |
@Override public CompletableFuture<Value> invokeMethod(ObjectReference thisContext, String methodName, String methodSignature, Value[] args, ThreadReference thread, boolean invokeSuper) { CompletableFuture<Value> completableFuture = new CompletableFuture<>(); try { ensureDebugTarget(thisContext.virtualMachine(), thisContext.type().name()); JDIThread jdiThread = getMockJDIThread(thread); JDIObjectValue jdiObject = new JDIObjectValue(debugTarget, thisContext); List<IJavaValue> arguments = null; if (args == null) { arguments = Collections.EMPTY_LIST; } else { arguments = new ArrayList<>(args.length); for (Value arg : args) { arguments.add(new JDIValue(debugTarget, arg)); } } IJavaValue javaValue = jdiObject.sendMessage(methodName, methodSignature, arguments.toArray(new IJavaValue[0]), jdiThread, invokeSuper); // we need to read fValue from the result Value instance implements by JDT Value value = (Value) FieldUtils.readField(javaValue, "fValue", true); completableFuture.complete(value); return completableFuture; } catch (Exception ex) { completableFuture.completeExceptionally(ex); return completableFuture; } }
Example #29
Source File: ProcessAttachDebugger.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String main_args[]) throws Exception { String pid = main_args[0]; // find ProcessAttachingConnector List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors(); AttachingConnector ac = null; for (AttachingConnector c: l) { if (c.name().equals("com.sun.jdi.ProcessAttach")) { ac = c; break; } } if (ac == null) { throw new RuntimeException("Unable to locate ProcessAttachingConnector"); } Map<String,Connector.Argument> args = ac.defaultArguments(); Connector.StringArgument arg = (Connector.StringArgument)args.get("pid"); arg.setValue(pid); System.out.println("Debugger is attaching to: " + pid + " ..."); VirtualMachine vm = ac.attach(args); System.out.println("Attached! Now listing threads ..."); // list all threads for (ThreadReference thr: vm.allThreads()) { System.out.println(thr); } System.out.println("Debugger done."); }
Example #30
Source File: ProcessAttachDebugger.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String main_args[]) throws Exception { String pid = main_args[0]; // find ProcessAttachingConnector List<AttachingConnector> l = Bootstrap.virtualMachineManager().attachingConnectors(); AttachingConnector ac = null; for (AttachingConnector c: l) { if (c.name().equals("com.sun.jdi.ProcessAttach")) { ac = c; break; } } if (ac == null) { throw new RuntimeException("Unable to locate ProcessAttachingConnector"); } Map<String,Connector.Argument> args = ac.defaultArguments(); Connector.StringArgument arg = (Connector.StringArgument)args.get("pid"); arg.setValue(pid); System.out.println("Debugger is attaching to: " + pid + " ..."); VirtualMachine vm = ac.attach(args); System.out.println("Attached! Now listing threads ..."); // list all threads for (ThreadReference thr: vm.allThreads()) { System.out.println(thr); } System.out.println("Debugger done."); }