📄 commands.java
字号:
MessageOutput.println("Nothing suspended."); return; } clearPreviousStep(threadInfo.getThread()); EventRequestManager reqMgr = Env.vm().eventRequestManager(); StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(), StepRequest.STEP_LINE, StepRequest.STEP_OVER); Env.addExcludes(request); // We want just the next step event and no others request.addCountFilter(1); request.enable(); ThreadInfo.invalidateAll(); Env.vm().resume(); } void doKill(ThreadReference thread, StringTokenizer t) { if (!t.hasMoreTokens()) { MessageOutput.println("No exception object specified."); return; } String expr = t.nextToken(""); Value val = evaluate(expr); if ((val != null) && (val instanceof ObjectReference)) { try { thread.stop((ObjectReference)val); MessageOutput.println("killed", thread.toString()); } catch (InvalidTypeException e) { MessageOutput.println("Invalid exception object"); } } else { MessageOutput.println("Expression must evaluate to an object"); } } void doKillThread(final ThreadReference threadToKill, final StringTokenizer tokenizer) { new AsyncExecution() { void action() { doKill(threadToKill, tokenizer); } }; } void commandKill(StringTokenizer t) { if (!t.hasMoreTokens()) { MessageOutput.println("Usage: kill <thread id> <throwable>"); return; } ThreadInfo threadInfo = doGetThread(t.nextToken()); if (threadInfo != null) { MessageOutput.println("killing thread:", threadInfo.getThread().name()); doKillThread(threadInfo.getThread(), t); return; } } void listCaughtExceptions() { boolean noExceptions = true; // Print a listing of the catch patterns currently in place Iterator iter = Env.specList.eventRequestSpecs().iterator(); while (iter.hasNext()) { EventRequestSpec spec = (EventRequestSpec)iter.next(); if (spec instanceof ExceptionSpec) { if (noExceptions) { noExceptions = false; MessageOutput.println("Exceptions caught:"); } MessageOutput.println("tab", spec.toString()); } } if (noExceptions) { MessageOutput.println("No exceptions caught."); } } private EventRequestSpec parseExceptionSpec(StringTokenizer t) { String notification = t.nextToken(); boolean notifyCaught = false; boolean notifyUncaught = false; EventRequestSpec spec = null; String classPattern = null; if (notification.equals("uncaught")) { notifyCaught = false; notifyUncaught = true; } else if (notification.equals("caught")) { notifyCaught = true; notifyUncaught = false; } else if (notification.equals("all")) { notifyCaught = true; notifyUncaught = true; } else { /* * Handle the same as "all" for backward * compatibility with existing .jdbrc files. * * Insert an "all" and take the current token as the * intended classPattern * */ notifyCaught = true; notifyUncaught = true; classPattern = notification; } if (classPattern == null && t.hasMoreTokens()) { classPattern = t.nextToken(); } if (notifyCaught || notifyUncaught) { try { spec = Env.specList.createExceptionCatch(classPattern, notifyCaught, notifyUncaught); } catch (ClassNotFoundException exc) { MessageOutput.println("is not a valid class name", classPattern); } } return spec; } void commandCatchException(StringTokenizer t) { if (!t.hasMoreTokens()) { listCaughtExceptions(); } else { EventRequestSpec spec = parseExceptionSpec(t); if (spec != null) { resolveNow(spec); } else { MessageOutput.println("Usage: catch exception"); } } } void commandIgnoreException(StringTokenizer t) { if (!t.hasMoreTokens()) { listCaughtExceptions(); } else { EventRequestSpec spec = parseExceptionSpec(t); if (Env.specList.delete(spec)) { MessageOutput.println("Removed:", spec.toString()); } else { if (spec != null) { MessageOutput.println("Not found:", spec.toString()); } MessageOutput.println("Usage: ignore exception"); } } } void commandUp(StringTokenizer t) { ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); if (threadInfo == null) { MessageOutput.println("Current thread not set."); return; } int nLevels = 1; if (t.hasMoreTokens()) { String idToken = t.nextToken(); int i; try { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setParseIntegerOnly(true); Number n = nf.parse(idToken); i = n.intValue(); } catch (java.text.ParseException jtpe) { i = 0; } if (i <= 0) { MessageOutput.println("Usage: up [n frames]"); return; } nLevels = i; } try { threadInfo.up(nLevels); } catch (IncompatibleThreadStateException e) { MessageOutput.println("Current thread isnt suspended."); } catch (ArrayIndexOutOfBoundsException e) { MessageOutput.println("End of stack."); } } void commandDown(StringTokenizer t) { ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); if (threadInfo == null) { MessageOutput.println("Current thread not set."); return; } int nLevels = 1; if (t.hasMoreTokens()) { String idToken = t.nextToken(); int i; try { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setParseIntegerOnly(true); Number n = nf.parse(idToken); i = n.intValue(); } catch (java.text.ParseException jtpe) { i = 0; } if (i <= 0) { MessageOutput.println("Usage: down [n frames]"); return; } nLevels = i; } try { threadInfo.down(nLevels); } catch (IncompatibleThreadStateException e) { MessageOutput.println("Current thread isnt suspended."); } catch (ArrayIndexOutOfBoundsException e) { MessageOutput.println("End of stack."); } } private void dumpStack(ThreadInfo threadInfo, boolean showPC) { List stack = null; try { stack = threadInfo.getStack(); } catch (IncompatibleThreadStateException e) { MessageOutput.println("Current thread isnt suspended."); return; } if (stack == null) { MessageOutput.println("Thread is not running (no stack)."); } else { int nFrames = stack.size(); for (int i = threadInfo.getCurrentFrameIndex(); i < nFrames; i++) { StackFrame frame = (StackFrame)stack.get(i); dumpFrame (i, showPC, frame); } } } private void dumpFrame (int frameNumber, boolean showPC, StackFrame frame) { Location loc = frame.location(); long pc = -1; if (showPC) { pc = loc.codeIndex(); } Method meth = loc.method(); long lineNumber = loc.lineNumber(); String methodInfo = null; if (meth instanceof Method && ((Method)meth).isNative()) { methodInfo = MessageOutput.format("native method"); } else if (lineNumber != -1) { try { methodInfo = loc.sourceName() + MessageOutput.format("line number", new Object [] {new Long(lineNumber)}); } catch (AbsentInformationException e) { methodInfo = MessageOutput.format("unknown"); } } if (pc != -1) { MessageOutput.println("stack frame dump with pc", new Object [] {new Integer(frameNumber + 1), meth.declaringType().name(), meth.name(), methodInfo, new Long(pc)}); } else { MessageOutput.println("stack frame dump", new Object [] {new Integer(frameNumber + 1), meth.declaringType().name(), meth.name(), methodInfo}); } } void commandWhere(StringTokenizer t, boolean showPC) { if (!t.hasMoreTokens()) { ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); if (threadInfo == null) { MessageOutput.println("No thread specified."); return; } dumpStack(threadInfo, showPC); } else { String token = t.nextToken(); if (token.toLowerCase().equals("all")) { Iterator iter = ThreadInfo.threads().iterator(); while (iter.hasNext()) { ThreadInfo threadInfo = (ThreadInfo)iter.next(); MessageOutput.println("Thread:", threadInfo.getThread().name()); dumpStack(threadInfo, showPC); } } else { ThreadInfo threadInfo = doGetThread(token); if (threadInfo != null) { ThreadInfo.setCurrentThreadInfo(threadInfo); dumpStack(threadInfo, showPC); } } } } void commandInterrupt(StringTokenizer t) { if (!t.hasMoreTokens()) { ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); if (threadInfo == null) { MessageOutput.println("No thread specified."); return; } threadInfo.getThread().interrupt(); } else { ThreadInfo threadInfo = doGetThread(t.nextToken()); if (threadInfo != null) { threadInfo.getThread().interrupt(); } } } void commandMemory() { MessageOutput.println("The memory command is no longer supported."); } void commandGC() { MessageOutput.println("The gc command is no longer necessary."); } /* * The next two methods are used by this class and by EventHandler * to print consistent locations and error messages. */ static String locationString(Location loc) { return MessageOutput.format("locationString", new Object [] {loc.declaringType().name(), loc.method().name(), new Integer (loc.lineNumber()), new Long (loc.codeIndex())});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -