@Override
    protected void execute(final DataRequestMonitor<FormattedValueDMData> rm) {
      DsfSession session = DsfSession.getSession(frame.getSessionId());
      IExpressions expressions = dsfServicesTracker.getService(IExpressions.class);
      if (expressions == null) {
        rm.setStatus(
            DsfUIPlugin.newErrorStatus(
                IDsfStatusConstants.REQUEST_FAILED, "No expression service", null)); // $NON-NLS-1$
        rm.done();
        return;
      }
      IExpressionDMContext expressionDMC = expressions.createExpression(frame, expression);
      FormattedValueDMContext formattedValueContext =
          expressions.getFormattedValueContext(expressionDMC, getHoverFormat());
      expressions.getFormattedExpressionValue(
          formattedValueContext,
          new DataRequestMonitor<FormattedValueDMData>(session.getExecutor(), rm) {
            @Override
            protected void handleSuccess() {
              rm.setData(getData());
              rm.done();
            }

            @Override
            protected void handleFailure() {
              rm.done();
            }
          });
    }
  public IRegisterDMData readRegister(Object element) {
    /*
     * Get the DMC and the session. If element is not an register DMC, or
     * session is stale, then bail out.
     */
    IRegisterDMContext dmc = getRegisterDMC(element);
    if (dmc == null) return null;
    DsfSession session = DsfSession.getSession(dmc.getSessionId());
    if (session == null) return null;

    /*
     * Create the query to request the value from service. Note: no need to
     * guard agains RejectedExecutionException, because
     * DsfSession.getSession() above would only return an active session.
     */
    GetRegisterValueQuery query = new GetRegisterValueQuery(dmc);
    session.getExecutor().execute(query);

    /*
     * Now we have the data, go and get it. Since the call is completed now
     * the ".get()" will not suspend it will immediately return with the
     * data.
     */
    try {
      return query.get();
    } catch (InterruptedException e) {
      assert false;
      return null;
    } catch (ExecutionException e) {
      return null;
    }
  }
  @Override
  protected String evaluateExpression(String expression) {
    IFrameDMContext frame = getFrame();
    if (frame == null) {
      return null;
    }

    String sessionId = frame.getSessionId();
    DsfServicesTracker dsfServicesTracker =
        new DsfServicesTracker(DsfUIPlugin.getBundleContext(), sessionId);
    try {
      GetExpressionValueQuery query =
          new GetExpressionValueQuery(frame, expression, dsfServicesTracker);
      DsfSession session = DsfSession.getSession(sessionId);
      if (session != null) {
        session.getExecutor().execute(query);
        try {
          FormattedValueDMData data = query.get();
          if (data != null) return data.getFormattedValue();
        } catch (Exception e) {
        }
      }
    } finally {
      dsfServicesTracker.dispose();
    }
    return null;
  }
Example #4
0
  @Override
  public boolean canMoveToLine(final String fileName, final int lineNumber) {
    DsfSession session = DsfSession.getSession(fContext.getSessionId());
    if (session != null && session.isActive()) {
      try {
        Query<Boolean> query =
            new Query<Boolean>() {
              @Override
              protected void execute(DataRequestMonitor<Boolean> rm) {
                DsfServicesTracker tracker =
                    new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());

                IRunControl2 runControl = tracker.getService(IRunControl2.class);
                if (runControl != null) {
                  runControl.canMoveToLine(fContext, fileName, lineNumber, false, rm);
                } else {
                  rm.setData(false);
                  rm.done();
                }
                tracker.dispose();
              }
            };
        session.getExecutor().execute(query);
        return query.get();
      } catch (RejectedExecutionException e) {
      } catch (InterruptedException e) {
      } catch (ExecutionException e) {
      }
    }
    return false;
  }
