blob: 119cfb845c375ecc7fa9e6af3121fccbb5dd8e6c (
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
|
/*******************************************************************************
* Copyright (c) 2007, 2010 Wind River 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.AddressRangePosition;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.DisassemblyPosition;
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.DisassemblyDocument;
import org.eclipse.jface.text.BadLocationException;
/**
* A vertical ruler column to display the function + offset of instructions.
*/
public class FunctionOffsetRulerColumn extends DisassemblyRulerColumn {
/** Maximum width of column (in characters) */
private static final int MAXWIDTH= 20;
/**
* Default constructor.
*/
public FunctionOffsetRulerColumn() {
super();
}
/*
* @see org.eclipse.jface.text.source.LineNumberRulerColumn#createDisplayString(int)
*/
@Override
protected String createDisplayString(int line) {
DisassemblyDocument doc = (DisassemblyDocument)getParentRuler().getTextViewer().getDocument();
int offset;
try {
offset = doc.getLineOffset(line);
AddressRangePosition pos = doc.getDisassemblyPosition(offset);
if (pos instanceof DisassemblyPosition && pos.length > 0 && pos.offset == offset && pos.fValid) {
DisassemblyPosition disassPos = (DisassemblyPosition)pos;
int length = disassPos.fFunction.length;
if (length > MAXWIDTH) {
return "..." + new String(disassPos.fFunction, length - MAXWIDTH + 3, MAXWIDTH - 3); //$NON-NLS-1$
}
return new String(disassPos.fFunction);
} else if (pos != null && !pos.fValid) {
return DOTS.substring(0, Math.min(MAXWIDTH, doc.getMaxFunctionLength()));
}
} catch (BadLocationException e) {
// silently ignored
}
return ""; //$NON-NLS-1$
}
@Override
protected int computeNumberOfCharacters() {
DisassemblyDocument doc = (DisassemblyDocument)getParentRuler().getTextViewer().getDocument();
return Math.min(MAXWIDTH, doc.getMaxFunctionLength());
}
}
|