Exemplo n.º 1
0
  /*
   * This method should not be called from the UI thread.
   * (non-Javadoc)
   * @see org.eclipse.cdt.dsf.gdb.actions.IConnect#canConnect()
   */
  @Override
  public boolean canConnect() {
    Query<Boolean> canConnectQuery =
        new Query<Boolean>() {
          @Override
          public void execute(DataRequestMonitor<Boolean> rm) {
            IProcesses procService = fTracker.getService(IProcesses.class);
            ICommandControlService commandControl =
                fTracker.getService(ICommandControlService.class);

            if (procService != null && commandControl != null) {
              procService.isDebuggerAttachSupported(commandControl.getContext(), rm);
            } else {
              rm.setData(false);
              rm.done();
            }
          }
        };
    try {
      fExecutor.execute(canConnectQuery);
      return canConnectQuery.get();
    } catch (InterruptedException e) {
    } catch (ExecutionException e) {
    } catch (RejectedExecutionException e) {
      // Can be thrown if the session is shutdown
    }

    return false;
  }
  @Override
  protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request)
      throws CoreException {
    if (targets.length != 1) {
      return;
    }

    final ITraceTargetDMContext dmc =
        DMContexts.getAncestorOfType(
            ((IDMVMContext) targets[0]).getDMContext(), ITraceTargetDMContext.class);
    if (dmc == null) {
      return;
    }

    Query<Object> selectRecordQuery =
        new Query<Object>() {
          @Override
          public void execute(final DataRequestMonitor<Object> rm) {
            final IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);

            if (traceControl != null) {
              traceControl.getCurrentTraceRecordContext(
                  dmc,
                  new DataRequestMonitor<ITraceRecordDMContext>(fExecutor, rm) {
                    @Override
                    protected void handleSuccess() {
                      final ITraceRecordDMContext prevDmc =
                          traceControl.createPrevRecordContext(getData());
                      traceControl.selectTraceRecord(
                          prevDmc,
                          new ImmediateRequestMonitor(rm) {
                            @Override
                            protected void handleSuccess() {
                              fSession.dispatchEvent(
                                  new TraceRecordSelectedChangedEvent(prevDmc),
                                  new Hashtable<String, String>());
                              rm.done();
                            }
                          });
                    };
                  });
            } else {
              rm.done();
            }
          }
        };
    try {
      fExecutor.execute(selectRecordQuery);
      selectRecordQuery.get();
    } catch (InterruptedException e) {
    } catch (ExecutionException e) {
    } catch (RejectedExecutionException e) {
      // Can be thrown if the session is shutdown
    }
  }
Exemplo n.º 3
0
 private void shutdownService(final IDsfService service)
     throws InterruptedException, ExecutionException {
   Query<Object> shutdownQuery =
       new Query<Object>() {
         @Override
         protected void execute(DataRequestMonitor<Object> rm) {
           rm.setData(new Object());
           service.shutdown(rm);
         }
       };
   fDsfExecutor.execute(shutdownQuery);
   shutdownQuery.get();
 }
 @Override
 public void getValue(final int index, final DataRequestMonitor<Integer> rm) {
   // Artificially delay the retrieval of the sum data to simulate
   // real processing time.
   fExecutor.schedule(
       new Runnable() {
         @Override
         public void run() {
           doGetValue(index, rm);
         }
       },
       PROCESSING_DELAY,
       TimeUnit.MILLISECONDS);
 }
Exemplo n.º 5
0
 @Override
 protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request)
     throws CoreException {
   Query<Boolean> connectQuery =
       new Query<Boolean>() {
         @Override
         public void execute(DataRequestMonitor<Boolean> rm) {
           connect(rm);
         }
       };
   try {
     fExecutor.execute(connectQuery);
     connectQuery.get();
   } catch (InterruptedException e) {
   } catch (ExecutionException e) {
   } catch (CancellationException e) {
     // Nothing to do, just ignore the command since the user
     // cancelled it.
   } catch (RejectedExecutionException e) {
     // Can be thrown if the session is shutdown
   }
 }
