cdt/cdt_5_0_x/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java
author ryall
Tue, 21 Apr 2009 17:41:02 -0500
changeset 6 648636cfa849
parent 1 a7cc18b7a772
permissions -rw-r--r--
Syns with CDT HEAD
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
cawthron
parents:
diff changeset
     1
/*******************************************************************************
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2004, 2008 QNX Software Systems and others.
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
cawthron
parents:
diff changeset
     7
 *
cawthron
parents:
diff changeset
     8
 * Contributors:
cawthron
parents:
diff changeset
     9
 * QNX Software Systems - Initial API and implementation
cawthron
parents:
diff changeset
    10
 * Ken Ryall (Nokia) - Added support for CSourceNotFoundElement ( 167305 )
cawthron
parents:
diff changeset
    11
 * ARM Limited - https://bugs.eclipse.org/bugs/show_bug.cgi?id=186981
cawthron
parents:
diff changeset
    12
 * Ken Ryall (Nokia) - Bug 201165 don't toss images on dispose.
cawthron
parents:
diff changeset
    13
 *******************************************************************************/
cawthron
parents:
diff changeset
    14
package org.eclipse.cdt.debug.internal.ui;
cawthron
parents:
diff changeset
    15
cawthron
parents:
diff changeset
    16
import java.io.File;
cawthron
parents:
diff changeset
    17
import java.text.MessageFormat;
cawthron
parents:
diff changeset
    18
import java.util.HashMap;
cawthron
parents:
diff changeset
    19
cawthron
parents:
diff changeset
    20
import org.eclipse.cdt.core.IAddress;
cawthron
parents:
diff changeset
    21
import org.eclipse.cdt.core.model.CoreModel;
cawthron
parents:
diff changeset
    22
import org.eclipse.cdt.core.model.ICProject;
cawthron
parents:
diff changeset
    23
import org.eclipse.cdt.core.resources.FileStorage;
cawthron
parents:
diff changeset
    24
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
cawthron
parents:
diff changeset
    25
import org.eclipse.cdt.debug.core.CDebugUtils;
cawthron
parents:
diff changeset
    26
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
cawthron
parents:
diff changeset
    27
import org.eclipse.cdt.debug.core.cdi.ICDIExitInfo;
cawthron
parents:
diff changeset
    28
import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryEvent;
cawthron
parents:
diff changeset
    29
import org.eclipse.cdt.debug.core.cdi.ICDISignalExitInfo;
cawthron
parents:
diff changeset
    30
import org.eclipse.cdt.debug.core.cdi.ICDISignalReceived;
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointScope;
cawthron
parents:
diff changeset
    32
import org.eclipse.cdt.debug.core.cdi.ICDIWatchpointTrigger;
cawthron
parents:
diff changeset
    33
import org.eclipse.cdt.debug.core.cdi.model.ICDISignal;
cawthron
parents:
diff changeset
    34
import org.eclipse.cdt.debug.core.model.CDebugElementState;
cawthron
parents:
diff changeset
    35
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
cawthron
parents:
diff changeset
    36
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
cawthron
parents:
diff changeset
    37
import org.eclipse.cdt.debug.core.model.ICDebugElement;
cawthron
parents:
diff changeset
    38
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
cawthron
parents:
diff changeset
    39
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
cawthron
parents:
diff changeset
    40
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
cawthron
parents:
diff changeset
    41
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
cawthron
parents:
diff changeset
    42
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
cawthron
parents:
diff changeset
    43
import org.eclipse.cdt.debug.core.model.ICModule;
cawthron
parents:
diff changeset
    44
import org.eclipse.cdt.debug.core.model.ICSignal;
cawthron
parents:
diff changeset
    45
import org.eclipse.cdt.debug.core.model.ICStackFrame;
cawthron
parents:
diff changeset
    46
import org.eclipse.cdt.debug.core.model.ICThread;
cawthron
parents:
diff changeset
    47
import org.eclipse.cdt.debug.core.model.ICType;
cawthron
parents:
diff changeset
    48
import org.eclipse.cdt.debug.core.model.ICValue;
cawthron
parents:
diff changeset
    49
import org.eclipse.cdt.debug.core.model.ICVariable;
cawthron
parents:
diff changeset
    50
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
cawthron
parents:
diff changeset
    51
import org.eclipse.cdt.debug.core.model.IDummyStackFrame;
cawthron
parents:
diff changeset
    52
import org.eclipse.cdt.debug.core.model.IEnableDisableTarget;
cawthron
parents:
diff changeset
    53
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement;
cawthron
parents:
diff changeset
    54
import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput;
cawthron
parents:
diff changeset
    55
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
cawthron
parents:
diff changeset
    56
import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
cawthron
parents:
diff changeset
    57
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
cawthron
parents:
diff changeset
    58
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
cawthron
parents:
diff changeset
    59
import org.eclipse.cdt.ui.CUIPlugin;
cawthron
parents:
diff changeset
    60
import org.eclipse.core.filesystem.URIUtil;
cawthron
parents:
diff changeset
    61
import org.eclipse.core.resources.IFile;
cawthron
parents:
diff changeset
    62
import org.eclipse.core.resources.IMarker;
cawthron
parents:
diff changeset
    63
import org.eclipse.core.resources.IProject;
cawthron
parents:
diff changeset
    64
import org.eclipse.core.resources.IResource;
cawthron
parents:
diff changeset
    65
import org.eclipse.core.resources.IStorage;
cawthron
parents:
diff changeset
    66
import org.eclipse.core.resources.ResourcesPlugin;
cawthron
parents:
diff changeset
    67
import org.eclipse.core.runtime.CoreException;
cawthron
parents:
diff changeset
    68
import org.eclipse.core.runtime.IPath;
cawthron
parents:
diff changeset
    69
import org.eclipse.core.runtime.Path;
cawthron
parents:
diff changeset
    70
import org.eclipse.core.runtime.Platform;
cawthron
parents:
diff changeset
    71
import org.eclipse.debug.core.DebugException;
cawthron
parents:
diff changeset
    72
import org.eclipse.debug.core.DebugPlugin;
cawthron
parents:
diff changeset
    73
import org.eclipse.debug.core.model.IBreakpoint;
cawthron
parents:
diff changeset
    74
import org.eclipse.debug.core.model.IDebugTarget;
cawthron
parents:
diff changeset
    75
import org.eclipse.debug.core.model.IDisconnect;
cawthron
parents:
diff changeset
    76
import org.eclipse.debug.core.model.IExpression;
cawthron
parents:
diff changeset
    77
import org.eclipse.debug.core.model.IRegister;
cawthron
parents:
diff changeset
    78
import org.eclipse.debug.core.model.IRegisterGroup;
cawthron
parents:
diff changeset
    79
import org.eclipse.debug.core.model.IStackFrame;
cawthron
parents:
diff changeset
    80
import org.eclipse.debug.core.model.ITerminate;
cawthron
parents:
diff changeset
    81
import org.eclipse.debug.core.model.IThread;
cawthron
parents:
diff changeset
    82
import org.eclipse.debug.core.model.IValue;
cawthron
parents:
diff changeset
    83
import org.eclipse.debug.core.model.IVariable;
cawthron
parents:
diff changeset
    84
import org.eclipse.debug.core.model.IWatchExpression;
cawthron
parents:
diff changeset
    85
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
cawthron
parents:
diff changeset
    86
import org.eclipse.debug.ui.DebugUITools;
cawthron
parents:
diff changeset
    87
import org.eclipse.debug.ui.IDebugModelPresentation;
cawthron
parents:
diff changeset
    88
import org.eclipse.debug.ui.IDebugUIConstants;
cawthron
parents:
diff changeset
    89
import org.eclipse.debug.ui.IValueDetailListener;
cawthron
parents:
diff changeset
    90
import org.eclipse.jface.resource.ImageDescriptor;
cawthron
parents:
diff changeset
    91
import org.eclipse.jface.viewers.ILabelProvider;
cawthron
parents:
diff changeset
    92
import org.eclipse.jface.viewers.LabelProvider;
cawthron
parents:
diff changeset
    93
import org.eclipse.swt.graphics.Image;
cawthron
parents:
diff changeset
    94
