// copied from XDebugSessionImpl processDependencies
  public void processBreakpointHit(@NotNull final Breakpoint breakpoint) {
    XDependentBreakpointManager dependentBreakpointManager =
        ((XBreakpointManagerImpl) getXBreakpointManager()).getDependentBreakpointManager();
    XBreakpoint xBreakpoint = breakpoint.myXBreakpoint;
    if (!dependentBreakpointManager.isMasterOrSlave(xBreakpoint)) {
      return;
    }
    List<XBreakpoint<?>> breakpoints = dependentBreakpointManager.getSlaveBreakpoints(xBreakpoint);
    for (final XBreakpoint<?> slaveBreakpoint : breakpoints) {
      DebuggerInvocationUtil.invokeLater(
          myProject,
          new Runnable() {
            @Override
            public void run() {
              slaveBreakpoint.setEnabled(true);
            }
          });
    }

    if (dependentBreakpointManager.getMasterBreakpoint(xBreakpoint) != null
        && !dependentBreakpointManager.isLeaveEnabled(xBreakpoint)) {
      DebuggerInvocationUtil.invokeLater(
          myProject,
          new Runnable() {
            @Override
            public void run() {
              breakpoint.setEnabled(false);
            }
          });
      // myDebuggerManager.getBreakpointManager().getLineBreakpointManager().queueBreakpointUpdate(breakpoint);
    }
  }
Exemple #2
0
    public void threadAction() {
      if (myRefreshOnly && myThreadDescriptorsToUpdate.length != myThreadsCombo.getItemCount()) {
        // there is no sense in refreshing combobox if thread list has changed since creation of
        // this command
        return;
      }

      final DebuggerContextImpl context = getDebuggerContext();

      final ThreadReferenceProxyImpl threadToSelect = context.getThreadProxy();
      if (threadToSelect == null) {
        return;
      }

      final SuspendContextImpl threadContext =
          SuspendManagerUtil.getSuspendContextForThread(
              context.getSuspendContext(), threadToSelect);
      final ThreadDescriptorImpl currentThreadDescriptor =
          (ThreadDescriptorImpl) myThreadsCombo.getSelectedItem();
      final ThreadReferenceProxyImpl currentThread =
          currentThreadDescriptor != null ? currentThreadDescriptor.getThreadReference() : null;

      if (myRefreshOnly && threadToSelect.equals(currentThread)) {
        context
            .getDebugProcess()
            .getManagerThread()
            .schedule(new UpdateFramesListCommand(context, threadContext));
      } else {
        context
            .getDebugProcess()
            .getManagerThread()
            .schedule(new RebuildFramesListCommand(context, threadContext));
      }

      if (myRefreshOnly) {
        final EvaluationContextImpl evaluationContext = context.createEvaluationContext();
        for (ThreadDescriptorImpl descriptor : myThreadDescriptorsToUpdate) {
          descriptor.setContext(evaluationContext);
          descriptor.updateRepresentation(
              evaluationContext, DescriptorLabelListener.DUMMY_LISTENER);
        }
        DebuggerInvocationUtil.swingInvokeLater(
            getProject(),
            new Runnable() {
              public void run() {
                try {
                  myThreadsListener.setEnabled(false);
                  selectThread(threadToSelect);
                  myFramesList.repaint();
                } finally {
                  myThreadsListener.setEnabled(true);
                }
              }
            });
      } else { // full rebuild
        refillThreadsCombo(threadToSelect);
      }
    }
