Ejemplo n.º 1
0
 // Remote this from our thread list
 private void processThreadKilled(String thread_id) {
   PyThread threadToDelete = findThreadByID(thread_id);
   if (threadToDelete != null) {
     int j = 0;
     PyThread[] newThreads = new PyThread[threads.length - 1];
     for (int i = 0; i < threads.length; i++) {
       if (threads[i] != threadToDelete) {
         newThreads[j++] = threads[i];
       }
     }
     threads = newThreads;
     fireEvent(new DebugEvent(threadToDelete, DebugEvent.TERMINATE));
   }
 }
Ejemplo n.º 2
0
  /** ThreadRun event processing */
  private void processThreadRun(String payload) {
    try {
      Tuple<String, String> threadIdAndReason = getThreadIdAndReason(payload);
      int resumeReason = DebugEvent.UNSPECIFIED;
      try {
        int raw_reason = Integer.parseInt(threadIdAndReason.o2);
        if (raw_reason == AbstractDebuggerCommand.CMD_STEP_OVER)
          resumeReason = DebugEvent.STEP_OVER;
        else if (raw_reason == AbstractDebuggerCommand.CMD_STEP_RETURN)
          resumeReason = DebugEvent.STEP_RETURN;
        else if (raw_reason == AbstractDebuggerCommand.CMD_STEP_INTO)
          resumeReason = DebugEvent.STEP_INTO;
        else if (raw_reason == AbstractDebuggerCommand.CMD_RUN_TO_LINE)
          resumeReason = DebugEvent.UNSPECIFIED;
        else if (raw_reason == AbstractDebuggerCommand.CMD_SET_NEXT_STATEMENT)
          resumeReason = DebugEvent.UNSPECIFIED;
        else if (raw_reason == AbstractDebuggerCommand.CMD_THREAD_RUN)
          resumeReason = DebugEvent.CLIENT_REQUEST;
        else {
          PydevDebugPlugin.log(IStatus.ERROR, "Unexpected resume reason code", null);
          resumeReason = DebugEvent.UNSPECIFIED;
        }
      } catch (NumberFormatException e) {
        // expected, when pydevd reports "None"
        resumeReason = DebugEvent.UNSPECIFIED;
      }

      String threadID = threadIdAndReason.o1;
      PyThread t = (PyThread) findThreadByID(threadID);
      if (t != null) {
        t.setSuspended(false, null);
        fireEvent(new DebugEvent(t, DebugEvent.RESUME, resumeReason));

      } else {
        FastStringBuffer buf = new FastStringBuffer();
        for (PyThread thread : threads) {
          if (buf.length() > 0) {
            buf.append(", ");
          }
          buf.append("id: " + thread.getId());
        }
        String msg = "Unable to find thread: " + threadID + " available: " + buf;
        PydevDebugPlugin.log(IStatus.ERROR, msg, new RuntimeException(msg));
      }
    } catch (CoreException e1) {
      Log.log(e1);
    }
  }
Ejemplo n.º 3
0
  private void processThreadSuspended(String payload) {
    Object[] threadNstack;
    try {
      threadNstack = XMLUtils.XMLToStack(this, payload);
    } catch (CoreException e) {
      PydevDebugPlugin.errorDialog("Error reading ThreadSuspended", e);
      return;
    }

    PyThread t = (PyThread) threadNstack[0];
    int reason = DebugEvent.UNSPECIFIED;
    String stopReason = (String) threadNstack[1];

    if (stopReason != null) {
      int stopReason_i = Integer.parseInt(stopReason);

      if (stopReason_i == AbstractDebuggerCommand.CMD_STEP_OVER
          || stopReason_i == AbstractDebuggerCommand.CMD_STEP_INTO
          || stopReason_i == AbstractDebuggerCommand.CMD_STEP_RETURN
          || stopReason_i == AbstractDebuggerCommand.CMD_RUN_TO_LINE
          || stopReason_i == AbstractDebuggerCommand.CMD_SET_NEXT_STATEMENT) {
        reason = DebugEvent.STEP_END;

      } else if (stopReason_i == AbstractDebuggerCommand.CMD_THREAD_SUSPEND) {
        reason = DebugEvent.CLIENT_REQUEST;

      } else if (stopReason_i == AbstractDebuggerCommand.CMD_SET_BREAK) {
        reason = DebugEvent.BREAKPOINT;

      } else {
        PydevDebugPlugin.log(IStatus.ERROR, "Unexpected reason for suspension", null);
        reason = DebugEvent.UNSPECIFIED;
      }
    }
    if (t != null) {
      modificationChecker.onlyLeaveThreads((PyThread[]) this.threads);

      IStackFrame stackFrame[] = (IStackFrame[]) threadNstack[2];
      t.setSuspended(true, stackFrame);
      fireEvent(new DebugEvent(t, DebugEvent.SUSPEND, reason));
    }
  }