import org.eclipse.ui.IEditorDescriptor;
cawthron
parents:
diff changeset
    95
import org.eclipse.ui.IEditorInput;
cawthron
parents:
diff changeset
    96
import org.eclipse.ui.IEditorRegistry;
cawthron
parents:
diff changeset
    97
import org.eclipse.ui.PlatformUI;
cawthron
parents:
diff changeset
    98
import org.eclipse.ui.part.FileEditorInput;
cawthron
parents:
diff changeset
    99
cawthron
parents:
diff changeset
   100
/**
cawthron
parents:
diff changeset
   101
 * @see IDebugModelPresentation
cawthron
parents:
diff changeset
   102
 */
cawthron
parents:
diff changeset
   103
public class CDebugModelPresentation extends LabelProvider implements IDebugModelPresentation {
cawthron
parents:
diff changeset
   104
cawthron
parents:
diff changeset
   105
	public final static String DISPLAY_FULL_PATHS = "DISPLAY_FULL_PATHS"; //$NON-NLS-1$
cawthron
parents:
diff changeset
   106
cawthron
parents:
diff changeset
   107
	private static final String DUMMY_STACKFRAME_LABEL = "..."; //$NON-NLS-1$
cawthron
parents:
diff changeset
   108
cawthron
parents:
diff changeset
   109
	protected HashMap fAttributes = new HashMap( 3 );
cawthron
parents:
diff changeset
   110
cawthron
parents:
diff changeset
   111
	protected CDebugImageDescriptorRegistry fDebugImageRegistry = CDebugUIPlugin.getImageDescriptorRegistry();
cawthron
parents:
diff changeset
   112
cawthron
parents:
diff changeset
   113
	private OverlayImageCache fImageCache = new OverlayImageCache();
cawthron
parents:
diff changeset
   114
	
cawthron
parents:
diff changeset
   115
	private static CDebugModelPresentation gfInstance = null;
cawthron
parents:
diff changeset
   116
cawthron
parents:
diff changeset
   117
	public static CDebugModelPresentation getDefault() {
cawthron
parents:
diff changeset
   118
		if ( gfInstance == null )
cawthron
parents:
diff changeset
   119
			gfInstance = new CDebugModelPresentation();
cawthron
parents:
diff changeset
   120
		return gfInstance;
cawthron
parents:
diff changeset
   121
	}
cawthron
parents:
diff changeset
   122
cawthron
parents:
diff changeset
   123
	/* (non-Javadoc)
cawthron
parents:
diff changeset
   124
	 * @see org.eclipse.debug.ui.IDebugModelPresentation#setAttribute(java.lang.String, java.lang.Object)
cawthron
parents:
diff changeset
   125
	 */
cawthron
parents:
diff changeset
   126
	public void setAttribute( String attribute, Object value ) {
cawthron
parents:
diff changeset
   127
		if ( value == null )
cawthron
parents:
diff changeset
   128
			return;
cawthron
parents:
diff changeset
   129
		getAttributes().put( attribute, value );
cawthron
parents:
diff changeset
   130
	}
cawthron
parents:
diff changeset
   131
cawthron
parents:
diff changeset
   132
	/* (non-Javadoc)
cawthron
parents:
diff changeset
   133
	 * @see org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(org.eclipse.debug.core.model.IValue, org.eclipse.debug.ui.IValueDetailListener)
cawthron
parents:
diff changeset
   134
	 */
cawthron
parents:
diff changeset
   135
	public void computeDetail( IValue value, IValueDetailListener listener ) {
cawthron
parents:
diff changeset
   136
		CValueDetailProvider.getDefault().computeDetail( value, listener );
cawthron
parents:
diff changeset
   137
	}
cawthron
parents:
diff changeset
   138
cawthron
parents:
diff changeset
   139
	/* (non-Javadoc)
cawthron
parents:
diff changeset
   140
	 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object)
cawthron
parents:
diff changeset
   141
	 */
cawthron
parents:
diff changeset
   142
	public IEditorInput getEditorInput( Object element ) {
cawthron
parents:
diff changeset
   143
		if ( element instanceof IMarker ) {
cawthron
parents:
diff changeset
   144
			IResource resource = ((IMarker)element).getResource();
cawthron
parents:
diff changeset
   145
			if ( resource instanceof IFile )
cawthron
parents:
diff changeset
   146
				return new FileEditorInput( (IFile)resource );
cawthron
parents:
diff changeset
   147
		}
cawthron
parents:
diff changeset
   148
		if ( element instanceof IFile ) {
cawthron
parents:
diff changeset
   149
			return new FileEditorInput( (IFile)element );
cawthron
parents:
diff changeset
   150
		}
cawthron
parents:
diff changeset
   151
		if ( element instanceof ICBreakpoint ) {
cawthron
parents:
diff changeset
   152
			ICBreakpoint b = (ICBreakpoint)element;
cawthron
parents:
diff changeset
   153
			IFile file = null;
cawthron
parents:
diff changeset
   154
			try {
cawthron
parents:
diff changeset
   155
				String handle = b.getSourceHandle();
cawthron
parents:
diff changeset
   156
				if ( handle != null ) {
cawthron
parents:
diff changeset
   157
					IPath path = new Path( handle );
cawthron
parents:
diff changeset
   158
					if ( path.isValidPath( handle ) ) {
cawthron
parents:
diff changeset
   159
						IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path );
cawthron
parents:
diff changeset
   160
						if ( files.length > 0 ) {
cawthron
parents:
diff changeset
   161
							// default to the first file found in the workspace
cawthron
parents:
diff changeset
   162
							file = files[0];
cawthron
parents:
diff changeset
   163
							
cawthron
parents:
diff changeset
   164
							// now try to match any finding to the project in the breakpoint
cawthron
parents:
diff changeset
   165
							IProject project = b.getMarker().getResource().getProject();
cawthron
parents:
diff changeset
   166
							for (IFile f : files) {
cawthron
parents:
diff changeset
   167
								if (f.getProject().equals(project)) {
cawthron
parents:
diff changeset
   168
									file = f;
cawthron
parents:
diff changeset
   169
									break;
cawthron
parents:
diff changeset
   170
								}
cawthron
parents:
diff changeset
   171
							}
cawthron
parents:
diff changeset
   172
						}
cawthron
parents:
diff changeset
   173
						else {
cawthron
parents:
diff changeset
   174
							File fsfile = new File( handle );
cawthron
parents:
diff changeset
   175
							if ( fsfile.isFile() && fsfile.exists() ) {
cawthron
parents:
diff changeset
   176
								// create an ExternalEditorInput with an external tu so when you
cawthron
parents:
diff changeset
   177
								// open the file from the breakpoints view it opens in the
cawthron
parents:
diff changeset
   178
								// proper editor.
cawthron
parents:
diff changeset
   179
								IProject project = b.getMarker().getResource().getProject();
6
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   180
								if (project != null)
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   181
									{
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   182
									ICProject cproject = CoreModel.getDefault().create(project);
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   183
									String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment());
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   184
									ExternalTranslationUnit tu = new ExternalTranslationUnit(cproject, URIUtil.toURI(path), id);
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   185
									return new ExternalEditorInput( tu, new LocalFileStorage( fsfile ) );
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   186
									}
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   187
								else
648636cfa849 Syns with CDT HEAD
ryall
parents: 1
diff changeset
   188
									return new FileEditorInput( file );
1
cawthron
parents:
diff changeset
   189
							}
cawthron
parents:
diff changeset
   190
						}
cawthron
parents:
diff changeset
   191
					}
cawthron
parents:
diff changeset
   192
				}
cawthron
parents:
diff changeset
   193
			}
cawthron
parents:
diff changeset
   194
			catch( CoreException e ) {
cawthron
parents:
diff changeset
   195
			}
cawthron
parents:
diff changeset
   196
			if ( file == null )
cawthron
parents:
diff changeset
   197
				file = (IFile)b.getMarker().getResource().getAdapter( IFile.class );
cawthron
parents:
diff changeset
   198
			if ( file != null )
cawthron
parents:
diff changeset
   199
				return new FileEditorInput( file );
cawthron
parents:
diff changeset
   200
		}