Exemple #3
0
  @Override
  public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();

    ClassLoaderReference classLoader;
    try {
      classLoader = getClassLoader(evaluationContext, process);
    } catch (Exception e) {
      throw new EvaluateException("Error creating evaluation class loader: " + e, e);
    }

    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(version);
    Collection<OutputFileObject> classes =
        compile(sdkVersion != null ? sdkVersion.getDescription() : null);

    try {
      defineClasses(classes, evaluationContext, process, classLoader);
    } catch (Exception e) {
      throw new EvaluateException("Error during classes definition " + e, e);
    }

    try {
      // invoke base evaluator on call code
      final Project project =
          ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<Project>() {
                    @Override
                    public Project compute() {
                      return myPsiContext.getProject();
                    }
                  });
      ExpressionEvaluator evaluator =
          DebuggerInvocationUtil.commitAndRunReadAction(
              project,
              new EvaluatingComputable<ExpressionEvaluator>() {
                @Override
                public ExpressionEvaluator compute() throws EvaluateException {
                  final TextWithImports callCode = getCallCode();
                  PsiElement copyContext = myData.getAnchor();
                  final CodeFragmentFactory factory =
                      DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                  return factory
                      .getEvaluatorBuilder()
                      .build(
                          factory.createCodeFragment(callCode, copyContext, project),
                          ContextUtil.getSourcePosition(evaluationContext));
                }
              });
      ((EvaluationContextImpl) evaluationContext).setClassLoader(classLoader);
      return evaluator.evaluate(evaluationContext);
    } catch (Exception e) {
      throw new EvaluateException("Error during generated code invocation " + e, e);
    }
  }
 private void remove(final BreakpointWithHighlighter breakpoint) {
   DebuggerInvocationUtil.invokeLater(
       myProject,
       new Runnable() {
         @Override
         public void run() {
           removeBreakpoint(breakpoint);
         }
       });
 }
 private void showHint(final SimpleColoredText text, final WatchItemDescriptor descriptor) {
   DebuggerInvocationUtil.invokeLater(
       getProject(),
       new Runnable() {
         public void run() {
           if (!isHintHidden()) {
             JComponent component;
             if (!isActiveTooltipApplicable(descriptor.getValue())) {
               component = HintUtil.createInformationLabel(text);
             } else {
               component =
                   createExpandableHintComponent(
                       text,
                       new Runnable() {
                         public void run() {
                           final DebuggerContextImpl debuggerContext =
                               DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                           final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
                           debugProcess
                               .getManagerThread()
                               .schedule(
                                   new DebuggerContextCommandImpl(debuggerContext) {
                                     public void threadAction() {
                                       descriptor.setRenderer(
                                           debugProcess.getAutoRenderer(descriptor));
                                       final InspectDebuggerTree tree = getInspectTree(descriptor);
                                       final String expressionText =
                                           ApplicationManager.getApplication()
                                               .runReadAction(
                                                   new Computable<String>() {
                                                     @Override
                                                     public String compute() {
                                                       return myCurrentExpression.getText();
                                                     }
                                                   });
                                       showTreePopup(
                                           tree,
                                           debuggerContext,
                                           expressionText,
                                           new ValueHintTreeComponent(
                                               ValueHint.this, tree, expressionText));
                                     }
                                   });
                         }
                       });
             }
             if (!showHint(component)) return;
             if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
               HintUtil.createInformationLabel(text).requestFocusInWindow();
             }
           }
         }
       });
 }
 public void actionPerformed(ActionEvent e) {
   final TextWithImports text = getEditor().getText();
   doCancelAction();
   DebuggerInvocationUtil.invokeLater(
       getProject(),
       new Runnable() {
         public void run() {
           EvaluateActionHandler.showEvaluationDialog(
               getProject(), text, DebuggerSettings.EVALUATE_FRAGMENT);
         }
       });
 }
  private void runAction(final EvaluationContextImpl context, LocatableEvent event) {
    if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) {
      final StringBuilder buf = StringBuilderSpinAllocator.alloc();
      try {
        if (LOG_ENABLED) {
          buf.append(getEventMessage(event));
          buf.append("\n");
        }
        final DebugProcessImpl debugProcess = context.getDebugProcess();
        final TextWithImports expressionToEvaluate = getLogMessage();
        if (LOG_EXPRESSION_ENABLED
            && expressionToEvaluate != null
            && !"".equals(expressionToEvaluate.getText())) {
          if (!debugProcess.isAttached()) {
            return;
          }

          try {
            ExpressionEvaluator evaluator =
                DebuggerInvocationUtil.commitAndRunReadAction(
                    getProject(),
                    new EvaluatingComputable<ExpressionEvaluator>() {
                      public ExpressionEvaluator compute() throws EvaluateException {
                        return EvaluatorBuilderImpl.build(
                            expressionToEvaluate,
                            ContextUtil.getContextElement(context),
                            ContextUtil.getSourcePosition(context));
                      }
                    });
            final Value eval = evaluator.evaluate(context);
            final String result =
                eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval);
            buf.append(result);
          } catch (EvaluateException e) {
            buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression"));
            buf.append(" \"");
            buf.append(expressionToEvaluate);
            buf.append("\"");
            buf.append(" : ");
            buf.append(e.getMessage());
          }
          buf.append("\n");
        }
        if (buf.length() > 0) {
          debugProcess.printToConsole(buf.toString());
        }
      } finally {
        StringBuilderSpinAllocator.dispose(buf);
      }
    }
  }
 public void showTreePopup(
     final InspectDebuggerTree tree,
     final DebuggerContextImpl debuggerContext,
     final String title,
     final AbstractValueHintTreeComponent<?> component) {
   DebuggerInvocationUtil.invokeLater(
       getProject(),
       new Runnable() {
         public void run() {
           tree.rebuild(debuggerContext);
           showTreePopup(component, tree, title);
         }
       });
 }
  /** updates the state of breakpoint and all the related UI widgets etc */
  @Override
  public final void updateUI() {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      return;
    }
    final Project project = getProject();
    DebuggerInvocationUtil.swingInvokeLater(
        project,
        new Runnable() {
          @Override
          public void run() {
            if (!isValid()) {
              return;
            }

            DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(project).getContext();
            final DebugProcessImpl debugProcess = context.getDebugProcess();
            if (debugProcess == null || !debugProcess.isAttached()) {
              updateCaches(null);
              updateGutter();
            } else {
              debugProcess
                  .getManagerThread()
                  .invoke(
                      new DebuggerCommandImpl() {
                        @Override
                        protected void action() throws Exception {
                          ApplicationManager.getApplication()
                              .runReadAction(
                                  new Runnable() {
                                    @Override
                                    public void run() {
                                      updateCaches(debugProcess);
                                    }
                                  });
                          DebuggerInvocationUtil.swingInvokeLater(
                              project,
                              new Runnable() {
                                @Override
                                public void run() {
                                  updateGutter();
                                }
                              });
                        }
                      });
            }
          }
        });
  }
 /** called by BreakpointManager when destroying the breakpoint */
 @Override
 public void delete() {
   if (isVisible()) {
     final RangeHighlighter highlighter = getHighlighter();
     if (highlighter != null) {
       DebuggerInvocationUtil.invokeLater(
           getProject(),
           new Runnable() {
             @Override
             public void run() {
               highlighter.dispose();
               // we should delete it here, so gutter will not fire events to deleted breakpoint
               BreakpointWithHighlighter.super.delete();
             }
           });
     }
   }
 }
