1 7 34 35 package com.sun.tools.example.debug.tty; 36 37 import com.sun.jdi.*; 38 import com.sun.jdi.event.*; 39 import com.sun.jdi.request.*; 40 import com.sun.jdi.connect.*; 41 42 import java.util.*; 43 import java.io.*; 44 45 public class TTY implements EventNotifier { 46 EventHandler handler = null; 47 48 51 private List monitorCommands = new ArrayList(); 52 private int monitorCount = 0; 53 54 57 private static final String progname = "jdb"; 58 59 public void vmStartEvent(VMStartEvent se) { 60 Thread.yield(); MessageOutput.lnprint("VM Started:"); 62 } 63 64 public void vmDeathEvent(VMDeathEvent e) { 65 } 66 67 public void vmDisconnectEvent(VMDisconnectEvent e) { 68 } 69 70 public void threadStartEvent(ThreadStartEvent e) { 71 } 72 73 public void threadDeathEvent(ThreadDeathEvent e) { 74 } 75 76 public void classPrepareEvent(ClassPrepareEvent e) { 77 } 78 79 public void classUnloadEvent(ClassUnloadEvent e) { 80 } 81 82 public void breakpointEvent(BreakpointEvent be) { 83 Thread.yield(); MessageOutput.lnprint("Breakpoint hit:"); 85 } 86 87 public void fieldWatchEvent(WatchpointEvent fwe) { 88 Field field = fwe.field(); 89 ObjectReference obj = fwe.object(); 90 Thread.yield(); 92 if (fwe instanceof ModificationWatchpointEvent) { 93 MessageOutput.lnprint("Field access encountered before after", 94 new Object [] {field, 95 fwe.valueCurrent(), 96 ((ModificationWatchpointEvent)fwe).valueToBe()}); 97 } else { 98 MessageOutput.lnprint("Field access encountered", field.toString()); 99 } 100 } 101 102 public void stepEvent(StepEvent se) { 103 Thread.yield(); MessageOutput.lnprint("Step completed:"); 105 } 106 107 public void exceptionEvent(ExceptionEvent ee) { 108 Thread.yield(); Location catchLocation = ee.catchLocation(); 110 if (catchLocation == null) { 111 MessageOutput.lnprint("Exception occurred uncaught", 112 ee.exception().referenceType().name()); 113 } else { 114 MessageOutput.lnprint("Exception occurred caught", 115 new Object [] {ee.exception().referenceType().name(), 116 Commands.locationString(catchLocation)}); 117 } 118 } 119 120 public void methodEntryEvent(MethodEntryEvent me) { 121 Thread.yield(); 127 if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { 128 MessageOutput.lnprint("Method entered:"); 130 } else { 131 MessageOutput.print("Method entered:"); 133 printLocationOfEvent(me); 134 } 135 } 136 137 public boolean methodExitEvent(MethodExitEvent me) { 138 Thread.yield(); 142 Method mmm = Env.atExitMethod(); 143 Method meMethod = me.method(); 144 145 if (mmm == null || mmm.equals(meMethod)) { 146 149 if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { 150 MessageOutput.println(); 152 } 153 if (Env.vm().canGetMethodReturnValues()) { 154 MessageOutput.print("Method exitedValue:", me.returnValue() + ""); 155 } else { 156 MessageOutput.print("Method exited:"); 157 } 158 159 if (me.request().suspendPolicy() == EventRequest.SUSPEND_NONE) { 160 printLocationOfEvent(me); 162 163 } 164 165 if (false) { 168 Env.setAtExitMethod(null); 171 EventRequestManager erm = Env.vm().eventRequestManager(); 172 Iterator it = erm.methodExitRequests().iterator(); 173 while (it.hasNext()) { 174 EventRequest eReq = (EventRequest)it.next(); 175 if (eReq.equals(me.request())) { 176 eReq.disable(); 177 } 178 } 179 } 180 return true; 181 } 182 183 return false; 185 } 186 187 public void vmInterrupted() { 188 Thread.yield(); printCurrentLocation(); 190 Iterator it = monitorCommands.iterator(); 191 while (it.hasNext()) { 192 StringTokenizer t = new StringTokenizer((String )it.next()); 193 t.nextToken(); executeCommand(t); 195 } 196 MessageOutput.printPrompt(); 197 } 198 199 public void receivedEvent(Event event) { 200 } 201 202 private void printBaseLocation(String threadName, Location loc) { 203 MessageOutput.println("location", 204 new Object [] {threadName, 205 Commands.locationString(loc)}); 206 } 207 208 private void printCurrentLocation() { 209 ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); 210 StackFrame frame; 211 try { 212 frame = threadInfo.getCurrentFrame(); 213 } catch (IncompatibleThreadStateException exc) { 214 MessageOutput.println("<location unavailable>"); 215 return; 216 } 217 if (frame == null) { 218 MessageOutput.println("No frames on the current call stack"); 219 } else { 220 Location loc = frame.location(); 221 printBaseLocation(threadInfo.getThread().name(), loc); 222 if (loc.lineNumber() != -1) { 224 String line; 225 try { 226 line = Env.sourceLine(loc, loc.lineNumber()); 227 } catch (java.io.IOException e) { 228 line = null; 229 } 230 if (line != null) { 231 MessageOutput.println("source line number and line", 232 new Object [] {new Integer (loc.lineNumber()), 233 line}); 234 } 235 } 236 } 237 MessageOutput.println(); 238 } 239 240 private void printLocationOfEvent(LocatableEvent theEvent) { 241 printBaseLocation(theEvent.thread().name(), theEvent.location()); 242 } 243 244 void help() { 245 MessageOutput.println("zz help text"); 246 } 247 248 private static final String [][] commandList = { 249 257 {"!!", "n", "y"}, 258 {"?", "y", "y"}, 259 {"bytecodes", "n", "y"}, 260 {"catch", "y", "n"}, 261 {"class", "n", "y"}, 262 {"classes", "n", "y"}, 263 {"classpath", "n", "y"}, 264 {"clear", "y", "n"}, 265 {"connectors", "y", "y"}, 266 {"cont", "n", "n"}, 267 {"disablegc", "n", "n"}, 268 {"down", "n", "y"}, 269 {"dump", "n", "y"}, 270 {"enablegc", "n", "n"}, 271 {"eval", "n", "y"}, 272 {"exclude", "y", "n"}, 273 {"exit", "y", "y"}, 274 {"extension", "n", "y"}, 275 {"fields", "n", "y"}, 276 {"gc", "n", "n"}, 277 {"help", "y", "y"}, 278 {"ignore", "y", "n"}, 279 {"interrupt", "n", "n"}, 280 {"kill", "n", "n"}, 281 {"lines", "n", "y"}, 282 {"list", "n", "y"}, 283 {"load", "n", "y"}, 284 {"locals", "n", "y"}, 285 {"lock", "n", "n"}, 286 {"memory", "n", "y"}, 287 {"methods", "n", "y"}, 288 {"monitor", "n", "n"}, 289 {"next", "n", "n"}, 290 {"pop", "n", "n"}, 291 {"print", "n", "y"}, 292 {"quit", "y", "y"}, 293 {"read", "y", "y"}, 294 {"redefine", "n", "n"}, 295 {"reenter", "n", "n"}, 296 {"resume", "n", "n"}, 297 {"run", "y", "n"}, 298 {"save", "n", "n"}, 299 {"set", "n", "n"}, 300 {"sourcepath", "y", "y"}, 301 {"step", "n", "n"}, 302 {"stepi", "n", "n"}, 303 {"stop", "y", "n"}, 304 {"suspend", "n", "n"}, 305 {"thread", "n", "y"}, 306 {"threadgroup", "n", "y"}, 307 {"threadgroups", "n", "y"}, 308 {"threadlocks", "n", "y"}, 309 {"threads", "n", "y"}, 310 {"trace", "n", "n"}, 311 {"unmonitor", "n", "n"}, 312 {"untrace", "n", "n"}, 313 {"unwatch", "y", "n"}, 314 {"up", "n", "y"}, 315 {"use", "y", "y"}, 316 {"version", "y", "y"}, 317 {"watch", "y", "n"}, 318 {"where", "n", "y"}, 319 {"wherei", "n", "y"}, 320 }; 321 322 327 private int isCommand(String key) { 328 int low = 0; 331 int high = commandList.length - 1; 332 long i = 0; 333 while (low <= high) { 334 int mid = (low + high) >>> 1; 335 String midVal = commandList[mid][0]; 336 int compare = midVal.compareTo(key); 337 if (compare < 0) 338 low = mid + 1; 339 else if (compare > 0) 340 high = mid - 1; 341 else 342 return mid; } 344 return -(low + 1); }; 346 347 350 private boolean isDisconnectCmd(int ii) { 351 if (ii < 0 || ii >= commandList.length) return false; 352 return (commandList[ii][1].equals("y")); 353 } 354 355 358 private boolean isReadOnlyCmd(int ii) { 359 if (ii < 0 || ii >= commandList.length) return false; 360 return (commandList[ii][2].equals("y")); 361 }; 362 363 364 void executeCommand(StringTokenizer t) { 365 String cmd = t.nextToken().toLowerCase(); 366 boolean showPrompt = true; 368 369 370 373 if (!cmd.startsWith("#")) { 374 378 if (Character.isDigit(cmd.charAt(0)) && t.hasMoreTokens()) { 379 try { 380 int repeat = Integer.parseInt(cmd); 381 String subcom = t.nextToken(""); 382 while (repeat-- > 0) { 383 executeCommand(new StringTokenizer(subcom)); 384 showPrompt = false; } 386 } catch (NumberFormatException exc) { 387 MessageOutput.println("Unrecognized command. Try help...", cmd); 388 } 389 } else { 390 int commandNumber = isCommand(cmd); 391 394 if (commandNumber < 0) { 395 MessageOutput.println("Unrecognized command. Try help...", cmd); 396 } else if (!Env.connection().isOpen() && !isDisconnectCmd(commandNumber)) { 397 MessageOutput.println("Command not valid until the VM is started with the run command", 398 cmd); 399 } else if (Env.connection().isOpen() && !Env.vm().canBeModified() && 400 !isReadOnlyCmd(commandNumber)) { 401 MessageOutput.println("Command is not supported on a read-only VM connection", 402 cmd); 403 } else { 404 405 Commands evaluator = new Commands(); 406 try { 407 if (cmd.equals("print")) { 408 evaluator.commandPrint(t, false); 409 showPrompt = false; } else if (cmd.equals("eval")) { 411 evaluator.commandPrint(t, false); 412 showPrompt = false; } else if (cmd.equals("set")) { 414 evaluator.commandSet(t); 415 showPrompt = false; } else if (cmd.equals("dump")) { 417 evaluator.commandPrint(t, true); 418 showPrompt = false; } else if (cmd.equals("locals")) { 420 evaluator.commandLocals(); 421 } else if (cmd.equals("classes")) { 422 evaluator.commandClasses(); 423 } else if (cmd.equals("class")) { 424 evaluator.commandClass(t); 425 } else if (cmd.equals("connectors")) { 426 evaluator.commandConnectors(Bootstrap.virtualMachineManager()); 427 } else if (cmd.equals("methods")) { 428 evaluator.commandMethods(t); 429 } else if (cmd.equals("fields")) { 430 evaluator.commandFields(t); 431 } else if (cmd.equals("threads")) { 432 evaluator.commandThreads(t); 433 } else if (cmd.equals("thread")) { 434 evaluator.commandThread(t); 435 } else if (cmd.equals("suspend")) { 436 evaluator.commandSuspend(t); 437 } else if (cmd.equals("resume")) { 438 evaluator.commandResume(t); 439 } else if (cmd.equals("cont")) { 440 evaluator.commandCont(); 441 } else if (cmd.equals("threadgroups")) { 442 evaluator.commandThreadGroups(); 443 } else if (cmd.equals("threadgroup")) { 444 evaluator.commandThreadGroup(t); 445 } else if (cmd.equals("catch")) { 446 evaluator.commandCatchException(t); 447 } else if (cmd.equals("ignore")) { 448 evaluator.commandIgnoreException(t); 449 } else if (cmd.equals("step")) { 450 evaluator.commandStep(t); 451 } else if (cmd.equals("stepi")) { 452 evaluator.commandStepi(); 453 } else if (cmd.equals("next")) { 454 evaluator.commandNext(); 455 } else if (cmd.equals("kill")) { 456 evaluator.commandKill(t); 457 } else if (cmd.equals("interrupt")) { 458 evaluator.commandInterrupt(t); 459 } else if (cmd.equals("trace")) { 460 evaluator.commandTrace(t); 461 } else if (cmd.equals("untrace")) { 462 evaluator.commandUntrace(t); 463 } else if (cmd.equals("where")) { 464 evaluator.commandWhere(t, false); 465 } else if (cmd.equals("wherei")) { 466 evaluator.commandWhere(t, true); 467 } else if (cmd.equals("up")) { 468 evaluator.commandUp(t); 469 } else if (cmd.equals("down")) { 470 evaluator.commandDown(t); 471 } else if (cmd.equals("load")) { 472 evaluator.commandLoad(t); 473 } else if (cmd.equals("run")) { 474 evaluator.commandRun(t); 475 481 if ((handler == null) && Env.connection().isOpen()) { 482 handler = new EventHandler(this, false); 483 } 484 } else if (cmd.equals("memory")) { 485 evaluator.commandMemory(); 486 } else if (cmd.equals("gc")) { 487 evaluator.commandGC(); 488 } else if (cmd.equals("stop")) { 489 evaluator.commandStop(t); 490 } else if (cmd.equals("clear")) { 491 evaluator.commandClear(t); 492 } else if (cmd.equals("watch")) { 493 evaluator.commandWatch(t); 494 } else if (cmd.equals("unwatch")) { 495 evaluator.commandUnwatch(t); 496 } else if (cmd.equals("list")) { 497 evaluator.commandList(t); 498 } else if (cmd.equals("lines")) { evaluator.commandLines(t); 500 } else if (cmd.equals("classpath")) { 501 evaluator.commandClasspath(t); 502 } else if (cmd.equals("use") || cmd.equals("sourcepath")) { 503 evaluator.commandUse(t); 504 } else if (cmd.equals("monitor")) { 505 monitorCommand(t); 506 } else if (cmd.equals("unmonitor")) { 507 unmonitorCommand(t); 508 } else if (cmd.equals("lock")) { 509 evaluator.commandLock(t); 510 showPrompt = false; } else if (cmd.equals("threadlocks")) { 512 evaluator.commandThreadlocks(t); 513 } else if (cmd.equals("disablegc")) { 514 evaluator.commandDisableGC(t); 515 showPrompt = false; } else if (cmd.equals("enablegc")) { 517 evaluator.commandEnableGC(t); 518 showPrompt = false; } else if (cmd.equals("save")) { evaluator.commandSave(t); 521 showPrompt = false; } else if (cmd.equals("bytecodes")) { evaluator.commandBytecodes(t); 524 } else if (cmd.equals("redefine")) { 525 evaluator.commandRedefine(t); 526 } else if (cmd.equals("pop")) { 527 evaluator.commandPopFrames(t, false); 528 } else if (cmd.equals("reenter")) { 529 evaluator.commandPopFrames(t, true); 530 } else if (cmd.equals("extension")) { 531 evaluator.commandExtension(t); 532 } else if (cmd.equals("exclude")) { 533 evaluator.commandExclude(t); 534 } else if (cmd.equals("read")) { 535 readCommand(t); 536 } else if (cmd.equals("help") || cmd.equals("?")) { 537 help(); 538 } else if (cmd.equals("version")) { 539 evaluator.commandVersion(progname, 540 Bootstrap.virtualMachineManager()); 541 } else if (cmd.equals("quit") || cmd.equals("exit")) { 542 if (handler != null) { 543 handler.shutdown(); 544 } 545 Env.shutdown(); 546 } else { 547 MessageOutput.println("Unrecognized command. Try help...", cmd); 548 } 549 } catch (VMCannotBeModifiedException rovm) { 550 MessageOutput.println("Command is not supported on a read-only VM connection", cmd); 551 } catch (UnsupportedOperationException uoe) { 552 MessageOutput.println("Command is not supported on the target VM", cmd); 553 } catch (VMNotConnectedException vmnse) { 554 MessageOutput.println("Command not valid until the VM is started with the run command", 555 cmd); 556 } catch (Exception e) { 557 MessageOutput.printException("Internal exception:", e); 558 } 559 } 560 } 561 } 562 if (showPrompt) { 563 MessageOutput.printPrompt(); 564 } 565 } 566 567 570 void monitorCommand(StringTokenizer t) { 571 if (t.hasMoreTokens()) { 572 ++monitorCount; 573 monitorCommands.add(monitorCount + ": " + t.nextToken("")); 574 } else { 575 Iterator it = monitorCommands.iterator(); 576 while (it.hasNext()) { 577 MessageOutput.printDirectln((String )it.next()); } 579 } 580 } 581 582 void unmonitorCommand(StringTokenizer t) { 583 if (t.hasMoreTokens()) { 584 String monTok = t.nextToken(); 585 int monNum; 586 try { 587 monNum = Integer.parseInt(monTok); 588 } catch (NumberFormatException exc) { 589 MessageOutput.println("Not a monitor number:", monTok); 590 return; 591 } 592 String monStr = monTok + ":"; 593 Iterator it = monitorCommands.iterator(); 594 while (it.hasNext()) { 595 String cmd = (String )it.next(); 596 StringTokenizer ct = new StringTokenizer(cmd); 597 if (ct.nextToken().equals(monStr)) { 598 monitorCommands.remove(cmd); 599 MessageOutput.println("Unmonitoring", cmd); 600 return; 601 } 602 } 603 MessageOutput.println("No monitor numbered:", monTok); 604 } else { 605 MessageOutput.println("Usage: unmonitor <monitor#>"); 606 } 607 } 608 609 610 void readCommand(StringTokenizer t) { 611 if (t.hasMoreTokens()) { 612 String cmdfname = t.nextToken(); 613 if (!readCommandFile(cmdfname)) { 614 MessageOutput.println("Could not open:", cmdfname); 615 } 616 } else { 617 MessageOutput.println("Usage: read <command-filename>"); 618 } 619 } 620 621 625 boolean readCommandFile(String filename) { 626 File f = new File(filename); 627 BufferedReader inFile = null; 628 try { 629 if (f.canRead()) { 630 MessageOutput.println("*** Reading commands from", f.getCanonicalPath()); 631 inFile = new BufferedReader(new FileReader(f)); 633 String ln; 634 while ((ln = inFile.readLine()) != null) { 635 StringTokenizer t = new StringTokenizer(ln); 636 if (t.hasMoreTokens()) { 637 executeCommand(t); 638 } 639 } 640 } 641 } catch (IOException e) { 642 } finally { 643 if (inFile != null) { 644 try { 645 inFile.close(); 646 } catch (Exception exc) { 647 } 648 } 649 } 650 return inFile != null; 651 } 652 653 public TTY() throws Exception { 654 655 MessageOutput.println("Initializing progname", progname); 656 657 if (Env.connection().isOpen() && Env.vm().canBeModified()) { 658 663 this.handler = new EventHandler(this, true); 664 } 665 try { 666 BufferedReader in = 667 new BufferedReader(new InputStreamReader(System.in)); 668 669 String lastLine = null; 670 671 Thread.currentThread().setPriority(Thread.NORM_PRIORITY); 672 673 677 if (!readCommandFile(System.getProperty("user.home") + 678 File.separator + "jdb.ini")) { 679 readCommandFile(System.getProperty("user.home") + 680 File.separator + ".jdbrc"); 681 } 682 683 if (!readCommandFile(System.getProperty("user.dir") + 685 File.separator + "jdb.ini")) { 686 readCommandFile(System.getProperty("user.dir") + 687 File.separator + ".jdbrc"); 688 } 689 690 MessageOutput.printPrompt(); 692 while (true) { 693 String ln = in.readLine(); 694 if (ln == null) { 695 MessageOutput.println("Input stream closed."); 696 return; 697 } 698 699 if (ln.startsWith("!!") && lastLine != null) { 700 ln = lastLine + ln.substring(2); 701 MessageOutput.printDirectln(ln); } 703 704 StringTokenizer t = new StringTokenizer(ln); 705 if (t.hasMoreTokens()) { 706 lastLine = ln; 707 executeCommand(t); 708 } else { 709 MessageOutput.printPrompt(); 710 } 711 } 712 } catch (VMDisconnectedException e) { 713 handler.handleDisconnectedException(); 714 } 715 } 716 717 private static void usage() { 718 MessageOutput.println("zz usage text", new Object [] {progname, 719 File.pathSeparator}); 720 System.exit(1); 721 } 722 723 static void usageError(String messageKey) { 724 MessageOutput.println(messageKey); 725 MessageOutput.println(); 726 usage(); 727 } 728 729 static void usageError(String messageKey, String argument) { 730 MessageOutput.println(messageKey, argument); 731 MessageOutput.println(); 732 usage(); 733 } 734 735 private static boolean supportsSharedMemory() { 736 List connectors = Bootstrap.virtualMachineManager().allConnectors(); 737 Iterator iter = connectors.iterator(); 738 while (iter.hasNext()) { 739 Connector connector = (Connector)iter.next(); 740 if (connector.transport() == null) { 741 continue; 742 } 743 if ("dt_shmem".equals(connector.transport().name())) { 744 return true; 745 } 746 } 747 return false; 748 } 749 750 private static String addressToSocketArgs(String address) { 751 int index = address.indexOf(':'); 752 if (index != -1) { 753 String hostString = address.substring(0, index); 754 String portString = address.substring(index + 1); 755 return "hostname=" + hostString + ",port=" + portString; 756 } else { 757 return "port=" + address; 758 } 759 } 760 761 private static boolean hasWhitespace(String string) { 762 int length = string.length(); 763 for (int i = 0; i < length; i++) { 764 if (Character.isWhitespace(string.charAt(i))) { 765 return true; 766 } 767 } 768 return false; 769 } 770 771 private static String addArgument(String string, String argument) { 772 if (hasWhitespace(argument) || argument.indexOf(',') != -1) { 773 StringBuffer buffer = new StringBuffer (string); 775 buffer.append('"'); 776 for (int i = 0; i < argument.length(); i++) { 777 char c = argument.charAt(i); 778 if (c == '"') { 779 buffer.append('\\'); 780 } 781 buffer.append(c); 782 } 783 buffer.append("\" "); 784 return buffer.toString(); 785 } else { 786 return string + argument + ' '; 787 } 788 } 789 790 public static void main(String argv[]) throws MissingResourceException { 791 String cmdLine = ""; 792 String javaArgs = ""; 793 int traceFlags = VirtualMachine.TRACE_NONE; 794 boolean launchImmediately = false; 795 String connectSpec = null; 796 797 MessageOutput.textResources = ResourceBundle.getBundle 798 ("com.sun.tools.example.debug.tty.TTYResources", 799 Locale.getDefault()); 800 801 for (int i = 0; i < argv.length; i++) { 802 String token = argv[i]; 803 if (token.equals("-dbgtrace")) { 804 if ((i == argv.length - 1) || 805 ! Character.isDigit(argv[i+1].charAt(0))) { 806 traceFlags = VirtualMachine.TRACE_ALL; 807 } else { 808 String flagStr = ""; 809 try { 810 flagStr = argv[++i]; 811 traceFlags = Integer.decode(flagStr).intValue(); 812 } catch (NumberFormatException nfe) { 813 usageError("dbgtrace flag value must be an integer:", 814 flagStr); 815 return; 816 } 817 } 818 } else if (token.equals("-X")) { 819 usageError("Use java minus X to see"); 820 return; 821 } else if ( 822 token.equals("-v") || token.startsWith("-v:") || token.startsWith("-verbose") || token.startsWith("-D") || 826 token.startsWith("-X") || 829 token.equals("-noasyncgc") || token.equals("-prof") || 832 token.equals("-verify") || token.equals("-noverify") || 833 token.equals("-verifyremote") || 834 token.equals("-verbosegc") || 835 token.startsWith("-ms") || token.startsWith("-mx") || 836 token.startsWith("-ss") || token.startsWith("-oss") ) { 837 838 javaArgs = addArgument(javaArgs, token); 839 } else if (token.equals("-tclassic")) { 840 usageError("Classic VM no longer supported."); 841 return; 842 } else if (token.equals("-tclient")) { 843 javaArgs = "-client " + javaArgs; 845 } else if (token.equals("-tserver")) { 846 javaArgs = "-server " + javaArgs; 848 } else if (token.equals("-sourcepath")) { 849 if (i == (argv.length - 1)) { 850 usageError("No sourcepath specified."); 851 return; 852 } 853 Env.setSourcePath(argv[++i]); 854 } else if (token.equals("-classpath")) { 855 if (i == (argv.length - 1)) { 856 usageError("No classpath specified."); 857 return; 858 } 859 javaArgs = addArgument(javaArgs, token); 860 javaArgs = addArgument(javaArgs, argv[++i]); 861 } else if (token.equals("-attach")) { 862 if (connectSpec != null) { 863 usageError("cannot redefine existing connection", token); 864 return; 865 } 866 if (i == (argv.length - 1)) { 867 usageError("No attach address specified."); 868 return; 869 } 870 String address = argv[++i]; 871 872 878 if (supportsSharedMemory()) { 879 connectSpec = "com.sun.jdi.SharedMemoryAttach:name=" + 880 address; 881 } else { 882 String suboptions = addressToSocketArgs(address); 883 connectSpec = "com.sun.jdi.SocketAttach:" + suboptions; 884 } 885 } else if (token.equals("-listen") || token.equals("-listenany")) { 886 if (connectSpec != null) { 887 usageError("cannot redefine existing connection", token); 888 return; 889 } 890 String address = null; 891 if (token.equals("-listen")) { 892 if (i == (argv.length - 1)) { 893 usageError("No attach address specified."); 894 return; 895 } 896 address = argv[++i]; 897 } 898 899 905 if (supportsSharedMemory()) { 906 connectSpec = "com.sun.jdi.SharedMemoryListen:"; 907 if (address != null) { 908 connectSpec += ("name=" + address); 909 } 910 } else { 911 connectSpec = "com.sun.jdi.SocketListen:"; 912 if (address != null) { 913 connectSpec += addressToSocketArgs(address); 914 } 915 } 916 } else if (token.equals("-launch")) { 917 launchImmediately = true; 918 } else if (token.equals("-listconnectors")) { 919 Commands evaluator = new Commands(); 920 evaluator.commandConnectors(Bootstrap.virtualMachineManager()); 921 return; 922 } else if (token.equals("-connect")) { 923 929 if (connectSpec != null) { 930 usageError("cannot redefine existing connection", token); 931 return; 932 } 933 if (i == (argv.length - 1)) { 934 usageError("No connect specification."); 935 return; 936 } 937 connectSpec = argv[++i]; 938 } else if (token.equals("-help")) { 939 usage(); 940 } else if (token.equals("-version")) { 941 Commands evaluator = new Commands(); 942 evaluator.commandVersion(progname, 943 Bootstrap.virtualMachineManager()); 944 System.exit(0); 945 } else if (token.startsWith("-")) { 946 usageError("invalid option", token); 947 return; 948 } else { 949 cmdLine = addArgument("", token); 951 for (i++; i < argv.length; i++) { 952 cmdLine = addArgument(cmdLine, argv[i]); 953 } 954 break; 955 } 956 } 957 958 961 962 979 if (connectSpec == null) { 980 connectSpec = "com.sun.jdi.CommandLineLaunch:"; 981 } else if (!connectSpec.endsWith(",") && !connectSpec.endsWith(":")) { 982 connectSpec += ","; } 984 985 cmdLine = cmdLine.trim(); 986 javaArgs = javaArgs.trim(); 987 988 if (cmdLine.length() > 0) { 989 if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) { 990 usageError("Cannot specify command line with connector:", 991 connectSpec); 992 return; 993 } 994 connectSpec += "main=" + cmdLine + ","; 995 } 996 997 if (javaArgs.length() > 0) { 998 if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) { 999 usageError("Cannot specify target vm arguments with connector:", 1000 connectSpec); 1001 return; 1002 } 1003 connectSpec += "options=" + javaArgs + ","; 1004 } 1005 1006 try { 1007 if (! connectSpec.endsWith(",")) { 1008 connectSpec += ","; } 1010 Env.init(connectSpec, launchImmediately, traceFlags); 1011 new TTY(); 1012 } catch(Exception e) { 1013 MessageOutput.printException("Internal exception:", e); 1014 } 1015 } 1016} 1017 1018 | Popular Tags |