From 614db741313b6d88d6ed82034852e9038b1dd7c8 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Wed, 28 May 2008 18:25:13 +0000 Subject: [PATCH] [230932] - [debug view] When a stack frame is selected another thread suspending causes the selection to change. --- ...DefaultDsfModelSelectionPolicyFactory.java | 43 +++++ .../launch/DefaultDsfSelectionPolicy.java | 153 ++++++++++++++++++ .../dd/gdb/internal/ui/GdbAdapterFactory.java | 8 + 3 files changed, 204 insertions(+) create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfModelSelectionPolicyFactory.java create mode 100644 plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfSelectionPolicy.java diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfModelSelectionPolicyFactory.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfModelSelectionPolicyFactory.java new file mode 100644 index 00000000000..00d1d7b19eb --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfModelSelectionPolicyFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.dd.dsf.debug.internal.provisional.ui.viewmodel.launch; + +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicyFactory; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +/** + * Default model selection policy factory for DSF. + */ +@SuppressWarnings("restriction") +public class DefaultDsfModelSelectionPolicyFactory implements IModelSelectionPolicyFactory { + + /* + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicyFactory#createModelSelectionPolicyAdapter(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext) + */ + public IModelSelectionPolicy createModelSelectionPolicyAdapter(Object element, IPresentationContext context) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { + if (element instanceof IDMVMContext) { + IDMVMContext dmvmContext= (IDMVMContext) element; + IDMContext dmContext= dmvmContext.getDMContext(); + if (dmContext != null) { + return new DefaultDsfSelectionPolicy(dmContext); + } + } + } + return null; + } + +} diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfSelectionPolicy.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfSelectionPolicy.java new file mode 100644 index 00000000000..c835ffe313a --- /dev/null +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/internal/provisional/ui/viewmodel/launch/DefaultDsfSelectionPolicy.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.dsf.debug.internal.provisional.ui.viewmodel.launch; + +import org.eclipse.dd.dsf.datamodel.DMContexts; +import org.eclipse.dd.dsf.datamodel.IDMContext; +import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin; +import org.eclipse.dd.dsf.debug.service.IRunControl; +import org.eclipse.dd.dsf.debug.service.IRunControl.IExecutionDMContext; +import org.eclipse.dd.dsf.debug.service.IStack.IFrameDMContext; +import org.eclipse.dd.dsf.service.DsfServicesTracker; +import org.eclipse.dd.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; + +/** + * Default DSF selection policy implementation modelled after platform version + * (DefaultSelectionPolicy). + */ +@SuppressWarnings("restriction") +public class DefaultDsfSelectionPolicy implements IModelSelectionPolicy { + + private IDMContext fDMContext; + + /** + * Create selection policy instance for the given data model context. + * + * @param dmContext + */ + public DefaultDsfSelectionPolicy(IDMContext dmContext) { + fDMContext= dmContext; + } + + /* + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy#contains(org.eclipse.jface.viewers.ISelection, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext) + */ + public boolean contains(ISelection selection, IPresentationContext context) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss= (IStructuredSelection) selection; + Object element= ss.getFirstElement(); + if (element instanceof IDMVMContext) { + IDMVMContext dmvmContext= (IDMVMContext) element; + IDMContext dmContext= dmvmContext.getDMContext(); + if (dmContext != null) { + return fDMContext.getSessionId().equals(dmContext.getSessionId()); + } + } + } + } + return false; + } + + /* + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy#isSticky(org.eclipse.jface.viewers.ISelection, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext) + */ + public boolean isSticky(ISelection selection, IPresentationContext context) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss= (IStructuredSelection) selection; + Object element= ss.getFirstElement(); + return isSticky(element); + } + } + return false; + } + + protected boolean isSticky(Object element) { + if (element instanceof IDMVMContext) { + IDMVMContext dmvmContext= (IDMVMContext) element; + IDMContext dmContext= dmvmContext.getDMContext(); + if (dmContext instanceof IFrameDMContext) { + IExecutionDMContext execContext= DMContexts.getAncestorOfType(dmContext, IExecutionDMContext.class); + if (execContext != null) { + DsfServicesTracker servicesTracker = new DsfServicesTracker(DsfDebugUIPlugin.getBundleContext(), dmContext.getSessionId()); + try { + IRunControl runControl= servicesTracker.getService(IRunControl.class); + if (runControl != null) { + if (runControl.isSuspended(execContext)) { + return true; + } + } + } finally { + servicesTracker.dispose(); + } + } + } + } + return false; + } + + /* + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy#overrides(org.eclipse.jface.viewers.ISelection, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext) + */ + public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { + if (existing instanceof IStructuredSelection && candidate instanceof IStructuredSelection) { + IStructuredSelection ssExisting = (IStructuredSelection) existing; + IStructuredSelection ssCandidate = (IStructuredSelection) candidate; + return overrides(ssExisting.getFirstElement(), ssCandidate.getFirstElement()); + } + } + return true; + } + + + protected boolean overrides(Object existing, Object candidate) { + if (existing == null || existing.equals(candidate)) { + return true; + } + if (existing instanceof IDMVMContext && candidate instanceof IDMVMContext) { + IDMContext curr = ((IDMVMContext) existing).getDMContext(); + IDMContext cand = ((IDMVMContext) candidate).getDMContext(); + if (curr instanceof IFrameDMContext && cand instanceof IFrameDMContext) { + IExecutionDMContext currExecContext= DMContexts.getAncestorOfType(curr, IExecutionDMContext.class); + if (currExecContext != null) { + IExecutionDMContext candExecContext= DMContexts.getAncestorOfType(cand, IExecutionDMContext.class); + return currExecContext.equals(candExecContext) || !isSticky(existing); + } + } + } + return !isSticky(existing); + } + + /* + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy#replaceInvalidSelection(org.eclipse.jface.viewers.ISelection, org.eclipse.jface.viewers.ISelection) + */ + public ISelection replaceInvalidSelection(ISelection invalidSelection, ISelection newSelection) { + if (invalidSelection instanceof ITreeSelection) { + ITreeSelection treeSelection = (ITreeSelection)invalidSelection; + if (treeSelection.getPaths().length == 1) { + TreePath path = treeSelection.getPaths()[0]; + return new TreeSelection(path.getParentPath()); + } + } + return newSelection; + } + +} diff --git a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java index d34b960920c..2ea44db1a2d 100644 --- a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java +++ b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.debug.core.model.ISteppingModeTarget; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.dd.dsf.concurrent.Immutable; import org.eclipse.dd.dsf.concurrent.ThreadSafe; +import org.eclipse.dd.dsf.debug.internal.provisional.ui.viewmodel.launch.DefaultDsfModelSelectionPolicyFactory; import org.eclipse.dd.dsf.debug.ui.actions.DsfResumeCommand; import org.eclipse.dd.dsf.debug.ui.actions.DsfStepIntoCommand; import org.eclipse.dd.dsf.debug.ui.actions.DsfStepOverCommand; @@ -47,6 +48,7 @@ import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicyFactory; import org.eclipse.debug.ui.contexts.ISuspendTrigger; import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; @@ -76,6 +78,7 @@ public class GdbAdapterFactory final IDebugModelProvider fDebugModelProvider; final DsfSuspendTrigger fSuspendTrigger; final DsfSteppingModeTarget fSteppingModeTarget; + final IModelSelectionPolicyFactory fModelSelectionPolicyFactory; SessionAdapterSet(GdbLaunch launch) { fLaunch = launch; @@ -99,6 +102,8 @@ public class GdbAdapterFactory fRestartCommand = new GdbRestartCommand(session, fLaunch); fTerminateCommand = new DsfTerminateCommand(session); fSuspendTrigger = new DsfSuspendTrigger(session, fLaunch); + fModelSelectionPolicyFactory = new DefaultDsfModelSelectionPolicyFactory(); + session.registerModelAdapter(ISteppingModeTarget.class, fSteppingModeTarget); session.registerModelAdapter(IStepIntoHandler.class, fStepIntoCommand); session.registerModelAdapter(IStepOverHandler.class, fStepOverCommand); @@ -107,6 +112,7 @@ public class GdbAdapterFactory session.registerModelAdapter(IResumeHandler.class, fResumeCommand); session.registerModelAdapter(IRestart.class, fRestartCommand); session.registerModelAdapter(ITerminateHandler.class, fTerminateCommand); + session.registerModelAdapter(IModelSelectionPolicyFactory.class, fModelSelectionPolicyFactory); fDebugModelProvider = new IDebugModelProvider() { // @see org.eclipse.debug.core.model.IDebugModelProvider#getModelIdentifiers() @@ -140,6 +146,8 @@ public class GdbAdapterFactory session.unregisterModelAdapter(IResumeHandler.class); session.unregisterModelAdapter(IRestart.class); session.unregisterModelAdapter(ITerminateHandler.class); + session.unregisterModelAdapter(IModelSelectionPolicyFactory.class); + fStepIntoCommand.dispose(); fStepOverCommand.dispose(); fStepReturnCommand.dispose();