Ejemplo n.º 4
0
  public void terminate() {

    if (socket != null) {
      try {
        socket.shutdownInput(); // trying to make my pydevd notice that the socket is gone
      } catch (Exception e) {
        // ok, ignore
      }
      try {
        socket.shutdownOutput();
      } catch (Exception e) {
        // ok, ignore
      }
      try {
        socket.close();
      } catch (Exception e) {
        // ok, ignore
      }
    }
    socket = null;
    disconnected = true;

    if (writer != null) {
      writer.done();
      writer = null;
    }
    if (reader != null) {
      reader.done();
      reader = null;
    }

    if (DEBUG) {
      System.out.println("TERMINATE");
    }

    threads = new PyThread[0];
    fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
  }
Ejemplo n.º 5
0
  /** Add it to the list of threads */
  private void processThreadCreated(String payload) {

    PyThread[] newThreads;
    try {
      newThreads = XMLUtils.ThreadsFromXML(this, payload);
    } catch (CoreException e) {
      PydevDebugPlugin.errorDialog("Error in processThreadCreated", e);
      return;
    }

    // Hide Pydevd threads if requested
    if (PydevDebugPlugin.getDefault()
        .getPreferenceStore()
        .getBoolean(PydevDebugPreferencesInitializer.HIDE_PYDEVD_THREADS)) {
      int removeThisMany = 0;

      for (int i = 0; i < newThreads.length; i++) {
        if (((PyThread) newThreads[i]).isPydevThread()) {
          removeThisMany++;
        }
      }

      if (removeThisMany > 0) {
        int newSize = newThreads.length - removeThisMany;

        if (newSize == 0) { // no threads to add
          return;

        } else {

          PyThread[] newnewThreads = new PyThread[newSize];
          int i = 0;

          for (PyThread newThread : newThreads) {
            if (!((PyThread) newThread).isPydevThread()) {
              newnewThreads[i] = newThread;
              i += 1;
            }
          }

          newThreads = newnewThreads;
        }
      }
    }

    // add threads to the thread list, and fire event
    if (threads == null) {
      threads = newThreads;

    } else {
      PyThread[] combined = new PyThread[threads.length + newThreads.length];
      int i = 0;
      for (i = 0; i < threads.length; i++) {
        combined[i] = threads[i];
      }

      for (int j = 0; j < newThreads.length; i++, j++) {
        combined[i] = newThreads[j];
      }
      threads = combined;
    }
    // Now notify debugger that new threads were added
    for (int i = 0; i < newThreads.length; i++) {
      fireEvent(new DebugEvent(newThreads[i], DebugEvent.CREATE));
    }
  }
Ejemplo n.º 6
0
 /**
  * This method is called when some value has to be changed to some other expression.
  *
  * <p>Note that it will (currently) only work for changing local values that are in the topmost
  * frame. -- python has no way of making it work right now (see: pydevd_vars.changeAttrExpression)
  */
 public void setValue(String expression) throws DebugException {
   ChangeVariableCommand changeVariableCommand = getChangeVariableCommand(target, expression);
   target.postCommand(changeVariableCommand);
   this.value = expression;
   target.fireEvent(new DebugEvent(this, DebugEvent.CONTENT | DebugEvent.CHANGE));
 }