cawthron
parents:
diff changeset
   201
		if ( element instanceof FileStorage || element instanceof LocalFileStorage ) {
cawthron
parents:
diff changeset
   202
			return new ExternalEditorInput( (IStorage)element );
cawthron
parents:
diff changeset
   203
		}
cawthron
parents:
diff changeset
   204
		if ( element instanceof ExternalTranslationUnit ) {
cawthron
parents:
diff changeset
   205
			ExternalTranslationUnit etu = (ExternalTranslationUnit) element;
cawthron
parents:
diff changeset
   206
			return new ExternalEditorInput( etu , new LocalFileStorage( etu.getLocation().toFile() ) );
cawthron
parents:
diff changeset
   207
		}
cawthron
parents:
diff changeset
   208
		if (element instanceof CSourceNotFoundElement)
cawthron
parents:
diff changeset
   209
		{
cawthron
parents:
diff changeset
   210
			return new CSourceNotFoundEditorInput((CSourceNotFoundElement) element);
cawthron
parents:
diff changeset
   211
		}
cawthron
parents:
diff changeset
   212
		return null;
cawthron
parents:
diff changeset
   213
	}
cawthron
parents:
diff changeset
   214
cawthron
parents:
diff changeset
   215
	/* (non-Javadoc)
cawthron
parents:
diff changeset
   216
	 * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput, java.lang.Object)
cawthron
parents:
diff changeset
   217
	 */
cawthron
parents:
diff changeset
   218
	public String getEditorId( IEditorInput input, Object element ) {
cawthron
parents:
diff changeset
   219
		if (element instanceof CSourceNotFoundElement)
cawthron
parents:
diff changeset
   220
			return ICDebugUIConstants.CSOURCENOTFOUND_EDITOR_ID;
cawthron
parents:
diff changeset
   221
		String id = null;
cawthron
parents:
diff changeset
   222
		if ( input != null ) {
cawthron
parents:
diff changeset
   223
			IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
cawthron
parents:
diff changeset
   224
			IEditorDescriptor descriptor = registry.getDefaultEditor( input.getName() );
cawthron
parents:
diff changeset
   225
			id = (descriptor != null) ? descriptor.getId() : CUIPlugin.EDITOR_ID;
cawthron
parents:
diff changeset
   226
		}
cawthron
parents:
diff changeset
   227
		return id;
cawthron
parents:
diff changeset
   228
	}
cawthron
parents:
diff changeset
   229
cawthron
parents:
diff changeset
   230
	public Image getImage( Object element ) {
cawthron
parents:
diff changeset
   231
		Image baseImage = getBaseImage( element );
cawthron
parents:
diff changeset
   232
		if ( baseImage != null ) {
cawthron
parents:
diff changeset
   233
			ImageDescriptor[] overlays = new ImageDescriptor[]{ null, null, null, null };
cawthron
parents:
diff changeset
   234
			if ( element instanceof ICDebugElementStatus && !((ICDebugElementStatus)element).isOK() ) {
cawthron
parents:
diff changeset
   235
				switch( ((ICDebugElementStatus)element).getSeverity() ) {
cawthron
parents:
diff changeset
   236
					case ICDebugElementStatus.WARNING:
cawthron
parents:
diff changeset
   237
						overlays[OverlayImageDescriptor.BOTTOM_LEFT] = CDebugImages.DESC_OVRS_WARNING;
cawthron
parents:
diff changeset
   238
						break;
cawthron
parents:
diff changeset
   239
					case ICDebugElementStatus.ERROR:
cawthron
parents:
diff changeset
   240
						overlays[OverlayImageDescriptor.BOTTOM_LEFT] = CDebugImages.DESC_OVRS_ERROR;
cawthron
parents:
diff changeset
   241
						break;
cawthron
parents:
diff changeset
   242
				}
cawthron
parents:
diff changeset
   243
			}
cawthron
parents:
diff changeset
   244
			if ( element instanceof IWatchExpression && ((IWatchExpression)element).hasErrors() )
cawthron
parents:
diff changeset
   245
				overlays[OverlayImageDescriptor.BOTTOM_LEFT] = CDebugImages.DESC_OVRS_ERROR;
cawthron
parents:
diff changeset
   246
			if ( element instanceof ICVariable && ((ICVariable)element).isArgument() )
cawthron
parents:
diff changeset
   247
				overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_ARGUMENT;
cawthron
parents:
diff changeset
   248
			if ( element instanceof ICGlobalVariable && !(element instanceof IRegister) )
cawthron
parents:
diff changeset
   249
				overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_GLOBAL;
cawthron
parents:
diff changeset
   250
			return getImageCache().getImageFor( new OverlayImageDescriptor( baseImage, overlays ) );
cawthron
parents:
diff changeset
   251
		}
cawthron
parents:
diff changeset
   252
		return null;
cawthron
parents:
diff changeset
   253
	}
cawthron
parents:
diff changeset
   254
cawthron
parents:
diff changeset
   255
	private Image getBaseImage( Object element ) {
cawthron
parents:
diff changeset
   256
		if ( element instanceof ICDebugTarget ) {
cawthron
parents:
diff changeset
   257
			ICDebugTarget target = (ICDebugTarget)element;
cawthron
parents:
diff changeset
   258
			if ( target.isPostMortem() ) {
cawthron
parents:
diff changeset
   259
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED ) );
cawthron
parents:
diff changeset
   260
			}
cawthron
parents:
diff changeset
   261
			if ( target.isTerminated() || target.isDisconnected() ) {
cawthron
parents:
diff changeset
   262
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_DEBUG_TARGET_TERMINATED ) );
cawthron
parents:
diff changeset
   263
			}
cawthron
parents:
diff changeset
   264
			return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_DEBUG_TARGET ) );
cawthron
parents:
diff changeset
   265
		}
cawthron
parents:
diff changeset
   266
		if ( element instanceof ICThread ) {
cawthron
parents:
diff changeset
   267
			ICThread thread = (ICThread)element;
cawthron
parents:
diff changeset
   268
			ICDebugTarget target = (ICDebugTarget)thread.getDebugTarget();
cawthron
parents:
diff changeset
   269
			if ( target.isPostMortem() ) {
cawthron
parents:
diff changeset
   270
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED ) );
cawthron
parents:
diff changeset
   271
			}
cawthron
parents:
diff changeset
   272
			if ( thread.isSuspended() ) {
cawthron
parents:
diff changeset
   273
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_THREAD_SUSPENDED ) );
cawthron
parents:
diff changeset
   274
			}
cawthron
parents:
diff changeset
   275
			else if ( thread.isTerminated() ) {
cawthron
parents:
diff changeset
   276
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_THREAD_TERMINATED ) );
cawthron
parents:
diff changeset
   277
			}
cawthron
parents:
diff changeset
   278
			else {
cawthron
parents:
diff changeset
   279
				return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_THREAD_RUNNING ) );
cawthron
parents:
diff changeset
   280
			}
cawthron
parents:
diff changeset
   281
		}
cawthron
parents:
diff changeset
   282
		if ( element instanceof IMarker ) {
cawthron
parents:
diff changeset
   283
			IBreakpoint bp = getBreakpoint( (IMarker)element );
cawthron
parents:
diff changeset
   284
			if ( bp != null && bp instanceof ICBreakpoint ) {
cawthron
parents:
diff changeset
   285
				return getBreakpointImage( (ICBreakpoint)bp );
cawthron
parents:
diff changeset
   286
			}
cawthron
parents:
diff changeset
   287
		}
cawthron
parents:
diff changeset
   288
		if ( element instanceof ICBreakpoint ) {
cawthron
parents:
diff changeset
   289
			return getBreakpointImage( (ICBreakpoint)element );
cawthron
parents:
diff changeset
   290
		}
cawthron
parents:
diff changeset
   291
		if ( element instanceof IRegisterGroup ) {
cawthron
parents:
diff changeset
   292
			return getRegisterGroupImage( (IRegisterGroup)element );
cawthron
parents:
diff changeset
   293
		}
cawthron
parents:
diff changeset
   294
		if ( element instanceof IExpression ) {
cawthron
parents:
diff changeset
   295
			return getExpressionImage( (IExpression)element );
cawthron
parents:
diff changeset
   296
		}
