1 17 18 package org.objectweb.jac.aspects.tracing; 19 20 import org.objectweb.jac.core.*; 21 import java.util.*; 22 import java.io.*; 23 24 32 33 public class Debugger { 34 35 36 public static final int STEP = 0; 37 38 public static final int STEP_INTO = 1; 39 40 41 public int mode = STEP; 42 43 public boolean stepping = true; 44 45 public transient Stack stepIntoStack; 46 47 48 49 public Debugger() { 50 stepIntoStack = new Stack(); 51 } 52 53 60 61 public void setDebuggingMode( int mode ) { 62 this.mode = mode; 63 } 64 65 72 73 public int getDebuggingMode() { 74 return mode; 75 } 76 77 85 86 public void disableStepping() { 87 stepping = false; 88 } 89 90 98 99 100 public void enableStepping() { 101 stepping = true; 102 } 103 104 111 112 public boolean isStepping() { 113 return stepping; 114 } 115 116 126 127 public void startOfMethod( String container, 128 String objectName, 129 String method, 130 Object [] args ) { 131 132 if( isStepping() && getDebuggingMode() == STEP_INTO ) { 133 if( stepIntoStack.isEmpty() ) { 134 setDebuggingMode( STEP ); 135 } else { 136 stepIntoStack.push( "" ); 137 } 138 } 139 140 if( isStepping() && getDebuggingMode() == STEP && 141 Collaboration.get().getAttribute( "step_into" ) == null ) { 142 143 System.out.println( "Debugging is calling " + method + " (on container " + container + "):" ); 144 System.out.println( "wrappee = " + objectName ); 145 System.out.println( "args = " + Arrays.asList( args ) ); 146 147 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 148 boolean ok = false; 149 String answer = ""; 150 151 while (!ok) { 152 153 System.out.println(" - [s]tep"); 154 System.out.println(" - step [i]nto"); 155 System.out.println(" - [r]un"); 156 System.out.println(" - [q]uit"); 157 System.out.print("> "); 158 159 try { 160 answer = in.readLine(); 161 162 if (answer.equals("q")) { 163 System.out.println("Ciao!"); 164 System.exit(0); 165 } else if (answer.equals("i")) { 166 stepIntoStack.push( "" ); 167 setDebuggingMode( STEP_INTO ); 168 ok = true; 169 } else if (answer.equals("s")) { 170 setDebuggingMode( STEP ); 171 ok = true; 172 } else if (answer.equals("r")) { 173 disableStepping(); 174 ok = true; 175 } 176 177 } catch (Exception e) { 178 e.printStackTrace(); 179 } 180 181 } 182 } 183 } 184 185 195 196 public void endOfMethod( String container, 197 String objectName, 198 String method, 199 Object [] args, 200 Object ret, 201 long executionTime ) { 202 203 if( isStepping() && getDebuggingMode() == STEP_INTO ) { 204 if( stepIntoStack.isEmpty() ) { 205 setDebuggingMode( STEP ); 206 } else { 207 stepIntoStack.pop(); 208 } 209 } 210 211 if( isStepping() && getDebuggingMode() == STEP && 212 Collaboration.get().getAttribute( "step_into" ) == null ) { 213 214 System.out.println( "Debugging is returning from " + method + " (on container " + container + "):" ); 215 System.out.println( "wrappee = " + objectName ); 216 System.out.println( "args =" + Arrays.asList( args ) ); 217 System.out.println( "return =" + ret ); 218 System.out.println( "duration = " + executionTime + " ms" 219 ); 220 } 221 } 222 } 223 224 225 226 227 228 229 230 231 | Popular Tags |