From 69a0850c87b988ceefb165b167fedfc856d231bb Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 8 Oct 2004 18:40:29 +0000 Subject: [PATCH] Added the bookkeeping of registers and register groups. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 8 +++ .../cdt/debug/core/model/ICVariable.java | 24 +-------- .../core/model/IEnableDisableTarget.java | 42 ++++++++++++++++ .../core/model/AbstractCVariable.java | 10 ++++ .../debug/internal/core/model/CRegister.java | 7 --- .../internal/core/model/CRegisterGroup.java | 49 ++++++++++++++++++- debug/org.eclipse.cdt.debug.ui/ChangeLog | 7 +++ debug/org.eclipse.cdt.debug.ui/plugin.xml | 26 ++++++++++ .../ui/CDTDebugModelPresentation.java | 40 ++++++++++----- .../cdt/debug/internal/ui/CDebugImages.java | 4 ++ .../EnableVariablesActionDelegate.java | 40 +++++++++------ 11 files changed, 198 insertions(+), 59 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IEnableDisableTarget.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 6f69756a9b1..8730d03ef82 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,11 @@ +2004-10-08 Mikhail Khodjaiants + Added the bookkeeping of registers and register groups. + * ICVariable.java + * IEnableDisableTarget.java: new + * AbstractCVariable.java + * CRegister.java + * CRegisterGroup.java + 2004-10-07 Mikhail Khodjaiants Pass the current stack frame to the registers manager to provide the evaluation context. * ICRegisterManager.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java index 13a39d20ada..d7a3a576289 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java @@ -17,7 +17,7 @@ import org.eclipse.debug.core.model.IVariable; /** * C/C++ specific extension IVariable. */ -public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, ICastToArray, IValueModification { +public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, ICastToArray, IValueModification, IEnableDisableTarget { /** * Returns the type of this variable. @@ -27,28 +27,6 @@ public interface ICVariable extends IVariable, ICDebugElement, IFormatSupport, I */ ICType getType() throws DebugException; - /** - * Returns whether this variable is enabled. - * - * @return whether this variable is enabled - */ - boolean isEnabled(); - - /** - * Sets the enabled state of this action. - * - * @param enabled true to enable, and false to disable - * @throws DebugException - */ - void setEnabled( boolean enabled ) throws DebugException; - - /** - * Returns whether this variable supports enable/disable operation. - * - * @return whether this variable supports enable/disable operation - */ - boolean canEnableDisable(); - /** * Returns whether this variable is an argument. * diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IEnableDisableTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IEnableDisableTarget.java new file mode 100644 index 00000000000..a1404644b9a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IEnableDisableTarget.java @@ -0,0 +1,42 @@ +/********************************************************************** + * 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; + +import org.eclipse.debug.core.DebugException; + +/** + * Provides support for enable/disable actions. + */ +public interface IEnableDisableTarget { + + /** + * Returns whether this object supports enable/disable operations. + * + * @return whether this object supports enable/disable operations + */ + boolean canEnableDisable(); + + /** + * Returns whether this object is enabled. + * + * @return true if this obvject is enabled, + * or false otherwise. + */ + boolean isEnabled(); + + /** + * Enables/disables this object + * + * @param enabled enablement flag value + * @throws DebugException + */ + void setEnabled( boolean enabled ) throws DebugException; +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java index 3a4dde9f224..baf135743cf 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AbstractCVariable.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.debug.internal.core.model; import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; import org.eclipse.debug.core.DebugException; /** @@ -52,6 +53,15 @@ public abstract class AbstractCVariable extends CDebugElement implements ICVaria return null; } + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter( Class adapter ) { + if ( IEnableDisableTarget.class.equals( adapter ) ) + return this; + return super.getAdapter( adapter ); + } + /** * Returns the text presentation of this variable as an expression. * 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 04f625ce8aa..1ab0c5b89e6 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 @@ -46,11 +46,4 @@ public class CRegister extends CGlobalVariable implements IRegister { public IRegisterGroup getRegisterGroup() throws DebugException { return (IRegisterGroup)getParent(); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.model.ICVariable#isEnabled() - */ - public boolean isEnabled() { - return true; - } } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java index 4a6c9a0165a..4a650687711 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CRegisterGroup.java @@ -13,6 +13,8 @@ package org.eclipse.cdt.debug.internal.core.model; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegister; import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject; +import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IRegister; import org.eclipse.debug.core.model.IRegisterGroup; @@ -20,7 +22,7 @@ import org.eclipse.debug.core.model.IRegisterGroup; /** * Represents a group of registers. */ -public class CRegisterGroup extends CDebugElement implements IRegisterGroup { +public class CRegisterGroup extends CDebugElement implements IRegisterGroup, IEnableDisableTarget { private String fName; @@ -28,6 +30,8 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup { private IRegister[] fRegisters; + private boolean fIsEnabled = true; + /** * Constructor for CRegisterGroup. */ @@ -57,6 +61,7 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup { catch( DebugException e ) { fRegisters[i] = new CRegister( this, fRegisterObjects[i], e.getMessage() ); } + ((CRegister)fRegisters[i]).setEnabled( isEnabled() ); } } return fRegisters; @@ -97,4 +102,46 @@ public class CRegisterGroup extends CDebugElement implements IRegisterGroup { } } } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter( Class adapter ) { + if ( IEnableDisableTarget.class.equals( adapter ) ) + return this; + return super.getAdapter( adapter ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#canEnableDisable() + */ + public boolean canEnableDisable() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#isEnabled() + */ + public boolean isEnabled() { + return fIsEnabled; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.IEnableDisableTarget#setEnabled(boolean) + */ + public void setEnabled( boolean enabled ) throws DebugException { + if ( fRegisters != null ) { + synchronized( fRegisters ) { + if ( fRegisters != null ) { + for ( int i = 0; i < fRegisters.length; ++i ) { + if ( fRegisters[i] instanceof CRegister ) { + ((CRegister)fRegisters[i]).setEnabled( enabled ); + } + } + } + } + } + fIsEnabled = enabled; + fireChangeEvent( DebugEvent.CONTENT ); + } } \ No newline at end of file diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 2049f6c010e..1a1739bb055 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,10 @@ +2004-10-08 Mikhail Khodjaiants + Added the bookkeeping of registers and register groups. + * CDebugImages.java + * CDTDebugModelPresentation.java + * EnableVariablesActionDelegate.java + * plugin.xml + 2004-10-07 Mikhail Khodjaiants Added images of disabled registers and register groups. * icons/full/obj16/registerd_obj.gif: new diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index c4aca405156..c5190a25895 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -751,6 +751,32 @@ id="org.eclipse.cdt.debug.ui"/> + + + + + + + + ", ((ICDebugElementStatus)element).getMessage() ) ); //$NON-NLS-1$ } + if ( element instanceof IAdaptable ) { + IEnableDisableTarget target = (IEnableDisableTarget)((IAdaptable)element).getAdapter( IEnableDisableTarget.class ); + if ( target != null ) { + if ( !target.isEnabled() ) { + baseText.append( ' ' ); + baseText.append( CDebugUIMessages.getString( "CDTDebugModelPresentation.25" ) ); //$NON-NLS-1$ + } + } + } return baseText.toString(); } @@ -490,9 +501,11 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo result.insert( 0, typeName + ' ' ); } } - String valueString = DebugUIPlugin.getModelPresentation().getText( value ); - if ( valueString.length() > 0 ) { - result.append( " = " ).append( valueString ); //$NON-NLS-1$ + if ( expression.isEnabled() ) { + String valueString = DebugUIPlugin.getModelPresentation().getText( value ); + if ( valueString.length() > 0 ) { + result.append( " = " ).append( valueString ); //$NON-NLS-1$ + } } } } @@ -523,16 +536,14 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo if ( name != null ) label.append( name.trim() ); IValue value = var.getValue(); - String valueString = DebugUIPlugin.getModelPresentation().getText( value ); - if ( !isEmpty( valueString ) ) { - label.append( " = " ); //$NON-NLS-1$ - label.append( valueString ); + if ( value != null ) { + String valueString = DebugUIPlugin.getModelPresentation().getText( value ); + if ( !isEmpty( valueString ) ) { + label.append( " = " ); //$NON-NLS-1$ + label.append( valueString ); + } } } - if ( !((ICVariable)var).isEnabled() ) { - label.append( ' ' ); - label.append( CDebugUIMessages.getString( "CDTDebugModelPresentation.25" ) ); //$NON-NLS-1$ - } return label.toString(); } @@ -804,11 +815,14 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo } protected Image getRegisterGroupImage( IRegisterGroup element ) { + IEnableDisableTarget target = (IEnableDisableTarget)element.getAdapter( IEnableDisableTarget.class ); + if ( target != null && !target.isEnabled() ) + return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_GROUP_DISABLED ); return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_GROUP ); } protected Image getRegisterImage( IRegister element ) { - return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER ); + return ( ( element instanceof ICVariable && ((ICVariable)element).isEnabled() ) ) ? fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER ) : fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_DISABLED ); } protected Image getExpressionImage( IExpression element ) { @@ -825,6 +839,8 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo private String getVariableTypeName( ICType type ) { StringBuffer result = new StringBuffer(); String typeName = type.getName(); + if ( typeName != null ) + typeName = typeName.trim(); if ( type.isArray() && typeName != null ) { int index = typeName.indexOf( '[' ); if ( index != -1 ) 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 96650db7ce3..d20faf205a6 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 @@ -88,7 +88,9 @@ public class CDebugImages public static final String IMG_OBJS_VARIABLE_POINTER_DISABLED = NAME_PREFIX + "vard_pointer.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_VARIABLE_STRING = NAME_PREFIX + "var_string.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_REGISTER_GROUP = NAME_PREFIX + "registergroup_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_REGISTER_GROUP_DISABLED = NAME_PREFIX + "registergroupd_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_REGISTER = NAME_PREFIX + "register_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_REGISTER_DISABLED = NAME_PREFIX + "registerd_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_DISASSEMBLY = NAME_PREFIX + "disassembly_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_PROJECT = NAME_PREFIX + "project_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_CLOSED_PROJECT = NAME_PREFIX + "cproject_obj.gif"; //$NON-NLS-1$ @@ -160,7 +162,9 @@ public class CDebugImages public static final ImageDescriptor DESC_OBJS_VARIABLE_POINTER_DISABLED = createManaged( T_OBJ, IMG_OBJS_VARIABLE_POINTER_DISABLED ); public static final ImageDescriptor DESC_OBJS_VARIABLE_STRING = createManaged( T_OBJ, IMG_OBJS_VARIABLE_STRING ); public static final ImageDescriptor DESC_OBJS_REGISTER_GROUP = createManaged( T_OBJ, IMG_OBJS_REGISTER_GROUP ); + public static final ImageDescriptor DESC_OBJS_REGISTER_GROUP_DISABLED = createManaged( T_OBJ, IMG_OBJS_REGISTER_GROUP_DISABLED ); public static final ImageDescriptor DESC_OBJS_REGISTER = createManaged( T_OBJ, IMG_OBJS_REGISTER ); + public static final ImageDescriptor DESC_OBJS_REGISTER_DISABLED = createManaged( T_OBJ, IMG_OBJS_REGISTER_DISABLED ); public static final ImageDescriptor DESC_OBJS_DISASSEMBLY = createManaged( T_OBJ, IMG_OBJS_DISASSEMBLY ); public static final ImageDescriptor DESC_OBJS_PROJECT = createManaged( T_OBJ, IMG_OBJS_PROJECT ); public static final ImageDescriptor DESC_OBJS_CLOSED_PROJECT = createManaged( T_OBJ, IMG_OBJS_CLOSED_PROJECT ); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableVariablesActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableVariablesActionDelegate.java index c6663a80cfa..bf7eca60127 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableVariablesActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableVariablesActionDelegate.java @@ -11,8 +11,9 @@ package org.eclipse.cdt.debug.internal.ui.actions; import java.util.Iterator; -import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.cdt.debug.core.model.IEnableDisableTarget; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.debug.core.DebugException; import org.eclipse.jface.action.IAction; @@ -83,19 +84,18 @@ public class EnableVariablesActionDelegate implements IViewActionDelegate { public void run() { while( enum.hasNext() ) { - ICVariable var = (ICVariable)enum.next(); - try { - if ( size > 1 ) { - if ( isEnableAction() ) - var.setEnabled( true ); + IEnableDisableTarget target = getEnableDisableTarget( enum.next() ); + if ( target != null ) { + try { + if ( size > 1 ) { + target.setEnabled( isEnableAction() ); + } else - var.setEnabled( false ); + target.setEnabled( !target.isEnabled() ); + } + catch( DebugException e ) { + ms.merge( e.getStatus() ); } - else - var.setEnabled( !var.isEnabled() ); - } - catch( DebugException e ) { - ms.merge( e.getStatus() ); } } update(); @@ -117,16 +117,16 @@ public class EnableVariablesActionDelegate implements IViewActionDelegate { return; IStructuredSelection sel = (IStructuredSelection)selection; Object o = sel.getFirstElement(); - if ( !(o instanceof ICVariable) ) + if ( getEnableDisableTarget( o ) == null ) return; Iterator enum = sel.iterator(); boolean allEnabled = true; boolean allDisabled = true; while( enum.hasNext() ) { - ICVariable var = (ICVariable)enum.next(); - if ( !var.canEnableDisable() ) + IEnableDisableTarget target = getEnableDisableTarget( enum.next() ); + if ( target != null && !target.canEnableDisable() ) continue; - if ( var.isEnabled() ) + if ( target.isEnabled() ) allDisabled = false; else allEnabled = false; @@ -144,4 +144,12 @@ public class EnableVariablesActionDelegate implements IViewActionDelegate { protected void update() { getView().getViewSite().getSelectionProvider().setSelection( getView().getViewSite().getSelectionProvider().getSelection() ); } + + protected IEnableDisableTarget getEnableDisableTarget( Object obj ) { + IEnableDisableTarget target = null; + if ( obj instanceof IAdaptable ) { + target = (IEnableDisableTarget)((IAdaptable)obj).getAdapter( IEnableDisableTarget.class ); + } + return target; + } }