cawthron
parents:
diff changeset
   297
		if ( element instanceof IRegister ) {
cawthron
parents:
diff changeset
   298
			return getRegisterImage( (IRegister)element );
cawthron
parents:
diff changeset
   299
		}
cawthron
parents:
diff changeset
   300
		if ( element instanceof IVariable ) {
cawthron
parents:
diff changeset
   301
			return getVariableImage( (IVariable)element );
cawthron
parents:
diff changeset
   302
		}
cawthron
parents:
diff changeset
   303
		if ( element instanceof ICModule ) {
cawthron
parents:
diff changeset
   304
			return getModuleImage( (ICModule)element );
cawthron
parents:
diff changeset
   305
		}
cawthron
parents:
diff changeset
   306
		if ( element instanceof ICSignal ) {
cawthron
parents:
diff changeset
   307
			return getSignalImage( (ICSignal)element );
cawthron
parents:
diff changeset
   308
		}
cawthron
parents:
diff changeset
   309
		return super.getImage( element );
cawthron
parents:
diff changeset
   310
	}
cawthron
parents:
diff changeset
   311
cawthron
parents:
diff changeset
   312
	protected Image getSignalImage( ICSignal signal ) {
cawthron
parents:
diff changeset
   313
		return CDebugUIPlugin.getImageDescriptorRegistry().get( CDebugImages.DESC_OBJS_SIGNAL );
cawthron
parents:
diff changeset
   314
	}
cawthron
parents:
diff changeset
   315
cawthron
parents:
diff changeset
   316
	protected Image getRegisterGroupImage( IRegisterGroup element ) {
cawthron
parents:
diff changeset
   317
		IEnableDisableTarget target = (IEnableDisableTarget)element.getAdapter( IEnableDisableTarget.class );
cawthron
parents:
diff changeset
   318
		if ( target != null && !target.isEnabled() )
cawthron
parents:
diff changeset
   319
			return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_GROUP_DISABLED );
cawthron
parents:
diff changeset
   320
		return fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_GROUP );
cawthron
parents:
diff changeset
   321
	}
cawthron
parents:
diff changeset
   322
cawthron
parents:
diff changeset
   323
	protected Image getBreakpointImage( ICBreakpoint breakpoint ) {
cawthron
parents:
diff changeset
   324
		// if adapter installed for breakpoint, call the adapter
cawthron
parents:
diff changeset
   325
		ILabelProvider adapter = (ILabelProvider) Platform.getAdapterManager().getAdapter(breakpoint, ILabelProvider.class);
cawthron
parents:
diff changeset
   326
		if (adapter!=null) { 
cawthron
parents:
diff changeset
   327
			Image image = adapter.getImage(breakpoint);
cawthron
parents:
diff changeset
   328
			if (image!=null) return image;
cawthron
parents:
diff changeset
   329
		}
cawthron
parents:
diff changeset
   330
		try {
cawthron
parents:
diff changeset
   331
			if ( breakpoint instanceof ICLineBreakpoint ) {
cawthron
parents:
diff changeset
   332
				return getLineBreakpointImage( (ICLineBreakpoint)breakpoint );
cawthron
parents:
diff changeset
   333
			}
cawthron
parents:
diff changeset
   334
			if ( breakpoint instanceof ICWatchpoint ) {
cawthron
parents:
diff changeset
   335
				return getWatchpointImage( (ICWatchpoint)breakpoint );
cawthron
parents:
diff changeset
   336
			}
cawthron
parents:
diff changeset
   337
		}
cawthron
parents:
diff changeset
   338
		catch( CoreException e ) {
cawthron
parents:
diff changeset
   339
		}
cawthron
parents:
diff changeset
   340
		return null;
cawthron
parents:
diff changeset
   341
	}
cawthron
parents:
diff changeset
   342
cawthron
parents:
diff changeset
   343
	protected Image getLineBreakpointImage( ICLineBreakpoint breakpoint ) throws CoreException {
cawthron
parents:
diff changeset
   344
		ImageDescriptor descriptor = null;
cawthron
parents:
diff changeset
   345
		if ( breakpoint.isEnabled() ) {
cawthron
parents:
diff changeset
   346
			descriptor = CDebugImages.DESC_OBJS_BREAKPOINT_ENABLED;
cawthron
parents:
diff changeset
   347
		}
cawthron
parents:
diff changeset
   348
		else {
cawthron
parents:
diff changeset
   349
			descriptor = CDebugImages.DESC_OBJS_BREAKPOINT_DISABLED;
cawthron
parents:
diff changeset
   350
		}
cawthron
parents:
diff changeset
   351
		return getImageCache().getImageFor( new OverlayImageDescriptor( fDebugImageRegistry.get( descriptor ), computeBreakpointOverlays( breakpoint ) ) );
cawthron
parents:
diff changeset
   352
	}
cawthron
parents:
diff changeset
   353
cawthron
parents:
diff changeset
   354
	protected Image getWatchpointImage( ICWatchpoint watchpoint ) throws CoreException {
cawthron
parents:
diff changeset
   355
		ImageDescriptor descriptor = null;
cawthron
parents:
diff changeset
   356
		if ( watchpoint.isEnabled() ) {
cawthron
parents:
diff changeset
   357
			if ( watchpoint.isReadType() && !watchpoint.isWriteType() )
cawthron
parents:
diff changeset
   358
				descriptor = CDebugImages.DESC_OBJS_READ_WATCHPOINT_ENABLED;
cawthron
parents:
diff changeset
   359
			else if ( !watchpoint.isReadType() && watchpoint.isWriteType() )
cawthron
parents:
diff changeset
   360
				descriptor = CDebugImages.DESC_OBJS_WRITE_WATCHPOINT_ENABLED;
cawthron
parents:
diff changeset
   361
			else
cawthron
parents:
diff changeset
   362
				descriptor = CDebugImages.DESC_OBJS_WATCHPOINT_ENABLED;
cawthron
parents:
diff changeset
   363
		}
cawthron
parents:
diff changeset
   364
		else {
cawthron
parents:
diff changeset
   365
			if ( watchpoint.isReadType() && !watchpoint.isWriteType() )
cawthron
parents:
diff changeset
   366
				descriptor = CDebugImages.DESC_OBJS_READ_WATCHPOINT_DISABLED;
cawthron
parents:
diff changeset
   367
			else if ( !watchpoint.isReadType() && watchpoint.isWriteType() )
cawthron
parents:
diff changeset
   368
				descriptor = CDebugImages.DESC_OBJS_WRITE_WATCHPOINT_DISABLED;
cawthron
parents:
diff changeset
   369
			else
cawthron
parents:
diff changeset
   370
				descriptor = CDebugImages.DESC_OBJS_WATCHPOINT_DISABLED;
cawthron
parents:
diff changeset
   371
		}
cawthron
parents:
diff changeset
   372
		return getImageCache().getImageFor( new OverlayImageDescriptor( fDebugImageRegistry.get( descriptor ), computeBreakpointOverlays( watchpoint ) ) );
cawthron
parents:
diff changeset
   373
	}
cawthron
parents:
diff changeset
   374
cawthron
parents:
diff changeset
   375
	public String getText( Object element ) {
cawthron
parents:
diff changeset
   376
		String bt = getBaseText( element );
cawthron
parents:
diff changeset
   377
		if ( bt == null )
cawthron
parents:
diff changeset
   378
			return null;
cawthron
parents:
diff changeset
   379
		return CDebugUIUtils.decorateText( element, bt );
cawthron
parents:
diff changeset
   380
	}
cawthron
parents:
diff changeset
   381