Exemple #11
0
 public void contextAction() throws Exception {
   updateFrameList(myDebuggerContext.getThreadProxy());
   DebuggerInvocationUtil.swingInvokeLater(
       getProject(),
       new Runnable() {
         public void run() {
           try {
             myFramesListener.setEnabled(false);
             final StackFrameProxyImpl contextFrame = getDebuggerContext().getFrameProxy();
             if (contextFrame != null) {
               selectFrame(contextFrame);
             }
           } finally {
             myFramesListener.setEnabled(true);
           }
         }
       });
 }
Exemple #12
0
 public void contextAction() throws Exception {
   final StackFrameDescriptorImpl descriptor = new StackFrameDescriptorImpl(myFrame, myTracker);
   descriptor.setContext(myEvaluationContext);
   descriptor.updateRepresentation(myEvaluationContext, DescriptorLabelListener.DUMMY_LISTENER);
   final Project project = getProject();
   DebuggerInvocationUtil.swingInvokeLater(
       project,
       new Runnable() {
         public void run() {
           try {
             myFramesListener.setEnabled(false);
             synchronized (myFramesList) {
               final DefaultListModel model = myFramesList.getModel();
               if (model.isEmpty() || myFramesLastUpdateTime < myTimestamp) {
                 myFramesLastUpdateTime = myTimestamp;
                 model.clear();
                 for (int idx = 0; idx < myTotalFramesCount; idx++) {
                   final String label = "<frame " + idx + ">";
                   model.addElement(
                       new Object() {
                         public String toString() {
                           return label;
                         }
                       });
                 }
               }
               if (myTimestamp != myFramesLastUpdateTime) {
                 return; // the command has expired
               }
               model.removeElementAt(myIndexToInsert); // remove placeholder
               model.insertElementAt(descriptor, myIndexToInsert);
               if (myIsContextFrame) {
                 myFramesList.setSelectedIndex(myIndexToInsert);
               }
             }
           } finally {
             myFramesListener.setEnabled(true);
           }
         }
       });
 }
 public void editBreakpoint(final Breakpoint breakpoint, final Editor editor) {
   DebuggerInvocationUtil.swingInvokeLater(
       myProject,
       new Runnable() {
         @Override
         public void run() {
           XBreakpoint xBreakpoint = breakpoint.myXBreakpoint;
           if (xBreakpoint instanceof XLineBreakpointImpl) {
             RangeHighlighter highlighter = ((XLineBreakpointImpl) xBreakpoint).getHighlighter();
             if (highlighter != null) {
               GutterIconRenderer renderer = highlighter.getGutterIconRenderer();
               if (renderer != null) {
                 DebuggerSupport.getDebuggerSupport(JavaDebuggerSupport.class)
                     .getEditBreakpointAction()
                     .editBreakpoint(myProject, editor, breakpoint.myXBreakpoint, renderer);
               }
             }
           }
         }
       });
 }
