From f7b0d8de3bdb5647a512a8e88f436d8d2725fd78 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Thu, 27 May 2004 21:53:39 +0000 Subject: [PATCH] Display global variables in the Variables view. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 15 + .../eclipse/cdt/debug/core/CDIDebugModel.java | 18 + .../debug/core/ICGlobalVariableManager.java | 48 +++ .../debug/core/model/ICGlobalVariable.java | 18 + .../cdt/debug/core/model/IExecFileInfo.java | 2 +- ...le.java => IGlobalVariableDescriptor.java} | 2 +- .../internal/core/CGlobalVariableManager.java | 124 ++++++ .../internal/core/model/CDebugTarget.java | 30 +- .../internal/core/model/CGlobalVariable.java | 26 +- .../debug/internal/core/model/CRegister.java | 8 - .../internal/core/model/CStackFrame.java | 18 +- .../debug/internal/core/model/CVariable.java | 6 +- debug/org.eclipse.cdt.debug.ui/ChangeLog | 15 + .../icons/full/dlcl16/rem_all_co.gif | Bin 0 -> 187 bytes .../icons/full/dlcl16/rem_co.gif | Bin 0 -> 159 bytes .../icons/full/elcl16/rem_all_co.gif | Bin 0 -> 204 bytes .../icons/full/elcl16/rem_co.gif | Bin 0 -> 163 bytes .../icons/full/ovr16/global_ovr.gif | Bin 0 -> 54 bytes .../plugin.properties | 4 + debug/org.eclipse.cdt.debug.ui/plugin.xml | 130 ++++-- .../ui/CDTDebugModelPresentation.java | 3 + .../cdt/debug/internal/ui/CDebugImages.java | 2 + .../ui/actions/AddGlobalsActionDelegate.java | 389 +++++++----------- .../RemoveAllGlobalsActionDelegate.java | 51 +++ .../actions/RemoveGlobalsActionDelegate.java | 120 ++++++ 25 files changed, 729 insertions(+), 300 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java rename debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/{IGlobalVariable.java => IGlobalVariableDescriptor.java} (86%) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/rem_all_co.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/rem_co.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_all_co.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_co.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/ovr16/global_ovr.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveAllGlobalsActionDelegate.java create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveGlobalsActionDelegate.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 37d21e99c1b..7873bc34126 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,18 @@ +2004-05-27 Mikhail Khodjaiants + Display global variables in the Variables view. + * CDIDebugModel.java + * ICGlobalVariableManager.java: new + * IGlobalVariable.java: removed + * ICGlobalVariable.java + * IExecFileInfo.java + * IGlobalVariableDescriptor.java: new + * CGlobalVariableManager.java: new + * CDebugTarget.java + * CGlobalVariable.java + * CRegister.java + * CStackFrame.java + * CVariable.java + 2004-05-20 Mikhail Khodjaiants Removed dependencies on the compatibility plugin and replaced deprecated classes and methods. Warning cleanup. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java index 93a2945d8bd..1fdd789ef98 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java @@ -19,14 +19,17 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint; +import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; import org.eclipse.cdt.debug.internal.core.breakpoints.CAddressBreakpoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CFunctionBreakpoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint; import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint; import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; import org.eclipse.cdt.debug.internal.core.model.CExpression; +import org.eclipse.cdt.debug.internal.core.model.CGlobalVariable; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -389,4 +392,19 @@ public class CDIDebugModel { } return null; } + + public static ICGlobalVariable createGlobalVariable( IDebugTarget target, IGlobalVariableDescriptor info ) throws DebugException { + if ( target != null && target instanceof CDebugTarget ) { + ICDIVariableObject vo = null; + try { + vo = ((CDebugTarget)target).getCDISession().getVariableManager().getGlobalVariableObject( info.getPath().lastSegment(), null, info.getName() ); + ICDIVariable cdiVariable = ((CDebugTarget)target).getCDISession().getVariableManager().createVariable( vo ); + return new CGlobalVariable( (CDebugTarget)target, cdiVariable ); + } + catch( CDIException e ) { + throw new DebugException( new Status( IStatus.ERROR, getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, (vo != null) ? vo.getName() + ": " + e.getMessage() : e.getMessage(), null ) ); //$NON-NLS-1$ + } + } + return null; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java new file mode 100644 index 00000000000..bb7d54bbf2a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICGlobalVariableManager.java @@ -0,0 +1,48 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.core; + +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; +import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; +import org.eclipse.debug.core.DebugException; + +/** + * Manages the collection of global variables added to a debug target. + */ +public interface ICGlobalVariableManager { + + /** + * Registers with this manager the global variables specified by given descriptors. + * + * @param descriptors the descriptors of global variables to register with this manager + * @throws DebugException + */ + public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException; + + /** + * Removes specified global variables from this manager. + * + * @param globals global variables to remove + */ + public void removeGlobals( ICGlobalVariable[] globals ); + + /** + * Removes all global variables from this manager. + */ + public void removeAllGlobals(); + + /** + * Returns the array of the global variables descriptors registered with this manager. + * + * @return the array of the global variables descriptors registered with this manager + */ + public IGlobalVariableDescriptor[] getDescriptors(); +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java new file mode 100644 index 00000000000..db5d740b271 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICGlobalVariable.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.core.model; + +/** + * Represents a global C/C++ variable. + */ +public interface ICGlobalVariable extends ICVariable { + public void dispose(); +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IExecFileInfo.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IExecFileInfo.java index 677f4f41ac9..b258694f09f 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IExecFileInfo.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IExecFileInfo.java @@ -22,5 +22,5 @@ public interface IExecFileInfo { public boolean isLittleEndian(); - public IGlobalVariable[] getGlobals() throws DebugException; + public IGlobalVariableDescriptor[] getGlobals() throws DebugException; } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariableDescriptor.java similarity index 86% rename from debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariable.java rename to debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariableDescriptor.java index 1b488a9a27f..be5e0fc711b 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IGlobalVariableDescriptor.java @@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IPath; * * @since: Nov 4, 2002 */ -public interface IGlobalVariable +public interface IGlobalVariableDescriptor { String getName(); IPath getPath(); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java new file mode 100644 index 00000000000..b3aee134f6a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CGlobalVariableManager.java @@ -0,0 +1,124 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import org.eclipse.cdt.debug.core.CDIDebugModel; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICGlobalVariableManager; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; +import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; +import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; +import org.eclipse.cdt.debug.internal.core.model.CVariable; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; + +/** + * Manages all global variables registered with a debug target. + */ +public class CGlobalVariableManager implements ICGlobalVariableManager { + + private CDebugTarget fDebugTarget; + + private ArrayList fGlobals = new ArrayList( 10 ); + + /** + * Constructor for CGlobalVariableManager. + */ + public CGlobalVariableManager( CDebugTarget target ) { + super(); + setDebugTarget( target ); + } + + protected CDebugTarget getDebugTarget() { + return fDebugTarget; + } + + private void setDebugTarget( CDebugTarget debugTarget ) { + fDebugTarget = debugTarget; + } + + public ICGlobalVariable[] getGlobals() { + return (ICGlobalVariable[])fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#addGlobals(IGlobalVariableDescriptor[]) + */ + public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException { + MultiStatus ms = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), 0, "", null ); //$NON-NLS-1$ + ArrayList globals = new ArrayList( descriptors.length ); + for ( int i = 0; i < descriptors.length; ++i ) { + try { + globals.add( CDIDebugModel.createGlobalVariable( getDebugTarget(), descriptors[i] ) ); + } + catch( DebugException e ) { + ms.add( e.getStatus() ); + } + } + if ( globals.size() > 0 ) { + synchronized( fGlobals ) { + fGlobals.addAll( globals ); + } + getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); + } + if ( !ms.isOK() ) { + throw new DebugException( ms ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeGlobals(ICGlobalVariable[]) + */ + public void removeGlobals( ICGlobalVariable[] globals ) { + synchronized( fGlobals ) { + fGlobals.removeAll( Arrays.asList( globals ) ); + } + for ( int i = 0; i < globals.length; ++i ) { + globals[i].dispose(); + } + getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeAllGlobals() + */ + public void removeAllGlobals() { + ICGlobalVariable[] globals = new ICGlobalVariable[0]; + synchronized( fGlobals ) { + globals = (ICGlobalVariable[])fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] ); + fGlobals.clear(); + } + for ( int i = 0; i < globals.length; ++i ) { + ((CVariable)globals[i]).dispose(); + } + getDebugTarget().fireChangeEvent( DebugEvent.CONTENT ); + } + + public void dispose() { + Iterator it = fGlobals.iterator(); + while( it.hasNext() ) { + ((ICGlobalVariable)it.next()).dispose(); + } + fGlobals.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#getDescriptors() + */ + public IGlobalVariableDescriptor[] getDescriptors() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index 00163f7a6ce..c8e246fe6dc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugModel; import org.eclipse.cdt.debug.core.CDebugUtils; +import org.eclipse.cdt.debug.core.ICGlobalVariableManager; import org.eclipse.cdt.debug.core.ICMemoryManager; import org.eclipse.cdt.debug.core.ICRegisterManager; import org.eclipse.cdt.debug.core.ICSharedLibraryManager; @@ -66,7 +67,7 @@ import org.eclipse.cdt.debug.core.model.ICSignal; import org.eclipse.cdt.debug.core.model.IDebuggerProcessSupport; import org.eclipse.cdt.debug.core.model.IDisassembly; import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.cdt.debug.core.model.IGlobalVariable; +import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; import org.eclipse.cdt.debug.core.model.IJumpToAddress; import org.eclipse.cdt.debug.core.model.IJumpToLine; import org.eclipse.cdt.debug.core.model.IRunToAddress; @@ -75,6 +76,7 @@ import org.eclipse.cdt.debug.core.model.IState; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.internal.core.CBreakpointManager; import org.eclipse.cdt.debug.internal.core.CExpressionTarget; +import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager; import org.eclipse.cdt.debug.internal.core.CMemoryManager; import org.eclipse.cdt.debug.internal.core.CRegisterManager; import org.eclipse.cdt.debug.internal.core.CSharedLibraryManager; @@ -250,6 +252,8 @@ public class CDebugTarget extends CDebugElement private CExpressionTarget fExpressionTarget; + private CGlobalVariableManager fGlobalVariableManager; + /** * The suspension thread. */ @@ -302,6 +306,7 @@ public class CDebugTarget extends CDebugElement setSignalManager( new CSignalManager( this ) ); setRegisterManager( new CRegisterManager( this ) ); setBreakpointManager( new CBreakpointManager( this ) ); + setGlobalVariableManager( new CGlobalVariableManager( this ) ); initialize(); DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this ); DebugPlugin.getDefault().getExpressionManager().addExpressionListener( this ); @@ -997,6 +1002,8 @@ public class CDebugTarget extends CDebugElement return getRegisterManager(); if ( adapter.equals( CExpressionTarget.class ) ) return getExpressionTarget(); + if ( adapter.equals( ICGlobalVariableManager.class ) ) + return getGlobalVariableManager(); if ( adapter.equals( ICDISession.class ) ) return getCDISession(); return super.getAdapter( adapter ); @@ -1226,6 +1233,7 @@ public class CDebugTarget extends CDebugElement DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this ); DebugPlugin.getDefault().getExpressionManager().removeExpressionListener( this ); DebugPlugin.getDefault().getLaunchManager().removeLaunchListener( this ); + disposeGlobalVariableManager(); disposeMemoryManager(); disposeSharedLibraryManager(); disposeSignalManager(); @@ -1988,7 +1996,7 @@ public class CDebugTarget extends CDebugElement /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.IExecFileInfo#getGlobals() */ - public IGlobalVariable[] getGlobals() throws DebugException + public IGlobalVariableDescriptor[] getGlobals() throws DebugException { ArrayList list = new ArrayList(); if ( getExecFile() != null && CoreModel.getDefault().isBinary( getExecFile() ) ) @@ -1999,7 +2007,7 @@ public class CDebugTarget extends CDebugElement list.addAll( getCFileGlobals( (IParent)cFile ) ); } } - return (IGlobalVariable[])list.toArray( new IGlobalVariable[list.size()] ); + return (IGlobalVariableDescriptor[])list.toArray( new IGlobalVariableDescriptor[list.size()] ); } private List getCFileGlobals( IParent file ) throws DebugException @@ -2027,9 +2035,9 @@ public class CDebugTarget extends CDebugElement return list; } - private IGlobalVariable createGlobalVariable( final org.eclipse.cdt.core.model.IVariable var ) + private IGlobalVariableDescriptor createGlobalVariable( final org.eclipse.cdt.core.model.IVariable var ) { - return new IGlobalVariable() + return new IGlobalVariableDescriptor() { public String getName() { @@ -2084,6 +2092,10 @@ public class CDebugTarget extends CDebugElement fRegisterManager.dispose(); } + protected void disposeGlobalVariableManager() { + fGlobalVariableManager.dispose(); + } + /** * @see org.eclipse.cdt.debug.core.model.IRunToAddress#canRunToAddress(long) */ @@ -2488,4 +2500,12 @@ public class CDebugTarget extends CDebugElement } return fExpressionTarget; } + + protected CGlobalVariableManager getGlobalVariableManager() { + return fGlobalVariableManager; + } + + private void setGlobalVariableManager( CGlobalVariableManager globalVariableManager ) { + fGlobalVariableManager = globalVariableManager; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java index 2d09c7f93d0..b7e7fd21c56 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CGlobalVariable.java @@ -8,6 +8,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; @@ -17,7 +18,7 @@ import org.eclipse.debug.core.model.IValue; * * @since: Oct 2, 2002 */ -public class CGlobalVariable extends CModificationVariable +public class CGlobalVariable extends CModificationVariable implements ICGlobalVariable { /** * Constructor for CGlobalVariable. @@ -37,6 +38,8 @@ public class CGlobalVariable extends CModificationVariable */ public IValue getValue() throws DebugException { + if ( !isEnabled() ) + return fDisabledValue; if ( fValue == null ) { ICDIValue cdiValue = getCurrentValue(); @@ -90,4 +93,25 @@ public class CGlobalVariable extends CModificationVariable } } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.core.model.CVariable#dispose() + */ + public void dispose() { + if ( getShadow() != null ) + getShadow().dispose(); + try { + getCDISession().getVariableManager().destroyVariable( getCDIVariable() ); + } + catch( CDIException e ) { + } + super.dispose(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() + */ + public boolean canEnableDisable() { + return true; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java index 8f8f3192a7f..66a811eacd9 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegister.java @@ -69,12 +69,4 @@ public class CRegister extends CGlobalVariable implements IRegister { return true; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable() - */ - public boolean canEnableDisable() - { - return false; - } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java index 0557da42140..26a643ca315 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CStackFrame.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent; import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener; import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.model.IRestart; import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal; @@ -29,6 +30,7 @@ import org.eclipse.cdt.debug.core.model.IRunToAddress; import org.eclipse.cdt.debug.core.model.IRunToLine; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.internal.core.CExpressionTarget; +import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IRegisterGroup; @@ -95,8 +97,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart * @see org.eclipse.debug.core.model.IStackFrame#getVariables() */ public IVariable[] getVariables() throws DebugException { - List list = getVariables0(); - return (IVariable[])list.toArray( new IVariable[list.size()] ); + ICGlobalVariable[] globals = getGlobals(); + List vars = getVariables0(); + List all = new ArrayList( globals.length + vars.size() ); + all.addAll( Arrays.asList( globals ) ); + all.addAll( vars ); + return (IVariable[])all.toArray( new IVariable[all.size()] ); } protected synchronized List getVariables0() throws DebugException { @@ -712,4 +718,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart CExpressionTarget target = (CExpressionTarget)getDebugTarget().getAdapter( CExpressionTarget.class ); return (target != null) ? target.evaluateExpression( expression ) : null; } + + private ICGlobalVariable[] getGlobals() { + CGlobalVariableManager gvm = ((CDebugTarget)getDebugTarget()).getGlobalVariableManager(); + if ( gvm != null ) { + return gvm.getGlobals(); + } + return new ICGlobalVariable[0]; + } } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java index c1a732005e5..0ae7386dfc7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java @@ -350,7 +350,7 @@ public abstract class CVariable extends CDebugElement * Temporary solution to avoid NPE in VariablesView. * This is fixed in the Eclipse 2.1.1 Maintenance Build. */ - static private IValue fDisabledValue = new IValue() + static protected IValue fDisabledValue = new IValue() { public String getReferenceTypeName() throws DebugException { @@ -559,7 +559,7 @@ public abstract class CVariable extends CDebugElement return ( fValue instanceof CValue ) ? ((CValue)fValue).getUnderlyingValue() : null; } - protected void dispose() + public void dispose() { if ( fValue != null ) { @@ -807,7 +807,7 @@ public abstract class CVariable extends CDebugElement return ( fOriginal != null ) ? fOriginal.getCDIVariable() : null; } - private InternalVariable getShadow() + protected InternalVariable getShadow() { return fShadow; } diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 0d8db234c5a..cd52bd0a3ff 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,18 @@ +2004-05-27 Mikhail Khodjaiants + Display global variables in the Variables view. + * CDebugImages.java + * CDTDebugModelPresentation.java + * AddGlobalsActionDelegate.java + * RemoveAllGlobalsActionDelegate.java: new + * RemoveGlobalsActionDelegate.java: new + * plugin.properties + * plugin.xml + * icons/full/dlcl16/rem_all_co.gif: new + * icons/full/dlcl16/rem_co.gif: new + * icons/full/elcl16/rem_all_co.gif: new + * icons/full/elcl16/rem_co.gif: new + * icons/full/ovr16/global_ovr.gif: new + 2004-05-25 Mikhail Khodjaiants New instructuion pointer images for the Disassembly view. * icons/full/obj16/inst_ptr_top.gif diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/rem_all_co.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/rem_all_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..ecd1be5681503e61dad33db001934298624edddd GIT binary patch literal 187 zcmV;s07U;sNk%w1VGsZi0J8u9y1Kcxwza~+!RYAd%gf8g#>T6*6 p&5U4BfoP92mqubfZ|ElS#Gi0I}eMb=?0hv=!;iZy|UTOS9Ern3j>2S03Llh A4*&oF literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_all_co.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_all_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..28a3785aaca7c24373e69a73b2307fdb4331b725 GIT binary patch literal 204 zcmZ?wbhEHb6krfw*v!Dt(a|trLdS{~3vS%Fv0=l86+qU41v6&Mm;e+7$~81pR8$lc z6l7#%BqSvK|Nmd{CkrD313!Zf0}z1BU|^~IuvcM;=)qeJFP_d6<6(9$NpZ+va*#XV z$Tanv0@q6Ij$F;fM->-rkP#C*lC&X!LwxVz&)al#c-qnqcDm}#WIy(BLW0V%N5`2M zYBi)fD)t0U*`nI(nzTRThYA-TS95cdU1Kv3A5Uwk5NlIM^h7?h?zV>Mb~Eg!3Nly& E026Ie7ytkO literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_co.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/rem_co.gif new file mode 100644 index 0000000000000000000000000000000000000000..2cd9c544436c47a57f20b348b3fb024bb50701a7 GIT binary patch literal 163 zcmZ?wbhEHb6krfw*v!DNV#SID3l_|nF=N7n2^}3B4Gj$y6%_>q1sNF`2?+`R|Nmz| z1&Tje7#SG27<53wATtBYuHJj2L#xNM)vQ#JRl<>hDKU#-N&yE`p}?0M(Gw4T zcQCOfDoF5h^e6?|s2Q}nBw9^ - - - - - - - - @@ -752,7 +733,7 @@ helpContextId="restore_default_type_action_context" tooltip="%RestoreDefaultTypeAction.tooltip" class="org.eclipse.cdt.debug.internal.ui.actions.RestoreDefaultTypeActionDelegate" - menubarPath="additions" + menubarPath="variableGroup" enablesFor="1" id="org.eclipse.cdt.debug.internal.ui.actions.RestoreDefaultTypeActionDelegate"> @@ -768,7 +749,7 @@ helpContextId="cast_to_type_action_context" tooltip="%CastToTypeAction.tooltip" class="org.eclipse.cdt.debug.internal.ui.actions.CastToTypeActionDelegate" - menubarPath="additions" + menubarPath="variableGroup" enablesFor="1" id="org.eclipse.cdt.debug.internal.ui.actions.CastToTypeActionDelegate"> @@ -784,7 +765,7 @@ helpContextId="cast_to_array_action_context" tooltip="%CastToArrayAction.tooltip" class="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionDelegate" - menubarPath="additions" + menubarPath="variableGroup" enablesFor="1" id="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionDelegate"> @@ -818,6 +799,50 @@ + + + + + + + + + + + + + + + + targetID="org.eclipse.debug.ui.VariableView" + id="org.eclipse.debug.ui.variablesView.toolbar"> + helpContextId="remove_all_globals_action_context" + disabledIcon="icons/full/dlcl16/rem_all_co.gif" + hoverIcon="icons/full/elcl16/rem_all_co.gif" + enablesFor="*" + toolbarPath="additions" + label="%RemoveAllGlobalsAction.label" + tooltip="%RemoveAllGlobalsAction.tooltip" + icon="icons/full/elcl16/rem_all_co.gif" + class="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate" + id="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate"> - + id="org.eclipse.cdt.debug.ui"/> + + + + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java index cb655211927..9fcb1440c97 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.ICDebugElementErrorStatus; import org.eclipse.cdt.debug.core.model.ICDebugTargetType; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.cdt.debug.core.model.ICSharedLibrary; import org.eclipse.cdt.debug.core.model.ICStackFrame; @@ -219,6 +220,8 @@ public class CDTDebugModelPresentation extends LabelProvider overlays[OverlayImageDescriptor.BOTTOM_LEFT] = CDebugImages.DESC_OVRS_ERROR; if ( element instanceof ICVariable && ((ICVariable)element).isArgument() ) overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_ARGUMENT; + if ( element instanceof ICGlobalVariable && !(element instanceof IRegister) ) + overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_GLOBAL; return fImageCache.getImageFor( new OverlayImageDescriptor( baseImage, overlays ) ); } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugImages.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugImages.java index d19b23d0abb..e9f20f40e54 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugImages.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugImages.java @@ -62,6 +62,7 @@ public class CDebugImages public static final String IMG_OVRS_SYMBOLS = NAME_PREFIX + "symbols_ovr.gif"; //$NON-NLS-1$ public static final String IMG_OVRS_VARIABLE_CASTED = NAME_PREFIX + "casttype_ovr.gif"; //$NON-NLS-1$ public static final String IMG_OVRS_ARGUMENT = NAME_PREFIX + "argument_ovr.gif"; //$NON-NLS-1$ + public static final String IMG_OVRS_GLOBAL = NAME_PREFIX + "global_ovr.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BREAKPOINT_ENABLED = NAME_PREFIX + "brkp_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BREAKPOINT_DISABLED = NAME_PREFIX + "brkpd_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_ADDRESS_BREAKPOINT_ENABLED = NAME_PREFIX + "addrbrkp_obj.gif"; //$NON-NLS-1$ @@ -137,6 +138,7 @@ public class CDebugImages public static final ImageDescriptor DESC_OVRS_SYMBOLS = createManaged( T_OVR, IMG_OVRS_SYMBOLS ); public static final ImageDescriptor DESC_OVRS_VARIABLE_CASTED = createManaged( T_OVR, IMG_OVRS_VARIABLE_CASTED ); public static final ImageDescriptor DESC_OVRS_ARGUMENT = createManaged( T_OVR, IMG_OVRS_ARGUMENT ); + public static final ImageDescriptor DESC_OVRS_GLOBAL = createManaged( T_OVR, IMG_OVRS_GLOBAL ); public static final ImageDescriptor DESC_OBJS_BREAKPOINT_ENABLED = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT_ENABLED ); public static final ImageDescriptor DESC_OBJS_BREAKPOINT_DISABLED = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT_DISABLED ); public static final ImageDescriptor DESC_OBJS_WATCHPOINT_ENABLED = createManaged( T_OBJ, IMG_OBJS_WATCHPOINT_ENABLED ); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java index a3be2282125..9d09ddb2212 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java @@ -1,23 +1,24 @@ -/* - *(c) Copyright QNX Software Systems Ltd. 2002. - * All Rights Reserved. - * - */ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ package org.eclipse.cdt.debug.internal.ui.actions; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.CDebugModel; +import java.util.Arrays; +import java.util.List; +import org.eclipse.cdt.debug.core.ICGlobalVariableManager; import org.eclipse.cdt.debug.core.model.IExecFileInfo; -import org.eclipse.cdt.debug.core.model.IGlobalVariable; +import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.IAction; @@ -40,354 +41,256 @@ import org.eclipse.ui.actions.ActionDelegate; import org.eclipse.ui.dialogs.ListSelectionDialog; /** - * Enter type comment. - * - * @since: Nov 4, 2002 + * A delegate for the "Add Globals" action. */ -public class AddGlobalsActionDelegate extends ActionDelegate - implements IViewActionDelegate, - ISelectionListener, - IPartListener -{ - protected class Global - { - private String fName; - private IPath fPath; +public class AddGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate, ISelectionListener, IPartListener { - /** - * Constructor for Global. - */ - public Global( String name, IPath path ) - { - fName = name; - fPath = path; - } + private IGlobalVariableDescriptor[] fGlobals; - public String getName() - { - return fName; - } - - public IPath getPath() - { - return fPath; - } - } - - private Global[] fGlobals; private IViewPart fView = null; + private IAction fAction; + private IStructuredSelection fSelection; + private IStatus fStatus = null; - /** - * Constructor for AddGlobalsActionDelegate. - */ - public AddGlobalsActionDelegate() - { - super(); - } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) */ - public void init( IViewPart view ) - { + public void init( IViewPart view ) { fView = view; view.getSite().getPage().addPartListener( this ); view.getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) */ - public void selectionChanged( IWorkbenchPart part, ISelection selection ) - { - if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) - { - if ( selection instanceof IStructuredSelection ) - { + public void selectionChanged( IWorkbenchPart part, ISelection selection ) { + if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) { + if ( selection instanceof IStructuredSelection ) { setSelection( (IStructuredSelection)selection ); } - else - { + else { setSelection( null ); } update( getAction() ); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IActionDelegate#run(IAction) */ - public void run( IAction action ) - { + public void run( IAction action ) { final IStructuredSelection selection = getSelection(); if ( selection != null && selection.size() != 1 ) return; - BusyIndicator.showWhile( Display.getCurrent(), - new Runnable() - { - public void run() - { - try - { - doAction( selection.getFirstElement() ); - setStatus( null ); - } - catch( DebugException e ) - { - setStatus( e.getStatus() ); - } - } - } ); - if ( getStatus() != null && !getStatus().isOK() ) - { - IWorkbenchWindow window= CDebugUIPlugin.getActiveWorkbenchWindow(); - if ( window != null ) - { + BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { + + public void run() { + try { + doAction( selection.getFirstElement() ); + setStatus( null ); + } + catch( DebugException e ) { + setStatus( e.getStatus() ); + } + } + } ); + if ( getStatus() != null && !getStatus().isOK() ) { + IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow(); + if ( window != null ) { CDebugUIPlugin.errorDialog( getErrorDialogMessage(), getStatus() ); - } - else - { + } + else { CDebugUIPlugin.log( getStatus() ); } - } + } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) */ - public void selectionChanged( IAction action, ISelection selection ) - { + public void selectionChanged( IAction action, ISelection selection ) { setAction( action ); - if ( getView() != null ) - { + if ( getView() != null ) { update( action ); } } - protected void update( IAction action ) - { - if ( action != null ) - { + protected void update( IAction action ) { + if ( action != null ) { action.setEnabled( getEnableStateForSelection( getSelection() ) ); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart) */ - public void partActivated( IWorkbenchPart part ) - { + public void partActivated( IWorkbenchPart part ) { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart) */ - public void partBroughtToTop( IWorkbenchPart part ) - { + public void partBroughtToTop( IWorkbenchPart part ) { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart) */ - public void partClosed( IWorkbenchPart part ) - { - if ( part.equals( getView() ) ) - { + public void partClosed( IWorkbenchPart part ) { + if ( part.equals( getView() ) ) { dispose(); } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart) */ - public void partDeactivated( IWorkbenchPart part ) - { + public void partDeactivated( IWorkbenchPart part ) { } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart) */ - public void partOpened( IWorkbenchPart part ) - { + public void partOpened( IWorkbenchPart part ) { } - - protected IViewPart getView() - { + + protected IViewPart getView() { return fView; } - protected void setView( IViewPart viewPart ) - { + protected void setView( IViewPart viewPart ) { fView = viewPart; } - - protected void setAction( IAction action ) - { + + protected void setAction( IAction action ) { fAction = action; } - protected IAction getAction() - { + protected IAction getAction() { return fAction; } - private void setSelection( IStructuredSelection selection ) - { + private void setSelection( IStructuredSelection selection ) { fSelection = selection; } - private IStructuredSelection getSelection() - { + private IStructuredSelection getSelection() { return fSelection; } - public void dispose() - { - if ( getView() != null ) - { + public void dispose() { + if ( getView() != null ) { getView().getViewSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); getView().getViewSite().getPage().removePartListener( this ); - } + } } - protected boolean getEnableStateForSelection( IStructuredSelection selection ) - { - if ( selection == null || selection.size() != 1 ) - { + protected boolean getEnableStateForSelection( IStructuredSelection selection ) { + if ( selection == null || selection.size() != 1 ) { return false; } Object element = selection.getFirstElement(); - return ( element != null && - element instanceof IDebugElement && - ((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ) != null ); + return (element != null && element instanceof IDebugElement && ((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ) != null); } - private ListSelectionDialog createDialog() - { - return new ListSelectionDialog( getView().getSite().getShell(), - fGlobals, - new IStructuredContentProvider() - { - public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) - { - } - - public void dispose() - { - } - - public Object[] getElements( Object parent ) - { - return getGlobals(); - } - }, - new LabelProvider() - { - public String getText( Object element ) - { - if ( element instanceof Global ) - { - String path = ""; //$NON-NLS-1$ - if ( ((Global)element).getPath() != null ) - { - path = ((Global)element).getPath().toString(); - int index = path.lastIndexOf( '/' ); - if ( index != -1 ) - path = path.substring( index + 1 ); - } - return ( path.length() > 0 ? ( '\'' + path + "\'::" ) : "" ) + ((Global)element).getName(); //$NON-NLS-1$ //$NON-NLS-2$ - } - return null; - } - }, - CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Select_Variables") ); //$NON-NLS-1$ + private ListSelectionDialog createDialog() { + return new ListSelectionDialog( getView().getSite().getShell(), fGlobals, new IStructuredContentProvider() { + + public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { + } + + public void dispose() { + } + + public Object[] getElements( Object parent ) { + return getGlobals(); + } + }, new LabelProvider() { + + public String getText( Object element ) { + if ( element instanceof IGlobalVariableDescriptor ) { + String path = ""; //$NON-NLS-1$ + if ( ((IGlobalVariableDescriptor)element).getPath() != null ) { + path = ((IGlobalVariableDescriptor)element).getPath().toString(); + int index = path.lastIndexOf( '/' ); + if ( index != -1 ) + path = path.substring( index + 1 ); + } + return (path.length() > 0 ? ('\'' + path + "\'::") : "") + ((IGlobalVariableDescriptor)element).getName(); //$NON-NLS-1$ //$NON-NLS-2$ + } + return null; + } + }, CDebugUIPlugin.getResourceString( "internal.ui.actions.AddGlobalsActionDelegate.Select_Variables" ) ); //$NON-NLS-1$ } - - protected Global[] getGlobals() - { + + protected IGlobalVariableDescriptor[] getGlobals() { return fGlobals; } - protected void doAction( Object element ) throws DebugException - { + protected void doAction( Object element ) throws DebugException { if ( getView() == null ) return; - if ( element != null && element instanceof IDebugElement ) - { + if ( element != null && element instanceof IDebugElement ) { IExecFileInfo info = (IExecFileInfo)((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ); - if ( info != null ) - { - IGlobalVariable[] globalVars = info.getGlobals(); - fGlobals = new Global[globalVars.length]; - for ( int i = 0; i < globalVars.length; ++i ) - { - fGlobals[i] = new Global( globalVars[i].getName(), globalVars[i].getPath() ); - } + ICGlobalVariableManager gvm = (ICGlobalVariableManager)((IDebugElement)element).getDebugTarget().getAdapter( ICGlobalVariableManager.class ); + if ( info != null && gvm != null ) { + fGlobals = info.getGlobals(); ListSelectionDialog dlg = createDialog(); - if ( dlg.open() == Window.OK ) - { - MultiStatus ms = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, getStatusMessage(), null ); - Object[] selections = dlg.getResult(); - for ( int i = 0; i < selections.length; ++i ) - { - try - { - createExpression( ((IDebugElement)element).getDebugTarget(), (Global)selections[i] ); - } - catch( DebugException e ) - { - ms.merge( e.getStatus() ); - } - } - if ( !ms.isOK() ) - { - throw new DebugException( ms ); - } + if ( dlg.open() == Window.OK ) { + List list = Arrays.asList( dlg.getResult() ); + IGlobalVariableDescriptor[] selections = (IGlobalVariableDescriptor[])list.toArray( new IGlobalVariableDescriptor[list.size()] ); + gvm.addGlobals( selections ); } } } } - protected String getStatusMessage() - { - return CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Exceptions_occurred_attempting_to_add_global_variables."); //$NON-NLS-1$ - } - /** * @see AbstractDebugActionDelegate#getErrorDialogMessage() */ - protected String getErrorDialogMessage() - { - return CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Add_global_variables_failed"); //$NON-NLS-1$ + protected String getErrorDialogMessage() { + return CDebugUIPlugin.getResourceString( "internal.ui.actions.AddGlobalsActionDelegate.Add_global_variables_failed" ); //$NON-NLS-1$ } - - protected void setStatus( IStatus status ) - { + + protected void setStatus( IStatus status ) { fStatus = status; } - - protected IStatus getStatus() - { + + protected IStatus getStatus() { return fStatus; } - private void createExpression( IDebugTarget target, Global global ) throws DebugException - { - IExpression expression = CDebugModel.createExpressionForGlobalVariable( target, global.getPath(), global.getName() ); - DebugPlugin.getDefault().getExpressionManager().addExpression( expression ); - } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) */ - public void init( IAction action ) - { + public void init( IAction action ) { super.init( action ); Object element = DebugUITools.getDebugContext(); - setSelection( (element != null ) ? new StructuredSelection( element ) : new StructuredSelection() ); + setSelection( (element != null) ? new StructuredSelection( element ) : new StructuredSelection() ); update( action ); } -} +} \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveAllGlobalsActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveAllGlobalsActionDelegate.java new file mode 100644 index 00000000000..2dc10eca5fc --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveAllGlobalsActionDelegate.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.cdt.debug.core.ICGlobalVariableManager; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionDelegate; + +/** + * A delegate for the "Remove All Globals" action. + */ +public class RemoveAllGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate { + + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init( IViewPart view ) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run( IAction action ) { + IAdaptable context = DebugUITools.getDebugContext(); + if ( context instanceof IDebugElement ) { + final ICGlobalVariableManager gvm = (ICGlobalVariableManager)((IDebugElement)context).getDebugTarget().getAdapter( ICGlobalVariableManager.class ); + if ( gvm != null ) { + DebugPlugin.getDefault().asyncExec( + new Runnable() { + public void run() { + gvm.removeAllGlobals(); + } + } ); + } + } + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveGlobalsActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveGlobalsActionDelegate.java new file mode 100644 index 00000000000..5cdb17f32b4 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RemoveGlobalsActionDelegate.java @@ -0,0 +1,120 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import java.util.ArrayList; +import java.util.Iterator; +import org.eclipse.cdt.debug.core.ICGlobalVariableManager; +import org.eclipse.cdt.debug.core.model.ICGlobalVariable; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionDelegate; + +/** + * A delegate for the "Remove Globals" action. + */ +public class RemoveGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate { + + private IAction fAction; + + private ISelection fSelection; + + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init( IViewPart view ) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init( IAction action ) { + setAction( action ); + update(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run( IAction action ) { + ISelection selection = getSelection(); + if ( !(selection instanceof IStructuredSelection) ) + return; + IStructuredSelection ss = (IStructuredSelection)selection; + final Iterator enum = ss.iterator(); + ArrayList list = new ArrayList( ss.size() ); + while( enum.hasNext() ) { + Object obj = enum.next(); + if ( obj instanceof ICGlobalVariable ) + list.add( obj ); + } + if ( list.size() == 0 ) + return; + final ICGlobalVariable[] globals = (ICGlobalVariable[])list.toArray( new ICGlobalVariable[list.size()] ); + final ICGlobalVariableManager gvm = (ICGlobalVariableManager)globals[0].getDebugTarget().getAdapter( ICGlobalVariableManager.class ); + if ( gvm == null ) + return; + Runnable r = new Runnable() { + public void run() { + gvm.removeGlobals( globals ); + } + }; + DebugPlugin.getDefault().asyncExec( r ); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged( IAction action, ISelection selection ) { + setSelection( selection ); + update(); + } + + protected IAction getAction() { + return fAction; + } + + protected ISelection getSelection() { + return fSelection; + } + + private void setAction( IAction action ) { + fAction = action; + } + + private void setSelection( ISelection selection ) { + fSelection = selection; + } + + private void update() { + IAction action = getAction(); + if ( action != null ) { + ISelection selection = getSelection(); + boolean enabled = false; + if ( selection instanceof IStructuredSelection ) { + Iterator it = ((IStructuredSelection)selection).iterator(); + while( it.hasNext() ) { + if ( it.next() instanceof ICGlobalVariable ) { + enabled = true; + break; + } + } + } + action.setEnabled( enabled ); + } + } +}