Exemplo n.º 6
0
  /** @throws java.lang.Exception */
  @Override
  protected void tearDown() throws Exception {
    fVMProvider.getNode().setFormattedValuesListener(null);
    fModel.setTestModelListener(null);

    fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
    fVMProvider.getNode().setVMUpdateListener(null);

    fVMAdapter.dispose();

    fVMListener.dispose();
    fViewerListener.dispose();

    shutdownService(fDummyValuesService);
    shutdownService(fModel);
    fViewer.getPresentationContext().dispose();
    // Close the shell and exit.
    fShell.close();
    while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch()) fDisplay.sleep();
    DsfSession.endSession(fDsfSession);
    fDsfExecutor.shutdown();
  }
Exemplo n.º 7
0
  /*
   * This method should not be called from the UI thread.
   * (non-Javadoc)
   * @see org.eclipse.cdt.dsf.gdb.actions.IConnect#canConnect()
   */
  @Override
  public void connect(final RequestMonitor rm) {
    fExecutor.execute(
        new DsfRunnable() {
          @Override
          public void run() {
            final IProcesses procService = fTracker.getService(IProcesses.class);
            ICommandControlService commandControl =
                fTracker.getService(ICommandControlService.class);

            if (procService != null && commandControl != null) {
              final ICommandControlDMContext controlCtx = commandControl.getContext();

              // First check if the "New..." button should be enabled.
              procService.isDebugNewProcessSupported(
                  controlCtx,
                  new DataRequestMonitor<Boolean>(fExecutor, rm) {
                    @Override
                    protected void handleCompleted() {
                      final boolean newProcessSupported = isSuccess() && getData();

                      // Now get the list of all processes
                      procService.getRunningProcesses(
                          controlCtx,
                          new DataRequestMonitor<IProcessDMContext[]>(fExecutor, rm) {
                            @Override
                            protected void handleSuccess() {

                              final List<IProcessExtendedInfo> procInfoList =
                                  new ArrayList<IProcessExtendedInfo>();

                              final CountingRequestMonitor countingRm =
                                  new CountingRequestMonitor(fExecutor, rm) {
                                    @Override
                                    protected void handleSuccess() {
                                      // Prompt the user to choose one or more processes, or to
                                      // start a new one
                                      new PromptForPidJob(
                                              LaunchUIMessages.getString(
                                                  "ProcessPrompter.PromptJob"), //$NON-NLS-1$
                                              newProcessSupported,
                                              procInfoList.toArray(
                                                  new IProcessExtendedInfo[procInfoList.size()]),
                                              new DataRequestMonitor<Object>(fExecutor, rm) {
                                                @Override
                                                protected void handleCancel() {
                                                  rm.cancel();
                                                  rm.done();
                                                }

                                                @Override
                                                protected void handleSuccess() {
                                                  Object data = getData();
                                                  if (data instanceof String) {
                                                    // User wants to start a new process
                                                    startNewProcess(controlCtx, (String) data, rm);
                                                  } else if (data
                                                      instanceof IProcessExtendedInfo[]) {
                                                    attachToProcesses(
                                                        controlCtx,
                                                        (IProcessExtendedInfo[]) data,
                                                        rm);
                                                  } else {
                                                    rm.done(
                                                        new Status(
                                                            IStatus.ERROR,
                                                            GdbUIPlugin.PLUGIN_ID,
                                                            IDsfStatusConstants.INTERNAL_ERROR,
                                                            "Invalid return type for process prompter",
                                                            null)); //$NON-NLS-1$
                                                  }
                                                }
                                              })
                                          .schedule();
                                    }
                                  };

                              if (getData().length > 0 && getData()[0] instanceof IThreadDMData) {
                                // The list of running processes also contains the name of the
                                // processes
                                // This is much more efficient.  Let's use it.
                                for (IProcessDMContext processCtx : getData()) {
                                  IThreadDMData processData = (IThreadDMData) processCtx;
                                  int pid = 0;
                                  try {
                                    pid = Integer.parseInt(processData.getId());
                                  } catch (NumberFormatException e) {
                                  }
                                  String[] cores = null;
                                  String owner = null;
                                  if (processData instanceof IGdbThreadDMData) {
                                    cores = ((IGdbThreadDMData) processData).getCores();
                                    owner = ((IGdbThreadDMData) processData).getOwner();
                                  }
                                  procInfoList.add(
                                      new ProcessInfo(pid, processData.getName(), cores, owner));
                                }

                                // Re-use the counting monitor and trigger it right away.
                                // No need to call done() in this case.
                                countingRm.setDoneCount(0);
                              } else {
                                // The list of running processes does not contain the names, so
                                // we must obtain it individually

                                // For each process, obtain its name
                                // Once all the names are obtained, prompt the user for the pid to
                                // use

                                // New cycle, look for service again
                                final IProcesses procService =
                                    fTracker.getService(IProcesses.class);

                                if (procService != null) {
                                  countingRm.setDoneCount(getData().length);

                                  for (IProcessDMContext processCtx : getData()) {
                                    procService.getExecutionData(
                                        processCtx,
                                        new DataRequestMonitor<IThreadDMData>(
                                            fExecutor, countingRm) {
                                          @Override
                                          protected void handleSuccess() {
                                            IThreadDMData processData = getData();
                                            int pid = 0;
                                            try {
                                              pid = Integer.parseInt(processData.getId());
                                            } catch (NumberFormatException e) {
                                            }
                                            String[] cores = null;
                                            String owner = null;
                                            if (processData instanceof IGdbThreadDMData) {
                                              cores = ((IGdbThreadDMData) processData).getCores();
                                              owner = ((IGdbThreadDMData) processData).getOwner();
                                            }
                                            procInfoList.add(
                                                new ProcessInfo(
                                                    pid, processData.getName(), cores, owner));
                                            countingRm.done();
                                          }
                                        });
                                  }
                                } else {
                                  // Trigger right away.  No need to call done() in this case.
                                  countingRm.setDoneCount(0);
                                }
                              }
                            }
                          });
                    }
                  });
            } else {
              rm.done();
            }
          }
        });
  }
  @Override
  protected boolean isExecutable(
      Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request)
      throws CoreException {
    if (targets.length != 1) {
      return false;
    }

    final ITraceTargetDMContext dmc =
        DMContexts.getAncestorOfType(
            ((IDMVMContext) targets[0]).getDMContext(), ITraceTargetDMContext.class);
    if (dmc == null) {
      return false;
    }

    Query<Boolean> canSelectRecordQuery =
        new Query<Boolean>() {
          @Override
          public void execute(final DataRequestMonitor<Boolean> rm) {
            IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);

            if (traceControl != null) {
              traceControl.getTraceStatus(
                  dmc,
                  new DataRequestMonitor<ITraceStatusDMData>(fExecutor, rm) {
                    @Override
                    protected void handleSuccess() {
                      if (getData().getNumberOfCollectedFrame() > 0) {
                        IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);
                        if (traceControl != null) {
                          traceControl.isTracing(
                              dmc,
                              new DataRequestMonitor<Boolean>(fExecutor, rm) {
                                @Override
                                protected void handleSuccess() {
                                  rm.setData(!getData());
                                  rm.done();
                                };
                              });
                        } else {
                          rm.setData(false);
                          rm.done();
                        }
                      } else {
                        rm.setData(false);
                        rm.done();
                      }
                    };
                  });
            } else {
              rm.setData(false);
              rm.done();
            }
          }
        };
    try {
      fExecutor.execute(canSelectRecordQuery);
      return canSelectRecordQuery.get();
    } catch (InterruptedException e) {
    } catch (ExecutionException e) {
    } catch (RejectedExecutionException e) {
      // Can be thrown if the session is shutdown
    }

    return false;
  }