diff options
author | Pawel Piech | 2009-01-16 23:44:55 +0000 |
---|---|---|
committer | Pawel Piech | 2009-01-16 23:44:55 +0000 |
commit | 710d2b7f0e09ad78957386e02787908caea8a72f (patch) | |
tree | b91ec78ff174dc0714704347467062213c191f38 /org.eclipse.debug.examples.ui/src/org/eclipse/debug | |
parent | 9cb32841fe223aeb0c43404f71bbb8eabfaa7d52 (diff) | |
download | eclipse.platform.debug-710d2b7f0e09ad78957386e02787908caea8a72f.tar.gz eclipse.platform.debug-710d2b7f0e09ad78957386e02787908caea8a72f.tar.xz eclipse.platform.debug-710d2b7f0e09ad78957386e02787908caea8a72f.zip |
Bug 261400 - Port the PDA example debugger's virtual machine from Perl to Java
Diffstat (limited to 'org.eclipse.debug.examples.ui/src/org/eclipse/debug')
7 files changed, 96 insertions, 78 deletions
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java index ab33ae4f2..ed0c069ee 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2009 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Pawel Piech (Wind River) - ported PDA Virtual Machine to Java (Bug 261400) *******************************************************************************/ package org.eclipse.debug.examples.ui.pda.adapters; @@ -27,7 +28,7 @@ public class PDADebugTargetContentProvider extends ElementContentProvider { * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) */ protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - PDAThread thread = ((PDADebugTarget) element).getThread(); + PDAThread thread = ((PDADebugTarget) element).getThread(0); if (thread != null) { if (thread.hasStackFrames()) { return thread.getStackFrames().length; @@ -40,7 +41,7 @@ public class PDADebugTargetContentProvider extends ElementContentProvider { * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) */ protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - PDAThread thread = ((PDADebugTarget) element).getThread(); + PDAThread thread = ((PDADebugTarget) element).getThread(0); if (thread != null) { return thread.hasStackFrames(); } @@ -52,7 +53,7 @@ public class PDADebugTargetContentProvider extends ElementContentProvider { */ protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { if (context.getId().equals(IDebugUIConstants.ID_DEBUG_VIEW)) { - PDAThread thread = ((PDADebugTarget) parent).getThread(); + PDAThread thread = ((PDADebugTarget) parent).getThread(0); if (thread != null) { return getElements(thread.getStackFrames(), index, length); } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java index 1c13bac19..43e35dc26 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2009 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 + * Pawel Piech (Wind River) - ported PDA Virtual Machine to Java (Bug 261400) *******************************************************************************/ package org.eclipse.debug.examples.ui.pda.editor; @@ -41,7 +42,7 @@ public class PopFrameActionDelegate implements IObjectActionDelegate, IActionDel //# // TODO: Exercise 5 - pop the top frame //#else try { - fThread.pop(); + fThread.popFrame(); } catch (DebugException e) { } //#endif @@ -61,7 +62,7 @@ public class PopFrameActionDelegate implements IObjectActionDelegate, IActionDel //#else fThread = (PDAThread) frame.getThread(); try { - action.setEnabled(fThread.canPop() && fThread.getTopStackFrame().equals(frame)); + action.setEnabled(fThread.canPopFrame() && fThread.getTopStackFrame().equals(frame)); } catch (DebugException e) { } return; diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java index 2fd5ec826..d9a279f4b 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. + * Copyright (c) 2008, 2009 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 @@ -13,9 +13,8 @@ package org.eclipse.debug.examples.ui.pda.views; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.examples.core.pda.model.PDADebugElement; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; +import org.eclipse.debug.examples.core.pda.model.PDAThread; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -34,16 +33,20 @@ abstract public class AbstractDataStackViewHandler extends AbstractHandler { ISelection selection = DebugUITools.getDebugContextForEventChecked(event); if (selection instanceof IStructuredSelection) { - IStructuredSelection ss = (IStructuredSelection)selection; - if (ss.getFirstElement() instanceof IAdaptable) { - PDADebugElement element = (PDADebugElement) - ((IAdaptable)ss.getFirstElement()).getAdapter(PDADebugElement.class); - if (element != null) { - doExecute( - view, - (PDADebugTarget)element.getDebugTarget(), - HandlerUtil.getCurrentSelectionChecked(event)); - } + Object element = ((IStructuredSelection)selection).getFirstElement(); + + PDAThread thread = null; + if (element instanceof PDAThread) { + thread = (PDAThread)element; + } else if (element instanceof PDAStackFrame) { + thread = (PDAThread)((PDAStackFrame)element).getThread(); + } + + if (element != null) { + doExecute( + view, + thread, + HandlerUtil.getCurrentSelectionChecked(event)); } } } else { @@ -59,5 +62,5 @@ abstract public class AbstractDataStackViewHandler extends AbstractHandler { * @param target The current active debug target. * @param selection The current selection in view. */ - abstract protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException; + abstract protected void doExecute(DataStackView view, PDAThread target, ISelection selection) throws ExecutionException; } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java index 9be29dceb..10b5acd31 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. + * Copyright (c) 2008, 2009 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 @@ -13,7 +13,8 @@ package org.eclipse.debug.examples.ui.pda.views; import org.eclipse.core.expressions.PropertyTester; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.examples.core.pda.model.PDADebugElement; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; +import org.eclipse.debug.examples.core.pda.model.PDAThread; /** * Property tester for use with standard expressions to determine whether @@ -28,9 +29,15 @@ public class CanPushTester extends PropertyTester { if (receiver instanceof IAdaptable) { PDADebugElement element = (PDADebugElement) ((IAdaptable)receiver).getAdapter(PDADebugElement.class); - if (element != null) { - PDADebugTarget target = (PDADebugTarget)element.getDebugTarget(); - return target.canPush(); + PDAThread thread = null; + if (element instanceof PDAThread) { + thread = (PDAThread)element; + } else if (element instanceof PDAStackFrame) { + thread = (PDAThread)((PDAStackFrame)element).getThread(); + } + + if (thread != null) { + return thread.canPushData(); } } } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java index 5eeaa37a6..5e204755b 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2009 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 @@ -9,37 +9,39 @@ * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation * Wind River - Pawel Piech - replaced actions with handlers (bug 229219) + * Pawel Piech (Wind River) - ported PDA Virtual Machine to Java (Bug 261400) ******************************************************************************/ package org.eclipse.debug.examples.ui.pda.views; -import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.examples.core.pda.DebugCorePlugin; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; +import org.eclipse.debug.examples.core.pda.model.PDAThread; import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.contexts.DebugContextEvent; +import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.progress.UIJob; /** * View of the PDA VM data stack */ -public class DataStackView extends AbstractDebugView implements ISelectionListener { +public class DataStackView extends AbstractDebugView implements IDebugContextListener { - private PDADebugTarget fTarget; + private PDAThread fThread; class StackViewContentProvider implements ITreeContentProvider { @@ -47,9 +49,9 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ public Object[] getChildren(Object parentElement) { - if (parentElement instanceof PDADebugTarget) { + if (parentElement instanceof PDAThread) { try { - return ((PDADebugTarget)parentElement).getDataStack(); + return ((PDAThread)parentElement).getDataStack(); } catch (DebugException e) { } } @@ -60,10 +62,10 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) */ public Object getParent(Object element) { - if (element instanceof IDebugTarget) { + if (element instanceof PDAThread) { return null; } else { - return ((IDebugElement)element).getDebugTarget(); + return fThread; } } @@ -71,10 +73,7 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) */ public boolean hasChildren(Object element) { - if (element instanceof IDebugElement) { - return getChildren(element).length > 0; - } - return false; + return element instanceof PDAThread; } /* (non-Javadoc) @@ -105,7 +104,7 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen TreeViewer viewer = new TreeViewer(parent); viewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); viewer.setContentProvider(new StackViewContentProvider()); - getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).addDebugContextListener(this); getSite().setSelectionProvider(viewer); return viewer; } @@ -135,33 +134,40 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen * @see org.eclipse.ui.IWorkbenchPart#dispose() */ public void dispose() { - getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).removeDebugContextListener(this); super.dispose(); } - /* (non-Javadoc) - * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - update(); + + public void debugContextChanged(final DebugContextEvent event) { + new UIJob(getSite().getShell().getDisplay(), "DataStackView update") { + { + setSystem(true); + } + + public IStatus runInUIThread(IProgressMonitor monitor) { + update(event.getContext()); + return Status.OK_STATUS; + } + }.schedule(); } /** - * Updates the view for the selected target (if suspended) + * Updates the view for the selected thread (if suspended) */ - private synchronized void update() { - IAdaptable adaptable = DebugUITools.getDebugContext(); - fTarget = null; - if (adaptable != null) { - IDebugElement element = (IDebugElement) adaptable.getAdapter(IDebugElement.class); - if (element != null) { - if (element.getModelIdentifier().equals(DebugCorePlugin.ID_PDA_DEBUG_MODEL)) { - fTarget = (PDADebugTarget) element.getDebugTarget(); - } - } - } + private void update(ISelection context) { + fThread = null; + + if (context instanceof IStructuredSelection) { + Object element = ((IStructuredSelection)context).getFirstElement(); + if (element instanceof PDAThread) { + fThread = (PDAThread)element; + } else if (element instanceof PDAStackFrame) { + fThread = (PDAThread)((PDAStackFrame)element).getThread(); + } + } Object input = null; - if (fTarget != null && fTarget.isSuspended()) { - input = fTarget; + if (fThread != null && fThread.isSuspended()) { + input = fThread; } getViewer().setInput(input); getViewer().refresh(); diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java index 59f00c857..1c0c5bc72 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. + * Copyright (c) 2008, 2009 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 @@ -16,7 +16,7 @@ import java.util.List; import org.eclipse.core.commands.ExecutionException; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAThread; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TreeViewer; @@ -27,28 +27,28 @@ import org.eclipse.jface.viewers.TreeViewer; */ public class PopHandler extends AbstractDataStackViewHandler { - protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException { + protected void doExecute(DataStackView view, PDAThread thread, ISelection selection) throws ExecutionException { TreeViewer viewer = (TreeViewer)view.getViewer(); Object popee = selection instanceof IStructuredSelection ? ((IStructuredSelection)selection).getFirstElement() : null; if (popee != null) { try { - IValue[] stack = target.getDataStack(); + IValue[] stack = thread.getDataStack(); List restore = new ArrayList(); for (int i = 0; i < stack.length; i++) { Object value = stack[i]; if (popee.equals(value)) { // pop & stop - target.pop(); + thread.popData(); break; } else { // remember value to push back on - restore.add(target.pop()); + restore.add(thread.popData()); } } while (!restore.isEmpty()) { IValue value = (IValue) restore.remove(restore.size() - 1); - target.push(value.getValueString()); + thread.pushData(value.getValueString()); } } catch (DebugException e) { throw new ExecutionException("Failed to execute push command", e); diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java index 306508f5a..58fbc7c0e 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems and others. + * Copyright (c) 2008, 2009 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 @@ -12,7 +12,7 @@ package org.eclipse.debug.examples.ui.pda.views; import org.eclipse.core.commands.ExecutionException; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAThread; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.Window; @@ -22,11 +22,11 @@ import org.eclipse.jface.window.Window; */ public class PushHandler extends AbstractDataStackViewHandler { - protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException { + protected void doExecute(DataStackView view, PDAThread thread, ISelection selection) throws ExecutionException { InputDialog dialog = new InputDialog(view.getSite().getShell(), "Specify Value", "Enter value to push", null, null); if (dialog.open() == Window.OK) { try { - target.push(dialog.getValue()); + thread.pushData(dialog.getValue()); } catch (DebugException e) { throw new ExecutionException("Failed to execute push command", e); } |