KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > tty > CommandLineDebugger


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.tty;
24
25 import com.sun.jdi.*;
26 import com.sun.jdi.event.*;
27 import com.sun.jdi.request.*;
28 import com.sun.jdi.connect.*;
29 import org.aspectj.debugger.base.*;
30 import org.aspectj.debugger.request.*;
31 import org.aspectj.tools.ide.SourceLine;
32 import java.awt.*;
33 import java.awt.event.*;
34 import java.io.*;
35 import java.util.*;
36 import java.util.List JavaDoc;
37 import javax.swing.*;
38 import javax.swing.event.*;
39 import javax.swing.text.*;
40
41 /**
42  * CommandLineDebugger.java
43  *
44  *
45  * Created: Wed Aug 23 14:53:57 2000
46  *
47  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
48  */

49
50 public class CommandLineDebugger
51     implements
52         DebuggerApp,
53         StopListener,
54         VMListener,
55         DebuggerListener,
56         PromptListener,
57         Runnable JavaDoc {
58
59     protected AJDebugger debugger; // = null;
60
private boolean isRunning = true;
61     private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
62     private static String JavaDoc title = "AspectJ Example Debugger";
63     private static String JavaDoc version = "v0.1";
64     private static String JavaDoc copyright = "(C) 2000 Xerox Corporation";
65     private String JavaDoc lastCommand = "";
66     private boolean echo = false;
67     private static String JavaDoc[] echoStrings = {
68
69     };
70     private boolean showPrompt;
71     private String JavaDoc[] cmdLineArgs;
72     private Thread JavaDoc thread;
73     private Options options = new Options();
74     protected boolean wantsToExit = true;
75
76     private boolean debug = false; //true;
77
private void db(Object JavaDoc o) {
78         if (debug) {
79             System.err.println("<CL DEBUGGER>: " + o);
80         }
81     }
82
83     public CommandLineDebugger(String JavaDoc[] args) {
84         this(args, true);
85     }
86
87     public CommandLineDebugger(AJDebugger debugger, String JavaDoc[] args) {
88         this(debugger, args, true);
89     }
90
91     public CommandLineDebugger(String JavaDoc[] args, String JavaDoc scriptFile) {
92         this(args, false);
93         List JavaDoc commands = new Vector();
94         try {
95             commands = debugger.readCommand(scriptFile, true);
96         } catch (NoVMException nvme) {
97         } catch (DebuggerException de) {
98         }
99         for (int i = 0; i < commands.size(); i++) {
100             String JavaDoc command = commands.get(i) + "";
101             executeCommand(command);
102         }
103         while (debugger.isRunning()) {}
104         exit();
105     }
106
107     public CommandLineDebugger(String JavaDoc args[], boolean showPrompt) {
108         this.debugger = new AJDebugger(this, showPrompt);
109         debugger.addStopListener(this);
110         debugger.addVMListener(this);
111         debugger.addDebuggerListener(this);
112         debugger.addPromptListener(this);
113         this.showPrompt = showPrompt;
114         this.cmdLineArgs = args;
115         options.fill(args);
116     }
117
118     public CommandLineDebugger(AJDebugger db,
119                                String JavaDoc args[],
120                                boolean showPrompt) {
121         this.debugger = db;
122         debugger.addStopListener(this);
123         debugger.addVMListener(this);
124         debugger.addDebuggerListener(this);
125         debugger.addPromptListener(this);
126         this.showPrompt = showPrompt;
127         this.cmdLineArgs = args;
128         options.fill(args);
129     }
130
131     public void go() {
132         debugger.setOptions(options);
133         String JavaDoc mainClass = options.getClassName();
134         boolean runNow = false;
135         if (!options.isSet("now") &&
136             mainClass != null &&
137             !mainClass.equals("")) {
138             debugger.loadMainClass(options);
139         }
140         start();
141         if (options.isSet("now")) {
142             debugger.runCommand();
143         }
144     }
145
146     public void start() {
147         if (thread == null) {
148             thread = new Thread JavaDoc(this);
149             thread.start();
150         }
151     }
152
153     public void run() {
154         if (showPrompt /*&& !isGUI()*/) {
155             while (true) {
156                 prompt();
157                 executeCommand(line());
158             }
159         }
160     }
161
162     public boolean isGUI() {
163         return false;
164     }
165
166     public AJDebugger getDebugger() {
167         return debugger;
168     }
169
170     /****************************** Misc. Stuff ******************************/
171
172     private boolean runNow(String JavaDoc[] args) {
173         return !options.getClassName().equals("");
174     }
175
176     String JavaDoc className(String JavaDoc[] args) {
177         if (args != null && args.length > 0) {
178             return args[0];
179         }
180         return "";
181     }
182
183     String JavaDoc exArgs(String JavaDoc[] args) {
184         String JavaDoc exArgs = "";
185         if (args != null && args.length > 1) {
186             for (int i = 1; i < args.length; i++) {
187                 exArgs += args[i] + " ";
188             }
189         }
190         return exArgs.trim();
191     }
192
193
194
195     /****************************** DebuggerApp ******************************/
196
197     // start-commands
198

199     public void runCommand(String JavaDoc className,
200                            String JavaDoc exArgs)
201         throws NoVMException, DebuggerException {
202     }
203
204     public void runCommand(String JavaDoc className,
205                            String JavaDoc vmArgs,
206                            String JavaDoc exArgs,
207                            boolean isSuspended, int debugTraceMode)
208         throws NoVMException, DebuggerException {
209     }
210
211     public void clearAtCommand(String JavaDoc className,
212                                int line,
213                                EventRequest request)
214         throws NoVMException, DebuggerException {
215     }
216
217     public void clearInCommand(String JavaDoc className,
218                                String JavaDoc methodProto,
219                                EventRequest request)
220         throws NoVMException, DebuggerException {
221     }
222
223     public void clearOnCommand(String JavaDoc sourceName,
224                                int line,
225                                EventRequest request)
226         throws NoVMException, DebuggerException {
227     }
228
229     public void clearCommand(List JavaDoc breakpoints)
230         throws NoVMException, DebuggerException {
231         result("Breakpoints:\n" + debugger.iter(breakpoints));
232     }
233
234     public void clearAllCommand(List JavaDoc breakpoints)
235         throws NoVMException, DebuggerException {
236         result("Breakpoint requests cleared:\n" + debugger.iter(breakpoints));
237     }
238
239     public void stopAtCommand(String JavaDoc className,
240                               int line,
241                               EventRequest request)
242         throws NoVMException, DebuggerException {
243     }
244
245     public void stopInCommand(String JavaDoc className,
246                               String JavaDoc methodProto,
247                               EventRequest request)
248         throws NoVMException, DebuggerException {
249     }
250
251     public void stopOnCommand(String JavaDoc sourceName,
252                               int line,
253                               EventRequest request)
254         throws NoVMException, DebuggerException {
255     }
256
257     public void stopCommand(List JavaDoc breakpoints)
258         throws NoVMException, DebuggerException {
259         clearCommand(breakpoints);
260     }
261
262     public void contCommand()
263         throws NoVMException, DebuggerException {
264     }
265
266     public void threadsCommand(String JavaDoc threadGroupName, List JavaDoc threads)
267         throws NoVMException, DebuggerException {
268         result(debugger.threads(threads));
269     }
270
271     public void threadGroupsCommand(List JavaDoc threadGroups)
272         throws NoVMException, DebuggerException {
273         result(debugger.threadGroups(threadGroups));
274     }
275
276     public void fieldsCommand(String JavaDoc className, List JavaDoc fields)
277         throws NoVMException, DebuggerException {
278         result(debugger.fields(fields));
279     }
280
281     public void methodsCommand(String JavaDoc className, List JavaDoc methods)
282         throws NoVMException, DebuggerException {
283         result(debugger.methods(methods));
284     }
285
286     public void classesCommand(List JavaDoc classes)
287         throws NoVMException, DebuggerException {
288         result(debugger.classes(classes));
289     }
290
291     public void classCommand(String JavaDoc className,
292                              ReferenceType refType)
293         throws NoVMException, DebuggerException {
294         result(debugger.clazz(refType));
295     }
296
297     public void threadCommand(String JavaDoc threadName,
298                               ThreadReference threadRef)
299         throws NoVMException, DebuggerException {
300     }
301
302     public void threadGroupCommand(String JavaDoc threadGroupName,
303                                    ThreadGroupReference threadGroupRef)
304         throws NoVMException, DebuggerException {
305     }
306
307     public void suspendCommand(List JavaDoc threadNames, List JavaDoc threads)
308         throws NoVMException, DebuggerException {
309     }
310
311     public void resumeCommand(List JavaDoc threadNames, List JavaDoc threads)
312         throws NoVMException, DebuggerException {
313     }
314
315     public void whereCommand(String JavaDoc threadName, List JavaDoc frames)
316         throws NoVMException, DebuggerException {
317         result(debugger.frames(frames));
318     }
319
320     public void localsCommand(List JavaDoc locals)
321         throws NoVMException, DebuggerException {
322         result(debugger.locals(locals));
323     }
324
325     public void interruptCommand(String JavaDoc threadName,
326                                  ThreadReference threadRef)
327         throws NoVMException, DebuggerException {
328     }
329
330     public void upCommand(int frames, StackFrame currentFrame)
331         throws NoVMException, DebuggerException {
332     }
333
334     public void downCommand(int frames, StackFrame currentFrame)
335         throws NoVMException, DebuggerException {
336     }
337
338     public void stepCommand(StepRequest request)
339         throws NoVMException, DebuggerException {
340     }
341
342     public void stepUpCommand(StepRequest request)
343         throws NoVMException, DebuggerException {
344     }
345
346     public void stepiCommand(StepRequest request)
347         throws NoVMException, DebuggerException {
348     }
349
350     public void nextCommand(StepRequest request)
351         throws NoVMException, DebuggerException {
352     }
353
354     public void printCommand(Object JavaDoc valueRep, Value value)
355         throws NoVMException, DebuggerException {
356         result(" " + valueRep + " = " + getValue(value));
357     }
358
359     public void dumpCommand(Object JavaDoc valueRep, Value value)
360         throws NoVMException, DebuggerException {
361         result(" " + valueRep + " = " + getValue(value));
362     }
363
364     public void evalCommand(Object JavaDoc valueRep, Value value)
365         throws NoVMException, DebuggerException {
366         result(" " + valueRep + " = " + getValue(value));
367     }
368
369     private String JavaDoc getValue(Value value) {
370         String JavaDoc valString = value + "";
371         if (!debugger.getOptions().isSet("extra")) {
372             return valString;
373         }
374         valString += " = " + value(value);
375         return valString;
376     }
377
378     /**
379      * render value by unwrapping as ObjectReference
380      * @return "null" if null, empty String if unsuccessful, rendering otherwise
381      */

382     private String JavaDoc value(Value value) {
383         if (value == null) {
384             return "null";
385         }
386         if (!(value instanceof ObjectReference)) {
387             return value+""; // todo: omit if only client is this.getValue(Value)
388
}
389         // get object reference to invoke toString or primitive value method
390
String JavaDoc valString = "";
391         try {
392             ObjectReference oRef = (ObjectReference) value;
393             if (oRef instanceof ArrayReference) {
394                 String JavaDoc result = "{";
395                 ArrayReference arrayRef = (ArrayReference) oRef;
396                 int length = arrayRef.length();
397                 for (int i = 0; i < length; i++) {
398                     try {
399                         result += value(arrayRef.getValue(i));
400                     } catch (NullPointerException JavaDoc npe) {
401                         result += "null";
402                     }
403                     result += i < length-1 ? ", " : "";
404                 }
405                 result += "}";
406                 return result;
407             }
408             ReferenceType refType = oRef.referenceType();
409             String JavaDoc name = refType.name();
410             ThreadReference thread = null;
411             try {
412                 if (debugger.getVM().canGetOwnedMonitorInfo()) {
413                     try {
414                         thread = oRef.owningThread();
415                     } catch (UnsupportedOperationException JavaDoc uoe) {
416                     }
417                 }
418                 if (thread == null) {
419                     thread = debugger.getDefaultThread();
420                 }
421             } catch (NoVMException nvme) {
422                 return valString;
423             }
424             int options = ObjectReference.INVOKE_NONVIRTUAL;
425             Method method = null;
426             // unwrap if a primitive value
427
if (name.equals("java.lang.Byte")) {
428                 method = (Method)refType.methodsByName("byteValue").get(0);
429             } else if (name.equals("java.lang.Boolean")) {
430                 method = (Method)refType.methodsByName("booleanValue").get(0);
431             } else if (name.equals("java.lang.Character")) {
432                 method = (Method)refType.methodsByName("charValue").get(0);
433             } else if (name.equals("java.lang.Double")) {
434                 method = (Method)refType.methodsByName("doubleValue").get(0);
435             } else if (name.equals("java.lang.Float")) {
436                 method = (Method)refType.methodsByName("floatValue").get(0);
437             } else if (name.equals("java.lang.Integer")) {
438                 method = (Method)refType.methodsByName("intValue").get(0);
439             } else if (name.equals("java.lang.Long")) {
440                 method = (Method)refType.methodsByName("longValue").get(0);
441             } else if (name.equals("java.lang.Short")) {
442                 method = (Method)refType.methodsByName("shortValue").get(0);
443             } else {
444                 List JavaDoc list = refType.methodsByName("toString");
445                 if (null != list) {
446                     for (Iterator it = list.iterator(); it.hasNext();) {
447                         Method m = (Method) it.next();
448                         List JavaDoc types = m.argumentTypes();
449                         if ((null == types) || (0 == types.size())) {
450                             method = m;
451                             System.err.println("method: " + method);
452                             break;
453                         }
454                     }
455                 }
456             }
457             if ((null != thread) && (null != method)) {
458                 Value newValue = oRef.invokeMethod(thread, method,
459                                                new Vector(), options);
460                 valString += newValue+"";
461             }
462         } catch (InvalidTypeException ite) { // todo: log all these?
463
} catch (ClassNotLoadedException cnle) {
464         } catch (IncompatibleThreadStateException itse) {
465         } catch (InvocationException ie) {
466         }
467         return valString;
468     }
469
470     public void setWantsToExit(boolean wantsToExit) {
471         this.wantsToExit = wantsToExit;
472     }
473
474     public void setCommand(Object JavaDoc lvalue,
475                            Object JavaDoc rvalue,
476                            Value oldValue,
477                            Value newValue)
478         throws NoVMException, DebuggerException {
479         result("Changed '" + lvalue + "' from '" +
480                oldValue + "' to '" + newValue + "'");
481     }
482
483     public void classpathCommand(String JavaDoc baseDirectory, List JavaDoc paths)
484         throws NoVMException, DebuggerException {
485         String JavaDoc result =
486             "base directory: " + baseDirectory + "\n" +
487             "classpath: " + paths;
488         result(result);
489     }
490
491     public void lockCommand(Object JavaDoc valueRep, LockInformation lockInfo)
492         throws NoVMException, DebuggerException {
493         result("Lock information for '" + valueRep + "':\n" + lockInfo);
494     }
495
496     public void threadlocksCommand(String JavaDoc threadName,
497                                    ThreadLockInformation threadLockInfo)
498         throws NoVMException, DebuggerException {
499         result("Thread lock information for '" +
500                threadName + "':\n" + threadLockInfo);
501     }
502
503     public void watchAccessCommand(String JavaDoc className,
504                                    String JavaDoc fieldName,
505                                    WatchpointRequest request)
506         throws NoVMException, DebuggerException {
507     }
508
509     public void watchAllCommand(String JavaDoc className,
510                                  String JavaDoc fieldName,
511                                  WatchpointRequest request)
512         throws NoVMException, DebuggerException {
513     }
514
515     public void unwatchAccessCommand(String JavaDoc className,
516                                      String JavaDoc fieldName,
517                                      WatchpointRequest request)
518         throws NoVMException, DebuggerException {
519     }
520
521     public void unwatchAllCommand(String JavaDoc className,
522                                   String JavaDoc fieldName,
523                                   WatchpointRequest request)
524         throws NoVMException, DebuggerException {
525     }
526
527     public void catchCommand(String JavaDoc className, ExceptionRequest request)
528         throws NoVMException, DebuggerException {
529     }
530
531     public void ignoreCommand(String JavaDoc className, ExceptionRequest request)
532         throws NoVMException, DebuggerException {
533     }
534
535     public void traceMethodsCommand(String JavaDoc threadName,
536                                     TraceMethodsRequest.EntryExitPair pair)
537         throws NoVMException, DebuggerException {
538     }
539
540     public void untraceMethodsCommand(String JavaDoc threadName,
541                                       UntraceMethodsRequest.EntryExitPair pair)
542         throws NoVMException, DebuggerException {
543     }
544
545     public void excludeCommand(List JavaDoc classNames, List JavaDoc classes)
546         throws NoVMException, DebuggerException {
547         result("Exclude:\n" + debugger.iter(classes));
548     }
549
550     public void quitCommand()
551         throws NoVMException, DebuggerException {
552     }
553
554     public void helpCommand(String JavaDoc helpString)
555         throws NoVMException, DebuggerException {
556         result(helpString);
557     }
558
559     public void versionCommand(Object JavaDoc version)
560         throws NoVMException, DebuggerException {
561         result(version);
562     }
563
564     public void killCommand(String JavaDoc threadName,
565                             String JavaDoc valueRep,
566                             ThreadReference threadRef)
567         throws NoVMException, DebuggerException {
568         result("Killed thread '" + threadName + "' = " +
569                threadRef + " with '" + valueRep + "'");
570     }
571
572     public void useCommand(String JavaDoc sourcePath, String JavaDoc newSourcePath)
573         throws NoVMException, DebuggerException {
574         result("Using sourcepath: " + newSourcePath);
575     }
576
577     public void workingdirCommand(String JavaDoc workingdirPath, String JavaDoc newWorkingdirPath)
578         throws NoVMException, DebuggerException {
579         result("Using workingdir: " + newWorkingdirPath);
580     }
581
582     public void listCommand(List JavaDoc sourceLines)
583         throws NoVMException, DebuggerException {
584         Object JavaDoc o = debugger.sourceLines(sourceLines, true);
585         if (sourceLines.size() == 0) {
586             o = "Source file not found: unkown.source";
587         }
588         result(o);
589     }
590
591     public void listCommand(String JavaDoc sourceName, List JavaDoc sourceLines)
592         throws NoVMException, DebuggerException {
593         Object JavaDoc o = debugger.sourceLines(sourceLines, true);
594         if (sourceLines.size() == 0) {
595             o =
596                 "Source file not found: " +
597                 (sourceName != null ? sourceName : "<unkown>");
598         }
599         result(o);
600     }
601
602     public void listCommand(String JavaDoc sourceName,
603                             int lineNumber,
604                             SourceManager.SourceLine sl)
605         throws NoVMException, DebuggerException {
606         Object JavaDoc o = debugger.sourceLine(sl);
607         if (sl.getLineNumber() < 0) {
608             o =
609                 "<no source available for " +
610                 sourceName + ":" + lineNumber + ">";
611         }
612         result(o);
613     }
614
615     public void listCommand(String JavaDoc sourceName,
616                             int startLine,
617                             int endLine,
618                             List JavaDoc sourceLines)
619         throws NoVMException, DebuggerException {
620         listCommand(sourceLines);
621     }
622
623     public void monitorCommand(String JavaDoc command, String JavaDoc result)
624         throws NoVMException, DebuggerException {
625     }
626
627     public void monitorCommand(List JavaDoc monitors)
628         throws NoVMException, DebuggerException {
629         result(monitors);
630     }
631
632     public void unmonitorCommand(int number, MonitorRequest request)
633         throws NoVMException, DebuggerException {
634         result("Unmonitoring " + request);
635     }
636
637     public void readCommand(String JavaDoc fileName, List JavaDoc commands)
638         throws NoVMException, DebuggerException {
639     }
640
641     public void viewCommand(String JavaDoc sourceName, List JavaDoc sourceLines)
642         throws NoVMException, DebuggerException {
643         listCommand(sourceName, sourceLines);
644     }
645
646     public void tostringCommand(String JavaDoc tostring)
647         throws NoVMException, DebuggerException {
648         result(tostring);
649     }
650
651     public void connectCommand(VirtualMachine vm)
652         throws NoVMException, DebuggerException {
653         throw new DebuggerException("connect is not valid on the command line");
654     }
655
656     public void pwdCommand(File file)
657         throws NoVMException, DebuggerException {
658         if (file != null) result(file.getAbsolutePath());
659     }
660
661     
662     public void lsCommand(String JavaDoc dir, List JavaDoc files)
663         throws NoVMException, DebuggerException {
664         result(dir + ":\n" + debugger.iter(files));
665     }
666
667     // end-commands
668

669
670     /************************** Handling Exceptions **************************/
671
672     public void handleParseException(ParseException e) {
673         result(e.getMessage());
674     }
675
676     public void handleNoVMException(NoVMException e) {
677         result("There is no VM: " + nonull(e.getMessage()));
678     }
679
680     public void handleDebuggerException(DebuggerException e) {
681         result(e.getMessage());
682     }
683
684     public void handleVMDisconnectedException(VMDisconnectedException e) {
685         result("The VM has already disconnected.");
686     }
687
688     public void handleInternalException(Throwable JavaDoc e) {
689         result("Internal error: " + e);
690         e.printStackTrace(getOutputStream());
691         new ErrorLogger(debugger).log(e);
692     }
693
694
695
696     public PrintStream getOutputStream() {
697         return System.out;
698     }
699
700     /*************************** End of DebuggerApp **************************/
701
702     public Object JavaDoc executeCommand(String JavaDoc str) {
703         if (echo(str)) {
704             result(str);
705         }
706         return debugger.execute(str.trim());
707     }
708
709     private boolean echo(String JavaDoc str) {
710         if (str != null) {
711             str = str.trim();
712             for (int i = 0; i < echoStrings.length; i++) {
713                 if (str.startsWith(echoStrings[i])) {
714                 return true;
715                 }
716             }
717         }
718         return false;
719     }
720
721     private void repeat() {
722         executeCommand(lastCommand);
723     }
724
725     protected boolean nonull(String JavaDoc str) {
726         return str != null && !"null".equals(str);
727     }
728
729     protected void result(Object JavaDoc str) {
730         if (str != null) outln(str);
731     }
732
733     protected void result(List JavaDoc list) {
734         Iterator iter = list.iterator();
735         while (iter.hasNext()) {
736             result(iter.next());
737         }
738     }
739
740     private void warn(String JavaDoc str) {
741         outln(" *** " + str);
742     }
743
744     public String JavaDoc line() {
745         String JavaDoc str = "";
746         try { db("get line?");
747             str = in.readLine();
748             db("got line str=" + str);
749         } catch (IOException e) {
750         }
751         return str;
752     }
753
754     public void exit() {
755         isRunning = false;
756         debugger.shutDown();
757         if (wantsToExit()) {
758             System.exit(0);
759         }
760     }
761
762     private void prompt() {
763         if (showPrompt) out(debugger.getPrompt() + " ");
764     }
765
766     private void out(Object JavaDoc o) {
767         System.out.print(o);
768         System.out.flush();
769     }
770
771     public void outln(Object JavaDoc o) {
772         out(o);
773         out("\n");
774     }
775
776     public void log(Object JavaDoc o) {
777     }
778
779     private VirtualMachine vm() {
780         return debugger.vm();
781     }
782
783
784     /****************************** Listeners ******************************/
785
786     /* PromptListener */
787     public void resetPrompt() {
788         prompt();
789     }
790
791     /* StopListener */
792     public void accessWatchpointEvent(AccessWatchpointEvent e){
793     }
794     public void breakpointEvent(BreakpointEvent e){
795         result("\n\nBreakpoint hit: " + debugger.format(e));
796     }
797     public void exceptionEvent(ExceptionEvent e){
798         result("\n\nException occured: " + debugger.format(e));
799     }
800     public void modificationWatchpointEvent(ModificationWatchpointEvent e){
801     }
802     public void stepEvent(StepEvent e){
803         result("\n\nStep completed: " + debugger.format(e));
804     }
805
806     /* VMListener */
807     private int deaths = 0;
808     public void vmDeathEvent(VMDeathEvent e) {
809         die();
810     }
811     public void vmDisconnectEvent(VMDisconnectEvent e) {
812         die();
813     }
814     public void vmStartEvent(VMStartEvent e) {
815         deaths = 0;
816         result("VM Started: ");
817     }
818     private void die() {
819         if (deaths++ == 0) result("\nThe application has exited.");
820         exit();
821     }
822
823     /* DebuggerListener */
824     public void requestSetEvent(RequestEvent re) {
825         RequestAction action = (RequestAction) re.getRequest();
826         result("Set " +
827                (action.isDeferred() ? " deferred " : "") +
828                re.getRequest());
829     }
830     public void requestClearEvent(RequestEvent re) {
831         result("Clear " + re.getRequest());
832     }
833     public void requestDeferredEvent(RequestEvent re) {
834         if (!debugger.isRunning()) {
835             result("Deferring " + re.getRequest() + "\n" +
836                    "It will be set after the class is loaded.");
837         }
838     }
839     public void requestFailedEvent(RequestEvent re) {
840         result("Unable to set " + re.getRequest() +
841                " : " + re.getErrorMessage());
842     }
843
844     public boolean wantsToExit() {
845         return wantsToExit;
846     }
847
848     public boolean canRestart() {
849         return false;
850     }
851
852     public VirtualMachine connect(String JavaDoc vmArgs,
853                                   String JavaDoc className,
854                                   String JavaDoc commandLine) {
855         return null;
856     }
857 }
858
859
860
Popular Tags