Example #5
0
  @Override
  public void moveToLine(final String fileName, final int lineNumber) throws DebugException {
    DsfSession session = DsfSession.getSession(fContext.getSessionId());
    if (session != null && session.isActive()) {
      Throwable exception = null;
      try {
        Query<Object> query =
            new Query<Object>() {
              @Override
              protected void execute(final DataRequestMonitor<Object> rm) {
                DsfServicesTracker tracker =
                    new DsfServicesTracker(DsfUIPlugin.getBundleContext(), fContext.getSessionId());

                IRunControl2 runControl = tracker.getService(IRunControl2.class);
                if (runControl != null) {
                  runControl.moveToLine(fContext, fileName, lineNumber, false, rm);
                } else {
                  rm.setStatus(
                      new Status(
                          IStatus.ERROR,
                          DsfUIPlugin.PLUGIN_ID,
                          IDsfStatusConstants.NOT_SUPPORTED,
                          "IRunControl2 service not available",
                          null)); //$NON-NLS-1$
                  rm.done();
                }
                tracker.dispose();
              }
            };
        session.getExecutor().execute(query);
        query.get();
      } catch (RejectedExecutionException e) {
        exception = e;
      } catch (InterruptedException e) {
        exception = e;
      } catch (ExecutionException e) {
        exception = e;
      }
      if (exception != null) {
        throw new DebugException(
            new Status(
                IStatus.ERROR,
                DsfUIPlugin.PLUGIN_ID,
                DebugException.REQUEST_FAILED,
                "Failed executing move to line",
                exception)); //$NON-NLS-1$
      }
    } else {
      throw new DebugException(
          new Status(
              IStatus.ERROR,
              DsfUIPlugin.PLUGIN_ID,
              DebugException.REQUEST_FAILED,
              "Debug session is not active",
              null)); //$NON-NLS-1$
    }
  }
 /*
  * @see org.eclipse.jface.text.ITextHoverExtension2#getHoverInfo2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
  */
 public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
   final String simpleInfo = getHoverInfo(textViewer, hoverRegion);
   if (!useExpressionExplorer() || simpleInfo == null) {
     return simpleInfo;
   }
   // improved version using ExpressionInformationControlCreator
   // see also getHoverControlCreator()
   final String text;
   text = getExpressionText(textViewer, hoverRegion);
   if (text != null && text.length() > 0) {
     final IFrameDMContext frameDmc = getFrame();
     if (frameDmc != null) {
       final DsfSession dsfSession = DsfSession.getSession(frameDmc.getSessionId());
       if (dsfSession != null) {
         Callable<IExpressionDMContext> callable =
             new Callable<IExpressionDMContext>() {
               public IExpressionDMContext call() throws Exception {
                 DsfServicesTracker tracker =
                     new DsfServicesTracker(
                         DsfUIPlugin.getBundleContext(), frameDmc.getSessionId());
                 try {
                   IExpressions expressions = tracker.getService(IExpressions.class);
                   if (expressions != null) {
                     return expressions.createExpression(frameDmc, text);
                   }
                   return null;
                 } finally {
                   tracker.dispose();
                 }
               }
             };
         try {
           return dsfSession.getExecutor().submit(callable).get();
         } catch (InterruptedException e) {
         } catch (ExecutionException e) {
         }
       }
     }
   }
   return null;
 }
  public String getFormattedBitFieldValue(Object element, String formatId) {

    /*
     * Get the DMC and the session. If element is not an register DMC, or
     * session is stale, then bail out.
     */
    IFormattedDataDMContext dmc = null;
    if (element instanceof IDMVMContext) {
      IDMContext vmcdmc = ((IDMVMContext) element).getDMContext();
      IBitFieldDMContext bitfielddmc =
          DMContexts.getAncestorOfType(vmcdmc, IBitFieldDMContext.class);
      dmc = DMContexts.getAncestorOfType(bitfielddmc, IFormattedDataDMContext.class);
    }

    if (dmc == null) return null;
    DsfSession session = DsfSession.getSession(dmc.getSessionId());
    if (session == null) return null;

    /*
     * Create the query to write the value to the service. Note: no need to
     * guard agains RejectedExecutionException, because
     * DsfSession.getSession() above would only return an active session.
     */
    GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(dmc, formatId);
    session.getExecutor().execute(query);

    /*
     * Now we have the data, go and get it. Since the call is completed now
     * the ".get()" will not suspend it will immediately return with the
     * data.
     */
    try {
      return query.get();
    } catch (InterruptedException e) {
      assert false;
      return null;
    } catch (ExecutionException e) {
      return null;
    }
  }
  public void writeBitField(Object element, String value, String formatId) {

    /*
     * Get the DMC and the session. If element is not an register DMC, or
     * session is stale, then bail out.
     */
    IBitFieldDMContext dmc = getBitFieldDMC(element);
    if (dmc == null) return;
    DsfSession session = DsfSession.getSession(dmc.getSessionId());
    if (session == null) return;

    /*
     * Create the query to write the value to the service. Note: no need to
     * guard agains RejectedExecutionException, because
     * DsfSession.getSession() above would only return an active session.
     */
    SetBitFieldValueQuery query = new SetBitFieldValueQuery(dmc, value, formatId);
    session.getExecutor().execute(query);

    /*
     * Now we have the data, go and get it. Since the call is completed now
     * the ".get()" will not suspend it will immediately return with the
     * data.
     */
    try {
      /*
       * Return value is irrelevant, any error would come through with an
       * exception.
       */
      query.get();
    } catch (InterruptedException e) {
      assert false;
    } catch (ExecutionException e) {
      assert false;
      /*
       * View must be shutting down, no need to show erro dialog.
       */
    }
  }
    @Override
    protected void execute(final DataRequestMonitor<V> rm) {
      /*
       * We're in another dispatch, so we must guard against executor
       * shutdown again.
       */
      final DsfSession session = DsfSession.getSession(fDmc.getSessionId());
      if (session == null) {
        rm.setStatus(
            new Status(
                IStatus.ERROR,
                DsfUIPlugin.PLUGIN_ID,
                IDsfStatusConstants.INVALID_STATE,
                "Debug session already shut down.",
                null)); //$NON-NLS-1$
        rm.done();
        return;
      }

      /*
       * Guard against a disposed service
       */
      IRegisters service = getService();
      if (service == null) {
        rm.setStatus(
            new Status(
                IStatus.ERROR,
                DsfUIPlugin.PLUGIN_ID,
                IDsfStatusConstants.INVALID_STATE,
                "Service unavailable",
                null)); //$NON-NLS-1$
        rm.done();
        return;
      }

      doExecute(service, rm);
    }
  public IBitFieldDMData getBitFieldDMData(Object element) {
    IBitFieldDMContext dmc = null;
    if (element instanceof IDMVMContext) {
      dmc =
          DMContexts.getAncestorOfType(
              ((IDMVMContext) element).getDMContext(), IBitFieldDMContext.class);
    }

    if (dmc != null) {
      DsfSession session = DsfSession.getSession(dmc.getSessionId());

      if (session != null) {
        GetBitFieldQuery query = new GetBitFieldQuery(dmc);
        session.getExecutor().execute(query);

        try {
          return query.get();
        } catch (InterruptedException e) {
        } catch (ExecutionException e) {
        }
      }
    }
    return null;
  }