Esempio n. 1
0
  private void commandLocals() throws NoSessionException {
    ThreadReference current = context.getCurrentThread();
    if (current == null) {
      env.failure("No default thread specified: " + "use the \"thread\" command first.");
      return;
    }
    StackFrame frame;
    try {
      frame = context.getCurrentFrame(current);
      if (frame == null) {
        env.failure("Thread has not yet created any stack frames.");
        return;
      }
    } catch (VMNotInterruptedException e) {
      env.failure("Target VM must be in interrupted state.");
      return;
    }

    List<LocalVariable> vars;
    try {
      vars = frame.visibleVariables();
      if (vars == null || vars.size() == 0) {
        env.failure("No local variables");
        return;
      }
    } catch (AbsentInformationException e) {
      env.failure(
          "Local variable information not available."
              + " Compile with -g to generate variable information");
      return;
    }

    OutputSink out = env.getOutputSink();
    out.println("Method arguments:");
    for (LocalVariable var : vars) {
      if (var.isArgument()) {
        printVar(out, var, frame);
      }
    }
    out.println("Local variables:");
    for (LocalVariable var : vars) {
      if (!var.isArgument()) {
        printVar(out, var, frame);
      }
    }
    out.show();
    return;
  }
Esempio n. 2
0
 private void commandPrint(StringTokenizer t, boolean dumpObject) throws NoSessionException {
   if (!t.hasMoreTokens()) {
     // ### Probably confused if expresion contains whitespace.
     env.error("No expression specified.");
     return;
   }
   ThreadReference current = context.getCurrentThread();
   if (current == null) {
     env.failure("No default thread specified: " + "use the \"thread\" command first.");
     return;
   }
   StackFrame frame;
   try {
     frame = context.getCurrentFrame(current);
     if (frame == null) {
       env.failure("Thread has not yet created any stack frames.");
       return;
     }
   } catch (VMNotInterruptedException e) {
     env.failure("Target VM must be in interrupted state.");
     return;
   }
   while (t.hasMoreTokens()) {
     String expr = t.nextToken("");
     Value val = null;
     try {
       val = runtime.evaluate(frame, expr);
     } catch (Exception e) {
       env.error("Exception: " + e);
       // ### Fix this!
     }
     if (val == null) {
       return; // Error message already printed
     }
     OutputSink out = env.getOutputSink();
     if (dumpObject && (val instanceof ObjectReference) && !(val instanceof StringReference)) {
       ObjectReference obj = (ObjectReference) val;
       ReferenceType refType = obj.referenceType();
       out.println(expr + " = " + val.toString() + " {");
       dump(out, obj, refType, refType);
       out.println("}");
     } else {
       out.println(expr + " = " + val.toString());
     }
     out.show();
   }
 }
Esempio n. 3
0
 private void commandList(StringTokenizer t) throws NoSessionException {
   ThreadReference current = context.getCurrentThread();
   if (current == null) {
     env.error("No thread specified.");
     return;
   }
   Location loc;
   try {
     StackFrame frame = context.getCurrentFrame(current);
     if (frame == null) {
       env.failure("Thread has not yet begun execution.");
       return;
     }
     loc = frame.location();
   } catch (VMNotInterruptedException e) {
     env.failure("Target VM must be in interrupted state.");
     return;
   }
   SourceModel source = sourceManager.sourceForLocation(loc);
   if (source == null) {
     if (loc.method().isNative()) {
       env.failure("Current method is native.");
       return;
     }
     env.failure("No source available for " + Utils.locationString(loc) + ".");
     return;
   }
   ReferenceType refType = loc.declaringType();
   int lineno = loc.lineNumber();
   if (t.hasMoreTokens()) {
     String id = t.nextToken();
     // See if token is a line number.
     try {
       lineno = Integer.valueOf(id).intValue();
     } catch (NumberFormatException nfe) {
       // It isn't -- see if it's a method name.
       List<Method> meths = refType.methodsByName(id);
       if (meths == null || meths.size() == 0) {
         env.failure(
             id + " is not a valid line number or " + "method name for class " + refType.name());
         return;
       } else if (meths.size() > 1) {
         env.failure(id + " is an ambiguous method name in" + refType.name());
         return;
       }
       loc = meths.get(0).location();
       lineno = loc.lineNumber();
     }
   }
   int startLine = (lineno > 4) ? lineno - 4 : 1;
   int endLine = startLine + 9;
   String sourceLine = source.sourceLine(lineno);
   if (sourceLine == null) {
     env.failure("" + lineno + " is an invalid line number for " + refType.name());
   } else {
     OutputSink out = env.getOutputSink();
     for (int i = startLine; i <= endLine; i++) {
       sourceLine = source.sourceLine(i);
       if (sourceLine == null) {
         break;
       }
       out.print(i);
       out.print("\t");
       if (i == lineno) {
         out.print("=> ");
       } else {
         out.print("   ");
       }
       out.println(sourceLine);
     }
     out.show();
   }
 }