Package com.sun.jdi

Examples of com.sun.jdi.VirtualMachine


  public static Value eval(ThreadReference threadRef, Expression exp,
      ObjectReference thisObj,boolean hasParents) {

    if (exp == null)
      return null;
    VirtualMachine vm = threadRef.virtualMachine();
    String expType = exp.getExpType();
    String expName = exp.getName();

    if (expType.equals(Expression.EXP_TYPE_BOOL)) {
      if (expName.equals("true"))
        return vm.mirrorOf(true);
      else
        return vm.mirrorOf(false);
    } else if (expType.equals(Expression.EXP_TYPE_STR)) {
      return vm.mirrorOf(expName);
    } else if (expType.equals(Expression.EXP_TYPE_NULL)) {
      return null;
    } else if (expType.equals(Expression.EXP_TYPE_NUM)) {
      if (expName.indexOf(".") > -1) {
        return vm.mirrorOf(Float.parseFloat(expName));
      } else {
        return vm.mirrorOf(Integer.parseInt(expName));
      }
    }

    Value basicExpValue = null;
    if (!exp.isMethod()) {
      basicExpValue = findValueInFrame(threadRef, expName,thisObj,hasParents);
    } else {
      List<Expression> params = exp.getParams();
      List<Value> arguments = new ArrayList<Value>();
      if (params.size() != 0) {
        for (Expression param : params) {
          Value paramValue = eval(threadRef, param, thisObj,false);
          arguments.add(paramValue);
        }
      }
      basicExpValue = invoke((ObjectReference) thisObj, expName, arguments);
    }
     
    if (exp.isArrayExp()) {
      if (basicExpValue instanceof ArrayReference) {
        ArrayReference array = (ArrayReference)basicExpValue;
        Value arrayIdxValue = eval(threadRef, exp.getArrayIdxExp(), thisObj,false);
        if (arrayIdxValue instanceof IntegerValue ) {
          int idx = ((IntegerValue)arrayIdxValue).value();
          basicExpValue = array.getValue(idx);
        else {
          throw new ExpressionEvalException("eval expression error, array index is not int type.");
        }
      }
    }

    List<Expression> members = exp.getMembers();
    if (members.size() == 0)
      return basicExpValue;
    if (exp.isStaticMember()) {
      Expression memberExp = members.get(0);
      List<Expression> params = memberExp.getParams();
      List<Value> arguments = new ArrayList<Value>();
      if (params.size() != 0) {
        for (Expression param : params) {
          Value paramValue = eval(threadRef, param, thisObj,false);
          arguments.add(paramValue);
        }
      }
      List<ReferenceType> refTypes = vm.classesByName(exp.getName());
      if (refTypes == null || refTypes.size() == 0) {
        throw new ExpressionEvalException("eval expression error, type '" + exp.getName() + "' can't be found ");
      }
       
      basicExpValue = invoke(refTypes.get(0), memberExp.getName(), arguments);
View Full Code Here


    return "success";
  }
 
  public void tryCreateExceptionRequest(String className) {
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    if (vm==null) return ;
    EventRequestManager erm = vm.eventRequestManager();
    if (erm == null) return;
   
    List<ReferenceType> refTypes = vm.classesByName(className);
    ExceptionRequest exReq = vm.eventRequestManager().createExceptionRequest(refTypes.get(0), true, true);
    exReq.setSuspendPolicy(ExceptionRequest.SUSPEND_EVENT_THREAD);
    exReq.setEnabled(true);
    requests.put(className, exReq);
   
  }
View Full Code Here

    return "success";
  }
 
  public void tryRemoveExceptionRequest(String className) {
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    if (vm==null) return ;
    EventRequestManager erm = vm.eventRequestManager();
    if (erm == null) return;
   
    ExceptionRequest exReq = requests.get(className);
    vm.eventRequestManager().deleteEventRequest(exReq);
  }
View Full Code Here

    }
    optionArg.setValue(optionSb.toString());
   

    try {
      VirtualMachine vm = launchingConnector.launch(defaultArguments);
      return vm;
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalConnectorArgumentsException e) {
      e.printStackTrace();
View Full Code Here

    Connector.Argument portArg = args.get("port");
    Connector.Argument hostArg = args.get("hostname");
    try {
      portArg.setValue(port);
      hostArg.setValue("127.0.0.1");
      VirtualMachine vm = connector.attach(args);
      return vm;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
View Full Code Here

  }

  public void tryCreatePrepareRequest() {
   
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    if (vm==null) return ;
    EventRequestManager erm = vm.eventRequestManager();
    if (erm == null) return;
   
    HashSet<String> names = new HashSet<String>();
   
    for (Breakpoint bp : allBreakpoints) {
View Full Code Here

  }

  public void tryRemoveBreakpointRequest(Breakpoint breakpoint) {
   
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    if (vm == null)
      return;
    List<BreakpointRequest> requests = breakpoint.getRequests();
    if (requests == null || requests.size() == 0)
      return;
    for (BreakpointRequest bp : requests) {
      try {
        vm.eventRequestManager().deleteEventRequest(bp);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

    }
   
    int lineNum = breakpoint.getLineNum();
   
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    if (vm == null)
      return;
    List<ReferenceType> refTypes = vm.classesByName(className);
    if (refTypes == null)
      return;

    for (int i = 0; i < refTypes.size(); i++) {
      ReferenceType rt = refTypes.get(i);
      if (!rt.isPrepared()) {
        continue;
      }
      List<Location> lines;

      try {
        lines = rt.locationsOfLine(lineNum);
        if (lines.size() == 0) {
          continue;
        }
        Location loc = lines.get(0);
        BreakpointRequest request = vm.eventRequestManager().createBreakpointRequest(loc);
        request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
        request.setEnabled(true);
        breakpoint.addRequest(request);
      } catch (AbsentInformationException e) {
        e.printStackTrace();
View Full Code Here

public class StepManager {

  public static String step(int stepDepth) {
    Debugger debugger = Debugger.getInstance();
    VirtualMachine vm = debugger.getVm();
    SuspendThreadStack threadStack = SuspendThreadStack.getInstance();
    ThreadReference threadRef = threadStack.getCurThreadRef();

    EventRequestManager mgr = vm.eventRequestManager();

    List<StepRequest> steps = mgr.stepRequests();
    for (int i = 0; i < steps.size(); i++) {
      StepRequest step = steps.get(i);
      if (step.thread().equals(threadRef)) {
View Full Code Here

      ThreadReference threadRef = checkAndGetCurrentThread();
      Debugger debugger = Debugger.getInstance();
      SuspendThreadStack threadStack = SuspendThreadStack.getInstance();
      StackFrame stackFrame = threadRef.frame(threadStack.getCurFrame());
      CompilerContext ctx = debugger.getCompilerContext();
      VirtualMachine vm = debugger.getVm();
      List<ReferenceType> refTypes = vm.classesByName("java.lang."+className);
      if (refTypes !=null && refTypes.size() >0 ) {
        return refTypes.get(0);
      }
      String locSourcePath = stackFrame.location().sourcePath();
      String abPath = ctx.findSourceFile(locSourcePath);
      BufferedReader br = new BufferedReader(new FileReader(abPath));
      Pattern pat = Pattern.compile("import\\s+(.*\\."+className+")\\s*;\\s*$");
      String qualifiedClass = null;
     
      int pkgIndex = locSourcePath.lastIndexOf(File.separator);
      String packageName = "";
      if (pkgIndex != -1 ){
        packageName = locSourcePath.substring(0,pkgIndex).replace(File.separator, ".");
      }
     
      while (true) {
        String tmp = br.readLine();
        if (tmp == null) break;
        tmp = tmp.trim();
        Matcher matcher = pat.matcher(tmp);
        if (matcher.matches()) {
          qualifiedClass = matcher.group(1);
          break;
        }
      }
      br.close();
      if (qualifiedClass == null && !packageName.equals("")) {
        qualifiedClass = packageName + "." + className;
      } else {
        qualifiedClass = className;
      }
      refTypes = vm.classesByName(qualifiedClass);
      if (refTypes !=null && refTypes.size() >0 ) {
        return refTypes.get(0);
      }
     
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.sun.jdi.VirtualMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.