Exemple #14
0
    private void refillThreadsCombo(final ThreadReferenceProxyImpl threadToSelect) {
      final List<ThreadDescriptorImpl> threadItems = createThreadDescriptorsList();
      DebuggerInvocationUtil.swingInvokeLater(
          getProject(),
          new Runnable() {
            public void run() {
              try {
                myThreadsListener.setEnabled(false);

                myThreadsCombo.removeAllItems();
                for (final ThreadDescriptorImpl threadItem : threadItems) {
                  myThreadsCombo.addItem(threadItem);
                }

                selectThread(threadToSelect);
              } finally {
                myThreadsListener.setEnabled(true);
              }
            }
          });
    }
Exemple #15
0
    public void contextAction() throws Exception {
      final ThreadReferenceProxyImpl thread = myDebuggerContext.getThreadProxy();
      try {
        if (!getSuspendContext().getDebugProcess().getSuspendManager().isSuspended(thread)) {
          DebuggerInvocationUtil.swingInvokeLater(
              getProject(),
              new Runnable() {
                public void run() {
                  try {
                    myFramesListener.setEnabled(false);
                    synchronized (myFramesList) {
                      final DefaultListModel model = myFramesList.getModel();
                      model.clear();
                      model.addElement(
                          new Object() {
                            public String toString() {
                              return DebuggerBundle.message("frame.panel.frames.not.available");
                            }
                          });
                      myFramesList.setSelectedIndex(0);
                    }
                  } finally {
                    myFramesListener.setEnabled(true);
                  }
                }
              });

          return;
        }
      } catch (ObjectCollectedException e) {
        return;
      }

      List<StackFrameProxyImpl> frames;
      try {
        frames = thread.frames();
      } catch (EvaluateException e) {
        frames = Collections.emptyList();
      }

      final StackFrameProxyImpl contextFrame = myDebuggerContext.getFrameProxy();
      final EvaluationContextImpl evaluationContext = myDebuggerContext.createEvaluationContext();
      final DebuggerManagerThreadImpl managerThread =
          myDebuggerContext.getDebugProcess().getManagerThread();
      final MethodsTracker tracker = new MethodsTracker();
      final int totalFramesCount = frames.size();
      int index = 0;
      final long timestamp = System.nanoTime();
      for (StackFrameProxyImpl stackFrameProxy : frames) {
        managerThread.schedule(
            new AppendFrameCommand(
                getSuspendContext(),
                stackFrameProxy,
                evaluationContext,
                tracker,
                index++,
                stackFrameProxy.equals(contextFrame),
                totalFramesCount,
                timestamp));
      }
    }