Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7fdd28b6c22c504621f87da62a3aa28671238027 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2004, 2006 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.views.disassembly;

import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.IDisassembly;
import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants;
import org.eclipse.debug.core.DebugException;
import org.eclipse.jface.text.source.Annotation;

/**
 * An annotation for the vertical ruler in the disassembly view that shows one 
 * of two images for the current instruction pointer when debugging (one for 
 * the top stack frame, one for all others).
 */
public class DisassemblyInstructionPointerAnnotation extends Annotation {

	private int fHashCode = 0;

	/**
	 * Construct an instruction pointer annotation for the given stack frame.
	 * 
	 * @param stackFrame frame to create an instruction pointer annotation for
	 * @param isTopFrame whether the given frame is the top stack frame in its thread 
	 */
	public DisassemblyInstructionPointerAnnotation( ICStackFrame stackFrame, boolean isTopFrame ) {
		super( isTopFrame ? IInternalCDebugUIConstants.ANN_DISASM_INSTR_POINTER_CURRENT : IInternalCDebugUIConstants.ANN_DISASM_INSTR_POINTER_SECONDARY, 
			   false, 
			   isTopFrame ? DisassemblyMessages.getString( "DisassemblyInstructionPointerAnnotation.Current_Pointer_1" ) : DisassemblyMessages.getString( "DisassemblyInstructionPointerAnnotation.Secondary_Pointer_1" ) ); //$NON-NLS-1$ //$NON-NLS-2$
		fHashCode = getHashCode( stackFrame );
	}

	private IDisassembly getDisassembly( ICStackFrame frame ) {
		if ( frame != null ) {
			ICDebugTarget target = (ICDebugTarget)frame.getDebugTarget();
			try {
				return target.getDisassembly();
			}
			catch( DebugException e ) {
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return fHashCode;
	}

	private int getHashCode( ICStackFrame frame ) {
		int hashCode = 17;
		IDisassembly disassembly = getDisassembly( frame );
		hashCode = 37*hashCode + (( disassembly != null ) ? disassembly.hashCode() : 0);
		if ( frame != null ) {
			IAddress address = frame.getAddress();
			hashCode = 37*hashCode + address.hashCode();
		}
		return hashCode;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals( Object obj ) {
		return ( obj != null ? obj.hashCode() == hashCode() : false );
	}
}

Back to the top