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; }
@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; }
@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(); } }); }
@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$ } }
@Override @Before public void doBeforeTest() throws Exception { deleteAllPlatformBreakpoints(); super.doBeforeTest(); Runnable runnable = new Runnable() { @Override public void run() { fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); Assert.assertTrue(fServicesTracker != null); fCommandControl = fServicesTracker.getService(IGDBControl.class); Assert.assertTrue(fCommandControl != null); // Register to breakpoint events fSession.addServiceEventListener(GDBConsoleBreakpointsTest.this, null); } }; fSession = getGDBLaunch().getSession(); fSession.getExecutor().submit(runnable).get(); IContainerDMContext containerDmc = SyncUtil.getContainerContext(); fBreakpointsDmc = DMContexts.getAncestorOfType(containerDmc, IBreakpointsTargetDMContext.class); Assert.assertTrue(fBreakpointsDmc != null); }
@Before public void init() throws Exception { fSession = getGDBLaunch().getSession(); Runnable runnable = new Runnable() { public void run() { // We obtain the services we need after the new // launch has been performed fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); ICommandControlService commandControl = fServicesTracker.getService(ICommandControlService.class); IMIProcesses procService = fServicesTracker.getService(IMIProcesses.class); IProcessDMContext procDmc = procService.createProcessContext( commandControl.getContext(), MIProcesses.UNIQUE_GROUP_ID); fContainerDmc = procService.createContainerContext(procDmc, MIProcesses.UNIQUE_GROUP_ID); fRegService = fServicesTracker.getService(IRegisters.class); fRunControl = fServicesTracker.getService(IRunControl.class); } }; fSession.getExecutor().submit(runnable).get(); }
/** @see java.lang.Process#waitFor() */ @Override public int waitFor() throws InterruptedException { if (!DsfSession.isSessionActive(getSession().getId())) { return fExitCode.get(); } try { Query<Object> query = new Query<Object>() { @Override protected void execute(final DataRequestMonitor<Object> rm) { if (!DsfSession.isSessionActive(getSession().getId()) || isDisposed() || fMIBackend.getState() == IMIBackend.State.TERMINATED) { rm.setData(new Object()); rm.done(); } else { fExitedEventListener.fWaitForRMs.add( new ImmediateRequestMonitor(rm) { @Override protected void handleSuccess() { rm.setData(new Object()); rm.done(); } }); } } }; getSession().getExecutor().execute(query); query.get(); } catch (RejectedExecutionException e) { } catch (ExecutionException e) { } return fExitCode.get(); }
/** @see java.lang.Process#exitValue() */ @Override public int exitValue() { if (!DsfSession.isSessionActive(getSession().getId())) { return fExitCode.get(); } try { getSession() .getExecutor() .submit( new Callable<Object>() { @Override public Object call() throws Exception { if (fMIBackend.getState() != IMIBackend.State.TERMINATED) { throw new IllegalThreadStateException( "Backend Process has not exited"); //$NON-NLS-1$ } return null; } }) .get(); } catch (RejectedExecutionException e) { } catch (InterruptedException e) { } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } } return fExitCode.get(); }
// This method cannot be tagged as @Before, because the launch is not // running yet. We have to call this manually after all the proper // parameters have been set for the launch @Override protected void doLaunch() throws Exception { // perform the launch super.doLaunch(); fSession = getGDBLaunch().getSession(); Runnable runnable = new Runnable() { @Override public void run() { fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); fExpService = fServicesTracker.getService(IExpressions.class); fGdbControl = fServicesTracker.getService(IGDBControl.class); } }; fSession.getExecutor().submit(runnable).get(); // Restart the program if we are testing such a case if (fRestart) { synchronized (this) { wait(1000); } fRestart = false; SyncUtil.restart(getGDBLaunch()); } }
@Override @After public void doAfterTest() throws Exception { if (fSession != null) { fSession .getExecutor() .submit(() -> fSession.removeServiceEventListener(GDBConsoleBreakpointsTest.this)) .get(); } fBreakpointEvents.clear(); if (fServicesTracker != null) { fServicesTracker.dispose(); fServicesTracker = null; } super.doAfterTest(); deleteAllPlatformBreakpoints(); }
/* * @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; }
@Override public void doBeforeTest() throws Exception { super.doBeforeTest(); final DsfSession session = getGDBLaunch().getSession(); Runnable runnable = new Runnable() { @Override public void run() { fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), session.getId()); fGDBCtrl = fServicesTracker.getService(IGDBControl.class); fRunCtrl = fServicesTracker.getService(IMIRunControl.class); } }; session.getExecutor().submit(runnable).get(); fContainerDmc = SyncUtil.getContainerContext(); }
private MIBreakpoint[] getTargetBreakpoints(int timeout, TimeUnit unit) throws Throwable { Query<MIBreakListInfo> query = new Query<MIBreakListInfo>() { @Override protected void execute(DataRequestMonitor<MIBreakListInfo> rm) { fCommandControl.queueCommand( fCommandControl.getCommandFactory().createMIBreakList(fBreakpointsDmc), rm); } }; fSession.getExecutor().execute(query); return query.get(timeout, unit).getMIBreakpoints(); }
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 init() { super.init(); fSession .getExecutor() .submit( new DsfRunnable() { @Override public void run() { fSession.addServiceEventListener(TracingConsole.this, null); } }); }
/** dispose method */ public void dispose() { // remove listener DsfSession.removeSessionEndedListener(this); // dispose of any filter if (m_filterSessionMap != null) { for (MulticoreVisualizerCanvasFilter filter : m_filterSessionMap.values()) { filter.dispose(); } m_filterSessionMap.clear(); m_filterSessionMap = null; } m_canvas = null; m_currentFilter = null; }
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; }
private void queueConsoleCommand(final String command, int timeout, TimeUnit unit) throws Throwable { Query<MIInfo> query = new Query<MIInfo>() { @Override protected void execute(DataRequestMonitor<MIInfo> rm) { fCommandControl.queueCommand( fCommandControl .getCommandFactory() .createMIInterpreterExecConsole(fCommandControl.getContext(), command), rm); } }; fSession.getExecutor().execute(query); query.get(timeout, unit); }
@ThreadSafe private synchronized IRegisters getService() { String serviceId = DsfServices.createServiceFilter(IRegisters.class, fSession.getId()); if (fServiceTracker == null) { try { fServiceTracker = new ServiceTracker( DsfUIPlugin.getBundleContext(), DsfUIPlugin.getBundleContext().createFilter(serviceId), null); fServiceTracker.open(); } catch (InvalidSyntaxException e) { return null; } } return (IRegisters) fServiceTracker.getService(); }
/** @throws java.lang.Exception */ @Override protected void setUp() throws Exception { fDsfExecutor = new DefaultDsfExecutor(); fDsfSession = DsfSession.startSession(fDsfExecutor, getClass().getName()); fDisplay = PlatformUI.getWorkbench().getDisplay(); fShell = new Shell(fDisplay /*, SWT.ON_TOP | SWT.SHELL_TRIM*/); fShell.setMaximized(true); fShell.setLayout(new FillLayout()); fViewer = createViewer(fDisplay, fShell); fModel = new TestModel(fDsfSession); initializeService(fModel); fDummyValuesService = new DummyFormattedValueService(fDsfSession); initializeService(fDummyValuesService); fViewerListener = new TestModelUpdatesListener(fViewer, true, false); fModel.setRoot(new TestElement(fModel, "root", new TestElement[0])); fModel.setElementChildren( TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "model")); fVMAdapter = new AbstractVMAdapter() { @Override protected IVMProvider createViewModelProvider(IPresentationContext context) { return fVMProvider; } }; fVMProvider = new TestModelCachingVMProvider(fVMAdapter, fViewer.getPresentationContext(), fDsfSession); fVMListener = new TestModelUpdatesListener(); fVMProvider.getNode().setVMUpdateListener(fVMListener); fVMProvider.getNode().getLabelProvider().addPropertiesUpdateListener(fViewerListener); fFormattedValuesListener = new FormattedValuesListener(fModel); fVMProvider.getNode().setFormattedValuesListener(fFormattedValuesListener); fModel.setTestModelListener(fFormattedValuesListener); fShell.open(); }
@Override @After public void doAfterTest() throws Exception { Runnable runnable = new Runnable() { @Override public void run() { fSession.removeServiceEventListener(GDBConsoleBreakpointsTest.this); } }; fSession.getExecutor().submit(runnable).get(); fBreakpointEvents.clear(); fServicesTracker.dispose(); fServicesTracker = null; super.doAfterTest(); deleteAllPlatformBreakpoints(); }
/** * *********************************************************************** * * <p>The tests for the register service. * * <p>*********************************************************************** */ @Test public void getRegisterGroups() throws Throwable { final IRegisterGroupDMContext regGroupsDMC = getRegisterGroup(); Query<IRegisterGroupDMData> query = new Query<IRegisterGroupDMData>() { @Override protected void execute(DataRequestMonitor<IRegisterGroupDMData> rm) { fRegService.getRegisterGroupData(regGroupsDMC, rm); } }; fSession.getExecutor().execute(query); IRegisterGroupDMData data = query.get(); assertTrue( "The name of the main group should be: General Registers instead of: " + data.getName(), data.getName().equals("General Registers")); }
private void setStreamInService() { try { fSession .getExecutor() .submit( new DsfRunnable() { @Override public void run() { DsfServicesTracker tracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), fSession.getId()); IGDBControl control = tracker.getService(IGDBControl.class); tracker.dispose(); if (control != null) { // Special method that need not be called on the executor control.setTracingStream(fTracingStream); } } }); } catch (RejectedExecutionException e) { } }
@Override protected void dispose() { try { fTracingStream.close(); } catch (IOException e) { } try { fSession .getExecutor() .submit( new DsfRunnable() { @Override public void run() { fSession.removeServiceEventListener(TracingConsole.this); } }); } catch (RejectedExecutionException e) { // Session already disposed } super.dispose(); }
@Test public void getRegisters() throws Throwable { MIStoppedEvent stoppedEvent = getInitialStoppedEvent(); IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); final IRegisterDMContext[] regDMCs = getRegisters(frameDmc); List<String> regNames = get_X86_REGS(); Query<IRegisterDMData[]> query = new Query<IRegisterDMData[]>() { @Override protected void execute(DataRequestMonitor<IRegisterDMData[]> rm) { final IRegisterDMData[] datas = new IRegisterDMData[regDMCs.length]; rm.setData(datas); final CountingRequestMonitor countingRm = new ImmediateCountingRequestMonitor(rm); countingRm.setDoneCount(regDMCs.length); for (int i = 0; i < regDMCs.length; i++) { final int index = i; fRegService.getRegisterData( regDMCs[index], new ImmediateDataRequestMonitor<IRegisterDMData>(countingRm) { @Override protected void handleSuccess() { datas[index] = getData(); countingRm.done(); } }); } } }; fSession.getExecutor().execute(query); IRegisterDMData[] datas = query.get(); for (IRegisterDMData data : datas) { String regName = data.getName(); Assert.assertFalse( "GDB does not support register name: " + regName, !regNames.contains(regName)); } }
/** @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(); }
@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 GdbConnectCommand(DsfSession session) { fExecutor = session.getExecutor(); fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId()); }