diff --git a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/pop.gif b/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/pop.gif deleted file mode 100644 index 559e462985f..00000000000 Binary files a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/pop.gif and /dev/null differ diff --git a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/push.gif b/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/push.gif deleted file mode 100644 index f7e6cc089c2..00000000000 Binary files a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/dlcl16/push.gif and /dev/null differ diff --git a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/pop.gif b/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/pop.gif deleted file mode 100644 index 2cd9c544436..00000000000 Binary files a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/pop.gif and /dev/null differ diff --git a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/push.gif b/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/push.gif deleted file mode 100644 index a5ac28d4c56..00000000000 Binary files a/plugins/org.eclipse.dd.examples.pda.ui/icons/full/elcl16/push.gif and /dev/null differ diff --git a/plugins/org.eclipse.dd.examples.pda.ui/plugin.xml b/plugins/org.eclipse.dd.examples.pda.ui/plugin.xml index e53b8024b6f..4247cf66b16 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/plugin.xml +++ b/plugins/org.eclipse.dd.examples.pda.ui/plugin.xml @@ -27,29 +27,6 @@ - - --> diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java index 46243cb2619..c519506f688 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java @@ -26,7 +26,7 @@ import org.eclipse.dd.dsf.debug.ui.sourcelookup.MISourceDisplayAdapter; import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.examples.pda.PDAPlugin; import org.eclipse.dd.examples.pda.launch.PDALaunch; -import org.eclipse.dd.examples.pda.ui.actions.DsfTerminateCommand; +import org.eclipse.dd.examples.pda.ui.actions.PDATerminateCommand; import org.eclipse.dd.examples.pda.ui.viewmodel.PDAVMAdapter; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; @@ -45,47 +45,62 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactor import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; /** - * This implementation of platform adapter factory only retrieves the adapters - * for the launch object. It also manages the creation and destruction - * of the session-based adapters which are returned by the - * IDMContext.getAdapter() methods. + * The adapter factory is the central point of control of view model and other + * UI adapters of a DSF-based debugger. As new launches are created and + * old ones removed, this factory manages the life cycle of the associated + * UI adapters. + *

+ * As a platform adapter factory, this factory only provides adapters for + * the launch object. Adapters for all other objects in the DSF model hierarchy + * are registered with the DSF session. + *

*/ @ThreadSafe @SuppressWarnings({"restriction"}) public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 { + /** + * Contains the set of adapters that are created for eacy launch instance. + */ @Immutable - class LaunchAdapterSet { + private static class LaunchAdapterSet { + // View Model adapter final PDAVMAdapter fViewModelAdapter; + + // Source lookup and positioning adapter final MISourceDisplayAdapter fSourceDisplayAdapter; + + // Command adapters final DsfStepIntoCommand fStepIntoCommand; final DsfStepOverCommand fStepOverCommand; final DsfStepReturnCommand fStepReturnCommand; final DsfSuspendCommand fSuspendCommand; final DsfResumeCommand fResumeCommand; - final DsfTerminateCommand fTerminateCommand; + final PDATerminateCommand fTerminateCommand; + + // Adapters for integration with other UI actions final IDebugModelProvider fDebugModelProvider; final PDALaunch fLaunch; LaunchAdapterSet(PDALaunch launch) { + // Initialize launch and session. fLaunch = launch; DsfSession session = launch.getSession(); + // Initialize VM fViewModelAdapter = new PDAVMAdapter(session); - if (launch.getSourceLocator() instanceof ISourceLookupDirector) { - fSourceDisplayAdapter = new MISourceDisplayAdapter(session, (ISourceLookupDirector)launch.getSourceLocator()); - } else { - fSourceDisplayAdapter = null; - } + // Initialize source lookup + fSourceDisplayAdapter = new MISourceDisplayAdapter(session, (ISourceLookupDirector)launch.getSourceLocator()); session.registerModelAdapter(ISourceDisplay.class, fSourceDisplayAdapter); + // Initialize retargetable command handler. fStepIntoCommand = new DsfStepIntoCommand(session); fStepOverCommand = new DsfStepOverCommand(session); fStepReturnCommand = new DsfStepReturnCommand(session); fSuspendCommand = new DsfSuspendCommand(session); fResumeCommand = new DsfResumeCommand(session); - fTerminateCommand = new DsfTerminateCommand(session); + fTerminateCommand = new PDATerminateCommand(session); session.registerModelAdapter(IStepIntoHandler.class, fStepIntoCommand); session.registerModelAdapter(IStepOverHandler.class, fStepOverCommand); session.registerModelAdapter(IStepReturnHandler.class, fStepReturnCommand); @@ -93,19 +108,17 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 session.registerModelAdapter(IResumeHandler.class, fResumeCommand); session.registerModelAdapter(ITerminateHandler.class, fTerminateCommand); + // Initialize debug model provider fDebugModelProvider = new IDebugModelProvider() { - // @see org.eclipse.debug.core.model.IDebugModelProvider#getModelIdentifiers() public String[] getModelIdentifiers() { return new String[] { PDAPlugin.ID_PDA_DEBUG_MODEL }; } }; session.registerModelAdapter(IDebugModelProvider.class, fDebugModelProvider); - /* - * Registering the launch as an adapter, ensures that this launch, - * and debug model ID will be associated with all DMContexts from this - * session. - */ + // Register the launch as an adapter This ensures that the launch, + // and debug model ID will be associated with all DMContexts from this + // session. session.registerModelAdapter(ILaunch.class, fLaunch); } @@ -139,10 +152,8 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); } - /** - * This method only actually returns adapters for the launch object. - */ - @SuppressWarnings("unchecked") + // This IAdapterFactory method returns adapters for the PDA launch object only. + @SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3 public Object getAdapter(Object adaptableObject, Class adapterType) { if (!(adaptableObject instanceof PDALaunch)) return null; @@ -167,20 +178,15 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 else return null; } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3 public Class[] getAdapterList() { return new Class[] { IElementContentProvider.class, IModelProxyFactory.class, IColumnPresentationFactory.class }; } - public void sessionEnded(DsfSession session) { - } - public void launchesRemoved(ILaunch[] launches) { // Dispose the set of adapters for a launch only after the launch is - // removed. + // removed from the view. If the launch is terminated, the adapters + // are still needed to populate the contents of the view. for (ILaunch launch : launches) { if (launch instanceof PDALaunch) { PDALaunch pdaLaunch = (PDALaunch)launch; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java index f44fc65f030..327d9a9a399 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,16 +8,13 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui; import java.net.URL; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.Map.Entry; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; @@ -32,29 +29,16 @@ import org.osgi.framework.BundleContext; * The main plugin class to be used in the desktop. */ public class PDAUIPlugin extends AbstractUIPlugin { + + public static String PLUGIN_ID = "org.eclipse.dd.examples.pda.ui "; + //The shared instance. private static PDAUIPlugin plugin; - //Resource bundle. - private ResourceBundle resourceBundle; private static BundleContext fContext; private final static String ICONS_PATH = "icons/full/";//$NON-NLS-1$ private final static String PATH_OBJECT = ICONS_PATH + "obj16/"; //Model object icons //$NON-NLS-1$ - private final static String PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"; //Enabled local toolbar icons //$NON-NLS-1$ - private final static String PATH_DLOCALTOOL = ICONS_PATH + "dlcl16/"; //Disabled local toolbar icons //$NON-NLS-1$ - - /** - * Toolbar action to pop data stack - */ - public final static String IMG_ELCL_POP = "IMG_ELCL_POP"; - public final static String IMG_DLCL_POP = "IMG_DLCL_POP"; - - /** - * Toolbar action to push onto data stack - */ - public final static String IMG_ELCL_PUSH = "IMG_ELCL_PUSH"; - public final static String IMG_DLCL_PUSH = "IMG_DLCL_PUSH"; /** * PDA program image @@ -70,7 +54,7 @@ public class PDAUIPlugin extends AbstractUIPlugin { /** * Managed colors */ - private Map fColors = new HashMap(); + private Map fColors = new HashMap(); /** * The constructor. @@ -98,12 +82,9 @@ public class PDAUIPlugin extends AbstractUIPlugin { public void stop(BundleContext context) throws Exception { super.stop(context); plugin = null; - resourceBundle = null; fContext = null; - Iterator colors = fColors.entrySet().iterator(); - while (colors.hasNext()) { - Map.Entry entry = (Entry) colors.next(); - ((Color)entry.getValue()).dispose(); + for (Map.Entry entry : fColors.entrySet()) { + entry.getValue().dispose(); } } @@ -118,43 +99,8 @@ public class PDAUIPlugin extends AbstractUIPlugin { return fContext; } - - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String key) { - ResourceBundle bundle = PDAUIPlugin.getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key) : key; - } catch (MissingResourceException e) { - return key; - } - } - - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - try { - if (resourceBundle == null) - resourceBundle = ResourceBundle.getBundle("org.eclipse.debug.examples.ui.pda.DebugUIPluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - return resourceBundle; - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry) - */ protected void initializeImageRegistry(ImageRegistry reg) { declareImage(IMG_OBJ_PDA, PATH_OBJECT + "pda.gif"); - declareImage(IMG_ELCL_POP, PATH_ELOCALTOOL + "pop.gif"); - declareImage(IMG_DLCL_POP, PATH_DLOCALTOOL + "pop.gif"); - declareImage(IMG_ELCL_PUSH, PATH_ELOCALTOOL + "push.gif"); - declareImage(IMG_DLCL_PUSH, PATH_DLOCALTOOL + "push.gif"); } /** @@ -168,7 +114,7 @@ public class PDAUIPlugin extends AbstractUIPlugin { * false if this is not a shared image */ private void declareImage(String key, String path) { - URL url = BundleUtility.find("org.eclipse.debug.examples.ui", path); + URL url = BundleUtility.find("org.eclipse.dd.examples.pda.ui", path); ImageDescriptor desc = ImageDescriptor.createFromURL(url); getImageRegistry().put(key, desc); } @@ -180,7 +126,7 @@ public class PDAUIPlugin extends AbstractUIPlugin { * @return color */ public Color getColor(RGB rgb) { - Color color = (Color) fColors.get(rgb); + Color color = fColors.get(rgb); if (color == null) { color= new Color(Display.getCurrent(), rgb); fColors.put(rgb, color); diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/DsfTerminateCommand.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/DsfTerminateCommand.java deleted file mode 100644 index 720c4ec6fc4..00000000000 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/DsfTerminateCommand.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.ui.actions; - -import org.eclipse.dd.dsf.concurrent.DsfExecutor; -import org.eclipse.dd.dsf.concurrent.DsfRunnable; -import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.datamodel.DMContexts; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; -import org.eclipse.dd.dsf.service.DsfServicesTracker; -import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.dsf.ui.viewmodel.datamodel.IDMVMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.ui.PDAUIPlugin; -import org.eclipse.debug.core.commands.IDebugCommandRequest; -import org.eclipse.debug.core.commands.IEnabledStateRequest; -import org.eclipse.debug.core.commands.ITerminateHandler; - -public class DsfTerminateCommand implements ITerminateHandler { - private final DsfExecutor fExecutor; - private final DsfServicesTracker fTracker; - - public DsfTerminateCommand(DsfSession session) { - fExecutor = session.getExecutor(); - fTracker = new DsfServicesTracker(PDAUIPlugin.getBundleContext(), session.getId()); - } - - public void dispose() { - fTracker.dispose(); - } - - // Run control may not be avilable after a connection is terminated and shut down. - public void canExecute(final IEnabledStateRequest request) { - if (request.getElements().length != 1 || - !(request.getElements()[0] instanceof IDMVMContext) ) - { - request.setEnabled(false); - request.done(); - return; - } - - // Javac doesn't like the cast to "(AbstractDMVMLayoutNode.DMVMContext)" need to use the - // construct below and suppress warnings. - IDMVMContext vmc = (IDMVMContext)request.getElements()[0]; - final IExecutionDMContext dmc = DMContexts.getAncestorOfType(vmc.getDMContext(), IExecutionDMContext.class); - if (dmc == null) { - request.setEnabled(false); - request.done(); - return; - } - - fExecutor.execute( - new DsfRunnable() { - public void run() { - // Get the processes service and the exec context. - PDACommandControl commandControl = fTracker.getService(PDACommandControl.class); - if (commandControl == null || dmc == null) { - // Context or service already invalid. - request.setEnabled(false); - request.done(); - } else { - // Check the terminate. - request.setEnabled(!commandControl.isTerminated()); - request.done(); - } - } - }); - } - - public boolean execute(final IDebugCommandRequest request) { - if (request.getElements().length != 1) { - request.done(); - return false; - } - - fExecutor.submit(new DsfRunnable() { - public void run() { - PDACommandControl commandControl = fTracker.getService(PDACommandControl.class); - if (commandControl != null) { - commandControl.shutdown(new RequestMonitor(fExecutor, null)); - } - } - }); - return false; - } - -} diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/PDATerminateCommand.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/PDATerminateCommand.java new file mode 100644 index 00000000000..cbfb60c4f75 --- /dev/null +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/actions/PDATerminateCommand.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.examples.pda.ui.actions; + +import java.util.concurrent.RejectedExecutionException; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.dd.dsf.concurrent.DsfRunnable; +import org.eclipse.dd.dsf.concurrent.ImmediateExecutor; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.datamodel.DMContexts; +import org.eclipse.dd.dsf.service.DsfServicesTracker; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.dd.examples.pda.service.PDACommandControl; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; +import org.eclipse.dd.examples.pda.ui.PDAUIPlugin; +import org.eclipse.debug.core.commands.IDebugCommandRequest; +import org.eclipse.debug.core.commands.IEnabledStateRequest; +import org.eclipse.debug.core.commands.ITerminateHandler; + +/** + * The terminate command is specialized for the PDA debugger. Currently there + * is no standard interface for terminating a debug session in DSF, because the + * details of initiating and shutting down a debug session vary greatly in + * different debuggers. + */ +public class PDATerminateCommand implements ITerminateHandler { + // The executor and the services tracker, both initialized from a DSF session. + private final DsfSession fSession; + private final DsfServicesTracker fTracker; + + public PDATerminateCommand(DsfSession session) { + fSession = session; + fTracker = new DsfServicesTracker(PDAUIPlugin.getBundleContext(), session.getId()); + } + + public void dispose() { + // DSF services tracker always has to be disposed, because the OSGi services + // use reference counting. + fTracker.dispose(); + } + + // Run control may not be available after a connection is terminated and shut down. + public void canExecute(final IEnabledStateRequest request) { + // Terminate can only operate on a single element. + if (request.getElements().length != 1 || + !(request.getElements()[0] instanceof IDMVMContext) ) + { + request.setEnabled(false); + request.done(); + return; + } + + // Find the PDA program context in the selected element. If one is not found, + // the action should be disabled. + IDMVMContext vmc = (IDMVMContext)request.getElements()[0]; + final PDAProgramDMContext pdaProgramCtx = DMContexts.getAncestorOfType(vmc.getDMContext(), PDAProgramDMContext.class); + if (pdaProgramCtx == null) { + request.setEnabled(false); + request.done(); + return; + } + + try { + fSession.getExecutor().execute( + new DsfRunnable() { + public void run() { + // Get the processes service and the exec context. + PDACommandControl commandControl = fTracker.getService(PDACommandControl.class); + if (commandControl == null || pdaProgramCtx == null) { + // Context or service already invalid. + request.setEnabled(false); + request.done(); + } else { + // Check whether the control is terminated. + request.setEnabled(!commandControl.isTerminated()); + request.done(); + } + } + }); + } catch (RejectedExecutionException e) { + // The DSF session for this context is no longer active. It's possible to check + // for this condition before calling fSession.getExecutor().execute(), but + // since this method is executing in a different thread than the session control, + // there would still be a chance for a race condition leading to this exception. + request.setEnabled(false); + request.done(); + } + } + + public boolean execute(final IDebugCommandRequest request) { + // Skip the checks and assume that this method is called only if the action + // was enabled. + + try { + fSession.getExecutor().submit(new DsfRunnable() { + public void run() { + // If the command control service is available, attempt to terminate the program. + PDACommandControl commandControl = fTracker.getService(PDACommandControl.class); + if (commandControl != null) { + + commandControl.terminate( + new RequestMonitor(ImmediateExecutor.getInstance(), null) { + @Override + protected void handleCompleted() { + request.setStatus(getStatus()); + request.done(); + } + }); + } + } + }); + } catch (RejectedExecutionException e) { + request.setStatus(new Status(IStatus.ERROR, PDAUIPlugin.PLUGIN_ID, "PDA debug session is shut down.")); + request.done(); + } + return false; + } + +} diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDABreakpointAdapter.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDABreakpointAdapter.java index 006fbe1d6aa..f23551444b4 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDABreakpointAdapter.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDABreakpointAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.breakpoints; @@ -32,6 +33,10 @@ import org.eclipse.ui.texteditor.ITextEditor; /** * Adapter to create breakpoints in PDA files. + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples.ui. + *

*/ public class PDABreakpointAdapter implements IToggleBreakpointsTargetExtension { /* (non-Javadoc) diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDAEditorAdapterFactory.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDAEditorAdapterFactory.java index 30d8c770a39..5065cadaa68 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDAEditorAdapterFactory.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDAEditorAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,25 +8,28 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.breakpoints; - import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.dd.examples.pda.ui.editor.PDAEditor; -import org.eclipse.debug.ui.actions.IRunToLineTarget; import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; import org.eclipse.ui.texteditor.ITextEditor; + /** * Creates a toggle breakpoint adapter + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples.ui. + *

*/ public class PDAEditorAdapterFactory implements IAdapterFactory { - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) - */ - public Object getAdapter(Object adaptableObject, Class adapterType) { + + @SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3 + public Object getAdapter(Object adaptableObject, Class adapterType) { if (adaptableObject instanceof PDAEditor) { ITextEditor editorPart = (ITextEditor) adaptableObject; IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); @@ -36,22 +39,14 @@ public class PDAEditorAdapterFactory implements IAdapterFactory { if (adapterType.equals(IToggleBreakpointsTarget.class)) { return new PDABreakpointAdapter(); } - //#ifdef ex7 -//# // TODO: Exercise 7 - create run to line adapter - //#else - if (adapterType.equals(IRunToLineTarget.class)) { - return new PDARunToLineAdapter(); - } - //#endif } } } return null; } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ - public Class[] getAdapterList() { + + @SuppressWarnings("unchecked") // IAdapterFactory is Java 1.3 + public Class[] getAdapterList() { return new Class[]{IToggleBreakpointsTarget.class}; } } diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDARunToLineAdapter.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDARunToLineAdapter.java deleted file mode 100644 index e73fbeeedab..00000000000 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/breakpoints/PDARunToLineAdapter.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.ui.breakpoints; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.breakpoints.PDARunToLineBreakpoint; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.ISuspendResume; -import org.eclipse.debug.ui.actions.IRunToLineTarget; -import org.eclipse.debug.ui.actions.RunToLineHandler; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.texteditor.ITextEditor; - - -/** - * Run to line target for the Java debugger - */ -public class PDARunToLineAdapter implements IRunToLineTarget { - - /* (non-Javadoc) - * @see org.eclipse.debug.ui.actions.IRunToLineTarget#runToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) - */ - public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException { - IEditorPart editorPart = (IEditorPart)part; - ITextEditor textEditor = (ITextEditor)editorPart; - ITextSelection textSelection = (ITextSelection) selection; - int lineNumber = textSelection.getStartLine() + 1; - if (lineNumber > 0) { - if (target instanceof IAdaptable) { - IDebugTarget debugTarget = (IDebugTarget) ((IAdaptable)target).getAdapter(IDebugTarget.class); - if (debugTarget != null) { - //#ifdef ex7 -//# // TODO: Exercise 7 - perform the run-to-line with a run-to-line breakpoint and handler - //#else - IFile resource = (IFile) textEditor.getEditorInput().getAdapter(IResource.class); - IBreakpoint breakpoint= new PDARunToLineBreakpoint(resource, lineNumber); - RunToLineHandler handler = new RunToLineHandler(debugTarget, target, breakpoint); - handler.run(new NullProgressMonitor()); - //#endif - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.ui.actions.IRunToLineTarget#canRunToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) - */ - public boolean canRunToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) { - //#ifdef ex7 -//# // TODO: Exercise 7 - ensure the target is a PDA target -//# return false; - //#else - return target instanceof IDebugElement && - ((IDebugElement)target).getModelIdentifier().equals(PDAPlugin.ID_PDA_DEBUG_MODEL); - //#endif - } -} diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/AnnotationHover.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/AnnotationHover.java index 0e76a9ca3f7..c06509aeac4 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/AnnotationHover.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/AnnotationHover.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; @@ -22,12 +23,16 @@ import org.eclipse.jface.text.source.ISourceViewer; /** * Returns hover for breakpoints. + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples.ui. + *

*/ public class AnnotationHover implements IAnnotationHover { public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); - Iterator iterator = annotationModel.getAnnotationIterator(); + Iterator iterator = annotationModel.getAnnotationIterator(); while (iterator.hasNext()) { Annotation annotation = (Annotation) iterator.next(); Position position = annotationModel.getPosition(annotation); diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistProcessor.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistProcessor.java index 93519ba4680..795b8dd05a0 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistProcessor.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; @@ -41,7 +42,7 @@ public class PDAContentAssistProcessor implements IContentAssistProcessor { } } - List proposals = new ArrayList(); + List proposals = new ArrayList(); String[] keywords = PDAScanner.fgKeywords; if (prefix.length() > 0) { String word = prefix.toString(); @@ -59,7 +60,7 @@ public class PDAContentAssistProcessor implements IContentAssistProcessor { } } if (!proposals.isEmpty()) { - return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); + return proposals.toArray(new ICompletionProposal[proposals.size()]); } return null; } diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistant.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistant.java index 00d991204b5..287d302127c 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistant.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAContentAssistant.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAEditor.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAEditor.java index c40a80b516c..3b8fe43d794 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAEditor.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAScanner.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAScanner.java index b1b1e067893..87a149f0c10 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAScanner.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDAScanner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDASourceViewerConfiguration.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDASourceViewerConfiguration.java index f0b873eac44..bf0185e26bd 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDASourceViewerConfiguration.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PDASourceViewerConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PopFrameActionDelegate.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PopFrameActionDelegate.java index d9250db2bb4..1b9dee198a1 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PopFrameActionDelegate.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/PopFrameActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,10 +8,10 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; -import org.eclipse.debug.core.DebugException; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Event; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/TextHover.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/TextHover.java index 5874463e207..846a45d417f 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/TextHover.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/TextHover.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,15 +8,10 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.ITextViewer; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/WordFinder.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/WordFinder.java index 12cd611be11..e369e3be8c5 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/WordFinder.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/editor/WordFinder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.editor; diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDALaunchShortcut.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDALaunchShortcut.java deleted file mode 100644 index 2e295858be8..00000000000 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDALaunchShortcut.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.ui.launcher; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.ILaunchShortcut; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorPart; - - -/** - * Launches a PDA file - */ -public class PDALaunchShortcut implements ILaunchShortcut { - - /* (non-Javadoc) - * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.jface.viewers.ISelection, java.lang.String) - */ - public void launch(ISelection selection, String mode) { - // must be a structured selection with one file selected - IFile file = (IFile) ((IStructuredSelection)selection).getFirstElement(); - - // check for an existing launch config for the pda file - String path = file.getFullPath().toString(); - ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(PDAPlugin.ID_PDA_LAUNCH_CONFIGURATION_TYPE); - try { - ILaunchConfiguration[] configurations = launchManager.getLaunchConfigurations(type); - for (int i = 0; i < configurations.length; i++) { - ILaunchConfiguration configuration = configurations[i]; - String attribute = configuration.getAttribute(PDAPlugin.ATTR_PDA_PROGRAM, (String)null); - if (path.equals(attribute)) { - DebugUITools.launch(configuration, mode); - return; - } - } - } catch (CoreException e) { - return; - } - - try { - // create a new configuration for the pda file - ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, file.getName()); - workingCopy.setAttribute(PDAPlugin.ATTR_PDA_PROGRAM, path); - ILaunchConfiguration configuration = workingCopy.doSave(); - DebugUITools.launch(configuration, mode); - } catch (CoreException e1) { - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String) - */ - public void launch(IEditorPart editor, String mode) { - } - -} diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDAMainTab.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDAMainTab.java index 2770df962da..7b9a894abd9 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDAMainTab.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDAMainTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.launcher; @@ -42,6 +43,10 @@ import org.eclipse.ui.dialogs.ResourceListSelectionDialog; /** * Tab to specify the PDA program to run/debug. + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples.ui. + *

*/ public class PDAMainTab extends AbstractLaunchConfigurationTab { diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDATabGroup.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDATabGroup.java index 5df54b6f66d..af66ec6a5d4 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDATabGroup.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/launcher/PDATabGroup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.ui.launcher; @@ -19,6 +20,10 @@ import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; /** * Tab group for a PDA application + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples.ui. + *

*/ public class PDATabGroup extends AbstractLaunchConfigurationTabGroup { /* (non-Javadoc) diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/LaunchVMProvider.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/LaunchVMProvider.java index 2990aa9d968..3cbd4c36cef 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/LaunchVMProvider.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/LaunchVMProvider.java @@ -32,7 +32,15 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationCont /** - * + * View Model provider for the Launch (AKA Debug) view. The PDA debugger is + * single-threaded, so there is no need for a debug target element to be visible + * in the debug view. Therefore the launch VM provider is configured with three nodes: + *
    + *
  • LaunchRootVMNode - This is the root of the PDA view model.
  • + *
  • ThreadVMNode - Supplies the PDA program element.
  • + *
  • StackFramesVMNode - Supplies the stack frame elements.
  • + *
  • StandardProcessVMNode - Supplies elements representing the PDA debugger process.
  • + *
*/ @SuppressWarnings("restriction") public class LaunchVMProvider extends AbstractDMVMProvider @@ -46,15 +54,17 @@ public class LaunchVMProvider extends AbstractDMVMProvider IRootVMNode launchNode = new LaunchRootVMNode(this); setRootNode(launchNode); - // Container node to contain all processes and threads - IVMNode threadsNode = new ThreadVMNode(this, getSession()); + // Launch node is a parent to the processes and program nodes. + IVMNode threadsNode = new PDAProgramVMNode(this, getSession()); IVMNode processesNode = new StandardProcessVMNode(this); addChildNodes(launchNode, new IVMNode[] { threadsNode, processesNode}); + // Stack frames node is under the PDA program node. IVMNode stackFramesNode = new StackFramesVMNode(this, getSession()); addChildNodes(threadsNode, new IVMNode[] { stackFramesNode }); - + // Register the LaunchVM provider as a listener to debug and launch + // events. These events are used by the launch and processes nodes. DebugPlugin.getDefault().addDebugEventListener(this); DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); } @@ -63,8 +73,8 @@ public class LaunchVMProvider extends AbstractDMVMProvider public void handleDebugEvents(final DebugEvent[] events) { if (isDisposed()) return; - // We're in session's executor thread. Re-dispach to VM Adapter - // executor thread and then call root layout node. + // This method may be called on any thread. Switch to the + // view model executor thread before processing. try { getExecutor().execute(new Runnable() { public void run() { @@ -75,7 +85,7 @@ public class LaunchVMProvider extends AbstractDMVMProvider } }}); } catch (RejectedExecutionException e) { - // Ignore. This exception could be thrown if the provider is being + // Ignore. This exception could be thrown if the view model is being // shut down. } } @@ -106,8 +116,8 @@ public class LaunchVMProvider extends AbstractDMVMProvider private void handleLaunchesEvent(final LaunchesEvent event) { if (isDisposed()) return; - // We're in session's executor thread. Re-dispach to VM Adapter - // executor thread and then call root layout node. + // This method also may be called on any thread. Switch to the + // view model executor thread before processing. try { getExecutor().execute(new Runnable() { public void run() { @@ -119,7 +129,7 @@ public class LaunchVMProvider extends AbstractDMVMProvider } }}); } catch (RejectedExecutionException e) { - // Ignore. This exception could be thrown if the provider is being + // Ignore. This exception could be thrown if the view model is being // shut down. } } diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/ThreadVMNode.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/PDAProgramVMNode.java similarity index 53% rename from plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/ThreadVMNode.java rename to plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/PDAProgramVMNode.java index a044c1e09a6..16b27393312 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/ThreadVMNode.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/viewmodel/launch/PDAProgramVMNode.java @@ -17,12 +17,10 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; import org.eclipse.dd.dsf.concurrent.DsfRunnable; +import org.eclipse.dd.dsf.concurrent.ImmediateExecutor; import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.datamodel.IDMContext; import org.eclipse.dd.dsf.datamodel.IDMEvent; import org.eclipse.dd.dsf.debug.service.IRunControl; -import org.eclipse.dd.dsf.debug.service.IRunControl.IContainerResumedDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.IContainerSuspendedDMEvent; import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMData; import org.eclipse.dd.dsf.debug.service.IRunControl.IResumedDMEvent; @@ -36,8 +34,9 @@ import org.eclipse.dd.dsf.ui.viewmodel.datamodel.AbstractDMVMNode; import org.eclipse.dd.dsf.ui.viewmodel.datamodel.AbstractDMVMProvider; import org.eclipse.dd.examples.pda.PDAPlugin; import org.eclipse.dd.examples.pda.launch.PDALaunch; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.PDAStartedEvent; +import org.eclipse.dd.examples.pda.service.PDACommandControl; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; +import org.eclipse.dd.examples.pda.service.PDAStartedEvent; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; @@ -50,20 +49,32 @@ import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.viewers.TreePath; - +/** + * View Model node representing a PDA program. + */ @SuppressWarnings("restriction") -public class ThreadVMNode extends AbstractDMVMNode +public class PDAProgramVMNode extends AbstractDMVMNode implements IElementLabelProvider { - private class TerminatedThreadVMContext extends AbstractVMContext { - TerminatedThreadVMContext(IVMAdapter adapter, IVMNode node) { + // View model context representing a terminated PDA program. + // It's purpose is to show a terminated program in the debug view + // even after the DSF session is terminated. + // + // Note: this context does not implement the IDMVMContext + // interfaces, as it does not use an IDMContext as its root. + // + // To implement comparison methods, this contexts uses the + // VM node object, such that two terminated program contexts + // from the same instance of VM node will be equal. + private static class TerminatedProgramVMContext extends AbstractVMContext { + TerminatedProgramVMContext(IVMAdapter adapter, IVMNode node) { super(adapter, node); } @Override public boolean equals(Object obj) { - if (obj instanceof TerminatedThreadVMContext) { - TerminatedThreadVMContext context = (TerminatedThreadVMContext)obj; + if (obj instanceof TerminatedProgramVMContext) { + TerminatedProgramVMContext context = (TerminatedProgramVMContext)obj; return getVMNode().equals(context.getVMNode()); } return false; @@ -75,14 +86,17 @@ public class ThreadVMNode extends AbstractDMVMNode } } - public ThreadVMNode(AbstractDMVMProvider provider, DsfSession session) { + public PDAProgramVMNode(AbstractDMVMProvider provider, DsfSession session) { super(provider, session, IExecutionDMContext.class); } @Override public void update(IHasChildrenUpdate[] updates) { for (IHasChildrenUpdate update : updates) { - update.setHasChilren(true); + // Check if the launch is initialized. PDA program element should + // be shown only if the launch has completed initializing. + PDALaunch launch = findLaunchInPath(update.getElementPath()); + update.setHasChilren(launch != null && launch.isInitialized()); update.done(); } } @@ -90,7 +104,14 @@ public class ThreadVMNode extends AbstractDMVMNode @Override public void update(IChildrenCountUpdate[] updates) { for (IChildrenCountUpdate update : updates) { - update.setChildCount(1); + // Check if the launch is initialized. PDA program element should + // be shown only if the launch has completed initializing. + PDALaunch launch = findLaunchInPath(update.getElementPath()); + if (launch != null && launch.isInitialized()) { + update.setChildCount(1); + } else { + update.setChildCount(0); + } update.done(); } } @@ -100,10 +121,9 @@ public class ThreadVMNode extends AbstractDMVMNode for (IChildrenUpdate update : updates) { PDALaunch launch = findLaunchInPath(update.getElementPath()); if (launch != null && launch.isInitialized() && launch.isShutDown()) { - // If the debug session has been shut down. We cannot retrieve the - // DM context representing the thread. Instead add a dummy - // "terminated" PDA thread. - update.setChild(new TerminatedThreadVMContext(getVMProvider().getVMAdapter(), this), 0); + // If the debug session has been shut down, add a dummy + // VM context representing the PDA thread. + update.setChild(new TerminatedProgramVMContext(getVMProvider().getVMAdapter(), this), 0); update.done(); } else { super.update(new IChildrenUpdate[] { update }); @@ -113,24 +133,36 @@ public class ThreadVMNode extends AbstractDMVMNode @Override protected void updateElementsInSessionThread(final IChildrenUpdate update) { + // Check if service is still available. checkService() is a convenience + // method that marks the update as failed if the needed service is not + // available. if (!checkService(PDACommandControl.class, null, update)) return; + + // Get the instance of the service. Note that there is no race condition + // in getting the service since this method is called only in the + // service executor thred. final PDACommandControl commandControl = getServicesTracker().getService(PDACommandControl.class); - update.setChild(createVMContext(commandControl.getDMContext()), 0); + update.setChild(createVMContext(commandControl.getProgramDMContext()), 0); update.done(); } public void update(final ILabelUpdate[] updates) { for (final ILabelUpdate update : updates) { - if (update.getElement() instanceof TerminatedThreadVMContext) { + if (update.getElement() instanceof TerminatedProgramVMContext) { + // If the element is a terminated program, update the label + // in the View Model thread. updateTerminatedThreadLabel(update); } else { + // If the element is the PDA Program context, try to switch + // to the DSF session thread before updating the label. try { getSession().getExecutor().execute(new DsfRunnable() { public void run() { - updateActiveThreadLabelInSessionThread(update); + updateProgramLabelInSessionThread(update); }}); } catch (RejectedExecutionException e) { + // Acceptable race condition: DSF session terminated. handleFailedUpdate(update); } } @@ -138,53 +170,62 @@ public class ThreadVMNode extends AbstractDMVMNode } @ConfinedToDsfExecutor("getSession().getExecutor()") - private void updateActiveThreadLabelInSessionThread(final ILabelUpdate update) { + private void updateProgramLabelInSessionThread(final ILabelUpdate update) { + // Get a reference to the run control service. if (!checkService(IRunControl.class, null, update)) return; final IRunControl runControl = getServicesTracker().getService(IRunControl.class); - final IExecutionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExecutionDMContext.class); + // Find the PDA program context. + final PDAProgramDMContext programCtx = + findDmcInPath(update.getViewerInput(), update.getElementPath(), PDAProgramDMContext.class); + // Call service to get current program state + final boolean isSuspended = runControl.isSuspended(programCtx); + + // Set the program icon based on the running state of the program. String imageKey = null; - if (getServicesTracker().getService(IRunControl.class).isSuspended(dmc)) { + if (isSuspended) { imageKey = IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED; } else { imageKey = IDebugUIConstants.IMG_OBJS_THREAD_RUNNING; } update.setImageDescriptor(DebugUITools.getImageDescriptor(imageKey), 0); - final boolean isSuspended = runControl.isSuspended(dmc); - - // Find the Reason for the State - runControl.getExecutionData(dmc, - new DataRequestMonitor(getSession().getExecutor(), null) { - @Override - public void handleCompleted(){ - if (!getStatus().isOK()) { - handleFailedUpdate(update); - return; + // Retrieve the last state chagne reason + runControl.getExecutionData( + programCtx, + new DataRequestMonitor(ImmediateExecutor.getInstance(), null) + { + @Override + public void handleCompleted(){ + // If the request failed, fail the udpate. + if (!getStatus().isOK()) { + handleFailedUpdate(update); + return; + } + + // Compose the thread name string. + final StringBuilder builder = new StringBuilder(); + + builder.append("PDA ["); + builder.append(programCtx.getProgram()); + builder.append("]"); + + if(isSuspended) { + builder.append(" (Suspended"); + } else { + builder.append(" (Running"); + } + // Reason will be null before ContainerSuspendEvent is fired + if(getData().getStateChangeReason() != null) { + builder.append(" : "); + builder.append(getData().getStateChangeReason()); + } + builder.append(")"); + update.setLabel(builder.toString(), 0); + update.done(); } - - final StringBuilder builder = new StringBuilder(); - - builder.append("PDA ["); - builder.append(getProgramName(update)); - builder.append("]"); - - if(isSuspended) { - builder.append(" (Suspended"); - } else { - builder.append(" (Running"); - } - // Reason will be null before ContainerSuspendEvent is fired - if(getData().getStateChangeReason() != null) { - builder.append(" : "); - builder.append(getData().getStateChangeReason()); - } - builder.append(")"); - update.setLabel(builder.toString(), 0); - update.done(); - } - }); + }); } private void updateTerminatedThreadLabel(ILabelUpdate update) { @@ -194,6 +235,7 @@ public class ThreadVMNode extends AbstractDMVMNode } private String getProgramName(IViewerUpdate update) { + // Retrieve the program name from the launch object in the update path. String program = "unknown program"; ILaunch launch = findLaunchInPath(update.getElementPath()); if (launch != null) { @@ -214,33 +256,29 @@ public class ThreadVMNode extends AbstractDMVMNode } return null; } - + public int getDeltaFlags(Object e) { if(e instanceof IResumedDMEvent || e instanceof ISuspendedDMEvent) { - return IModelDelta.CONTENT; + return IModelDelta.STATE; } if (e instanceof PDAStartedEvent) { - return IModelDelta.EXPAND; + return IModelDelta.EXPAND | IModelDelta.SELECT; } return IModelDelta.NO_CHANGE; } public void buildDelta(Object e, VMDelta parentDelta, int nodeOffset, RequestMonitor rm) { - if(e instanceof IContainerResumedDMEvent) { - IDMContext triggeringContext = ((IContainerResumedDMEvent)e).getTriggeringContext(); - if (triggeringContext != null) { - parentDelta.addNode(createVMContext(triggeringContext), IModelDelta.CONTENT); - } - } else if (e instanceof IContainerSuspendedDMEvent) { - IDMContext triggeringContext = ((IContainerSuspendedDMEvent)e).getTriggeringContext(); - if (triggeringContext != null) { - parentDelta.addNode(createVMContext(triggeringContext), IModelDelta.CONTENT); - } - } else if(e instanceof IResumedDMEvent || e instanceof ISuspendedDMEvent) { - parentDelta.addNode(createVMContext(((IDMEvent)e).getDMContext()), IModelDelta.CONTENT); + if(e instanceof IResumedDMEvent || e instanceof ISuspendedDMEvent) { + // If a suspended/resumed event is received, just update the + // state of the program. StackFramesVMNode will take care of + // refreshing the stack frames. + parentDelta.addNode(createVMContext(((IDMEvent)e).getDMContext()), IModelDelta.STATE); } if (e instanceof PDAStartedEvent) { - parentDelta.addNode(createVMContext(((PDAStartedEvent)e).getDMContext()), IModelDelta.EXPAND); + // When debug session is started expand and select the program. + // If the program hits a breakpoint, the top stack frame will then + // be selected. + parentDelta.addNode(createVMContext(((PDAStartedEvent)e).getDMContext()), IModelDelta.EXPAND | IModelDelta.SELECT); } rm.done(); } diff --git a/plugins/org.eclipse.dd.examples.pda/META-INF/MANIFEST.MF b/plugins/org.eclipse.dd.examples.pda/META-INF/MANIFEST.MF index b3991100053..acf1d2ccb0e 100644 --- a/plugins/org.eclipse.dd.examples.pda/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.dd.examples.pda/META-INF/MANIFEST.MF @@ -12,10 +12,11 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.dd.dsf.debug;bundle-version="1.0.0", org.junit4;bundle-version="4.3.1", org.eclipse.cdt.core;bundle-version="5.0.0" -Eclipse-LazyStart: true +Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.dd.examples.pda, org.eclipse.dd.examples.pda.breakpoints, org.eclipse.dd.examples.pda.launch, - org.eclipse.dd.examples.pda.service.command, - org.eclipse.debug.examples.core.pda.sourcelookup + org.eclipse.dd.examples.pda.service, + org.eclipse.dd.examples.pda.service.commands, + org.eclipse.dd.examples.pda.sourcelookup Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/plugins/org.eclipse.dd.examples.pda/pdavm/docs/protocol.html b/plugins/org.eclipse.dd.examples.pda/pdavm/docs/protocol.html index 8717a8dbf61..9e2b92749f4 100644 --- a/plugins/org.eclipse.dd.examples.pda/pdavm/docs/protocol.html +++ b/plugins/org.eclipse.dd.examples.pda/pdavm/docs/protocol.html @@ -121,7 +121,7 @@ Sets a data value in the data stack at the given location Sets a variable value
-   C: setvar {variable} {value}
+   C: setvar {frame_number} {variable} {value}
    R: ok
 
diff --git a/plugins/org.eclipse.dd.examples.pda/plugin.xml b/plugins/org.eclipse.dd.examples.pda/plugin.xml index 053f2625f91..1841f1cb7fc 100644 --- a/plugins/org.eclipse.dd.examples.pda/plugin.xml +++ b/plugins/org.eclipse.dd.examples.pda/plugin.xml @@ -21,14 +21,14 @@ perlExecutable). */ public static final String VARIALBE_PERL_EXECUTABLE = "dsfPerlExecutable"; + /** * Launch configuration attribute key. Value is a path to a perl * program. The path is a string representing a full path diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDALineBreakpoint.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDALineBreakpoint.java index bc518e16fe0..3913c517bb3 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDALineBreakpoint.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDALineBreakpoint.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.breakpoints; @@ -23,6 +24,10 @@ import org.eclipse.debug.core.model.LineBreakpoint; /** * PDA line breakpoint + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples. + *

*/ public class PDALineBreakpoint extends LineBreakpoint { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDARunToLineBreakpoint.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDARunToLineBreakpoint.java deleted file mode 100644 index eda5308d957..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDARunToLineBreakpoint.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.breakpoints; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IBreakpoint; - -/** - * A run to line breakpoint. - */ -public class PDARunToLineBreakpoint extends PDALineBreakpoint { - - private IFile fSourceFile; - - /** - * Constructs a run-to-line breakpoint in the given PDA program. - * - * @param resource PDA source file - * @param lineNumber line to run to - * @exception DebugException if unable to create the breakpoint - */ - public PDARunToLineBreakpoint(final IFile resource, final int lineNumber) throws DebugException { - IWorkspaceRunnable runnable = new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - // associate with workspace root to avoid drawing in editor ruler - IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker("org.eclipse.debug.examples.core.pda.markerType.lineBreakpoint"); - setMarker(marker); - marker.setAttribute(IBreakpoint.ENABLED, Boolean.TRUE); - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - marker.setAttribute(IBreakpoint.ID, getModelIdentifier()); - setRegistered(false); - fSourceFile = resource; - } - }; - run(getMarkerRule(resource), runnable); - } - - /** - * Returns whether this breakpoint is a run-to-line breakpoint - * - * @return whether this breakpoint is a run-to-line breakpoint - */ - public boolean isRunToLineBreakpoint() { - return true; - } - - /** - * Returns the source file this breakpoint is contained in. - * - * @return the source file this breakpoint is contained in - */ - public IFile getSourceFile() { - return fSourceFile; - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDAWatchpoint.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDAWatchpoint.java index ac3e9bcc80a..6a9b1353371 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDAWatchpoint.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/breakpoints/PDAWatchpoint.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.breakpoints; @@ -22,6 +23,10 @@ import org.eclipse.debug.core.model.IWatchpoint; /** * A watchpoint. + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples. + *

*/ public class PDAWatchpoint extends PDALineBreakpoint implements IWatchpoint { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunch.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunch.java index 587d8c993fc..6341c937efe 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunch.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunch.java @@ -15,16 +15,14 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.dd.dsf.concurrent.DefaultDsfExecutor; -import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.ImmediateExecutor; import org.eclipse.dd.dsf.concurrent.RequestMonitor; import org.eclipse.dd.dsf.concurrent.Sequence; import org.eclipse.dd.dsf.concurrent.ThreadSafe; import org.eclipse.dd.dsf.service.DsfServiceEventHandler; -import org.eclipse.dd.dsf.service.DsfServicesTracker; import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.command.PDATerminatedEvent; +import org.eclipse.dd.examples.pda.service.PDATerminatedEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.Launch; @@ -32,23 +30,38 @@ import org.eclipse.debug.core.model.ISourceLocator; import org.eclipse.debug.core.model.ITerminate; /** - * A DSF-based debugger has to override the base launch class in order to - * supply its own content providers for the debug view. + * The PDA launch object. In general, a DSF-based debugger has to override + * the base launch class in order to supply its own content providers for the + * debug view. Additionally, the PDA launch is used to monitor the state of the + * PDA debugger and to shutdown the DSF services and session belonging to the + * launch. + *

+ * The PDA launch class mostly contains methods and fields that can be accessed + * on any thread. However, some fields and methods used for managing the DSF + * session need to be synchronized using the DSF executor. + *

*/ @ThreadSafe public class PDALaunch extends Launch implements ITerminate -{ +{ + // DSF executor and session. Both are created and shutdown by the launch. private final DefaultDsfExecutor fExecutor; private final DsfSession fSession; - - @ConfinedToDsfExecutor("getSession().getExecutor()") - private DsfServicesTracker fTracker; - + + // Objects used to track the status of the DSF session. private Sequence fInitializationSequence = null; private boolean fInitialized = false; private boolean fShutDown = false; + /** + * Launch constructor creates the launch for given parameters. The + * constructor also creates a DSF session and an executor, so that + * {@link #getSession()} returns a valid value, however no services + * are initialized yet. + * + * @see Launch + */ public PDALaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator) { super(launchConfiguration, mode, locator); @@ -60,34 +73,68 @@ public class PDALaunch extends Launch fSession = DsfSession.startSession(fExecutor, PDAPlugin.ID_PDA_DEBUG_MODEL); } - public DsfExecutor getDsfExecutor() { return fExecutor; } - + /** + * Returns the DSF services session that belongs to this launch. This + * method will always return a DsfSession object, however if the debugger + * is shut down, the session will no longer active. + */ public DsfSession getSession() { return fSession; } + /** + * Initializes the DSF services using the specified parameters. This + * method has to be called on the executor thread in order to avoid + * synchronization issues. + */ @ConfinedToDsfExecutor("getSession().getExecutor()") public void initializeServices(String program, int requestPort, int eventPort, final RequestMonitor rm) { - fTracker = new DsfServicesTracker(PDAPlugin.getBundleContext(), fSession.getId()); + // Double-check that we're being called in the correct thread. + assert fExecutor.isInExecutorThread(); + + // Check if shutdownServices() was called already, which would be + // highly unusual, but if so we don't need to do anything except set + // the initialized flag. + synchronized(this) { + if (fShutDown) { + fInitialized = true; + return; + } + } + + // Register the launch as listener for services events. fSession.addServiceEventListener(PDALaunch.this, null); + // Initialize the fInitializationSequence attribute in a synchronized + // block, because it may be accessed in another thread by shutdown(). + // The initialization sequence is stored in a field to allow it to be + // canceled if shutdownServices() is called before the sequence + // completes. synchronized(this) { fInitializationSequence = new PDAServicesInitSequence( - getSession(), this, program, requestPort, eventPort, + getSession(), program, requestPort, eventPort, new RequestMonitor(ImmediateExecutor.getInstance(), rm) { @Override protected void handleCompleted() { + // Set the initialized flag and check whether the + // shutdown flag is set. Access the flags in a + // synchronized section as these flags can be accessed + // on any thread. boolean doShutdown = false; - synchronized (this) - { + synchronized (this) { fInitialized = true; fInitializationSequence = null; if (fShutDown) { doShutdown = true; } } + if (doShutdown) { + // If shutdownServices() was already called, start the + // shutdown sequence now. doShutdown(rm); } else { + // If there was an error in the startup sequence, + // report the error to the client. if (getStatus().getSeverity() == IStatus.ERROR) { rm.setStatus(getStatus()); } @@ -97,18 +144,30 @@ public class PDALaunch extends Launch } }); } + + // Finally, execute the sequence. getSession().getExecutor().execute(fInitializationSequence); } + /** + * Event handler for a debugger terminated event. + */ @DsfServiceEventHandler public void eventDispatched(PDATerminatedEvent event) { shutdownServices(new RequestMonitor(ImmediateExecutor.getInstance(), null)); } + /** + * Returns whether the DSF service initialization sequence has completed yet. + */ public synchronized boolean isInitialized() { return fInitialized; } + /** + * Returns whether the DSF services have been set to shut down. + * @return + */ public synchronized boolean isShutDown() { return fShutDown; } @@ -144,9 +203,13 @@ public class PDALaunch extends Launch */ @ConfinedToDsfExecutor("getSession().getExecutor()") public void shutdownServices(final RequestMonitor rm) { + // Check initialize and shutdown flags to determine if the shutdown + // sequence can be called yet. boolean doShutdown = false; synchronized (this) { if (!fInitialized && fInitializationSequence != null) { + // Launch has not yet initialized, try to cancel the + // shutdown sequence. fInitializationSequence.cancel(false); } else { doShutdown = !fShutDown && fInitialized; @@ -164,7 +227,7 @@ public class PDALaunch extends Launch @ConfinedToDsfExecutor("getSession().getExecutor()") private void doShutdown(final RequestMonitor rm) { fExecutor.execute( new PDAServicesShutdownSequence( - getDsfExecutor(), fSession.getId(), + fExecutor, fSession.getId(), new RequestMonitor(fSession.getExecutor(), rm) { @Override public void handleCompleted() { @@ -174,8 +237,6 @@ public class PDALaunch extends Launch PDAPlugin.PLUGIN_ID, -1, new IStatus[]{getStatus()}, "Session shutdown failed", null)); //$NON-NLS-1$ } // Last order of business, shutdown the dispatch queue. - fTracker.dispose(); - fTracker = null; DsfSession.endSession(fSession); // endSession takes a full dispatch to distribute the // session-ended event, finish step only after the dispatch. diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunchDelegate.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunchDelegate.java index 0f203cf26d4..9aa119d29bd 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunchDelegate.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDALaunchDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ package org.eclipse.dd.examples.pda.launch; @@ -42,7 +43,7 @@ import org.eclipse.debug.core.sourcelookup.IPersistableSourceLocator2; /** - * Launches PDA program on a PDA interpretter written in Perl + * Launches PDA program on a PDA interpretter written in Perl */ public class PDALaunchDelegate extends LaunchConfigurationDelegate { @@ -59,9 +60,13 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { @Override public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + // PDA programs do not require building. return false; } + /** + * Returns a source locator created based on the attributes in the launch configuration. + */ private ISourceLocator getSourceLocator(ILaunchConfiguration configuration) throws CoreException { String type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null); if (type == null) { @@ -83,12 +88,7 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { return null; } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor) - */ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { - String program = configuration.getAttribute(PDAPlugin.ATTR_PDA_PROGRAM, (String)null); if (program == null) { abort("Perl program unspecified.", null); @@ -104,11 +104,21 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { PDALaunch pdaLaunch = (PDALaunch)launch; initServices(pdaLaunch, program, requestPort, eventPort); } - + + /** + * Launches PDA interpreter with the given program. + * + * @param launch Launch that will contain the new process. + * @param program PDA program to use in the interpreter. + * @param requestPort The port number for connecting the request socket. + * @param eventPort The port number for connecting the events socket. + * + * @throws CoreException + */ private void launchProcess(ILaunch launch, String program, int requestPort, int eventPort) throws CoreException { List commandList = new ArrayList(); - // Perl executable + // Find Perl executable IValueVariable perl = VariablesPlugin.getDefault().getStringVariableManager().getValueVariable(PDAPlugin.VARIALBE_PERL_EXECUTABLE); if (perl == null) { abort("Perl executable location undefined. Check value of ${dsfPerlExecutable}.", null); @@ -130,6 +140,7 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { } commandList.add(vm.getAbsolutePath()); + // Add PDA program IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(program)); if (!file.exists()) { abort(MessageFormat.format("Perl program {0} does not exist.", new Object[] {file.getFullPath().toString()}), null); @@ -137,19 +148,26 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { commandList.add(file.getLocation().toOSString()); - // add debug arguments - i.e. '-debug requestPort eventPort' + // Add debug arguments - i.e. '-debug requestPort eventPort' commandList.add("-debug"); commandList.add("" + requestPort); commandList.add("" + eventPort); + // Launch the perl process. String[] commandLine = commandList.toArray(new String[commandList.size()]); Process process = DebugPlugin.exec(commandLine, null); + + // Create a debug platform process object and add it to the launch. DebugPlugin.newProcess(launch, process, path); } + /** + * Calls the launch to initialize DSF services for this launch. + */ private void initServices(final PDALaunch pdaLaunch, final String program, final int requestPort, final int eventPort) throws CoreException { + // Synchronization object to use when waiting for the services initialization. Query initQuery = new Query() { @Override protected void execute(DataRequestMonitor rm) { @@ -157,8 +175,10 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { } }; + // Submit the query to the executor. pdaLaunch.getSession().getExecutor().execute(initQuery); try { + // Block waiting for query results. initQuery.get(); } catch (InterruptedException e1) { throw new DebugException(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, DebugException.INTERNAL_ERROR, "Interrupted Exception in dispatch thread", e1)); //$NON-NLS-1$ @@ -181,8 +201,6 @@ public class PDALaunchDelegate extends LaunchConfigurationDelegate { /** * Returns a free port number on localhost, or -1 if unable to find a free port. - * - * @return a free port number on localhost, or -1 if unable to find a free port */ public static int findFreePort() { ServerSocket socket= null; diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesInitSequence.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesInitSequence.java index 38b17950fd7..a92a61fc79d 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesInitSequence.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesInitSequence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. + * Copyright (c) 2008 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,29 +15,46 @@ import org.eclipse.dd.dsf.concurrent.Sequence; import org.eclipse.dd.dsf.debug.service.BreakpointsMediator; import org.eclipse.dd.dsf.debug.service.StepQueueManager; import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.examples.pda.service.breakpoints.PDABreakpointAttributeTranslator; -import org.eclipse.dd.examples.pda.service.breakpoints.PDABreakpoints; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.expressions.PDAExpressions; -import org.eclipse.dd.examples.pda.service.runcontrol.PDARunControl; -import org.eclipse.dd.examples.pda.service.stack.PDAStack; -import org.eclipse.debug.examples.core.pda.sourcelookup.PDASourceLookupDirector; +import org.eclipse.dd.examples.pda.service.PDABreakpointAttributeTranslator; +import org.eclipse.dd.examples.pda.service.PDABreakpoints; +import org.eclipse.dd.examples.pda.service.PDACommandControl; +import org.eclipse.dd.examples.pda.service.PDAExpressions; +import org.eclipse.dd.examples.pda.service.PDARunControl; +import org.eclipse.dd.examples.pda.service.PDAStack; +/** + * The initialization sequence for PDA debugger services. This sequence contains + * the series of steps that are executed to properly initialize the PDA-DSF debug + * session. If any of the individual steps fail, the initialization will abort. + *

+ * The order in which services are initialized is important. Some services depend + * on other services and they assume that they will be initialized only if those + * services are active. Also the service events are prioritized and their priority + * depends on the order in which the services were initialized. + *

+ */ public class PDAServicesInitSequence extends Sequence { Step[] fSteps = new Step[] { - // Create and initialize the Connection service. - new Step() { + new Step() + { @Override public void execute(RequestMonitor requestMonitor) { - // Create the connection. - fCommandControl = new PDACommandControl(fSession, fRequestPort, fEventPort); + // Create the connection to PDA debugger. + fCommandControl = new PDACommandControl(fSession, fProgram, fRequestPort, fEventPort); fCommandControl.initialize(requestMonitor); } + + @Override + public void rollBack(RequestMonitor rm) { + // TODO Auto-generated method stub + super.rollBack(rm); + } }, new Step() { @Override public void execute(RequestMonitor requestMonitor) { + // Start the run control service. fRunControl = new PDARunControl(fSession); fRunControl.initialize(requestMonitor); } @@ -45,62 +62,65 @@ public class PDAServicesInitSequence extends Sequence { new Step() { @Override public void execute(RequestMonitor requestMonitor) { + // Start the service to manage step actions. new StepQueueManager(fSession).initialize(requestMonitor); } }, new Step() { @Override public void execute(final RequestMonitor requestMonitor) { - // Create the low-level breakpoint service - new PDABreakpoints(fSession, fProgram).initialize(new RequestMonitor(getExecutor(), requestMonitor)); + // Start the low-level breakpoint service + new PDABreakpoints(fSession).initialize(new RequestMonitor(getExecutor(), requestMonitor)); } }, new Step() { @Override public void execute(final RequestMonitor requestMonitor) { + // Create the breakpoint mediator and start tracking PDA breakpoints. + final BreakpointsMediator bpmService = new BreakpointsMediator( fSession, new PDABreakpointAttributeTranslator()); bpmService.initialize(new RequestMonitor(getExecutor(), requestMonitor) { @Override protected void handleOK() { - bpmService.startTrackingBreakpoints(fCommandControl.getDMContext(), requestMonitor); + bpmService.startTrackingBreakpoints(fCommandControl.getProgramDMContext(), requestMonitor); } }); } }, new Step() { @Override public void execute(RequestMonitor requestMonitor) { + // Start the stack service. new PDAStack(fSession).initialize(requestMonitor); } }, new Step() { @Override public void execute(RequestMonitor requestMonitor) { + // Start the service to track expressions. new PDAExpressions(fSession).initialize(requestMonitor); } }, new Step() { @Override public void execute(RequestMonitor requestMonitor) { - fRunControl.resume(fCommandControl.getDMContext(), requestMonitor); + fRunControl.resume(fCommandControl.getProgramDMContext(), requestMonitor); } }, }; + // Sequence input parameters, used in initializing services. private DsfSession fSession; - private PDALaunch fLaunch; private String fProgram; private int fRequestPort; private int fEventPort; - PDACommandControl fCommandControl; - PDARunControl fRunControl; - PDASourceLookupDirector fSourceLookup; + // Service references, initialized when created and used in initializing other services. + private PDACommandControl fCommandControl; + private PDARunControl fRunControl; - public PDAServicesInitSequence(DsfSession session, PDALaunch launch, String program, int requestPort, - int eventPort, RequestMonitor rm) + public PDAServicesInitSequence(DsfSession session, String program, int requestPort, int eventPort, RequestMonitor rm) { super(session.getExecutor(), rm); fSession = session; - fLaunch = launch; fProgram = program; fRequestPort = requestPort; fEventPort = eventPort; diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesShutdownSequence.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesShutdownSequence.java index 583c11b3908..7404dbad668 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesShutdownSequence.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/launch/PDAServicesShutdownSequence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. + * Copyright (c) 2008 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,17 +20,95 @@ import org.eclipse.dd.dsf.debug.service.StepQueueManager; import org.eclipse.dd.dsf.service.DsfServicesTracker; import org.eclipse.dd.dsf.service.IDsfService; import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.breakpoints.PDABreakpoints; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.expressions.PDAExpressions; -import org.eclipse.dd.examples.pda.service.runcontrol.PDARunControl; -import org.eclipse.dd.examples.pda.service.stack.PDAStack; +import org.eclipse.dd.examples.pda.service.PDABreakpoints; +import org.eclipse.dd.examples.pda.service.PDACommandControl; +import org.eclipse.dd.examples.pda.service.PDAExpressions; +import org.eclipse.dd.examples.pda.service.PDARunControl; +import org.eclipse.dd.examples.pda.service.PDAStack; +/** + * The shutdown sequence for PDA debugger services. This sequence contains + * the series of steps that are executed to properly shutdown the PDA-DSF debug + * session. If any of the individual steps fail, the shutdown will abort. + *

+ * Services are shut down in the reverse order of initialization. + *

+ */ public class PDAServicesShutdownSequence extends Sequence { + + private final Step[] fSteps = new Step[] { + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + // Initialize services tracker. + assert PDAPlugin.getBundleContext() != null; + fTracker = new DsfServicesTracker(PDAPlugin.getBundleContext(), fSessionId); + requestMonitor.done(); + } + + @Override + public void rollBack(RequestMonitor requestMonitor) { + // In case the shutdown sequence aborts, ensure that the + // tracker is properly disposed. + fTracker.dispose(); + fTracker = null; + requestMonitor.done(); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(PDAExpressions.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(PDAStack.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(BreakpointsMediator.class, requestMonitor); + } + }, new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(PDABreakpoints.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(StepQueueManager.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(PDARunControl.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + shutdownService(PDACommandControl.class, requestMonitor); + } + }, + new Step() { + @Override + public void execute(RequestMonitor requestMonitor) { + fTracker.dispose(); + fTracker = null; + requestMonitor.done(); + } + } + }; - String fSessionId; - DsfServicesTracker fTracker; - + private String fSessionId; + private DsfServicesTracker fTracker; + public PDAServicesShutdownSequence(DsfExecutor executor, String sessionId, RequestMonitor requestMonitor) { super(executor, requestMonitor); fSessionId = sessionId; @@ -41,92 +119,6 @@ public class PDAServicesShutdownSequence extends Sequence { return fSteps; } - private final Step[] fSteps = new Step[] { new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - assert PDAPlugin.getBundleContext() != null; - fTracker = new DsfServicesTracker(PDAPlugin.getBundleContext(), fSessionId); - requestMonitor.done(); - } - - @Override - public void rollBack(RequestMonitor requestMonitor) { - fTracker.dispose(); - fTracker = null; - requestMonitor.done(); - } - }, -/* new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(MIRegisters.class, requestMonitor); - } - }, new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(MIBreakpointsManager.class, requestMonitor); - } - }, new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(MIBreakpoints.class, requestMonitor); - } - }, new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(CSourceLookup.class, requestMonitor); - } - },*/ - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(PDAExpressions.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(PDAStack.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(BreakpointsMediator.class, requestMonitor); - } - }, new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(PDABreakpoints.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(StepQueueManager.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(PDARunControl.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - shutdownService(PDACommandControl.class, requestMonitor); - } - }, - new Step() { - @Override - public void execute(RequestMonitor requestMonitor) { - fTracker.dispose(); - fTracker = null; - requestMonitor.done(); - } - } }; - @SuppressWarnings("unchecked") private void shutdownService(Class clazz, final RequestMonitor requestMonitor) { IDsfService service = fTracker.getService(clazz); diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpointAttributeTranslator.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpointAttributeTranslator.java similarity index 75% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpointAttributeTranslator.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpointAttributeTranslator.java index 0e342716357..ccdf9aef3ca 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpointAttributeTranslator.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpointAttributeTranslator.java @@ -8,7 +8,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.breakpoints; +package org.eclipse.dd.examples.pda.service; import java.util.ArrayList; import java.util.HashMap; @@ -29,22 +29,33 @@ import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IBreakpoint; /** - * + * Translator between {@link PDALineBreakpoint} object attributes and + * attributes used by the {@link PDABreakpoints} service. + *

+ * The attribute translator is used by the standard {@link BreakpointsMediator} + * service to map between platform breakpoint attributes and target-side DSF + * breakpoint attributes. Thus, this object encapsulates the model-specific + * functionality of synchronizing target side and IDE-side breakpoint objects. + *

*/ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTranslator { + // Arrays of common attributes between the two breakpoint types. These + // attributes can be copied directly without translation. private static final String[] fgPDALineBreakpointAttributes = { + IBreakpoint.ENABLED, IMarker.LINE_NUMBER, }; - private static final String[] fgPDAWatchpointAttributes = { + IBreakpoint.ENABLED, PDAWatchpoint.FUNCTION_NAME, PDAWatchpoint.VAR_NAME, PDAWatchpoint.ACCESS, PDAWatchpoint.MODIFICATION }; - + // PDA breakpoints translator doesn't keep any state and it doesn't + // need to initialize or clean up. public void initialize(BreakpointsMediator mediator) { } @@ -56,18 +67,22 @@ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTra { Map attrs = new HashMap(); + // Check that the marker exists and retrieve its attributes. + // Due to accepted race conditions, the breakpiont marker may become null + // while this method is being invoked. In this case throw an exception + // and let the caller handle it. IMarker marker = bp.getMarker(); if (marker == null || !marker.exists()) { throw new DebugException(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED, "Breakpoint marker does not exist", null)); } - // Suppress cast warning: platform is still on Java 1.3 @SuppressWarnings("unchecked") Map platformBpAttrs = marker.getAttributes(); + // Copy breakpoint attributes. if (bp instanceof PDAWatchpoint) { attrs.put(PDABreakpoints.ATTR_BREAKPOINT_TYPE, PDABreakpoints.PDA_WATCHPOINT); - + copyAttributes(platformBpAttrs, attrs, fgPDAWatchpointAttributes); } else if (bp instanceof PDALineBreakpoint) { attrs.put(PDABreakpoints.ATTR_BREAKPOINT_TYPE, PDABreakpoints.PDA_LINE_BREAKPOINT); @@ -81,6 +96,9 @@ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTra attrs.put(IBreakpoint.ENABLED, false); } + // The breakpoint mediator allows for multiple target-side breakpoints + // to be created for each IDE breakpoint. Although in case of PDA this + // feature is never used, we still have to return a list of attributes. List> retVal = new ArrayList>(1); retVal.add(attrs); return retVal; @@ -96,7 +114,7 @@ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTra public boolean canUpdateAttributes(IBreakpointDMContext bp, Map delta) { // PDA debugger only allows updating of the action property of the watchpoint. - // All other breakpoint updates will require a reinstallation. + // All other breakpoint updates will require a re-installation. if (bp instanceof PDAWatchpoint) { Map deltaCopy = new HashMap(delta); deltaCopy.remove(PDAWatchpoint.ACCESS); diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpoints.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpoints.java new file mode 100644 index 00000000000..b0a4aa77e41 --- /dev/null +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDABreakpoints.java @@ -0,0 +1,395 @@ +/******************************************************************************* + * Copyright (c) 2007 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ericsson - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.dd.examples.pda.service; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.Immutable; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.datamodel.AbstractDMContext; +import org.eclipse.dd.dsf.datamodel.DMContexts; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.debug.service.IBreakpoints; +import org.eclipse.dd.dsf.service.AbstractDsfService; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.examples.pda.PDAPlugin; +import org.eclipse.dd.examples.pda.breakpoints.PDAWatchpoint; +import org.eclipse.dd.examples.pda.service.commands.PDAClearBreakpointCommand; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDASetBreakpointCommand; +import org.eclipse.dd.examples.pda.service.commands.PDAWatchCommand; +import org.eclipse.debug.core.model.IBreakpoint; +import org.osgi.framework.BundleContext; + +/** + * Initial breakpoint service implementation. + * Implements the IBreakpoints interface. + */ +public class PDABreakpoints extends AbstractDsfService implements IBreakpoints +{ + /** + * Context representing a PDA line breakpoint. In PDA debugger, since there is only + * one file being debugged at a time, a breakpoint is uniquely identified using the + * line number only. + */ + @Immutable + private static class BreakpointDMContext extends AbstractDMContext implements IBreakpointDMContext { + + final Integer fLine; + + public BreakpointDMContext(String sessionId, PDAProgramDMContext commandControlCtx, Integer line) { + super(sessionId, new IDMContext[] { commandControlCtx }); + fLine = line; + } + + @Override + public boolean equals(Object obj) { + return baseEquals(obj) && (fLine.equals(((BreakpointDMContext) obj).fLine)); + } + + @Override + public int hashCode() { + return baseHashCode() + fLine.hashCode(); + } + + @Override + public String toString() { + return baseToString() + ".breakpoint(" + fLine + ")"; //$NON-NLS-1$//$NON-NLS-2$*/ + } + } + + /** + * Context representing a watch point. In PDA debugger, a watchpoint is + * uniquely identified using the function and variable. + */ + @Immutable + private static class WatchpointDMContext extends AbstractDMContext implements IBreakpointDMContext { + final String fFunction; + final String fVariable; + + public WatchpointDMContext(String sessionId, PDAProgramDMContext commandControlCtx, String function, + String variable) + { + super(sessionId, new IDMContext[] { commandControlCtx }); + fFunction = function; + fVariable = variable; + } + + @Override + public boolean equals(Object obj) { + if (baseEquals(obj)) { + WatchpointDMContext watchpointCtx = (WatchpointDMContext)obj; + return fFunction.equals(watchpointCtx.fFunction) && fVariable.equals(watchpointCtx.fVariable); + } + return false; + } + + @Override + public int hashCode() { + return baseHashCode() + fFunction.hashCode() + fVariable.hashCode(); + } + + @Override + public String toString() { + return baseToString() + ".watchpoint(" + fFunction + "::" + fVariable + ")"; + } + } + + // Attribute names + public static final String ATTR_BREAKPOINT_TYPE = PDAPlugin.PLUGIN_ID + ".pdaBreakpointType"; //$NON-NLS-1$ + public static final String PDA_LINE_BREAKPOINT = "breakpoint"; //$NON-NLS-1$ + public static final String PDA_WATCHPOINT = "watchpoint"; //$NON-NLS-1$ + public static final String ATTR_PROGRAM_PATH = PDAPlugin.PLUGIN_ID + ".pdaProgramPath"; //$NON-NLS-1$ + + // Services + private PDACommandControl fCommandControl; + + // Breakpoints currently installed + private Set fBreakpoints = new HashSet(); + + /** + * The service constructor + * + * @param session The debugging session this service belongs to. + */ + public PDABreakpoints(DsfSession session) { + super(session); + } + + @Override + public void initialize(final RequestMonitor rm) { + super.initialize(new RequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + doInitialize(rm); + } + }); + } + + private void doInitialize(final RequestMonitor rm) { + // Get the services references + fCommandControl = getServicesTracker().getService(PDACommandControl.class); + + // Register this service + register(new String[] { IBreakpoints.class.getName(), PDABreakpoints.class.getName() }, + new Hashtable()); + + rm.done(); + } + + @Override + public void shutdown(final RequestMonitor rm) { + unregister(); + rm.done(); + } + + @Override + protected BundleContext getBundleContext() { + return PDAPlugin.getBundleContext(); + } + + public void getBreakpoints(final IBreakpointsTargetDMContext context, final DataRequestMonitor rm) { + // Validate the context + if (!fCommandControl.getProgramDMContext().equals(context)) { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid breakpoints target context"); + return; + } + + rm.setData(fBreakpoints.toArray(new IBreakpointDMContext[fBreakpoints.size()])); + rm.done(); + } + + public void getBreakpointDMData(IBreakpointDMContext dmc, DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Retrieving breakpoint data is not supported"); + } + + public void insertBreakpoint(IBreakpointsTargetDMContext context, Map attributes, + DataRequestMonitor rm) + { + Boolean enabled = (Boolean)attributes.get(IBreakpoint.ENABLED); + if (enabled != null && !enabled.booleanValue()) { + // If the breakpoint is disabled, just fail the request. + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Breakpoint is disabled"); + } else { + String type = (String) attributes.get(ATTR_BREAKPOINT_TYPE); + + if (PDA_LINE_BREAKPOINT.equals(type)) { + // Retrieve the PDA program context from the context given in the + // argument. This service is typically only called by the + // breakpoints mediator, which was called with the program context + // in the services initialization sequence. So checking if + // programCtx != null is mostly a formality. + PDAProgramDMContext programCtx = DMContexts.getAncestorOfType(context, PDAProgramDMContext.class); + if (programCtx != null) { + doInsertBreakpoint(programCtx, attributes, rm); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Unknown breakpoint type"); + } + } + else if (PDA_WATCHPOINT.equals(type)) { + doInsertWatchpoint(attributes, rm); + } + else { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Unknown breakpoint type"); + } + } + } + + private void doInsertBreakpoint(PDAProgramDMContext programCtx, final Map attributes, final DataRequestMonitor rm) + { + // Compare the program path in the breakpoint with the path in the PDA + // program context. Only insert the breakpoint if the program matches. + String program = (String)attributes.get(ATTR_PROGRAM_PATH); + if (!programCtx.getProgram().equals(program)) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Invalid file name"); + return; + } + + // Retrieve the line. + Integer line = (Integer)attributes.get(IMarker.LINE_NUMBER); + if (line == null) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "No breakpoint line specified"); + return; + } + + // Create a new breakpoint context object and check that it's not + // installed already. PDA can only track a single breakpoint at a + // given line, attempting to set the second breakpoint should fail. + final BreakpointDMContext breakpointCtx = + new BreakpointDMContext(getSession().getId(), fCommandControl.getProgramDMContext(), line); + if (fBreakpoints.contains(breakpointCtx)) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Breakpoint already set"); + return; + } + + // Add the new breakpoint context to the list of known breakpoints. + // Adding it here, before the set command is completed will prevent + // a possibility of a second breakpoint being installed in the same + // location while this breakpoint is being processed. It will also + // allow the breakpoint to be removed or updated even while it is + // still being processed here. + fBreakpoints.add(breakpointCtx); + fCommandControl.queueCommand( + new PDASetBreakpointCommand(fCommandControl.getProgramDMContext(), line), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + rm.setData(breakpointCtx); + rm.done(); + } + + @Override + protected void handleErrorOrCancel() { + // If inserting of the breakpoint failed, remove it from + // the set of installed breakpoints. + fBreakpoints.remove(breakpointCtx); + super.handleErrorOrCancel(); + } + }); + } + + private void doInsertWatchpoint(final Map attributes, final DataRequestMonitor rm) + { + String function = (String)attributes.get(PDAWatchpoint.FUNCTION_NAME); + if (function == null) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "No function specified"); + return; + } + + String variable = (String)attributes.get(PDAWatchpoint.VAR_NAME); + if (variable == null) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "No variable specified"); + return; + } + + Boolean isAccess = (Boolean)attributes.get(PDAWatchpoint.ACCESS); + isAccess = isAccess != null ? isAccess : Boolean.FALSE; + + Boolean isModification = (Boolean)attributes.get(PDAWatchpoint.MODIFICATION); + isModification = isModification != null ? isModification : Boolean.FALSE; + + // Create a new watchpoint context object and check that it's not + // installed already. PDA can only track a single watchpoint for a given + // function::variable, attempting to set the second breakpoint should fail. + final WatchpointDMContext watchpointCtx = + new WatchpointDMContext(getSession().getId(), fCommandControl.getProgramDMContext(), function, variable); + if (fBreakpoints.contains(watchpointCtx)) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Watchpoint already set"); + return; + } + + // Determine the watch operation to perform. + PDAWatchCommand.WatchOperation watchOperation = PDAWatchCommand.WatchOperation.NONE; + if (isAccess && isModification) { + watchOperation = PDAWatchCommand.WatchOperation.BOTH; + } else if (isAccess) { + watchOperation = PDAWatchCommand.WatchOperation.READ; + } else if (isModification) { + watchOperation = PDAWatchCommand.WatchOperation.WRITE; + } + + // Add the new breakpoint context to the list of known breakpoints. + // Adding it here, before the set command is completed will prevent + // a possibility of a second breakpoint being installed in the same + // location while this breakpoint is being processed. It will also + // allow the breakpoint to be removed or updated even while it is + // still being processed here. + fBreakpoints.add(watchpointCtx); + fCommandControl.queueCommand( + new PDAWatchCommand(fCommandControl.getProgramDMContext(), function, variable, watchOperation), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + rm.setData(watchpointCtx); + rm.done(); + } + + @Override + protected void handleErrorOrCancel() { + // Since the command failed, we need to remove the breakpoint from + // the existing breakpoint set. + fBreakpoints.remove(watchpointCtx); + super.handleErrorOrCancel(); + } + }); + } + + public void removeBreakpoint(IBreakpointDMContext bpCtx, RequestMonitor rm) { + if (!fBreakpoints.contains(bpCtx)) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Breakpoint already removed"); + return; + } + + if (bpCtx instanceof BreakpointDMContext) { + doRemoveBreakpoint((BreakpointDMContext)bpCtx, rm); + } else if (bpCtx instanceof WatchpointDMContext) { + doRemoveWatchpoint((WatchpointDMContext)bpCtx, rm); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid breakpoint"); + } + } + + private void doRemoveBreakpoint(BreakpointDMContext bpCtx, RequestMonitor rm) { + // Remove the breakpoint from the table right away, so that even when + // the remove is being processed, a new breakpoint can be created at the same + // location. + fBreakpoints.remove(bpCtx); + + fCommandControl.queueCommand( + new PDAClearBreakpointCommand(fCommandControl.getProgramDMContext(), bpCtx.fLine), + new DataRequestMonitor(getExecutor(), rm)); + } + + private void doRemoveWatchpoint(WatchpointDMContext bpCtx, RequestMonitor rm) { + fBreakpoints.remove(bpCtx); + + // Watchpoints are cleared using the same command, but with a "no watch" operation + fCommandControl.queueCommand( + new PDAWatchCommand( + fCommandControl.getProgramDMContext(), bpCtx.fFunction, bpCtx.fVariable, PDAWatchCommand.WatchOperation.NONE), + new DataRequestMonitor(getExecutor(), rm)); + } + + public void updateBreakpoint(final IBreakpointDMContext bpCtx, Map attributes, final RequestMonitor rm) { + if (!fBreakpoints.contains(bpCtx)) { + PDAPlugin.failRequest(rm, REQUEST_FAILED, "Breakpoint not installed"); + return; + } + + if (bpCtx instanceof BreakpointDMContext) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Modifying PDA breakpoints is not supported"); + } else if (bpCtx instanceof WatchpointDMContext) { + // PDA debugger can only track one watchpoint in the same location, + // so we can simply remove the existing context from the set and + // call insert again. + fBreakpoints.remove(bpCtx); + doInsertWatchpoint( + attributes, + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + // The inserted watchpoint context will equal the + // current context. + assert bpCtx.equals(getData()); + rm.done(); + } + }); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid breakpoint"); + } + } +} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControl.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDACommandControl.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControl.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDACommandControl.java index 1c8013e1f7d..d835a549554 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControl.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDACommandControl.java @@ -1,4 +1,4 @@ -package org.eclipse.dd.examples.pda.service.command; +package org.eclipse.dd.examples.pda.service; import java.io.BufferedReader; import java.io.IOException; @@ -30,10 +30,10 @@ import org.eclipse.dd.dsf.debug.service.command.ICommandResult; import org.eclipse.dd.dsf.debug.service.command.IEventListener; import org.eclipse.dd.dsf.service.AbstractDsfService; import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.dsf.service.IDsfService; import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.command.commands.AbstractPDACommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDAExitCommand; +import org.eclipse.dd.examples.pda.service.commands.AbstractPDACommand; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDAExitCommand; import org.osgi.framework.BundleContext; @@ -53,6 +53,11 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } } + // Parameters that the command control is created with. + final private String fProgram; + final private int fRequestPort; + final private int fEventPort; + // Queue of commands waiting to be sent to the debugger. As long as commands // are in this queue, they can still be removed by clients. private final List fCommandQueue = new LinkedList(); @@ -71,15 +76,13 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon private boolean fTerminated = false; // Data Model context of this command control. - private PDACommandControlDMContext fDMContext; + private PDAProgramDMContext fDMContext; // Synchronous listeners for commands and events. private final List fCommandListeners = new ArrayList(); private final List fEventListeners = new ArrayList(); // Sockets for communicating with PDA debugger - final private int fRequestPort; - final private int fEventPort; private Socket fRequestSocket; private PrintWriter fRequestWriter; private BufferedReader fRequestReader; @@ -96,14 +99,16 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon * @param requestPort Port number for sending PDA commands. * @param eventPort Port for listening to PDA events. */ - public PDACommandControl(DsfSession session, int requestPort, int eventPort) { + public PDACommandControl(DsfSession session, String program, int requestPort, int eventPort) { super(session); + fProgram = program; fRequestPort = requestPort; fEventPort = eventPort; } @Override public void initialize(final RequestMonitor rm) { + // Call the super-class to perform initialization first. super.initialize( new RequestMonitor(getExecutor(), rm) { @Override protected void handleOK() { @@ -112,10 +117,11 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon }); } - public void doInitialize(final RequestMonitor rm) { + private void doInitialize(final RequestMonitor rm) { // Create the control's data model context. - fDMContext = new PDACommandControlDMContext(getSession().getId()); + fDMContext = new PDAProgramDMContext(getSession().getId(), fProgram); + // Add a listener for PDA events to track the started/terminated state. addEventListener(new IEventListener() { public void eventReceived(Object output) { if ("started".equals(output)) { @@ -170,11 +176,11 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon socketsInitializeRm.done(); } catch (UnknownHostException e) { socketsInitializeRm.setStatus(new Status( - IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.REQUEST_FAILED, "Unable to connect to PDA VM", e)); + IStatus.ERROR, PDAPlugin.PLUGIN_ID, REQUEST_FAILED, "Unable to connect to PDA VM", e)); socketsInitializeRm.done(); } catch (IOException e) { socketsInitializeRm.setStatus(new Status( - IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.REQUEST_FAILED, "Unable to connect to PDA VM", e)); + IStatus.ERROR, PDAPlugin.PLUGIN_ID, REQUEST_FAILED, "Unable to connect to PDA VM", e)); socketsInitializeRm.done(); } return Status.OK_STATUS; @@ -211,8 +217,11 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon return PDAPlugin.getBundleContext(); } - class CommandSendJob extends Job { - public CommandSendJob() { + /** + * Job that services the send command queue. + */ + private class CommandSendJob extends Job { + CommandSendJob() { super("PDA Command Send"); setSystem(true); } @@ -222,26 +231,45 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon while (!isTerminated()) { synchronized(fTxCommands) { try { + // Remove comamnd from send queue. final CommandHandle commandHandle = fTxCommands.take(); + + // Send the request to PDA fRequestWriter.println(commandHandle.fCommand.getRequest()); fRequestWriter.flush(); try { // wait for reply final String response = fRequestReader.readLine(); - getExecutor().execute(new DsfRunnable() { - public void run() { - processCommandDone(commandHandle, response); - } - }); - + // Process the reply in the executor thread. + try { + getExecutor().execute(new DsfRunnable() { + public void run() { + processCommandDone(commandHandle, response); + } + }); + } catch (RejectedExecutionException e) { + // Acceptable race condition may see the session shut down + // while we're waiting for command response. Still complete + // the request monitor. + assert isTerminated(); + assert isTerminated(); + PDAPlugin.failRequest(commandHandle.fRequestMonitor, REQUEST_FAILED, "Command control shut down."); + } } catch (final IOException e) { - getExecutor().execute(new DsfRunnable() { - public void run() { - processCommandException(commandHandle, e); - } - }); + // Process error it in the executor thread + try { + getExecutor().execute(new DsfRunnable() { + public void run() { + processCommandException(commandHandle, e); + } + }); + } catch (RejectedExecutionException re) { + // Acceptable race condition... see above + assert isTerminated(); + PDAPlugin.failRequest(commandHandle.fRequestMonitor, REQUEST_FAILED, "Command control shut down."); + } } } catch (InterruptedException e) { break; // Shutting down. @@ -254,13 +282,12 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } /** - * Listens to events from the PDA VM and fires corresponding - * debug events. + * Job that services the PDA event socket. */ class EventDispatchJob extends Job { public EventDispatchJob() { - super("PDA Event Dispatch"); + super("PDA Event Listner"); setSystem(true); } @@ -268,9 +295,11 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon protected IStatus run(IProgressMonitor monitor) { while (!isTerminated()) { try { + // Wait for an event. final String event = fEventReader.readLine(); if (event != null) { try { + // Process the event in executor thread. getExecutor().execute(new DsfRunnable() { public void run() { processEventReceived(event); @@ -285,6 +314,8 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } } if (!isTerminated()) { + // Exception from the event socket is an indicator that the PDA debugger + // has exited. Call setTerminated() in executor thread. try { getExecutor().execute(new DsfRunnable() { public void run() { @@ -309,11 +340,14 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon @SuppressWarnings("unchecked") DataRequestMonitor pdaRM = (DataRequestMonitor)rm; + // Add the command to the queue and notify command listeners. fCommandQueue.add( new CommandHandle(pdaCommand, pdaRM) ); for (ICommandListener listener : fCommandListeners) { listener.commandQueued(command); } + // In a separate dispatch cycle. This allows command listeners to repond to the + // command queued event. getExecutor().execute(new DsfRunnable() { public void run() { processQueues(); @@ -321,9 +355,7 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon }); } else { - rm.setStatus(new Status( - IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR, "Unrecognized command: " + command, null)); - rm.done(); + PDAPlugin.failRequest(rm, INTERNAL_ERROR, "Unrecognized command: " + command); } } @@ -333,6 +365,7 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } public void removeCommand(ICommand command) { + // Removes given command from the queue and notify the listeners for (Iterator itr = fCommandQueue.iterator(); itr.hasNext();) { CommandHandle handle = itr.next(); if (command.equals(handle.fCommand)) { @@ -361,29 +394,44 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } private void processCommandDone(CommandHandle handle, String response) { + // Trace to debug output. PDAPlugin.debug("R: " + response); + // Given the PDA response string, create the result using the command + // that was sent. PDACommandResult result = handle.fCommand.createResult(response); + + // Set the result to the request monitor and return to sender. + // Note: as long as PDA sends some response, a PDA command will never + // return an error. handle.fRequestMonitor.setData(result); handle.fRequestMonitor.done(); + // Notify listeners of the response for (ICommandListener listener : fCommandListeners) { listener.commandDone(handle.fCommand, result); } + + // Process next command in queue. processQueues(); } + private void processCommandException(CommandHandle handle, Throwable exception) { + + // If sending a command resulted in an exception, notify the client. handle.fRequestMonitor.setStatus(new Status( - IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.REQUEST_FAILED, "Exception reading request response", exception)); + IStatus.ERROR, PDAPlugin.PLUGIN_ID, REQUEST_FAILED, "Exception reading request response", exception)); handle.fRequestMonitor.done(); + // Notify listeners also. for (ICommandListener listener : fCommandListeners) { listener.commandDone(handle.fCommand, null); } } private void processEventReceived(String event) { + // Notify the listeners only. PDAPlugin.debug("E: " + event); for (IEventListener listener : fEventListeners) { listener.eventReceived(event); @@ -396,7 +444,7 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon // with an error. for (CommandHandle handle : fCommandQueue) { handle.fRequestMonitor.setStatus(new Status( - IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_STATE, "Command control is terminated", null)); + IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_STATE, "Command control is terminated", null)); handle.fRequestMonitor.done(); } fCommandQueue.clear(); @@ -414,19 +462,24 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon } } + /** + * Return the PDA Debugger top-level Data Model context. + * @see PDAProgramDMContext + */ @ThreadSafe - public PDACommandControlDMContext getDMContext() { + public PDAProgramDMContext getProgramDMContext() { return fDMContext; } private void setStarted() { + // Mark the command control as started and ready to process commands. fStarted = true; - // Process any waiting commands. + // Process any commands which may have been queued before the processQueues(); // Issue a data model event. - getSession().dispatchEvent(new PDAStartedEvent(getDMContext()), getProperties()); + getSession().dispatchEvent(new PDAStartedEvent(getProgramDMContext()), getProperties()); } /** @@ -448,7 +501,7 @@ public class PDACommandControl extends AbstractDsfService implements ICommandCon processQueues(); // Issue a data model event. - getSession().dispatchEvent(new PDATerminatedEvent(getDMContext()), getProperties()); + getSession().dispatchEvent(new PDATerminatedEvent(getProgramDMContext()), getProperties()); } } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java new file mode 100644 index 00000000000..2995b3388d0 --- /dev/null +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAExpressions.java @@ -0,0 +1,373 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.examples.pda.service; + +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.Immutable; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.datamodel.AbstractDMContext; +import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; +import org.eclipse.dd.dsf.datamodel.DMContexts; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.debug.service.IExpressions; +import org.eclipse.dd.dsf.debug.service.IStack; +import org.eclipse.dd.dsf.debug.service.IRegisters.IRegisterDMContext; +import org.eclipse.dd.dsf.debug.service.IRunControl.IResumedDMEvent; +import org.eclipse.dd.dsf.debug.service.IRunControl.ISuspendedDMEvent; +import org.eclipse.dd.dsf.debug.service.IRunControl.StateChangeReason; +import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; +import org.eclipse.dd.dsf.debug.service.command.CommandCache; +import org.eclipse.dd.dsf.service.AbstractDsfService; +import org.eclipse.dd.dsf.service.DsfServiceEventHandler; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.examples.pda.PDAPlugin; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDASetVarCommand; +import org.eclipse.dd.examples.pda.service.commands.PDAVarCommand; +import org.osgi.framework.BundleContext; + +/** + * + */ +public class PDAExpressions extends AbstractDsfService implements IExpressions { + + @Immutable + private static class ExpressionDMContext extends AbstractDMContext implements IExpressionDMContext { + + final private String fExpression; + + ExpressionDMContext(String sessionId, IFrameDMContext frameDmc, String expressin) { + super(sessionId, new IDMContext[] { frameDmc }); + fExpression = expressin; + } + + public String getExpression() { + return fExpression; + } + + @Override + public boolean equals(Object other) { + return super.baseEquals(other) && ((ExpressionDMContext)other).fExpression.equals(fExpression); + } + + @Override + public int hashCode() { + return super.baseHashCode() + fExpression.hashCode(); + } + + @Override + public String toString() { + return baseToString() + ".expression(" + fExpression + ")"; + } + } + + /** + * PDA expressions are simply variables. Only the variable name + * is relevant for its data. + */ + @Immutable + private static class ExpressionDMData implements IExpressionDMData { + + final private String fExpression; + + public ExpressionDMData(String expression) { + fExpression = expression; + } + + public BasicType getBasicType() { + return BasicType.basic; + } + + public String getEncoding() { + return null; + } + + public Map getEnumerations() { + return null; + } + + public String getName() { + return fExpression; + } + + public IRegisterDMContext getRegister() { + return null; + } + + public String getStringValue() { + return null; + } + + public String getTypeId() { + return null; + } + + public String getTypeName() { + return null; + } + + } + + // @see #createExpression() + @Immutable + private static class InvalidExpressionDMContext extends AbstractDMContext implements IExpressionDMContext { + final private String fExpression; + + public InvalidExpressionDMContext(String sessionId, IDMContext parent, String expr) { + super(sessionId, new IDMContext[] { parent }); + fExpression = expr; + } + + @Override + public boolean equals(Object other) { + return super.baseEquals(other) && + fExpression == null + ? ((InvalidExpressionDMContext) other).getExpression() == null + : fExpression.equals(((InvalidExpressionDMContext) other).getExpression()); + } + + @Override + public int hashCode() { + return fExpression == null ? super.baseHashCode() : super.baseHashCode() ^ fExpression.hashCode(); + } + + @Override + public String toString() { + return baseToString() + ".invalid_expr[" + fExpression + "]"; + } + + public String getExpression() { + return fExpression; + } + } + + @Immutable + private static class ExpressionChangedDMEvent extends AbstractDMEvent + implements IExpressionChangedDMEvent + { + ExpressionChangedDMEvent(IExpressionDMContext expression) { + super(expression); + } + } + + + private PDACommandControl fCommandControl; + private IStack fStack; + + private CommandCache fCommandCache; + + public PDAExpressions(DsfSession session) { + super(session); + } + + @Override + protected BundleContext getBundleContext() { + return PDAPlugin.getBundleContext(); + } + + @Override + public void initialize(final RequestMonitor rm) { + super.initialize( + new RequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + doInitialize(rm); + }}); + } + + private void doInitialize(final RequestMonitor rm) { + fCommandControl = getServicesTracker().getService(PDACommandControl.class); + fStack = getServicesTracker().getService(IStack.class); + fCommandCache = new CommandCache(fCommandControl); + + getSession().addServiceEventListener(this, null); + + register(new String[]{IExpressions.class.getName(), PDAExpressions.class.getName()}, new Hashtable()); + + rm.done(); + } + + @Override + public void shutdown(final RequestMonitor rm) { + getSession().removeServiceEventListener(this); + fCommandCache.reset(); + super.shutdown(rm); + } + + public void canWriteExpression(IExpressionDMContext expressionContext, DataRequestMonitor rm) { + rm.setData(true); + rm.done(); + } + + public IExpressionDMContext createExpression(IDMContext ctx, String expression) { + // Create an expression based on the given context and string expression. + // The PDA debugger can only evaluate variables as expressions and only + // in context of a frame. + IFrameDMContext frameCtx = DMContexts.getAncestorOfType(ctx, IFrameDMContext.class); + if (frameCtx != null) { + return new ExpressionDMContext(getSession().getId(), frameCtx, expression); + } else { + // If a frame cannot be found in context, return an "invalid" + // expression context, because a null return value is not allowed. + // Evaluating an invalid expression context will always yield an + // error. + return new InvalidExpressionDMContext(getSession().getId(), ctx, expression); + } + } + + public void getBaseExpressions(IExpressionDMContext exprContext, DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Not supported"); + } + + public void getExpressionAddressData(IExpressionDMContext dmc, DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Not supported"); + } + + public void getExpressionData(final IExpressionDMContext exprCtx, final DataRequestMonitor rm) { + // Since expression data doesn't contain any more information than the + // context, it doesn't require any debugger commmands. + if (exprCtx instanceof ExpressionDMContext) { + rm.setData(new ExpressionDMData(exprCtx.getExpression())); + rm.done(); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid expression context " + exprCtx); + } + } + + public void getSubExpressionCount(IExpressionDMContext exprCtx, DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Not supported"); + } + + public void getSubExpressions(IExpressionDMContext exprCtx, DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Not supported"); + } + + public void getSubExpressions(IExpressionDMContext exprCtx, int startIndex, int length, + DataRequestMonitor rm) + { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Not supported"); + } + + public void getAvailableFormats(IFormattedDataDMContext dmc, DataRequestMonitor rm) { + // PDA debugger doesn't support formatting the expression. Natural + // formatting is the only available option. + rm.setData(new String[] { NATURAL_FORMAT }); + rm.done(); + } + + public FormattedValueDMContext getFormattedValueContext(IFormattedDataDMContext exprCtx, String formatId) { + // Creates a context that can be used to retrieve a formatted value. + return new FormattedValueDMContext(this, exprCtx, formatId); + } + + public void getFormattedExpressionValue(FormattedValueDMContext formattedCtx, + final DataRequestMonitor rm) + { + final ExpressionDMContext exprCtx = DMContexts.getAncestorOfType(formattedCtx, ExpressionDMContext.class); + if (exprCtx != null) { + final IFrameDMContext frameCtx = DMContexts.getAncestorOfType(exprCtx, IFrameDMContext.class); + + // First retrieve the stack depth, needed to properly calculate + // the frame index that is used by the PDAVarCommand. + fStack.getStackDepth( + frameCtx, 0, + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + // Calculate the frame index. + int frameId = getData() - frameCtx.getLevel() - 1; + + // Send the command to evaluate the variable. + fCommandCache.execute( + new PDAVarCommand(fCommandControl.getProgramDMContext(), frameId, exprCtx.getExpression()), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + rm.setData(new FormattedValueDMData(getData().fResponseText)); + rm.done(); + } + }); + } + }); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid expression context " + formattedCtx); + rm.done(); + } + } + + public void writeExpression(final IExpressionDMContext exprCtx, final String exprValue, String formatId, + final RequestMonitor rm) + { + if (exprCtx instanceof ExpressionDMContext) { + final IFrameDMContext frameCtx = DMContexts.getAncestorOfType(exprCtx, IFrameDMContext.class); + + // Similarly to retrieving the variable, retrieve the + // stack depth first. + fStack.getStackDepth( + frameCtx, 0, + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + // Calculate the frame index. + int frameId = getData() - frameCtx.getLevel() - 1; + + // Send the "write" command to PDA debugger + fCommandCache.execute( + new PDASetVarCommand(fCommandControl.getProgramDMContext(), frameId, exprCtx.getExpression(), exprValue), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + getSession().dispatchEvent(new ExpressionChangedDMEvent(exprCtx), getProperties()); + rm.done(); + } + }); + } + }); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Invalid expression context " + exprCtx); + rm.done(); + } + } + + @SuppressWarnings("unchecked") + @Deprecated + public void getModelData(IDMContext dmc, DataRequestMonitor rm) { + if (dmc instanceof IExpressionDMContext) { + getExpressionData((IExpressionDMContext) dmc, (DataRequestMonitor) rm); + } else if (dmc instanceof FormattedValueDMContext) { + getFormattedExpressionValue((FormattedValueDMContext) dmc, (DataRequestMonitor) rm); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Unknown DMC type"); + rm.done(); + } + } + + @DsfServiceEventHandler + public void eventDispatched(IResumedDMEvent e) { + // Mark the cache as not available, so that data retrieval commands + // will fail. Also reset the cache unless it was a step command. + fCommandCache.setTargetAvailable(false); + if (!e.getReason().equals(StateChangeReason.STEP)) { + fCommandCache.reset(); + } + } + + + @DsfServiceEventHandler + public void eventDispatched(ISuspendedDMEvent e) { + // Enable sending commands to target and clear the cache. + fCommandCache.setTargetAvailable(true); + fCommandCache.reset(); + } +} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAProgramDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAProgramDMContext.java new file mode 100644 index 00000000000..4247483f78d --- /dev/null +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAProgramDMContext.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.examples.pda.service; + +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.dd.dsf.datamodel.AbstractDMContext; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; +import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; +import org.eclipse.dd.dsf.service.DsfSession; + +/** + * Top-level Data Model context for the PDA debugger representing the PDA + * program. + *

+ * The PDA debugger is a single-threaded application. Therefore this + * top level context implements IExecutionDMContext directly, hence this + * context can be used to call the IRunControl service to perform run + * control opreations. + *

+ *

+ * Also, the PDA debugger allows setting breakpoints in scope of the + * whole program only, so this context can be used with the breakpoints + * service to install/remove breakpoints. + *

+ *

+ * Note: There should only be one instance of PDACommandControlDMContext created + * by each PDA command control, so its equals method defaults to using + * instance comparison. + *

+ */ +public class PDAProgramDMContext extends PlatformObject + implements IExecutionDMContext, IBreakpointsTargetDMContext +{ + final static IDMContext[] EMPTY_PARENTS_ARRAY = new IDMContext[0]; + + final private String fSessionId; + final private String fProgram; + + public PDAProgramDMContext(String sessionId, String program) { + fSessionId = sessionId; + fProgram = program; + } + + public String getSessionId() { + return fSessionId; + } + + public String getProgram() { + return fProgram; + } + + public IDMContext[] getParents() { + return EMPTY_PARENTS_ARRAY; + } + + @Override + public String toString() { + return "PDA(" + getSessionId() + ")"; + } + + /** + * @see AbstractDMContext#getAdapter(Class) + */ + @Override + @SuppressWarnings("unchecked") + public Object getAdapter(Class adapterType) { + Object retVal = null; + DsfSession session = DsfSession.getSession(fSessionId); + if (session != null) { + retVal = session.getModelAdapter(adapterType); + } + if (retVal == null) { + retVal = super.getAdapter(adapterType); + } + return retVal; + } + +} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDARunControl.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDARunControl.java new file mode 100644 index 00000000000..62a59002dfa --- /dev/null +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDARunControl.java @@ -0,0 +1,317 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + * Ericsson AB - Modified for handling of multiple threads + *******************************************************************************/ +package org.eclipse.dd.examples.pda.service; + +import java.util.Hashtable; + +import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.Immutable; +import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.datamodel.IDMEvent; +import org.eclipse.dd.dsf.debug.service.IRunControl; +import org.eclipse.dd.dsf.debug.service.command.IEventListener; +import org.eclipse.dd.dsf.service.AbstractDsfService; +import org.eclipse.dd.dsf.service.DsfServiceEventHandler; +import org.eclipse.dd.dsf.service.DsfSession; +import org.eclipse.dd.dsf.service.IDsfService; +import org.eclipse.dd.examples.pda.PDAPlugin; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDAResumeCommand; +import org.eclipse.dd.examples.pda.service.commands.PDAStepCommand; +import org.eclipse.dd.examples.pda.service.commands.PDASuspendCommand; +import org.osgi.framework.BundleContext; + + +/** + * Service for monitoring and controlling execution state of the DPA + * program. + *

+ * This service depends on the {@link PDACommandControl} service. + * It must be initialized before this service is initialized. + *

+ */ +public class PDARunControl extends AbstractDsfService + implements IRunControl, IEventListener +{ + // Implementation note about tracking execution state: + // This class implements event handlers for the events that are generated by + // this service itself. When the event is dispatched, these handlers will + // be called first, before any of the clients. These handlers update the + // service's internal state information to make them consistent with the + // events being issued. Doing this in the handlers as opposed to when + // the events are generated, guarantees that the state of the service will + // always be consistent with the events. + // The purpose of this pattern is to allow clients that listen to service + // events and track service state, to be perfectly in sync with the service + // state. + + @Immutable + private static class ExecutionDMData implements IExecutionDMData { + private final StateChangeReason fReason; + ExecutionDMData(StateChangeReason reason) { + fReason = reason; + } + public StateChangeReason getStateChangeReason() { return fReason; } + } + + @Immutable + private static class ResumedEvent extends AbstractDMEvent + implements IResumedDMEvent + { + private final String fPDAEvent; + + ResumedEvent(IExecutionDMContext ctx, String pdaEvent) { + super(ctx); + fPDAEvent = pdaEvent; + } + + public StateChangeReason getReason() { + if (fPDAEvent.startsWith("resumed breakpoint") || fPDAEvent.startsWith("suspended watch")) { + return StateChangeReason.BREAKPOINT; + } else if (fPDAEvent.equals("resumed step") || fPDAEvent.equals("resumed drop")) { + return StateChangeReason.STEP; + } else if (fPDAEvent.equals("resumed client")) { + return StateChangeReason.USER_REQUEST; + } else { + return StateChangeReason.UNKNOWN; + } + } + } + + @Immutable + private static class SuspendedEvent extends AbstractDMEvent + implements ISuspendedDMEvent + { + private final String fPDAEvent; + + SuspendedEvent(IExecutionDMContext ctx, String pdaEvent) { + super(ctx); + fPDAEvent = pdaEvent; + } + + public StateChangeReason getReason() { + if (fPDAEvent.startsWith("suspended breakpoint") || fPDAEvent.startsWith("suspended watch")) { + return StateChangeReason.BREAKPOINT; + } else if (fPDAEvent.equals("suspended step") || fPDAEvent.equals("suspended drop")) { + return StateChangeReason.STEP; + } else if (fPDAEvent.equals("suspended client")) { + return StateChangeReason.USER_REQUEST; + } else { + return StateChangeReason.UNKNOWN; + } + } + } + + // Services + private PDACommandControl fCommandControl; + + // State flags + private boolean fSuspended = true; + private boolean fResumePending = false; + private boolean fStepping = false; + private StateChangeReason fStateChangeReason; + + public PDARunControl(DsfSession session) { + super(session); + } + + @Override + protected BundleContext getBundleContext() { + return PDAPlugin.getBundleContext(); + } + + @Override + public void initialize(final RequestMonitor rm) { + super.initialize( + new RequestMonitor(getExecutor(), rm) { + @Override + protected void handleOK() { + doInitialize(rm); + }}); + } + + private void doInitialize(final RequestMonitor rm) { + fCommandControl = getServicesTracker().getService(PDACommandControl.class); + + // Add ourselves as a listener to PDA events, to catch suspended/resumed + // events. + fCommandControl.addEventListener(this); + + // Add ourselves as a listener to service events, in order to process + // our own suspended/resumed events. + getSession().addServiceEventListener(this, null); + + // Register the service with OSGi + register(new String[]{IRunControl.class.getName(), PDARunControl.class.getName()}, new Hashtable()); + + rm.done(); + } + + @Override + public void shutdown(final RequestMonitor rm) { + fCommandControl.removeEventListener(this); + getSession().removeServiceEventListener(this); + super.shutdown(rm); + } + + @Deprecated + @SuppressWarnings("unchecked") + public void getModelData(IDMContext dmc, DataRequestMonitor rm) { + // The getModelData() is deprecated and clients are expected to switch + // to getExecutionData() and other data retrieve methods directly. + // However the UI cache still uses it for now. + if (dmc instanceof IExecutionDMContext) { + getExecutionData((IExecutionDMContext)dmc, (DataRequestMonitor)rm); + } else { + PDAPlugin.failRequest(rm, INVALID_HANDLE, "Unknown DMC type"); + } + } + + public void eventReceived(Object output) { + if (!(output instanceof String)) return; + String event = (String)output; + + // Handle PDA debugger suspende/resumed events and issue the + // corresponding Data Model events. Do not update the state + // information until we start dispatching the service events. + if (event.startsWith("suspended")) { + IDMEvent dmEvent = new SuspendedEvent(fCommandControl.getProgramDMContext(), event); + getSession().dispatchEvent(dmEvent, getProperties()); + } else if (event.startsWith("resumed")) { + IDMEvent dmEvent = new ResumedEvent(fCommandControl.getProgramDMContext(), event); + getSession().dispatchEvent(dmEvent, getProperties()); + } + } + + + @DsfServiceEventHandler + public void eventDispatched(ResumedEvent e) { + // This service should be the first to receive the ResumedEvent, + // (before any other listeners are called). Here, update the + // service state information based on the the resumed event. + fSuspended = false; + fResumePending = false; + fStateChangeReason = e.getReason(); + fStepping = e.getReason().equals(StateChangeReason.STEP); + } + + + @DsfServiceEventHandler + public void eventDispatched(SuspendedEvent e) { + // This service should be the first to receive the SuspendedEvent also, + // (before any other listeners are called). Here, update the + // service state information based on the the suspended event. + fStateChangeReason = e.getReason(); + fResumePending = false; + fSuspended = true; + fStepping = false; + } + + + public boolean canResume(IExecutionDMContext context) { + return isSuspended(context) && !fResumePending; + } + + public boolean canSuspend(IExecutionDMContext context) { + return !isSuspended(context); + } + + public boolean isSuspended(IExecutionDMContext context) { + return fSuspended; + } + + public boolean isStepping(IExecutionDMContext context) { + return !isSuspended(context) && fStepping; + } + + public void resume(IExecutionDMContext context, final RequestMonitor rm) { + assert context != null; + + if (canResume(context)) { + fResumePending = true; + fCommandControl.queueCommand( + new PDAResumeCommand(fCommandControl.getProgramDMContext()), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleErrorOrCancel() { + // If the resume command failed, we no longer + // expect to receive a resumed event. + fResumePending = false; + } + } + ); + }else { + PDAPlugin.failRequest(rm, INVALID_STATE, "Given context: " + context + ", is already running."); + } + } + + public void suspend(IExecutionDMContext context, final RequestMonitor rm){ + assert context != null; + + if (canSuspend(context)) { + fCommandControl.queueCommand( + new PDASuspendCommand(fCommandControl.getProgramDMContext()), + new DataRequestMonitor(getExecutor(), rm)); + + } else { + PDAPlugin.failRequest(rm, IDsfService.INVALID_STATE, "Given context: " + context + ", is already suspended."); + } + } + + public boolean canStep(IExecutionDMContext context) { + return canResume(context); + } + + public void step(IExecutionDMContext context, StepType stepType, final RequestMonitor rm) { + assert context != null; + + if (canResume(context)) { + fResumePending = true; + fStepping = true; + + fCommandControl.queueCommand( + new PDAStepCommand(fCommandControl.getProgramDMContext()), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleErrorOrCancel() { + // If the step command failed, we no longer + // expect to receive a resumed event. + fResumePending = false; + fStepping = false; + } + }); + + } else { + PDAPlugin.failRequest(rm, INVALID_STATE, "Cannot resume context"); + return; + } + } + + public boolean canInstructionStep(IExecutionDMContext context) { + return false; + } + + public void instructionStep(IExecutionDMContext context, StepType stepType, RequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Operation not implemented"); + } + + public void getExecutionContexts(final IContainerDMContext containerDmc, final DataRequestMonitor rm) { + PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Operation not implemented"); + } + + public void getExecutionData(IExecutionDMContext dmc, DataRequestMonitor rm){ + rm.setData( new ExecutionDMData(fStateChangeReason) ); + rm.done(); + } +} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/PDAStack.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java similarity index 51% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/PDAStack.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java index f533f191328..f85e2f9e52f 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/PDAStack.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStack.java @@ -8,14 +8,15 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.stack; +package org.eclipse.dd.examples.pda.service; import java.util.Hashtable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import org.eclipse.cdt.core.IAddress; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; +import org.eclipse.dd.dsf.concurrent.Immutable; import org.eclipse.dd.dsf.concurrent.RequestMonitor; +import org.eclipse.dd.dsf.datamodel.AbstractDMContext; import org.eclipse.dd.dsf.datamodel.DMContexts; import org.eclipse.dd.dsf.datamodel.IDMContext; import org.eclipse.dd.dsf.debug.service.IRunControl; @@ -30,20 +31,143 @@ import org.eclipse.dd.dsf.service.DsfServiceEventHandler; import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.dsf.service.IDsfService; import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.commands.PDAFrame; -import org.eclipse.dd.examples.pda.service.command.commands.PDAStackCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDAStackCommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDAFrame; +import org.eclipse.dd.examples.pda.service.commands.PDAStackCommand; +import org.eclipse.dd.examples.pda.service.commands.PDAStackCommandResult; import org.osgi.framework.BundleContext; /** - * + * Service for retrieving PDA debugger stack data. + *

+ * This service depends on the {@link PDACommandControl} service and the + * {@link IRunControl} service. These services must be initialized before + * this service is initialized. + *

*/ public class PDAStack extends AbstractDsfService implements IStack { + /** + * PDA stack frame contains only the stack frame level. It is only + * used as an index into the frame data returned by the PDA debugger. + */ + @Immutable + private static class FrameDMContext extends AbstractDMContext implements IFrameDMContext { + + final private int fLevel; + + FrameDMContext(String sessionId, IExecutionDMContext execDmc, int level) { + super(sessionId, new IDMContext[] { execDmc }); + fLevel = level; + } + + public int getLevel() { return fLevel; } + + @Override + public boolean equals(Object other) { + return super.baseEquals(other) && ((FrameDMContext)other).fLevel == fLevel; + } + + @Override + public int hashCode() { + return super.baseHashCode() ^ fLevel; + } + + @Override + public String toString() { + return baseToString() + ".frame[" + fLevel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Frame data based on the PDAFrame object returned by the PDA debugger. + */ + @Immutable + private static class FrameDMData implements IFrameDMData { + + final private PDAFrame fFrame; + + FrameDMData(PDAFrame frame) { + fFrame = frame; + } + + public String getFile() { + return fFrame.fFilePath.lastSegment(); + } + + public String getFunction() { + return fFrame.fFunction; + } + + public int getLine() { + return fFrame.fLine + 1; + } + + public int getColumn() { + return 0; + } + + public IAddress getAddress() { + return null; + } + } + + /** + * Context representing a variable in a given stack frame. + */ + @Immutable + private static class VariableDMContext extends AbstractDMContext implements IVariableDMContext { + + final private String fVariable; + + VariableDMContext(String sessionId, IFrameDMContext frameCtx, String variable) { + super(sessionId, new IDMContext[] { frameCtx }); + fVariable = variable; + } + + String getVariable() { return fVariable; } + + @Override + public boolean equals(Object other) { + return super.baseEquals(other) && ((VariableDMContext)other).fVariable.equals(fVariable); + } + + @Override + public int hashCode() { + return super.baseHashCode() + fVariable.hashCode(); + } + + @Override + public String toString() { + return baseToString() + ".variable(" + fVariable + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * PDA variable data, only supports returning the variable name. + */ + @Immutable + private static class VariableDMData implements IVariableDMData { + + final private String fVariable; + + VariableDMData(String variable) { + fVariable = variable; + } + + public String getName() { + return fVariable; + } + + public String getValue() { + return null; + } + } + + // Services that this service depends on. private PDACommandControl fCommandControl; private IRunControl fRunControl; + // Command cache private CommandCache fCommandCache; public PDAStack(DsfSession session) { @@ -66,12 +190,17 @@ public class PDAStack extends AbstractDsfService implements IStack { } private void doInitialize(final RequestMonitor rm) { + // Initialize service references that stack service depends on fCommandControl = getServicesTracker().getService(PDACommandControl.class); fRunControl = getServicesTracker().getService(IRunControl.class); + + // Create the commands cache fCommandCache = new CommandCache(fCommandControl); + // Register to listen for run control events, to clear cache accordingly. getSession().addServiceEventListener(this, null); + // Register stack service with OSGi register(new String[]{IStack.class.getName(), PDAStack.class.getName()}, new Hashtable()); rm.done(); @@ -84,46 +213,48 @@ public class PDAStack extends AbstractDsfService implements IStack { super.shutdown(rm); } + public void getArguments(IFrameDMContext frameCtx, DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.NOT_SUPPORTED, "PDA debugger does not support function arguments.", null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.NOT_SUPPORTED, "PDA debugger does not support function arguments."); } public void getFrameData(final IFrameDMContext frameCtx, final DataRequestMonitor rm) { - if ( !(frameCtx instanceof FrameDMContext) ) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context " + frameCtx, null)); //$NON-NLS-1$ - rm.done(); - return; - } - + // Execute the PDA stack command, or retrieve the result from cache if already available. fCommandCache.execute( - new PDAStackCommand(fCommandControl.getDMContext()), + new PDAStackCommand(fCommandControl.getProgramDMContext()), new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleOK() { + // PDAFrame array is ordered highest to lowest. We need to + // calculate the index based on frame level. int frameId = getData().fFrames.length - frameCtx.getLevel() - 1; if (frameId < 0) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid frame level " + frameCtx, null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid frame level " + frameCtx); return; } - + + // Create the frame data object based on the corresponding PDAFrame rm.setData(new FrameDMData(getData().fFrames[frameId])); rm.done(); } }); } + public void getFrames(IDMContext context, final DataRequestMonitor rm) { + // Can only create stack frames for an execution context as a parent, + // however the argument context is a generic context type, so it could + // be an execution context, a frame, a variable, etc. Search the + // hierarchy of the argument context to find the execution one. final IExecutionDMContext execCtx = DMContexts.getAncestorOfType(context, IExecutionDMContext.class); if (execCtx == null) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context " + context, null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid context " + context); return; } - + + // Execute the stack command and create the corresponding frame contexts. fCommandCache.execute( - new PDAStackCommand(fCommandControl.getDMContext()), + new PDAStackCommand(fCommandControl.getProgramDMContext()), new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleOK() { @@ -138,26 +269,21 @@ public class PDAStack extends AbstractDsfService implements IStack { } public void getLocals(final IFrameDMContext frameCtx, final DataRequestMonitor rm) { - if ( !(frameCtx instanceof FrameDMContext) ) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context " + frameCtx, null)); //$NON-NLS-1$ - rm.done(); - return; - } - + // Execute the stack command again. fCommandCache.execute( - new PDAStackCommand(fCommandControl.getDMContext()), + new PDAStackCommand(fCommandControl.getProgramDMContext()), new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleOK() { + // Find the correct PDAFrame int frameId = getData().fFrames.length - frameCtx.getLevel() - 1; if (frameId < 0) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid frame level " + frameCtx, null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid frame level " + frameCtx); return; } - - PDAFrame pdaFrame = getData().fFrames[frameId]; + + // Create variable contexts for all variables in frame. IVariableDMContext[] variableCtxs = new IVariableDMContext[pdaFrame.fVariables.length]; for (int i = 0; i < pdaFrame.fVariables.length; i++) { variableCtxs[i] = new VariableDMContext(getSession().getId(), frameCtx, pdaFrame.fVariables[i]); @@ -170,8 +296,9 @@ public class PDAStack extends AbstractDsfService implements IStack { } public void getStackDepth(IDMContext context, int maxDepth, final DataRequestMonitor rm) { + // Execute stack command and return the data's size. fCommandCache.execute( - new PDAStackCommand(fCommandControl.getDMContext()), + new PDAStackCommand(fCommandControl.getProgramDMContext()), new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleOK() { @@ -182,23 +309,30 @@ public class PDAStack extends AbstractDsfService implements IStack { } public void getTopFrame(IDMContext context, final DataRequestMonitor rm) { + // Can only create stack frames for an execution context as a parent, + // however the argument context is a generic context type, so it could + // be an execution context, a frame, a variable, etc. Search the + // hierarchy of the argument context to find the execution one. final IExecutionDMContext execCtx = DMContexts.getAncestorOfType(context, IExecutionDMContext.class); if (execCtx == null) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context " + context, null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid context " + context); return; } + + // Since the frame context only contain the level, there's no need to + // call the PDA debugger. Simply create a context for level 0. rm.setData(new FrameDMContext(getSession().getId(), execCtx, 0)); rm.done(); } public void getVariableData(IVariableDMContext variableCtx, DataRequestMonitor rm) { if ( !(variableCtx instanceof VariableDMContext) ) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Invalid context " + variableCtx, null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid context " + variableCtx); return; } + // The variable data doen't contain a value. So there's no need to + // go to the back end to retrieve it. String variable = ((VariableDMContext)variableCtx).getVariable(); rm.setData(new VariableDMData(variable)); @@ -206,26 +340,30 @@ public class PDAStack extends AbstractDsfService implements IStack { } public boolean isStackAvailable(IDMContext context) { + // Stack is available if the program is suspended or stepping. IExecutionDMContext execCtx = DMContexts.getAncestorOfType(context, IExecutionDMContext.class); return execCtx != null && (fRunControl.isSuspended(execCtx) || (fRunControl.isStepping(execCtx))); } + @SuppressWarnings("unchecked") @Deprecated public void getModelData(IDMContext dmc, DataRequestMonitor rm) { + // The getModelData() is deprecated and clients are expected to switch + // to getExecutionData() and other data retrieve methods directly. + // However the UI cache still uses it for now. if (dmc instanceof IFrameDMContext) { getFrameData((IFrameDMContext)dmc, (DataRequestMonitor)rm); - // getFrameData invokes rm } else if (dmc instanceof IVariableDMContext) { getVariableData((IVariableDMContext)dmc, (DataRequestMonitor)rm); - // getVariablesData invokes rm } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Unknown context type", null)); //$NON-NLS-1$ - rm.done(); + PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Unknown context type"); } } @DsfServiceEventHandler public void eventDispatched(IResumedDMEvent e) { + // Mark the cache as not available, so that stack commands will + // fail. Also reset the cache unless it was a step command. fCommandCache.setTargetAvailable(false); if (!e.getReason().equals(StateChangeReason.STEP)) { fCommandCache.reset(); @@ -235,6 +373,7 @@ public class PDAStack extends AbstractDsfService implements IStack { @DsfServiceEventHandler public void eventDispatched(ISuspendedDMEvent e) { + // Enable sending commands to target and clear the cache. fCommandCache.setTargetAvailable(true); fCommandCache.reset(); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDAStartedEvent.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStartedEvent.java similarity index 74% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDAStartedEvent.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStartedEvent.java index 0c9f16ab8d1..801c561f5bd 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDAStartedEvent.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDAStartedEvent.java @@ -8,15 +8,15 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command; +package org.eclipse.dd.examples.pda.service; import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; /** - * + * Event issued when the PDA debugger is started. */ -public class PDAStartedEvent extends AbstractDMEvent { - PDAStartedEvent(PDACommandControlDMContext context) { +public class PDAStartedEvent extends AbstractDMEvent { + PDAStartedEvent(PDAProgramDMContext context) { super(context); } } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDATerminatedEvent.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDATerminatedEvent.java similarity index 74% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDATerminatedEvent.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDATerminatedEvent.java index ebc43b642c5..0117f90c155 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDATerminatedEvent.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/PDATerminatedEvent.java @@ -8,15 +8,15 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command; +package org.eclipse.dd.examples.pda.service; import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; /** - * + * Event issued when the PDA debugger exits. */ -public class PDATerminatedEvent extends AbstractDMEvent { - PDATerminatedEvent(PDACommandControlDMContext context) { +public class PDATerminatedEvent extends AbstractDMEvent { + PDATerminatedEvent(PDAProgramDMContext context) { super(context); } } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/BreakpointDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/BreakpointDMContext.java deleted file mode 100644 index 0802693ccae..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/BreakpointDMContext.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.breakpoints; - -import org.eclipse.dd.dsf.concurrent.Immutable; -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; - -/** - * Context representing a PDA line breakpoint. In PDA debugger, since there is only - * one file being debugged at a time, a breakpoint is uniquely identified using the - * line number only. - */ -@Immutable -class BreakpointDMContext extends AbstractDMContext implements IBreakpointDMContext { - - final Integer fLine; - - public BreakpointDMContext(String sessionId, PDACommandControlDMContext commandControlCtx, Integer line) { - super(sessionId, new IDMContext[] { commandControlCtx }); - fLine = line; - } - - @Override - public boolean equals(Object obj) { - return baseEquals(obj) && (fLine.equals(((BreakpointDMContext) obj).fLine)); - } - - @Override - public int hashCode() { - return baseHashCode() + fLine.hashCode(); - } - - @Override - public String toString() { - return baseToString() + ".breakpoint(" + fLine + ")"; //$NON-NLS-1$//$NON-NLS-2$*/ - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpoints.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpoints.java deleted file mode 100644 index c943d8ae43c..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/PDABreakpoints.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Ericsson and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ericsson - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.dd.examples.pda.service.breakpoints; - -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; -import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.debug.service.IBreakpoints; -import org.eclipse.dd.dsf.service.AbstractDsfService; -import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.dsf.service.IDsfService; -import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.breakpoints.PDAWatchpoint; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; -import org.eclipse.dd.examples.pda.service.command.commands.PDAClearBreakpointCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDASetBreakpointCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDAWatchCommand; -import org.osgi.framework.BundleContext; - -/** - * Initial breakpoint service implementation. - * Implements the IBreakpoints interface. - */ -public class PDABreakpoints extends AbstractDsfService implements IBreakpoints -{ - public static final String ATTR_BREAKPOINT_TYPE = PDAPlugin.PLUGIN_ID + ".pdaBreakpointType"; //$NON-NLS-1$ - public static final String PDA_LINE_BREAKPOINT = "breakpoint"; //$NON-NLS-1$ - public static final String PDA_WATCHPOINT = "watchpoint"; //$NON-NLS-1$ - public static final String ATTR_PROGRAM_PATH = PDAPlugin.PLUGIN_ID + ".pdaProgramPath"; //$NON-NLS-1$ - - private final String fProgram; - - // Services - private PDACommandControl fCommandControl; - - // Service breakpoints tracking - // The breakpoints are stored per context and keyed on the back-end breakpoint reference - private Set fBreakpoints = new HashSet(); - - /** - * The service constructor - * - * @param session The debugging session this service belongs to. - * @param program The name of the program of this PDA debugger. - */ - public PDABreakpoints(DsfSession session, String program) { - super(session); - fProgram = program; - } - - @Override - public void initialize(final RequestMonitor rm) { - super.initialize(new RequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - doInitialize(rm); - } - }); - } - - private void doInitialize(final RequestMonitor rm) { - - // Get the services references - fCommandControl = getServicesTracker().getService(PDACommandControl.class); - - // Register this service - register(new String[] { IBreakpoints.class.getName(), PDABreakpoints.class.getName() }, - new Hashtable()); - - rm.done(); - } - - @Override - public void shutdown(final RequestMonitor rm) { - unregister(); - rm.done(); - } - - @Override - protected BundleContext getBundleContext() { - return PDAPlugin.getBundleContext(); - } - - public void getBreakpoints(final IBreakpointsTargetDMContext context, final DataRequestMonitor rm) { - // Validate the context - if (!fCommandControl.getDMContext().equals(context)) { - PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid breakpoints target context"); - return; - } - - rm.setData(fBreakpoints.toArray(new IBreakpointDMContext[fBreakpoints.size()])); - rm.done(); - } - - public void getBreakpointDMData(IBreakpointDMContext dmc, DataRequestMonitor rm) { - PDAPlugin.failRequest(rm, IDsfService.NOT_SUPPORTED, "Retrieving breakpoint data is not supported"); - } - - public void insertBreakpoint(IBreakpointsTargetDMContext context, Map attributes, - DataRequestMonitor rm) - { - String type = (String) attributes.get(ATTR_BREAKPOINT_TYPE); - - if (PDA_LINE_BREAKPOINT.equals(type)) { - doInsertBreakpoint(attributes, rm); - } - else if (PDA_WATCHPOINT.equals(type)) { - doInsertWatchpoint(attributes, rm); - } - else { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "Unknown breakpoint type"); - } - } - - private void doInsertBreakpoint(final Map attributes, final DataRequestMonitor rm) - { - String program = (String)attributes.get(ATTR_PROGRAM_PATH); - if (!fProgram.equals(program)) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "Invalid file name"); - return; - } - - Integer line = (Integer)attributes.get(IMarker.LINE_NUMBER); - if (line == null) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "No breakpoint line specified"); - return; - } - - final BreakpointDMContext breakpointCtx = - new BreakpointDMContext(getSession().getId(), fCommandControl.getDMContext(), line); - if (fBreakpoints.contains(breakpointCtx)) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "Breakpoint already set"); - return; - } - - fBreakpoints.add(breakpointCtx); - fCommandControl.queueCommand( - new PDASetBreakpointCommand(fCommandControl.getDMContext(), line), - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - rm.setData(breakpointCtx); - rm.done(); - } - - @Override - protected void handleErrorOrCancel() { - fBreakpoints.remove(breakpointCtx); - super.handleErrorOrCancel(); - } - }); - } - - private void doInsertWatchpoint(final Map attributes, final DataRequestMonitor rm) - { - String function = (String)attributes.get(PDAWatchpoint.FUNCTION_NAME); - if (function == null) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "No function specified"); - return; - } - - String variable = (String)attributes.get(PDAWatchpoint.VAR_NAME); - if (variable == null) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "No variable specified"); - return; - } - - Boolean isAccess = (Boolean)attributes.get(PDAWatchpoint.ACCESS); - isAccess = isAccess != null ? isAccess : Boolean.FALSE; - - Boolean isModification = (Boolean)attributes.get(PDAWatchpoint.MODIFICATION); - isModification = isModification != null ? isModification : Boolean.FALSE; - - final WatchpointDMContext watchpointCtx = - new WatchpointDMContext(getSession().getId(), fCommandControl.getDMContext(), function, variable); - if (fBreakpoints.contains(watchpointCtx)) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "Watchpoint already set"); - return; - } - - PDAWatchCommand.WatchOperation watchOperation = PDAWatchCommand.WatchOperation.NONE; - if (isAccess && isModification) { - watchOperation = PDAWatchCommand.WatchOperation.BOTH; - } else if (isAccess) { - watchOperation = PDAWatchCommand.WatchOperation.READ; - } else if (isModification) { - watchOperation = PDAWatchCommand.WatchOperation.WRITE; - } - - fBreakpoints.add(watchpointCtx); - fCommandControl.queueCommand( - new PDAWatchCommand(fCommandControl.getDMContext(), function, variable, watchOperation), - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - rm.setData(watchpointCtx); - rm.done(); - } - - @Override - protected void handleErrorOrCancel() { - // Since the command failed, we need to remove the breakpoint from - // the existing breakpoint set. - fBreakpoints.remove(watchpointCtx); - super.handleErrorOrCancel(); - } - }); - } - - public void removeBreakpoint(IBreakpointDMContext bpCtx, RequestMonitor rm) { - if (!fBreakpoints.contains(bpCtx)) { - PDAPlugin.failRequest(rm, IDsfService.REQUEST_FAILED, "Breakpoint already removed"); - return; - } - - if (bpCtx instanceof BreakpointDMContext) { - doRemoveBreakpoint((BreakpointDMContext)bpCtx, rm); - } else if (bpCtx instanceof WatchpointDMContext) { - doRemoveWatchpoint((WatchpointDMContext)bpCtx, rm); - } else { - PDAPlugin.failRequest(rm, IDsfService.INVALID_HANDLE, "Invalid breakpoint"); - } - } - - private void doRemoveBreakpoint(BreakpointDMContext bpCtx, RequestMonitor rm) { - // Remove the breakpoint from the table right away, so that even when - // the remove is being processed, a new breakpoint can be created at the same - // location. - fBreakpoints.remove(bpCtx); - - fCommandControl.queueCommand( - new PDAClearBreakpointCommand(fCommandControl.getDMContext(), bpCtx.fLine), - new DataRequestMonitor(getExecutor(), rm)); - } - - private void doRemoveWatchpoint(WatchpointDMContext bpCtx, RequestMonitor rm) { - fBreakpoints.remove(bpCtx); - - // Watchpoints are cleared using the same command, but with a "no watch" operation - fCommandControl.queueCommand( - new PDAWatchCommand(fCommandControl.getDMContext(), bpCtx.fFunction, bpCtx.fVariable, - PDAWatchCommand.WatchOperation.NONE), - new DataRequestMonitor(getExecutor(), rm)); - } - - public void updateBreakpoint(IBreakpointDMContext dmc, Map properties, RequestMonitor rm) { - PDAPlugin.failRequest(rm, IDsfService.NOT_SUPPORTED, "Modifying PDA breakpoints is not supported"); - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/WatchpointDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/WatchpointDMContext.java deleted file mode 100644 index 6e0e7252a87..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/breakpoints/WatchpointDMContext.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.breakpoints; - -import org.eclipse.dd.dsf.concurrent.Immutable; -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; - -/** - * Context representing a watch point. In PDA debugger, a watchpoint is - * uniquely identified using the function and variable. - */ -@Immutable -class WatchpointDMContext extends AbstractDMContext implements IBreakpointDMContext { - final String fFunction; - final String fVariable; - - public WatchpointDMContext(String sessionId, PDACommandControlDMContext commandControlCtx, String function, - String variable) - { - super(sessionId, new IDMContext[] { commandControlCtx }); - fFunction = function; - fVariable = variable; - } - - @Override - public boolean equals(Object obj) { - if (baseEquals(obj)) { - WatchpointDMContext watchpointCtx = (WatchpointDMContext)obj; - return fFunction.equals(watchpointCtx.fFunction) && fVariable.equals(watchpointCtx.fVariable); - } - return false; - } - - @Override - public int hashCode() { - return baseHashCode() + fFunction.hashCode() + fVariable.hashCode(); - } - - @Override - public String toString() { - return baseToString() + ".watchpoint(" + fFunction + "::" + fVariable + ")"; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControlDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControlDMContext.java deleted file mode 100644 index 2b34baf4477..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandControlDMContext.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command; - -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; - -/** - * - */ -public class PDACommandControlDMContext extends AbstractDMContext - implements IExecutionDMContext, IBreakpointsTargetDMContext -{ - - private Object fHashObject = new Object(); - - public PDACommandControlDMContext(String sessionId) { - super(sessionId, new IDMContext[0]); - } - - @Override - public boolean equals(Object obj) { - return obj == this; - } - - @Override - public int hashCode() { - return fHashObject.hashCode(); - } - - @Override - public String toString() { - return "PDA(" + getSessionId() + ")"; - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommandResult.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommandResult.java deleted file mode 100644 index 3275256f41a..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommandResult.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; - -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; - - -/** - * @see PDAVarCommand - */ -public class PDAVarCommandResult extends PDACommandResult { - - final public int fValue; - - PDAVarCommandResult(String response) { - super(response); - fValue = Integer.parseInt(response); - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/AbstractPDACommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/AbstractPDACommand.java similarity index 68% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/AbstractPDACommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/AbstractPDACommand.java index 719df9cd6ae..bd75d996c63 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/AbstractPDACommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/AbstractPDACommand.java @@ -8,23 +8,24 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; import org.eclipse.dd.dsf.datamodel.IDMContext; import org.eclipse.dd.dsf.debug.service.command.ICommand; import org.eclipse.dd.dsf.debug.service.command.ICommandResult; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** - * + * Base class for PDA commands. The PDA commands consist of a text request and + * a context. Since the PDA debugger protocol is stateless, the context is only + * needed to satisfy the ICommand interface. */ abstract public class AbstractPDACommand implements ICommand { final private IDMContext fContext; final private String fRequest; - public AbstractPDACommand(PDACommandControlDMContext context, String request) { + public AbstractPDACommand(PDAProgramDMContext context, String request) { fContext = context; fRequest = request; } @@ -36,11 +37,20 @@ abstract public class AbstractPDACommand implements public ICommand coalesceWith(ICommand command) { return null; } - + + /** + * Returns the request to be sent to PDA. + */ public String getRequest() { return fRequest; } - + + /** + * Returns the command result based on the given PDA response. This command + * uses the class type parameter as the return type to allow the compiler to + * enforce the correct command result. This class must be implemented by + * each command to create the concrete result type. + */ abstract public V createResult(String resultText); @Override diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAClearBreakpointCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAClearBreakpointCommand.java similarity index 75% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAClearBreakpointCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAClearBreakpointCommand.java index a394fb2e7f3..b0873d3254d 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAClearBreakpointCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAClearBreakpointCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Clears any breakpoint set on given line @@ -24,7 +23,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAClearBreakpointCommand extends AbstractPDACommand { - public PDAClearBreakpointCommand(PDACommandControlDMContext context, int line) { + public PDAClearBreakpointCommand(PDAProgramDMContext context, int line) { super(context, "clear " + (line - 1)); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandResult.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDACommandResult.java similarity index 84% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandResult.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDACommandResult.java index 31f49a68b55..053f2e99796 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/PDACommandResult.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDACommandResult.java @@ -8,14 +8,16 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command; +package org.eclipse.dd.examples.pda.service.commands; import org.eclipse.dd.dsf.debug.service.command.ICommand; import org.eclipse.dd.dsf.debug.service.command.ICommandResult; /** - * + * Basic command result object. This command result simply allows access to the + * PDA response. Sub-classes may override to optionally parse the response text + * and return higher-level objects. */ public class PDACommandResult implements ICommandResult { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommand.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommand.java index 835f5a638a5..fab0f679ba0 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Retrieves data stack information @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDADataCommand extends AbstractPDACommand { - public PDADataCommand(PDACommandControlDMContext context) { + public PDADataCommand(PDAProgramDMContext context) { super(context, "data"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommandResult.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommandResult.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommandResult.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommandResult.java index 20e895eeab8..e31b1c8ae58 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADataCommandResult.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADataCommandResult.java @@ -8,35 +8,33 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; /** * @see PDADataCommand */ public class PDADataCommandResult extends PDACommandResult { - final public int[] fValues; + final public String[] fValues; PDADataCommandResult(String response) { super(response); StringTokenizer st = new StringTokenizer(response, "|"); - List valuesList = new ArrayList(); + List valuesList = new ArrayList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.length() != 0) { - valuesList.add(new Integer(st.nextToken())); + valuesList.add(st.nextToken()); } } - - fValues = new int[valuesList.size()]; + fValues = new String[valuesList.size()]; for (int i = 0; i < valuesList.size(); i++) { fValues[i] = valuesList.get(i); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADropFrameCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADropFrameCommand.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADropFrameCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADropFrameCommand.java index 0c09a9b4f87..1a1f4cc8f92 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDADropFrameCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDADropFrameCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Returns from the current frame without executing the rest of instructions. @@ -26,7 +25,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDADropFrameCommand extends AbstractPDACommand { - public PDADropFrameCommand(PDACommandControlDMContext context) { + public PDADropFrameCommand(PDAProgramDMContext context) { super(context, "drop"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEvalCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEvalCommand.java similarity index 79% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEvalCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEvalCommand.java index da38d1957cf..082362e7415 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEvalCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEvalCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets what events cause the execution to stop. @@ -28,7 +27,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAEvalCommand extends AbstractPDACommand { - public PDAEvalCommand(PDACommandControlDMContext context, String operation) { + public PDAEvalCommand(PDAProgramDMContext context, String operation) { super(context, "eval " + operation); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEventStopCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEventStopCommand.java similarity index 80% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEventStopCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEventStopCommand.java index d19369f99d4..653f2aa945a 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAEventStopCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAEventStopCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets what events cause the execution to stop. @@ -29,7 +28,7 @@ public class PDAEventStopCommand extends AbstractPDACommand { public enum Event { UNIMPINSTR, NOSUCHLABEL }; - public PDAEventStopCommand(PDACommandControlDMContext context, Event event, boolean enable) { + public PDAEventStopCommand(PDAProgramDMContext context, Event event, boolean enable) { super(context, "eventstop " + (event == Event.UNIMPINSTR ? "unimpinstr " : "nosuchlabel ") + diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAExitCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAExitCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAExitCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAExitCommand.java index dd074c3ed1f..0514aa675f5 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAExitCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAExitCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Instructs the debugger to exit. @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAExitCommand extends AbstractPDACommand { - public PDAExitCommand(PDACommandControlDMContext context) { + public PDAExitCommand(PDAProgramDMContext context) { super(context, "exit"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAFrame.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAFrame.java similarity index 89% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAFrame.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAFrame.java index bc427e21fa4..ab2b2c5612a 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAFrame.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAFrame.java @@ -8,7 +8,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; import java.util.ArrayList; import java.util.List; @@ -17,7 +17,18 @@ import java.util.StringTokenizer; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +/** + * Object representing a frame in the stack command results. + * + * @see PDAStackCommand + */ public class PDAFrame { + + final public IPath fFilePath; + final public int fLine; + final public String fFunction; + final public String[] fVariables; + PDAFrame(String frameString) { StringTokenizer st = new StringTokenizer(frameString, "|"); @@ -31,8 +42,4 @@ public class PDAFrame { } fVariables = variablesList.toArray(new String[variablesList.size()]); } - final public IPath fFilePath; - final public int fLine; - final public String fFunction; - final public String[] fVariables; } \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPopDataCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPopDataCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPopDataCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPopDataCommand.java index 1f35dba715f..952e53cd17c 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPopDataCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPopDataCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Pops the top value from the data stack @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAPopDataCommand extends AbstractPDACommand { - public PDAPopDataCommand(PDACommandControlDMContext context) { + public PDAPopDataCommand(PDAProgramDMContext context) { super(context, "popdata"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPushDataCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPushDataCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPushDataCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPushDataCommand.java index a2b817e776c..7226c765518 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAPushDataCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAPushDataCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Pushes the given value on top of the data stack. @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAPushDataCommand extends AbstractPDACommand { - public PDAPushDataCommand(PDACommandControlDMContext context, int value) { + public PDAPushDataCommand(PDAProgramDMContext context, int value) { super(context, "pushdata " + value); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAResumeCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAResumeCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAResumeCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAResumeCommand.java index 40582908460..35b83c35a13 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAResumeCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAResumeCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Resumes the execution @@ -24,7 +23,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAResumeCommand extends AbstractPDACommand { - public PDAResumeCommand(PDACommandControlDMContext context) { + public PDAResumeCommand(PDAProgramDMContext context) { super(context, "resume"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetBreakpointCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetBreakpointCommand.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetBreakpointCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetBreakpointCommand.java index a46ce388d2c..7dd14c6456a 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetBreakpointCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetBreakpointCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets a breakpoint at given line @@ -26,7 +25,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDASetBreakpointCommand extends AbstractPDACommand { - public PDASetBreakpointCommand(PDACommandControlDMContext context, int line) { + public PDASetBreakpointCommand(PDAProgramDMContext context, int line) { super(context, "set " + (line - 1)); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetDataCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetDataCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetDataCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetDataCommand.java index fc4a94992da..b66772f8688 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetDataCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetDataCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets a data value in the data stack at the given location @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDASetDataCommand extends AbstractPDACommand { - public PDASetDataCommand(PDACommandControlDMContext context, int index, int value) { + public PDASetDataCommand(PDAProgramDMContext context, int index, String value) { super(context, "setdata " + index + " " + value); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetVarCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetVarCommand.java similarity index 67% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetVarCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetVarCommand.java index cafbe6d1372..5fcf7d77b49 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASetVarCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASetVarCommand.java @@ -8,23 +8,22 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets a variable value * *
- *    C: setvar {variable} {value}
+ *    C: setvar {frame_number} {variable} {value}
  *    R: ok
  * 
*/ public class PDASetVarCommand extends AbstractPDACommand { - public PDASetVarCommand(PDACommandControlDMContext context, String variable, String value) { - super(context, "setvar " + variable + " " + value); + public PDASetVarCommand(PDAProgramDMContext context, int frame, String variable, String value) { + super(context, "setvar " + frame + " " + variable + " " + value); } @Override diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommand.java similarity index 82% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommand.java index 3db048e2c4e..cd26fa07ff5 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommand.java @@ -8,9 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Retrieves command stack information @@ -22,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; */ public class PDAStackCommand extends AbstractPDACommand { - public PDAStackCommand(PDACommandControlDMContext context) { + public PDAStackCommand(PDAProgramDMContext context) { super(context, "stack"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommandResult.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommandResult.java similarity index 85% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommandResult.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommandResult.java index 1b4e07e5560..5cc1bf1fc71 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStackCommandResult.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStackCommandResult.java @@ -8,19 +8,22 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; /** * @see PDAStackCommand */ public class PDAStackCommandResult extends PDACommandResult { + /** + * Array of frames return by the stack commands. The frames are ordered + * with the highest-level frame first. + */ final public PDAFrame[] fFrames; PDAStackCommandResult(String response) { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepCommand.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepCommand.java index 9a3f536fbc5..a50713acc8b 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Executes next instruciton @@ -25,7 +24,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAStepCommand extends AbstractPDACommand { - public PDAStepCommand(PDACommandControlDMContext context) { + public PDAStepCommand(PDAProgramDMContext context) { super(context, "step"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepReturnCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepReturnCommand.java similarity index 77% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepReturnCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepReturnCommand.java index 4d1d6ec6996..8ba0dedfb3b 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAStepReturnCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAStepReturnCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Executes instructions until the current subroutine is finished @@ -25,7 +24,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAStepReturnCommand extends AbstractPDACommand { - public PDAStepReturnCommand(PDACommandControlDMContext context) { + public PDAStepReturnCommand(PDAProgramDMContext context) { super(context, "stepreturn"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASuspendCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASuspendCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASuspendCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASuspendCommand.java index 8972c83f830..f1c7e548b85 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDASuspendCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDASuspendCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Suspends execution @@ -24,7 +23,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDASuspendCommand extends AbstractPDACommand { - public PDASuspendCommand(PDACommandControlDMContext context) { + public PDASuspendCommand(PDAProgramDMContext context) { super(context, "suspend"); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAVarCommand.java similarity index 76% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAVarCommand.java index 95280892e65..745fa86a491 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAVarCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAVarCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Retrieves variable value @@ -23,7 +22,7 @@ import org.eclipse.dd.examples.pda.service.command.PDACommandResult; */ public class PDAVarCommand extends AbstractPDACommand { - public PDAVarCommand(PDACommandControlDMContext context, int frameId, String name) { + public PDAVarCommand(PDAProgramDMContext context, int frameId, String name) { super(context, "var " + frameId + " " + name); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAWatchCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAWatchCommand.java similarity index 81% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAWatchCommand.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAWatchCommand.java index 7d23b37c087..91d54e942a0 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/command/commands/PDAWatchCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/commands/PDAWatchCommand.java @@ -8,10 +8,9 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.command.commands; +package org.eclipse.dd.examples.pda.service.commands; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; /** * Sets a watchpoint on a given variable @@ -41,7 +40,7 @@ public class PDAWatchCommand extends AbstractPDACommand { } } - public PDAWatchCommand(PDACommandControlDMContext context, String function, String variable, WatchOperation operation) { + public PDAWatchCommand(PDAProgramDMContext context, String function, String variable, WatchOperation operation) { super(context, "watch " + function+ "::" + variable + " " + getWatchOperationCode(operation)); } diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMContext.java deleted file mode 100644 index 477ee85f6de..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMContext.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.expressions; - -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMContext; -import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; - -/** - * - */ -public class ExpressionDMContext extends AbstractDMContext implements IExpressionDMContext { - - private final String fExpression; - - ExpressionDMContext(String sessionId, IFrameDMContext frameDmc, String expressin) { - super(sessionId, new IDMContext[] { frameDmc }); - fExpression = expressin; - } - - public String getExpression() { - return fExpression; - } - - @Override - public boolean equals(Object other) { - return super.baseEquals(other) && ((ExpressionDMContext)other).fExpression.equals(fExpression); - } - - @Override - public int hashCode() { - return super.baseHashCode() + fExpression.hashCode(); - } - - @Override - public String toString() { - return baseToString() + ".expression(" + fExpression + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMData.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMData.java deleted file mode 100644 index 2929f61c020..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/ExpressionDMData.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.expressions; - -import java.util.Map; - -import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMData; -import org.eclipse.dd.dsf.debug.service.IRegisters.IRegisterDMContext; - -/** - * - */ -public class ExpressionDMData implements IExpressionDMData { - - final private String fExpression; - - public ExpressionDMData(String expression) { - fExpression = expression; - } - - public BasicType getBasicType() { - return BasicType.basic; - } - - public String getEncoding() { - return null; - } - - public Map getEnumerations() { - return null; - } - - public String getName() { - return fExpression; - } - - public IRegisterDMContext getRegister() { - return null; - } - - public String getStringValue() { - return null; - } - - public String getTypeId() { - return null; - } - - public String getTypeName() { - return null; - } - -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/InvalidExpressionDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/InvalidExpressionDMContext.java deleted file mode 100644 index 56124e06f87..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/InvalidExpressionDMContext.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.expressions; - -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMContext; - -class InvalidExpressionDMContext extends AbstractDMContext - implements IExpressionDMContext -{ - private final String expression; - - public InvalidExpressionDMContext(String sessionId, IDMContext parent, String expr) { - super(sessionId, new IDMContext[] { parent }); - expression = expr; - } - - @Override - public boolean equals(Object other) { - return super.baseEquals(other) && - expression == null - ? ((InvalidExpressionDMContext) other).getExpression() == null - : expression.equals(((InvalidExpressionDMContext) other).getExpression()); - } - - @Override - public int hashCode() { - return expression == null ? super.baseHashCode() : super.baseHashCode() ^ expression.hashCode(); - } - - @Override - public String toString() { - return baseToString() + ".invalid_expr[" + expression + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public String getExpression() { - return expression; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/PDAExpressions.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/PDAExpressions.java deleted file mode 100644 index 550882bc74c..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/expressions/PDAExpressions.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.expressions; - -import java.util.Hashtable; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; -import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.datamodel.DMContexts; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IExpressions; -import org.eclipse.dd.dsf.debug.service.IStack; -import org.eclipse.dd.dsf.debug.service.IRunControl.IResumedDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.ISuspendedDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.StateChangeReason; -import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; -import org.eclipse.dd.dsf.debug.service.command.CommandCache; -import org.eclipse.dd.dsf.service.AbstractDsfService; -import org.eclipse.dd.dsf.service.DsfServiceEventHandler; -import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; -import org.eclipse.dd.examples.pda.service.command.commands.PDASetVarCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDAVarCommand; -import org.osgi.framework.BundleContext; - -/** - * - */ -public class PDAExpressions extends AbstractDsfService implements IExpressions { - - private PDACommandControl fCommandControl; - private IStack fStack; - - private CommandCache fCommandCache; - - public PDAExpressions(DsfSession session) { - super(session); - } - - @Override - protected BundleContext getBundleContext() { - return PDAPlugin.getBundleContext(); - } - - @Override - public void initialize(final RequestMonitor rm) { - super.initialize( - new RequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - doInitialize(rm); - }}); - } - - private void doInitialize(final RequestMonitor rm) { - fCommandControl = getServicesTracker().getService(PDACommandControl.class); - fStack = getServicesTracker().getService(IStack.class); - fCommandCache = new CommandCache(fCommandControl); - - getSession().addServiceEventListener(this, null); - - register(new String[]{IExpressions.class.getName(), PDAExpressions.class.getName()}, new Hashtable()); - - rm.done(); - } - - @Override - public void shutdown(final RequestMonitor rm) { - getSession().removeServiceEventListener(this); - fCommandCache.reset(); - super.shutdown(rm); - } - - public void canWriteExpression(IExpressionDMContext expressionContext, DataRequestMonitor rm) { - rm.setData(true); - rm.done(); - } - - public IExpressionDMContext createExpression(IDMContext ctx, String expression) { - IFrameDMContext frameCtx = DMContexts.getAncestorOfType(ctx, IFrameDMContext.class); - if (frameCtx != null) { - return new ExpressionDMContext(getSession().getId(), frameCtx, expression); - } else { - return new InvalidExpressionDMContext(getSession().getId(), ctx, expression); - } - } - - public void getBaseExpressions(IExpressionDMContext exprContext, DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getExpressionAddressData(IExpressionDMContext dmc, DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getExpressionData(final IExpressionDMContext exprCtx, final DataRequestMonitor rm) { - if (exprCtx instanceof ExpressionDMContext) { - rm.setData(new ExpressionDMData(exprCtx.getExpression())); - rm.done(); - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid expression context " + exprCtx, null)); //$NON-NLS-1$ - rm.done(); - } - } - - public void getSubExpressionCount(IExpressionDMContext exprCtx, DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getSubExpressions(IExpressionDMContext exprCtx, DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getSubExpressions(IExpressionDMContext exprCtx, int startIndex, int length, - DataRequestMonitor rm) - { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$ - rm.done(); - } - - - public void writeExpression(IExpressionDMContext exprCtx, String exprValue, String formatId, RequestMonitor rm) - { - if (exprCtx instanceof ExpressionDMContext) { - fCommandCache.execute( - new PDASetVarCommand(fCommandControl.getDMContext(), exprCtx.getExpression(), exprValue), - new DataRequestMonitor(getExecutor(), rm)); - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid expression context " + exprCtx, null)); //$NON-NLS-1$ - rm.done(); - } - } - - public void getAvailableFormats(IFormattedDataDMContext dmc, DataRequestMonitor rm) { - rm.setData(new String[] { NATURAL_FORMAT }); - rm.done(); - } - - public FormattedValueDMContext getFormattedValueContext(IFormattedDataDMContext dmc, String formatId) { - return new FormattedValueDMContext(this, dmc, formatId); - } - - public void getFormattedExpressionValue(FormattedValueDMContext formattedCtx, final DataRequestMonitor rm) { - final ExpressionDMContext exprCtx = DMContexts.getAncestorOfType(formattedCtx, ExpressionDMContext.class); - if (exprCtx != null) { - getExpressionValue( - exprCtx, - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - rm.setData(new FormattedValueDMData(getData())); - rm.done(); - } - }); - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid expression context " + formattedCtx, null)); //$NON-NLS-1$ - rm.done(); - } - } - - private void getExpressionValue(final ExpressionDMContext exprCtx, final DataRequestMonitor rm) { - final IFrameDMContext frameCtx = DMContexts.getAncestorOfType(exprCtx, IFrameDMContext.class); - fStack.getStackDepth( - frameCtx, 0, - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - int frameId = getData() - frameCtx.getLevel() - 1; - fCommandCache.execute( - new PDAVarCommand(fCommandControl.getDMContext(), frameId, exprCtx.getExpression()), - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - rm.setData(getData().fResponseText); - rm.done(); - } - }); - } - }); - } - - @Deprecated - public void getModelData(IDMContext dmc, DataRequestMonitor rm) { - if (dmc instanceof IExpressionDMContext) { - getExpressionData((IExpressionDMContext) dmc, (DataRequestMonitor) rm); - } else if (dmc instanceof FormattedValueDMContext) { - getFormattedExpressionValue((FormattedValueDMContext) dmc, (DataRequestMonitor) rm); - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_HANDLE, "Unknown DMC type", null)); //$NON-NLS-1$ - rm.done(); - } - } - - @DsfServiceEventHandler - public void eventDispatched(IResumedDMEvent e) { - fCommandCache.setTargetAvailable(false); - if (!e.getReason().equals(StateChangeReason.STEP)) { - fCommandCache.reset(); - } - } - - - @DsfServiceEventHandler - public void eventDispatched(ISuspendedDMEvent e) { - fCommandCache.setTargetAvailable(true); - fCommandCache.reset(); - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ExecutionData.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ExecutionData.java deleted file mode 100644 index 8591e79c690..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ExecutionData.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.runcontrol; - -import org.eclipse.dd.dsf.concurrent.Immutable; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMData; -import org.eclipse.dd.dsf.debug.service.IRunControl.StateChangeReason; - -@Immutable -class ExecutionData implements IExecutionDMData { - private final StateChangeReason fReason; - ExecutionData(StateChangeReason reason) { - fReason = reason; - } - public StateChangeReason getStateChangeReason() { return fReason; } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/PDARunControl.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/PDARunControl.java deleted file mode 100644 index 5bc8ec49f41..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/PDARunControl.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - * Ericsson AB - Modified for handling of multiple threads - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.runcontrol; - -import java.util.Hashtable; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; -import org.eclipse.dd.dsf.concurrent.RequestMonitor; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.datamodel.IDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl; -import org.eclipse.dd.dsf.debug.service.command.CommandCache; -import org.eclipse.dd.dsf.debug.service.command.IEventListener; -import org.eclipse.dd.dsf.service.AbstractDsfService; -import org.eclipse.dd.dsf.service.DsfServiceEventHandler; -import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.dsf.service.IDsfService; -import org.eclipse.dd.examples.pda.PDAPlugin; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; -import org.eclipse.dd.examples.pda.service.command.commands.PDAResumeCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDAStepCommand; -import org.eclipse.dd.examples.pda.service.command.commands.PDASuspendCommand; -import org.osgi.framework.BundleContext; - - -/** - * - *

- * Implementation note: - * This class implements event handlers for the events that are generated by - * this service itself. When the event is dispatched, these handlers will - * be called first, before any of the clients. These handlers update the - * service's internal state information to make them consistent with the - * events being issued. Doing this in the handlers as opposed to when - * the events are generated, guarantees that the state of the service will - * always be consistent with the events. - * The purpose of this pattern is to allow clients that listen to service - * events and track service state, to be perfectly in sync with the service - * state. - */ -public class PDARunControl extends AbstractDsfService - implements IRunControl, IEventListener -{ - private PDACommandControl fCommandControl; - private CommandCache fCommandCache; - - // state flags - private boolean fSuspended = true; - private boolean fResumePending = false; - private boolean fStepping = false; - - private StateChangeReason fStateChangeReason; - - public PDARunControl(DsfSession session) { - super(session); - } - - @Override - protected BundleContext getBundleContext() { - return PDAPlugin.getBundleContext(); - } - - @Override - public void initialize(final RequestMonitor rm) { - super.initialize( - new RequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - doInitialize(rm); - }}); - } - - private void doInitialize(final RequestMonitor rm) { - fCommandControl = getServicesTracker().getService(PDACommandControl.class); - fCommandCache = new CommandCache(fCommandControl); - - fCommandControl.addEventListener(this); - getSession().addServiceEventListener(this, null); - - register(new String[]{IRunControl.class.getName(), PDARunControl.class.getName()}, new Hashtable()); - - rm.done(); - } - - @Override - public void shutdown(final RequestMonitor rm) { - fCommandControl.removeEventListener(this); - - getSession().removeServiceEventListener(this); - fCommandCache.reset(); - super.shutdown(rm); - } - - @SuppressWarnings("unchecked") - public void getModelData(IDMContext dmc, DataRequestMonitor rm) { - if (dmc instanceof IExecutionDMContext) { - getExecutionData((IExecutionDMContext)dmc, (DataRequestMonitor)rm); - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_HANDLE, "Unknown DMC type", null)); //$NON-NLS-1$ - rm.done(); - } - } - - public void eventReceived(Object output) { - if (!(output instanceof String)) return; - String event = (String)output; - - if (event.startsWith("suspended")) { - suspendedEventReceived(event); - } else if (event.startsWith("resumed")) { - resumedEventReceived(event); - } - } - - private void suspendedEventReceived(String event) { - IDMEvent dmEvent = new SuspendedEvent(fCommandControl.getDMContext(), event); - getSession().dispatchEvent(dmEvent, getProperties()); - } - - - @DsfServiceEventHandler - private void resumedEventReceived(String event) { - IDMEvent dmEvent = new ResumedEvent(fCommandControl.getDMContext(), event); - getSession().dispatchEvent(dmEvent, getProperties()); - } - - - @DsfServiceEventHandler - public void eventDispatched(ResumedEvent e) { - fSuspended = false; - fResumePending = false; - fStateChangeReason = e.getReason(); - fCommandCache.setTargetAvailable(false); - if (e.getReason().equals(StateChangeReason.STEP)) { - fStepping = true; - } else { - fCommandCache.reset(); - } - } - - - @DsfServiceEventHandler - public void eventDispatched(SuspendedEvent e) { - fCommandCache.setTargetAvailable(true); - fCommandCache.reset(); - fStateChangeReason = e.getReason(); - fResumePending = false; - fSuspended = true; - fStepping = false; - } - - - public boolean canResume(IExecutionDMContext context) { - return isSuspended(context) && !fResumePending; - } - - public boolean canSuspend(IExecutionDMContext context) { - return !isSuspended(context); - } - - public boolean isSuspended(IExecutionDMContext context) { - return fSuspended; - } - - public boolean isStepping(IExecutionDMContext context) { - return !isSuspended(context) && fStepping; - } - - public void resume(IExecutionDMContext context, final RequestMonitor rm) { - assert context != null; - - if (canResume(context)) { - fResumePending = true; - // Cygwin GDB will accept commands and execute them after the step - // which is not what we want, so mark the target as unavailable - // as soon as we send a resume command. - fCommandCache.setTargetAvailable(false); - - fCommandControl.queueCommand( - new PDAResumeCommand(fCommandControl.getDMContext()), - new DataRequestMonitor(getExecutor(), rm) { - @Override - protected void handleOK() { - rm.done(); - } - } - ); - }else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_STATE, "Given context: " + context + ", is already running.", null)); //$NON-NLS-1$ //$NON-NLS-2$ - rm.done(); - } - } - - public void suspend(IExecutionDMContext context, final RequestMonitor rm){ - assert context != null; - - if (canSuspend(context)) { - fCommandControl.queueCommand( - new PDASuspendCommand(fCommandControl.getDMContext()), - new DataRequestMonitor(getExecutor(), rm)); - - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, IDsfService.INVALID_STATE, "Given context: " + context + ", is already suspended.", null)); //$NON-NLS-1$ //$NON-NLS-2$ - rm.done(); - } - } - - public boolean canStep(IExecutionDMContext context) { - return canResume(context); - } - - public void step(IExecutionDMContext context, StepType stepType, final RequestMonitor rm) { - assert context != null; - - if (canResume(context)) { - fResumePending = true; - fStepping = true; - fCommandCache.setTargetAvailable(false); - - fCommandControl.queueCommand( - new PDAStepCommand(fCommandControl.getDMContext()), - new DataRequestMonitor(getExecutor(), rm)); - - } else { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, INVALID_STATE, "Cannot resume context", null)); //$NON-NLS-1$ - rm.done(); - return; - } - } - - public boolean canInstructionStep(IExecutionDMContext context) { - return false; - } - - public void instructionStep(IExecutionDMContext context, StepType stepType, RequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Operation not implemented", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getExecutionContexts(final IContainerDMContext containerDmc, final DataRequestMonitor rm) { - rm.setStatus(new Status(IStatus.ERROR, PDAPlugin.PLUGIN_ID, NOT_SUPPORTED, "Operation not implemented", null)); //$NON-NLS-1$ - rm.done(); - } - - public void getExecutionData(IExecutionDMContext dmc, DataRequestMonitor rm){ - rm.setData( new ExecutionData(fStateChangeReason) ); - rm.done(); - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ResumedEvent.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ResumedEvent.java deleted file mode 100644 index 68ee1d725d2..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/ResumedEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.runcontrol; - -import org.eclipse.dd.dsf.concurrent.Immutable; -import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; -import org.eclipse.dd.dsf.debug.service.IRunControl.IResumedDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.StateChangeReason; - -@Immutable -class ResumedEvent extends AbstractDMEvent - implements IResumedDMEvent -{ - private final String fPDAEvent; - - ResumedEvent(IExecutionDMContext ctx, String pdaEvent) { - super(ctx); - fPDAEvent = pdaEvent; - } - - public StateChangeReason getReason() { - if (fPDAEvent.startsWith("resumed breakpoint") || fPDAEvent.startsWith("suspended watch")) { - return StateChangeReason.BREAKPOINT; - } else if (fPDAEvent.equals("resumed step") || fPDAEvent.equals("resumed drop")) { - return StateChangeReason.STEP; - } else if (fPDAEvent.equals("resumed client")) { - return StateChangeReason.USER_REQUEST; - } else { - return StateChangeReason.UNKNOWN; - } - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/SuspendedEvent.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/SuspendedEvent.java deleted file mode 100644 index 04bf54aebd8..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/runcontrol/SuspendedEvent.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.eclipse.dd.examples.pda.service.runcontrol; - -import org.eclipse.dd.dsf.concurrent.Immutable; -import org.eclipse.dd.dsf.datamodel.AbstractDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; -import org.eclipse.dd.dsf.debug.service.IRunControl.ISuspendedDMEvent; -import org.eclipse.dd.dsf.debug.service.IRunControl.StateChangeReason; - -/** - * Indicates that the given thread has been suspended. - */ -@Immutable -class SuspendedEvent extends AbstractDMEvent - implements ISuspendedDMEvent -{ - private final String fPDAEvent; - - SuspendedEvent(IExecutionDMContext ctx, String pdaEvent) { - super(ctx); - fPDAEvent = pdaEvent; - } - - public StateChangeReason getReason() { - if (fPDAEvent.startsWith("suspended breakpoint") || fPDAEvent.startsWith("suspended watch")) { - return StateChangeReason.BREAKPOINT; - } else if (fPDAEvent.equals("suspended step") || fPDAEvent.equals("suspended drop")) { - return StateChangeReason.STEP; - } else if (fPDAEvent.equals("suspended client")) { - return StateChangeReason.USER_REQUEST; - } else { - return StateChangeReason.UNKNOWN; - } - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMContext.java deleted file mode 100644 index 48ac9084c67..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMContext.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.stack; - -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; -import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; - -/** - * - */ -class FrameDMContext extends AbstractDMContext implements IFrameDMContext { - - private final int fLevel; - - FrameDMContext(String sessionId, IExecutionDMContext execDmc, int level) { - super(sessionId, new IDMContext[] { execDmc }); - fLevel = level; - } - - public int getLevel() { return fLevel; } - - @Override - public boolean equals(Object other) { - return super.baseEquals(other) && ((FrameDMContext)other).fLevel == fLevel; - } - - @Override - public int hashCode() { - return super.baseHashCode() ^ fLevel; - } - - @Override - public String toString() { - return baseToString() + ".frame[" + fLevel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMData.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMData.java deleted file mode 100644 index 304388503c9..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/FrameDMData.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.stack; - -import org.eclipse.cdt.core.IAddress; -import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMData; -import org.eclipse.dd.examples.pda.service.command.commands.PDAFrame; - -/** - * - */ -public class FrameDMData implements IFrameDMData { - - final private PDAFrame fFrame; - - FrameDMData(PDAFrame frame) { - fFrame = frame; - } - - public String getFile() { - return fFrame.fFilePath.lastSegment(); - } - - public String getFunction() { - return fFrame.fFunction; - } - - public int getLine() { - return fFrame.fLine + 1; - } - - public int getColumn() { - return 0; - } - - public IAddress getAddress() { - return null; - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMContext.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMContext.java deleted file mode 100644 index 7ed5b51ff5d..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMContext.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.stack; - -import org.eclipse.dd.dsf.datamodel.AbstractDMContext; -import org.eclipse.dd.dsf.datamodel.IDMContext; -import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; -import org.eclipse.dd.dsf.debug.service.IStack.IVariableDMContext; - -/** - * - */ -class VariableDMContext extends AbstractDMContext implements IVariableDMContext { - - private final String fVariable; - - VariableDMContext(String sessionId, IFrameDMContext frameCtx, String variable) { - super(sessionId, new IDMContext[] { frameCtx }); - fVariable = variable; - } - - String getVariable() { return fVariable; } - - @Override - public boolean equals(Object other) { - return super.baseEquals(other) && ((VariableDMContext)other).fVariable.equals(fVariable); - } - - @Override - public int hashCode() { - return super.baseHashCode() + fVariable.hashCode(); - } - - @Override - public String toString() { - return baseToString() + ".variable(" + fVariable + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMData.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMData.java deleted file mode 100644 index 03087fd6012..00000000000 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/service/stack/VariableDMData.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.dd.examples.pda.service.stack; - -import org.eclipse.dd.dsf.debug.service.IStack.IVariableDMData; - -/** - * - */ -public class VariableDMData implements IVariableDMData { - - final private String fVariable; - - VariableDMData(String variable) { - fVariable = variable; - } - - public String getName() { - return fVariable; - } - - public String getValue() { - return null; - } -} diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourceLookupDirector.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourceLookupDirector.java similarity index 85% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourceLookupDirector.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourceLookupDirector.java index 27e1cdd8ce1..d22968d6be9 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourceLookupDirector.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourceLookupDirector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,8 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ -package org.eclipse.debug.examples.core.pda.sourcelookup; +package org.eclipse.dd.examples.pda.sourcelookup; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourcePathComputerDelegate.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourcePathComputerDelegate.java similarity index 85% rename from plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourcePathComputerDelegate.java rename to plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourcePathComputerDelegate.java index 6087abf01a5..64a8f06eaa7 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/debug/examples/core/pda/sourcelookup/PDASourcePathComputerDelegate.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/examples/pda/sourcelookup/PDASourcePathComputerDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,8 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation + * Wind River Systems - adopted to use with DSF *******************************************************************************/ -package org.eclipse.debug.examples.core.pda.sourcelookup; +package org.eclipse.dd.examples.pda.sourcelookup; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IProject; @@ -32,29 +33,25 @@ import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer; * The default source lookup path is the folder or project containing * the PDA program being launched. If the program is not specified, the workspace * is searched by default. + *

+ * This class is identical to the corresponding in PDA debugger implemented in + * org.eclipse.debug.examples. + *

*/ public class PDASourcePathComputerDelegate implements ISourcePathComputerDelegate { - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor) - */ public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { String path = configuration.getAttribute(PDAPlugin.ATTR_PDA_PROGRAM, (String)null); ISourceContainer sourceContainer = null; if (path != null) { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path)); if (resource != null) { - //#ifdef ex4 -//# // TODO: Exercise 4 - seed the source lookup path - //#else IContainer container = resource.getParent(); if (container.getType() == IResource.PROJECT) { sourceContainer = new ProjectSourceContainer((IProject)container, false); } else if (container.getType() == IResource.FOLDER) { sourceContainer = new FolderSourceContainer(container, false); } - //#endif } } if (sourceContainer == null) { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/BasicTests.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/BasicTests.java index abee9ba1650..f8124f277e8 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/BasicTests.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/BasicTests.java @@ -23,7 +23,7 @@ import org.eclipse.dd.dsf.concurrent.Query; import org.eclipse.dd.dsf.debug.service.command.ICommand; import org.eclipse.dd.dsf.debug.service.command.ICommandListener; import org.eclipse.dd.dsf.debug.service.command.ICommandResult; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; import org.junit.BeforeClass; import org.junit.Test; @@ -81,7 +81,7 @@ public class BasicTests extends CommandControlTestsBase { } }); - final PDATestCommand testCommand = new PDATestCommand(fCommandControl.getDMContext(), "data"); + final PDATestCommand testCommand = new PDATestCommand(fCommandControl.getProgramDMContext(), "data"); // Test sending the command and checking all listeners were called. Query sendCommandQuery = new Query() { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/CommandControlTestsBase.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/CommandControlTestsBase.java index 9d7a339177c..81ff0fc6257 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/CommandControlTestsBase.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/CommandControlTestsBase.java @@ -26,8 +26,8 @@ import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.Query; import org.eclipse.dd.dsf.debug.service.command.IEventListener; import org.eclipse.dd.dsf.service.DsfSession; -import org.eclipse.dd.examples.pda.service.command.PDACommandControl; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; +import org.eclipse.dd.examples.pda.service.PDACommandControl; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; import org.eclipse.dd.tests.pda.util.Launching; import org.junit.After; import org.junit.Before; @@ -66,7 +66,7 @@ public class CommandControlTestsBase { fExecutor = new DefaultDsfExecutor(); fSession = DsfSession.startSession(fExecutor, "PDA Test"); - fCommandControl = new PDACommandControl(fSession, requestPort, eventPort); + fCommandControl = new PDACommandControl(fSession, fProgram, requestPort, eventPort); fCommandControl.addEventListener(new IEventListener() { public void eventReceived(Object output) { @@ -105,7 +105,7 @@ public class CommandControlTestsBase { protected void sendCommand(String command, String expectedResult) throws Throwable { - final PDATestCommand testCommand = new PDATestCommand(fCommandControl.getDMContext(), command); + final PDATestCommand testCommand = new PDATestCommand(fCommandControl.getProgramDMContext(), command); // Test sending the command and checking all listeners were called. Query sendCommandQuery = new Query() { diff --git a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/PDATestCommand.java b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/PDATestCommand.java index 0aba7c8441c..36ba23c3527 100644 --- a/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/PDATestCommand.java +++ b/plugins/org.eclipse.dd.examples.pda/src/org/eclipse/dd/tests/pda/service/command/PDATestCommand.java @@ -10,15 +10,15 @@ *******************************************************************************/ package org.eclipse.dd.tests.pda.service.command; -import org.eclipse.dd.examples.pda.service.command.PDACommandControlDMContext; -import org.eclipse.dd.examples.pda.service.command.PDACommandResult; -import org.eclipse.dd.examples.pda.service.command.commands.AbstractPDACommand; +import org.eclipse.dd.examples.pda.service.PDAProgramDMContext; +import org.eclipse.dd.examples.pda.service.commands.AbstractPDACommand; +import org.eclipse.dd.examples.pda.service.commands.PDACommandResult; /** * */ class PDATestCommand extends AbstractPDACommand { - PDATestCommand(PDACommandControlDMContext context, String command) { + PDATestCommand(PDAProgramDMContext context, String command) { super(context, command); }