cawthron
parents:
diff changeset
   382
	private String getBaseText( Object element ) {
cawthron
parents:
diff changeset
   383
		boolean showQualified = isShowQualifiedNames();
cawthron
parents:
diff changeset
   384
		StringBuffer label = new StringBuffer();
cawthron
parents:
diff changeset
   385
		try {
cawthron
parents:
diff changeset
   386
			if ( element instanceof ICModule ) {
cawthron
parents:
diff changeset
   387
				label.append( getModuleText( (ICModule)element, showQualified ) );
cawthron
parents:
diff changeset
   388
				return label.toString();
cawthron
parents:
diff changeset
   389
			}
cawthron
parents:
diff changeset
   390
			if ( element instanceof ICSignal ) {
cawthron
parents:
diff changeset
   391
				label.append( getSignalText( (ICSignal)element ) );
cawthron
parents:
diff changeset
   392
				return label.toString();
cawthron
parents:
diff changeset
   393
			}
cawthron
parents:
diff changeset
   394
			if ( element instanceof IRegisterGroup ) {
cawthron
parents:
diff changeset
   395
				label.append( ((IRegisterGroup)element).getName() );
cawthron
parents:
diff changeset
   396
				return label.toString();
cawthron
parents:
diff changeset
   397
			}
cawthron
parents:
diff changeset
   398
			if ( element instanceof IWatchExpression ) {
cawthron
parents:
diff changeset
   399
				return getWatchExpressionText( (IWatchExpression)element );
cawthron
parents:
diff changeset
   400
			}
cawthron
parents:
diff changeset
   401
			if ( element instanceof IVariable ) {
cawthron
parents:
diff changeset
   402
				label.append( getVariableText( (IVariable)element ) );
cawthron
parents:
diff changeset
   403
				return label.toString();
cawthron
parents:
diff changeset
   404
			}
cawthron
parents:
diff changeset
   405
			if ( element instanceof IValue ) {
cawthron
parents:
diff changeset
   406
				label.append( getValueText( (IValue)element ) );
cawthron
parents:
diff changeset
   407
				return label.toString();
cawthron
parents:
diff changeset
   408
			}
cawthron
parents:
diff changeset
   409
			if ( element instanceof IStackFrame ) {
cawthron
parents:
diff changeset
   410
				label.append( getStackFrameText( (IStackFrame)element, showQualified ) );
cawthron
parents:
diff changeset
   411
				return label.toString();
cawthron
parents:
diff changeset
   412
			}
cawthron
parents:
diff changeset
   413
			if ( element instanceof CSourceNotFoundElement ) {
cawthron
parents:
diff changeset
   414
				return getBaseText(((CSourceNotFoundElement)element).getElement());
cawthron
parents:
diff changeset
   415
			}
cawthron
parents:
diff changeset
   416
			if ( element instanceof IMarker ) {
cawthron
parents:
diff changeset
   417
				IBreakpoint breakpoint = getBreakpoint( (IMarker)element );
cawthron
parents:
diff changeset
   418
				if ( breakpoint != null ) {
cawthron
parents:
diff changeset
   419
					return CDebugUtils.getBreakpointText( breakpoint, showQualified );
cawthron
parents:
diff changeset
   420
				}
cawthron
parents:
diff changeset
   421
				return null;
cawthron
parents:
diff changeset
   422
			}
cawthron
parents:
diff changeset
   423
			if ( element instanceof IBreakpoint ) {
cawthron
parents:
diff changeset
   424
				// if adapter installed for breakpoint, call adapter
cawthron
parents:
diff changeset
   425
				ILabelProvider adapter = (ILabelProvider) Platform.getAdapterManager().getAdapter(element, ILabelProvider.class);
cawthron
parents:
diff changeset
   426
				if (adapter!=null) { 
cawthron
parents:
diff changeset
   427
					String text = adapter.getText(element);
cawthron
parents:
diff changeset
   428
					if (text!=null) return text;
cawthron
parents:
diff changeset
   429
				}
cawthron
parents:
diff changeset
   430
				return CDebugUtils.getBreakpointText( (IBreakpoint)element, showQualified );
cawthron
parents:
diff changeset
   431
			}
cawthron
parents:
diff changeset
   432
			if ( element instanceof IDebugTarget )
cawthron
parents:
diff changeset
   433
				label.append( getTargetText( (IDebugTarget)element, showQualified ) );
cawthron
parents:
diff changeset
   434
			else if ( element instanceof IThread )
cawthron
parents:
diff changeset
   435
				label.append( getThreadText( (IThread)element, showQualified ) );
cawthron
parents:
diff changeset
   436
			if ( element instanceof ITerminate ) {
cawthron
parents:
diff changeset
   437
				if ( ((ITerminate)element).isTerminated() ) {
cawthron
parents:
diff changeset
   438
					label.insert( 0, CDebugUIMessages.getString( "CDTDebugModelPresentation.0" ) ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   439
					return label.toString();
cawthron
parents:
diff changeset
   440
				}
cawthron
parents:
diff changeset
   441
			}
cawthron
parents:
diff changeset
   442
			if ( element instanceof IDisconnect ) {
cawthron
parents:
diff changeset
   443
				if ( ((IDisconnect)element).isDisconnected() ) {
cawthron
parents:
diff changeset
   444
					label.insert( 0, CDebugUIMessages.getString( "CDTDebugModelPresentation.1" ) ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   445
					return label.toString();
cawthron
parents:
diff changeset
   446
				}
cawthron
parents:
diff changeset
   447
			}
cawthron
parents:
diff changeset
   448
			if ( label.length() > 0 ) {
cawthron
parents:
diff changeset
   449
				return label.toString();
cawthron
parents:
diff changeset
   450
			}
cawthron
parents:
diff changeset
   451
		}
cawthron
parents:
diff changeset
   452
		catch( DebugException e ) {
cawthron
parents:
diff changeset
   453
			return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.2" ), new String[] { e.getMessage() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   454
		}
cawthron
parents:
diff changeset
   455
		catch( CoreException e ) {
cawthron
parents:
diff changeset
   456
			CDebugUIPlugin.log( e );
cawthron
parents:
diff changeset
   457
		}
cawthron
parents:
diff changeset
   458
		return null;
cawthron
parents:
diff changeset
   459
	}
cawthron
parents:
diff changeset
   460
cawthron
parents:
diff changeset
   461
	protected String getModuleText( ICModule module, boolean qualified ) {
cawthron
parents:
diff changeset
   462
		StringBuffer sb = new StringBuffer();
cawthron
parents:
diff changeset
   463
		IPath path = module.getImageName();
cawthron
parents:
diff changeset
   464
		if ( !path.isEmpty() ) {
cawthron
parents:
diff changeset
   465
			sb.append( path.lastSegment() );
cawthron
parents:
diff changeset
   466
		}
cawthron
parents:
diff changeset
   467
		else {
cawthron
parents:
diff changeset
   468
			sb.append( CDebugUIMessages.getString( "CDebugModelPresentation.unknown_1" ) ); //$NON-NLS-1$		
cawthron
parents:
diff changeset
   469
		}
cawthron
parents:
diff changeset
   470
		return sb.toString();
cawthron
parents:
diff changeset
   471
	}
cawthron
parents:
diff changeset
   472
cawthron
parents:
diff changeset
   473
	protected String getRegisterGroupText( IRegisterGroup group ) {
cawthron
parents:
diff changeset
   474
		String name = CDebugUIMessages.getString( "CDebugModelPresentation.not_available_1" ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   475
		try {
cawthron
parents:
diff changeset
   476
			name = group.getName();
cawthron
parents:
diff changeset
   477
		}
cawthron
parents:
diff changeset
   478
		catch( DebugException e ) {
cawthron
parents:
diff changeset
   479
			CDebugUIPlugin.log( e.getStatus() );
cawthron
parents:
diff changeset
   480
		}
cawthron
parents:
diff changeset
   481
		return name;
cawthron
parents:
diff changeset
   482
	}
cawthron
parents:
diff changeset
   483
cawthron
parents:
diff changeset
   484
	protected boolean isShowQualifiedNames() {
cawthron
parents:
diff changeset
   485
		Boolean showQualified = (Boolean)getAttributes().get( DISPLAY_FULL_PATHS );
cawthron
parents:
diff changeset
   486
		showQualified = showQualified == null ? Boolean.FALSE : showQualified;
cawthron
parents:
diff changeset
   487
		return showQualified.booleanValue();
cawthron
parents:
diff changeset
   488
	}
cawthron
parents:
diff changeset
   489
cawthron
parents:
diff changeset
   490
	private HashMap getAttributes() {
cawthron
parents:
diff changeset
   491
		return this.fAttributes;
cawthron
parents:
diff changeset
   492
	}
cawthron
parents:
diff changeset
   493
cawthron
parents:
diff changeset
   494
	private OverlayImageCache getImageCache() {
cawthron
parents:
diff changeset
   495
		return this.fImageCache;
cawthron
parents:
diff changeset
   496
	}
cawthron
parents:
diff changeset
   497
cawthron
parents:
diff changeset
   498
	private boolean isEmpty( String string ) {
cawthron
parents:
diff changeset
   499
		return ( string == null || string.trim().length() == 0 );
cawthron
parents:
diff changeset
   500
	}
cawthron
parents:
diff changeset
   501
cawthron
parents:
diff changeset
   502
	protected IBreakpoint getBreakpoint( IMarker marker ) {
cawthron
parents:
diff changeset
   503
		return DebugPlugin.getDefault().getBreakpointManager().getBreakpoint( marker );
cawthron
parents:
diff changeset
   504
	}
cawthron
parents:
diff changeset
   505
cawthron
parents:
diff changeset
   506
	private ImageDescriptor[] computeBreakpointOverlays( ICBreakpoint breakpoint ) {
cawthron
parents:
diff changeset
   507
		ImageDescriptor[] overlays = new ImageDescriptor[]{ null, null, null, null };
cawthron
parents:
diff changeset
   508
		try {
cawthron
parents:
diff changeset
   509
			if ( CDebugCorePlugin.getDefault().getBreakpointActionManager().breakpointHasActions(breakpoint) ) {
cawthron
parents:
diff changeset
   510
				overlays[OverlayImageDescriptor.BOTTOM_RIGHT] = (breakpoint.isEnabled()) ? CDebugImages.DESC_OVRS_BREAKPOINT_WITH_ACTIONS : CDebugImages.DESC_OVRS_BREAKPOINT_WITH_ACTIONS_DISABLED;
cawthron
parents:
diff changeset
   511
			}
cawthron
parents:
diff changeset
   512
			if ( breakpoint.isConditional() ) {
cawthron
parents:
diff changeset
   513
				overlays[OverlayImageDescriptor.TOP_LEFT] = (breakpoint.isEnabled()) ? CDebugImages.DESC_OVRS_BREAKPOINT_CONDITIONAL : CDebugImages.DESC_OVRS_BREAKPOINT_CONDITIONAL_DISABLED;
cawthron
parents:
diff changeset
   514
			}
cawthron
parents:
diff changeset
   515
			if ( breakpoint.isInstalled() ) {
cawthron
parents:
diff changeset
   516
				overlays[OverlayImageDescriptor.BOTTOM_LEFT] = (breakpoint.isEnabled()) ? CDebugImages.DESC_OVRS_BREAKPOINT_INSTALLED : CDebugImages.DESC_OVRS_BREAKPOINT_INSTALLED_DISABLED;
cawthron
parents:
diff changeset
   517
			}
cawthron
parents:
diff changeset
   518
			if ( breakpoint instanceof ICAddressBreakpoint ) {
cawthron
parents:
diff changeset
   519
				overlays[OverlayImageDescriptor.TOP_RIGHT] = (breakpoint.isEnabled()) ? CDebugImages.DESC_OVRS_ADDRESS_BREAKPOINT : CDebugImages.DESC_OVRS_ADDRESS_BREAKPOINT_DISABLED;
cawthron
parents:
diff changeset
   520
			}
cawthron
parents:
diff changeset
   521
			if ( breakpoint instanceof ICFunctionBreakpoint ) {
cawthron
parents:
diff changeset
   522
				overlays[OverlayImageDescriptor.TOP_RIGHT] = (breakpoint.isEnabled()) ? CDebugImages.DESC_OVRS_FUNCTION_BREAKPOINT : CDebugImages.DESC_OVRS_FUNCTION_BREAKPOINT_DISABLED;
cawthron
parents:
diff changeset
   523
			}
cawthron
parents:
diff changeset
   524
		}
cawthron
parents:
diff changeset
   525
		catch( CoreException e ) {
cawthron
parents:
diff changeset
   526
			CDebugUIPlugin.log( e );
cawthron
parents:
diff changeset
   527
		}
cawthron
parents:
diff changeset
   528
		return overlays;
cawthron
parents:
diff changeset
   529
	}
cawthron
parents:
diff changeset
   530
cawthron
parents:
diff changeset
   531
cawthron
parents:
diff changeset
   532
	protected Image getVariableImage( IVariable element ) {
cawthron
parents:
diff changeset
   533
		if ( element instanceof ICVariable ) {
cawthron
parents:
diff changeset
   534
			ICType type = null;
cawthron
parents:
diff changeset
   535
			try {
cawthron
parents:
diff changeset
   536
				type = ((ICVariable)element).getType();
cawthron
parents:
diff changeset
   537
			}
cawthron
parents:
diff changeset
   538
			catch( DebugException e ) {
cawthron
parents:
diff changeset
   539
				// use default image
cawthron
parents:
diff changeset
   540
			}
cawthron
parents:
diff changeset
   541
			if ( type != null && (type.isPointer() || type.isReference()) )
cawthron
parents:
diff changeset
   542
				return fDebugImageRegistry.get( (((ICVariable)element).isEnabled()) ? CDebugImages.DESC_OBJS_VARIABLE_POINTER : CDebugImages.DESC_OBJS_VARIABLE_POINTER_DISABLED );
cawthron
parents:
diff changeset
   543
			else if ( type != null && (type.isArray() || type.isStructure()) )
cawthron
parents:
diff changeset
   544
				return fDebugImageRegistry.get( (((ICVariable)element).isEnabled()) ? CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE : CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE_DISABLED );
cawthron
parents:
diff changeset
   545
			else
cawthron
parents:
diff changeset
   546
				return fDebugImageRegistry.get( (((ICVariable)element).isEnabled()) ? CDebugImages.DESC_OBJS_VARIABLE_SIMPLE : CDebugImages.DESC_OBJS_VARIABLE_SIMPLE_DISABLED );
cawthron
parents:
diff changeset
   547
		}
cawthron
parents:
diff changeset
   548
		return null;
cawthron
parents:
diff changeset
   549
	}
cawthron
parents:
diff changeset
   550
cawthron
parents:
diff changeset
   551
	protected Image getRegisterImage( IRegister element ) {
cawthron
parents:
diff changeset
   552
		return ( ( element instanceof ICVariable && ((ICVariable)element).isEnabled() ) ) ? fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER ) : fDebugImageRegistry.get( CDebugImages.DESC_OBJS_REGISTER_DISABLED );
cawthron
parents:
diff changeset
   553
	}
cawthron
parents:
diff changeset
   554
cawthron
parents:
diff changeset
   555
	protected Image getExpressionImage( IExpression element ) {
cawthron
parents:
diff changeset
   556
		return fDebugImageRegistry.get( DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_OBJS_EXPRESSION ) );
cawthron
parents:
diff changeset
   557
	}
cawthron
parents:
diff changeset
   558
cawthron
parents:
diff changeset
   559
	protected Image getModuleImage( ICModule element ) {
cawthron
parents:
diff changeset
   560
		switch( element.getType() ) {
cawthron
parents:
diff changeset
   561
			case ICModule.EXECUTABLE:
cawthron
parents:
diff changeset
   562
				if ( element.areSymbolsLoaded() ) {
cawthron
parents:
diff changeset
   563
					return CDebugUIPlugin.getImageDescriptorRegistry().get( CDebugImages.DESC_OBJS_EXECUTABLE_WITH_SYMBOLS );
cawthron
parents:
diff changeset
   564
				}
cawthron
parents:
diff changeset
   565
				return CDebugUIPlugin.getImageDescriptorRegistry().get( CDebugImages.DESC_OBJS_EXECUTABLE );
cawthron
parents:
diff changeset
   566
			case ICModule.SHARED_LIBRARY:
cawthron
parents:
diff changeset
   567
				if ( element.areSymbolsLoaded() ) {
cawthron
parents:
diff changeset
   568
					return CDebugUIPlugin.getImageDescriptorRegistry().get( CDebugImages.DESC_OBJS_SHARED_LIBRARY_WITH_SYMBOLS );
cawthron
parents:
diff changeset
   569
				}
cawthron
parents:
diff changeset
   570
				return CDebugUIPlugin.getImageDescriptorRegistry().get( CDebugImages.DESC_OBJS_SHARED_LIBRARY );
cawthron
parents:
diff changeset
   571
		}
cawthron
parents:
diff changeset
   572
		return null;
cawthron
parents:
diff changeset
   573
	}
cawthron
parents:
diff changeset
   574
cawthron
parents:
diff changeset
   575
	protected String getVariableText( IVariable var ) throws DebugException {
cawthron
parents:
diff changeset
   576
		StringBuffer label = new StringBuffer();
cawthron
parents:
diff changeset
   577
		if ( var instanceof ICVariable ) {
cawthron
parents:
diff changeset
   578
			ICType type = null;
cawthron
parents:
diff changeset
   579
			try {
cawthron
parents:
diff changeset
   580
				type = ((ICVariable)var).getType();
cawthron
parents:
diff changeset
   581
			}
cawthron
parents:
diff changeset
   582
			catch( DebugException e ) {
cawthron
parents:
diff changeset
   583
				// don't display type
cawthron
parents:
diff changeset
   584
			}
cawthron
parents:
diff changeset
   585
			if ( type != null && isShowVariableTypeNames() ) {
cawthron
parents:
diff changeset
   586
				String typeName = CDebugUIUtils.getVariableTypeName( type );
cawthron
parents:
diff changeset
   587
				if ( typeName != null && typeName.length() > 0 ) {
cawthron
parents:
diff changeset
   588
					label.append( typeName ).append( ' ' );
cawthron
parents:
diff changeset
   589
				}
cawthron
parents:
diff changeset
   590
			}
cawthron
parents:
diff changeset
   591
			String name = var.getName();
cawthron
parents:
diff changeset
   592
			if ( name != null )
cawthron
parents:
diff changeset
   593
				label.append( name.trim() );
cawthron
parents:
diff changeset
   594
			String valueString = getValueText( var.getValue() );
cawthron
parents:
diff changeset
   595
			if ( !isEmpty( valueString ) ) {
cawthron
parents:
diff changeset
   596
				label.append( " = " ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   597
				label.append( valueString );
cawthron
parents:
diff changeset
   598
			}
cawthron
parents:
diff changeset
   599
		}
cawthron
parents:
diff changeset
   600
		return label.toString();
cawthron
parents:
diff changeset
   601
	}
cawthron
parents:
diff changeset
   602
cawthron
parents:
diff changeset
   603
	protected String getValueText( IValue value ) {
cawthron
parents:
diff changeset
   604
		return CDebugUIUtils.getValueText( value );
cawthron
parents:
diff changeset
   605
	}
cawthron
parents:
diff changeset
   606
cawthron
parents:
diff changeset
   607
	protected String getSignalText( ICSignal signal ) {
cawthron
parents:
diff changeset
   608
		StringBuffer sb = new StringBuffer( CDebugUIMessages.getString( "CDTDebugModelPresentation.12" ) ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   609
		try {
cawthron
parents:
diff changeset
   610
			String name = signal.getName();
cawthron
parents:
diff changeset
   611
			sb.append( " \'" ).append( name ).append( '\'' ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   612
		}
cawthron
parents:
diff changeset
   613
		catch( DebugException e ) {
cawthron
parents:
diff changeset
   614
		}
cawthron
parents:
diff changeset
   615
		return sb.toString();
cawthron
parents:
diff changeset
   616
	}
cawthron
parents:
diff changeset
   617
cawthron
parents:
diff changeset
   618
	protected String getWatchExpressionText( IWatchExpression expression ) {
cawthron
parents:
diff changeset
   619
		StringBuffer result = new StringBuffer();
cawthron
parents:
diff changeset
   620
		result.append( '"' ).append( expression.getExpressionText() ).append( '"' );
cawthron
parents:
diff changeset
   621
		if ( expression.isPending() ) {
cawthron
parents:
diff changeset
   622
			result.append( " = " ).append( "..." ); //$NON-NLS-1$//$NON-NLS-2$
cawthron
parents:
diff changeset
   623
		}
cawthron
parents:
diff changeset
   624
		else {
cawthron
parents:
diff changeset
   625
			IValue value = expression.getValue();
cawthron
parents:
diff changeset
   626
			if ( value instanceof ICValue ) {
cawthron
parents:
diff changeset
   627
				ICType type = null;
cawthron
parents:
diff changeset
   628
				try {
cawthron
parents:
diff changeset
   629
					type = ((ICValue)value).getType();
cawthron
parents:
diff changeset
   630
				}
cawthron
parents:
diff changeset
   631
				catch( DebugException e1 ) {
cawthron
parents:
diff changeset
   632
				}
cawthron
parents:
diff changeset
   633
				if ( type != null && isShowVariableTypeNames() ) {
cawthron
parents:
diff changeset
   634
					String typeName = CDebugUIUtils.getVariableTypeName( type );
cawthron
parents:
diff changeset
   635
					if ( !isEmpty( typeName ) ) {
cawthron
parents:
diff changeset
   636
						result.insert( 0, typeName + ' ' );
cawthron
parents:
diff changeset
   637
					}
cawthron
parents:
diff changeset
   638
				}
cawthron
parents:
diff changeset
   639
				if ( expression.isEnabled() ) {
cawthron
parents:
diff changeset
   640
					String valueString = getValueText( value );
cawthron
parents:
diff changeset
   641
					if ( valueString.length() > 0 ) {
cawthron
parents:
diff changeset
   642
						result.append( " = " ).append( valueString ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   643
					}
cawthron
parents:
diff changeset
   644
				}
cawthron
parents:
diff changeset
   645
			}
cawthron
parents:
diff changeset
   646
		}
cawthron
parents:
diff changeset
   647
		if ( !expression.isEnabled() ) {
cawthron
parents:
diff changeset
   648
			result.append( ' ' );
cawthron
parents:
diff changeset
   649
			result.append( CDebugUIMessages.getString( "CDTDebugModelPresentation.22" ) ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   650
		}
cawthron
parents:
diff changeset
   651
		return result.toString();
cawthron
parents:
diff changeset
   652
	}
cawthron
parents:
diff changeset
   653
cawthron
parents:
diff changeset
   654
	protected String getTargetText( IDebugTarget target, boolean qualified ) throws DebugException {
cawthron
parents:
diff changeset
   655
		ICDebugTarget t = (ICDebugTarget)target.getAdapter( ICDebugTarget.class );
cawthron
parents:
diff changeset
   656
		if ( t != null ) {
cawthron
parents:
diff changeset
   657
			if ( !t.isPostMortem() ) {
cawthron
parents:
diff changeset
   658
				CDebugElementState state = t.getState();
cawthron
parents:
diff changeset
   659
				if ( state.equals( CDebugElementState.EXITED )  || state.equals( CDebugElementState.TERMINATED )) {
cawthron
parents:
diff changeset
   660
					Object info = t.getCurrentStateInfo();
cawthron
parents:
diff changeset
   661
					String label = CDebugUIMessages.getString( "CDTDebugModelPresentation.3" ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   662
					String reason = ""; //$NON-NLS-1$
cawthron
parents:
diff changeset
   663
					if ( info != null && info instanceof ICDISignalExitInfo ) {
cawthron
parents:
diff changeset
   664
						ICDISignalExitInfo sigInfo = (ICDISignalExitInfo)info;
cawthron
parents:
diff changeset
   665
						reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.5" ), new String[]{ sigInfo.getName(), sigInfo.getDescription() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   666
					}
cawthron
parents:
diff changeset
   667
					else if ( info != null && info instanceof ICDIExitInfo ) {
cawthron
parents:
diff changeset
   668
						reason = ' ' + MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.6" ), new Integer[] { new Integer( ((ICDIExitInfo)info).getCode() ) } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   669
					}
cawthron
parents:
diff changeset
   670
					return MessageFormat.format( label, new String[] { target.getName(), reason } );
cawthron
parents:
diff changeset
   671
				}
cawthron
parents:
diff changeset
   672
				else if ( state.equals( CDebugElementState.SUSPENDED ) ) {
cawthron
parents:
diff changeset
   673
						return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.7" ), new String[] { target.getName() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   674
				}
cawthron
parents:
diff changeset
   675
			}
cawthron
parents:
diff changeset
   676
		}
cawthron
parents:
diff changeset
   677
		return target.getName();
cawthron
parents:
diff changeset
   678
	}
cawthron
parents:
diff changeset
   679
cawthron
parents:
diff changeset
   680
	protected String getThreadText( IThread thread, boolean qualified ) throws DebugException {
cawthron
parents:
diff changeset
   681
		ICDebugTarget target = (ICDebugTarget)thread.getDebugTarget().getAdapter( ICDebugTarget.class );
cawthron
parents:
diff changeset
   682
		if ( target.isPostMortem() ) {
cawthron
parents:
diff changeset
   683
			return getFormattedString( CDebugUIMessages.getString( "CDTDebugModelPresentation.8" ), thread.getName() ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   684
		}
cawthron
parents:
diff changeset
   685
		if ( thread.isTerminated() ) {
cawthron
parents:
diff changeset
   686
			return getFormattedString( CDebugUIMessages.getString( "CDTDebugModelPresentation.9" ), thread.getName() ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   687
		}
cawthron
parents:
diff changeset
   688
		if ( thread.isStepping() ) {
cawthron
parents:
diff changeset
   689
			return getFormattedString( CDebugUIMessages.getString( "CDTDebugModelPresentation.10" ), thread.getName() ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   690
		}
cawthron
parents:
diff changeset
   691
		if ( !thread.isSuspended() ) {
cawthron
parents:
diff changeset
   692
			return getFormattedString( CDebugUIMessages.getString( "CDTDebugModelPresentation.11" ), thread.getName() ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   693
		}
cawthron
parents:
diff changeset
   694
		if ( thread.isSuspended() ) {
cawthron
parents:
diff changeset
   695
			String reason = ""; //$NON-NLS-1$
cawthron
parents:
diff changeset
   696
			ICDebugElement element = (ICDebugElement)thread.getAdapter( ICDebugElement.class );
cawthron
parents:
diff changeset
   697
			if ( element != null ) {
cawthron
parents:
diff changeset
   698
				Object info = element.getCurrentStateInfo();
cawthron
parents:
diff changeset
   699
				if ( info != null && info instanceof ICDISignalReceived ) {
cawthron
parents:
diff changeset
   700
					ICDISignal signal = ((ICDISignalReceived)info).getSignal();
cawthron
parents:
diff changeset
   701
					reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.13" ), new String[]{ signal.getName(), signal.getDescription() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   702
				}
cawthron
parents:
diff changeset
   703
				else if ( info != null && info instanceof ICDIWatchpointTrigger ) {
cawthron
parents:
diff changeset
   704
					reason = MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.14" ), new String[]{ ((ICDIWatchpointTrigger)info).getOldValue(), ((ICDIWatchpointTrigger)info).getNewValue() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   705
				}
cawthron
parents:
diff changeset
   706
				else if ( info != null && info instanceof ICDIWatchpointScope ) {
cawthron
parents:
diff changeset
   707
					reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.15" ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   708
				}
cawthron
parents:
diff changeset
   709
				else if ( info != null && info instanceof ICDIBreakpointHit ) {
cawthron
parents:
diff changeset
   710
					reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.16" ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   711
				}
cawthron
parents:
diff changeset
   712
				else if ( info != null && info instanceof ICDISharedLibraryEvent ) {
cawthron
parents:
diff changeset
   713
					reason = CDebugUIMessages.getString( "CDTDebugModelPresentation.17" ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   714
				}
cawthron
parents:
diff changeset
   715
			}
cawthron
parents:
diff changeset
   716
			return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.18" ), new String[] { thread.getName(), reason } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   717
		}
cawthron
parents:
diff changeset
   718
		return MessageFormat.format( CDebugUIMessages.getString( "CDTDebugModelPresentation.19" ), new String[] { thread.getName() } ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   719
	}
cawthron
parents:
diff changeset
   720
cawthron
parents:
diff changeset
   721
	protected String getStackFrameText( IStackFrame f, boolean qualified ) throws DebugException {
cawthron
parents:
diff changeset
   722
		if ( f instanceof ICStackFrame ) {
cawthron
parents:
diff changeset
   723
			ICStackFrame frame = (ICStackFrame)f;
cawthron
parents:
diff changeset
   724
			StringBuffer label = new StringBuffer();
cawthron
parents:
diff changeset
   725
			label.append( frame.getLevel() );
cawthron
parents:
diff changeset
   726
			label.append( ' ' );
cawthron
parents:
diff changeset
   727
			String function = frame.getFunction();
cawthron
parents:
diff changeset
   728
			if ( isEmpty( function ) ) {
cawthron
parents:
diff changeset
   729
				label.append( CDebugUIMessages.getString( "CDTDebugModelPresentation.21" ) ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   730
			}
cawthron
parents:
diff changeset
   731
			else {
cawthron
parents:
diff changeset
   732
				function = function.trim();
cawthron
parents:
diff changeset
   733
				label.append( function );
cawthron
parents:
diff changeset
   734
				label.append( "() " ); //$NON-NLS-1$
cawthron
parents:
diff changeset
   735
				if ( frame.getFile() != null ) {
cawthron
parents:
diff changeset
   736
					IPath path = new Path( frame.getFile() );
cawthron
parents:
diff changeset
   737
					if ( !path.isEmpty() ) {
cawthron
parents:
diff changeset
   738
						label.append( (qualified ? path.toOSString() : path.lastSegment()) );
cawthron
parents:
diff changeset
   739
						label.append( ':' );
cawthron
parents:
diff changeset
   740
						if ( frame.getFrameLineNumber() != 0 )
cawthron
parents:
diff changeset
   741
							label.append( frame.getFrameLineNumber() );
cawthron
parents:
diff changeset
   742
					}
cawthron
parents:
diff changeset
   743
				}
cawthron
parents:
diff changeset
   744
			}
cawthron
parents:
diff changeset
   745
			IAddress address = frame.getAddress();
cawthron
parents:
diff changeset
   746
			if ( address != null ) {
cawthron
parents:
diff changeset
   747
				label.append( ' ' );
cawthron
parents:
diff changeset
   748
				label.append( address.toHexAddressString() );
cawthron
parents:
diff changeset
   749
			}
cawthron
parents:
diff changeset
   750
			return label.toString();
cawthron
parents:
diff changeset
   751
		}
cawthron
parents:
diff changeset
   752
		return (f.getAdapter( IDummyStackFrame.class ) != null) ? getDummyStackFrameLabel( f ) : f.getName();
cawthron
parents:
diff changeset
   753
	}
cawthron
parents:
diff changeset
   754
cawthron
parents:
diff changeset
   755
	private String getDummyStackFrameLabel( IStackFrame stackFrame ) {
cawthron
parents:
diff changeset
   756
		return DUMMY_STACKFRAME_LABEL;
cawthron
parents:
diff changeset
   757
	}
cawthron
parents:
diff changeset
   758
cawthron
parents:
diff changeset
   759
	protected boolean isShowVariableTypeNames() {
cawthron
parents:
diff changeset
   760
		Boolean show = (Boolean)fAttributes.get( DISPLAY_VARIABLE_TYPE_NAMES );
cawthron
parents:
diff changeset
   761
		show = show == null ? Boolean.FALSE : show;
cawthron
parents:
diff changeset
   762
		return show.booleanValue();
cawthron
parents:
diff changeset
   763
	}
cawthron
parents:
diff changeset
   764
cawthron
parents:
diff changeset
   765
	public static String getFormattedString( String key, String arg ) {
cawthron
parents:
diff changeset
   766
		return getFormattedString( key, new String[]{ arg } );
cawthron
parents:
diff changeset
   767
	}
cawthron
parents:
diff changeset
   768
cawthron
parents:
diff changeset
   769
	public static String getFormattedString( String string, String[] args ) {
cawthron
parents:
diff changeset
   770
		return MessageFormat.format( string, args );
cawthron
parents:
diff changeset
   771
	}
cawthron
parents:
diff changeset
   772
cawthron
parents:
diff changeset
   773
}