📄 commands.java
字号:
} void listBreakpoints() { boolean noBreakpoints = true; // Print set breakpoints Iterator iter = Env.specList.eventRequestSpecs().iterator(); while (iter.hasNext()) { EventRequestSpec spec = (EventRequestSpec)iter.next(); if (spec instanceof BreakpointSpec) { if (noBreakpoints) { noBreakpoints = false; MessageOutput.println("Breakpoints set:"); } MessageOutput.println("tab", spec.toString()); } } if (noBreakpoints) { MessageOutput.println("No breakpoints set."); } } private void printBreakpointCommandUsage(String atForm, String inForm) { MessageOutput.println("printbreakpointcommandusage", new Object [] {atForm, inForm}); } protected BreakpointSpec parseBreakpointSpec(StringTokenizer t, String atForm, String inForm) { EventRequestSpec breakpoint = null; try { String token = t.nextToken(":( \t\n\r"); // We can't use hasMoreTokens here because it will cause any leading // paren to be lost. String rest; try { rest = t.nextToken("").trim(); } catch (NoSuchElementException e) { rest = null; } if ((rest != null) && rest.startsWith(":")) { t = new StringTokenizer(rest.substring(1)); String classId = token; String lineToken = t.nextToken(); NumberFormat nf = NumberFormat.getNumberInstance(); nf.setParseIntegerOnly(true); Number n = nf.parse(lineToken); int lineNumber = n.intValue(); if (t.hasMoreTokens()) { printBreakpointCommandUsage(atForm, inForm); return null; } try { breakpoint = Env.specList.createBreakpoint(classId, lineNumber); } catch (ClassNotFoundException exc) { MessageOutput.println("is not a valid class name", classId); } } else { // Try stripping method from class.method token. int idot = token.lastIndexOf("."); if ( (idot <= 0) || /* No dot or dot in first char */ (idot >= token.length() - 1) ) { /* dot in last char */ printBreakpointCommandUsage(atForm, inForm); return null; } String methodName = token.substring(idot + 1); String classId = token.substring(0, idot); List argumentList = null; if (rest != null) { if (!rest.startsWith("(") || !rest.endsWith(")")) { MessageOutput.println("Invalid method specification:", methodName + rest); printBreakpointCommandUsage(atForm, inForm); return null; } // Trim the parens rest = rest.substring(1, rest.length() - 1); argumentList = new ArrayList(); t = new StringTokenizer(rest, ","); while (t.hasMoreTokens()) { argumentList.add(t.nextToken()); } } try { breakpoint = Env.specList.createBreakpoint(classId, methodName, argumentList); } catch (MalformedMemberNameException exc) { MessageOutput.println("is not a valid method name", methodName); } catch (ClassNotFoundException exc) { MessageOutput.println("is not a valid class name", classId); } } } catch (Exception e) { printBreakpointCommandUsage(atForm, inForm); return null; } return (BreakpointSpec)breakpoint; } private void resolveNow(EventRequestSpec spec) { boolean success = Env.specList.addEagerlyResolve(spec); if (success && !spec.isResolved()) { MessageOutput.println("Deferring.", spec.toString()); } } void commandStop(StringTokenizer t) { Location bploc; String atIn; byte suspendPolicy = EventRequest.SUSPEND_ALL; if (t.hasMoreTokens()) { atIn = t.nextToken(); if (atIn.equals("go") && t.hasMoreTokens()) { suspendPolicy = EventRequest.SUSPEND_NONE; atIn = t.nextToken(); } else if (atIn.equals("thread") && t.hasMoreTokens()) { suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; atIn = t.nextToken(); } } else { listBreakpoints(); return; } BreakpointSpec spec = parseBreakpointSpec(t, "stop at", "stop in"); if (spec != null) { // Enforcement of "at" vs. "in". The distinction is really // unnecessary and we should consider not checking for this // (and making "at" and "in" optional). if (atIn.equals("at") && spec.isMethodBreakpoint()) { MessageOutput.println("Use stop at to set a breakpoint at a line number"); printBreakpointCommandUsage("stop at", "stop in"); return; } spec.suspendPolicy = suspendPolicy; resolveNow(spec); } } void commandClear(StringTokenizer t) { if (!t.hasMoreTokens()) { listBreakpoints(); return; } BreakpointSpec spec = parseBreakpointSpec(t, "clear", "clear"); if (spec != null) { if (Env.specList.delete(spec)) { MessageOutput.println("Removed:", spec.toString()); } else { MessageOutput.println("Not found:", spec.toString()); } } } private List parseWatchpointSpec(StringTokenizer t) { List list = new ArrayList(); boolean access = false; boolean modification = false; int suspendPolicy = EventRequest.SUSPEND_ALL; String fieldName = t.nextToken(); if (fieldName.equals("go")) { suspendPolicy = EventRequest.SUSPEND_NONE; fieldName = t.nextToken(); } else if (fieldName.equals("thread")) { suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; fieldName = t.nextToken(); } if (fieldName.equals("access")) { access = true; fieldName = t.nextToken(); } else if (fieldName.equals("all")) { access = true; modification = true; fieldName = t.nextToken(); } else { modification = true; } int dot = fieldName.lastIndexOf('.'); if (dot < 0) { MessageOutput.println("Class containing field must be specified."); return list; } String className = fieldName.substring(0, dot); fieldName = fieldName.substring(dot+1); try { EventRequestSpec spec; if (access) { spec = Env.specList.createAccessWatchpoint(className, fieldName); spec.suspendPolicy = suspendPolicy; list.add(spec); } if (modification) { spec = Env.specList.createModificationWatchpoint(className, fieldName); spec.suspendPolicy = suspendPolicy; list.add(spec); } } catch (MalformedMemberNameException exc) { MessageOutput.println("is not a valid field name", fieldName); } catch (ClassNotFoundException exc) { MessageOutput.println("is not a valid class name", className); } return list; } void commandWatch(StringTokenizer t) { if (!t.hasMoreTokens()) { MessageOutput.println("Field to watch not specified"); return; } Iterator iter = parseWatchpointSpec(t).iterator(); while (iter.hasNext()) { resolveNow((WatchpointSpec)iter.next()); } } void commandUnwatch(StringTokenizer t) { if (!t.hasMoreTokens()) { MessageOutput.println("Field to unwatch not specified"); return; } Iterator iter = parseWatchpointSpec(t).iterator(); while (iter.hasNext()) { WatchpointSpec spec = (WatchpointSpec)iter.next(); if (Env.specList.delete(spec)) { MessageOutput.println("Removed:", spec.toString()); } else { MessageOutput.println("Not found:", spec.toString()); } } } void commandTrace(StringTokenizer t) { String modif; int suspendPolicy = EventRequest.SUSPEND_ALL; if (t.hasMoreTokens()) { modif = t.nextToken(); if (modif.equals("go")) { suspendPolicy = EventRequest.SUSPEND_NONE; modif = t.nextToken(); } else if (modif.equals("thread")) { suspendPolicy = EventRequest.SUSPEND_EVENT_THREAD; modif = t.nextToken(); } if (modif.equals("methods")) { // nothing to do until other traces } else { MessageOutput.println("Specify kind for example methods"); } } ThreadInfo threadInfo = null; if (t.hasMoreTokens()) { threadInfo = doGetThread(t.nextToken()); } EventRequestManager erm = Env.vm().eventRequestManager(); MethodEntryRequest entry = erm.createMethodEntryRequest(); MethodExitRequest exit = erm.createMethodExitRequest(); if (threadInfo != null) { entry.addThreadFilter(threadInfo.getThread()); exit.addThreadFilter(threadInfo.getThread()); } Env.addExcludes(entry); Env.addExcludes(exit); entry.setSuspendPolicy(suspendPolicy); exit.setSuspendPolicy(suspendPolicy); entry.enable(); exit.enable(); } void commandUntrace(StringTokenizer t) { EventRequestManager erm = Env.vm().eventRequestManager(); Iterator it = erm.methodEntryRequests().iterator(); while (it.hasNext()) { ((EventRequest)it.next()).disable(); } it = erm.methodExitRequests().iterator(); while (it.hasNext()) { ((EventRequest)it.next()).disable(); } } void commandList(StringTokenizer t) { StackFrame frame = null; ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); if (threadInfo == null) { MessageOutput.println("No thread specified."); return; } try { frame = threadInfo.getCurrentFrame(); } catch (IncompatibleThreadStateException e) { MessageOutput.println("Current thread isnt suspended."); return; } if (frame == null) { MessageOutput.println("No frames on the current call stack"); return; } Location loc = frame.location(); if (loc.method().isNative()) { MessageOutput.println("Current method is native"); return; } String sourceFileName = null; try { sourceFileName = loc.sourceName(); ReferenceType refType = loc.declaringType(); int lineno = loc.lineNumber(); if (t.hasMoreTokens()) { String id = t.nextToken(); // See if token is a line number. try { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setParseIntegerOnly(true); Number n = nf.parse(id);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -