Commit f7f99d0f authored by andrei's avatar andrei

1) fixed 305035: show hex values for numeric constants in the bytecode

2) view settings are now persistent between sessions
parent c5754d83
No preview for this file type
......@@ -68,3 +68,7 @@ action.showOnlySelectedElement.image=icons/selected_only.gif
action.linkViewToEditor.text=Link with editor
action.linkViewToEditor.toolTipText=Link With Editor
action.linkViewToEditor.image=icons/link_with_editor.gif
action.showHexValues.text=Show values in hex format
action.showHexValues.toolTipText=Show numerical constant values in hex format
action.showHexValues.image=icons/hex_mode.gif
\ No newline at end of file
......@@ -5,7 +5,9 @@ import java.util.BitSet;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.util.AbstractVisitor;
import org.objectweb.asm.util.TraceAnnotationVisitor;
import org.objectweb.asm.util.TraceClassVisitor;
import org.objectweb.asm.util.TraceFieldVisitor;
......@@ -24,6 +26,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
protected boolean showLines;
protected boolean showLocals;
protected boolean showStackMap;
protected boolean showHex;
public CommentedClassVisitor(final BitSet modes) {
super(null);
......@@ -32,6 +35,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
showLines = modes.get(BCOConstants.F_SHOW_LINE_INFO);
showLocals = modes.get(BCOConstants.F_SHOW_VARIABLES);
showStackMap = modes.get(BCOConstants.F_SHOW_STACKMAP);
showHex = modes.get(BCOConstants.F_SHOW_HEX_VALUES);
}
public void visitEnd() {
......@@ -264,6 +268,46 @@ public class CommentedClassVisitor extends TraceClassVisitor {
text.add(" " + increment + "\n");
}
public void visitIntInsn(int opcode, int operand) {
buf.setLength(0);
buf.append(tab2)
.append(OPCODES[opcode])
.append(' ')
.append(opcode == Opcodes.NEWARRAY
? TYPES[operand]
: formatValue(operand))
.append('\n');
text.add(buf.toString());
if (mv != null) {
mv.visitIntInsn(opcode, operand);
}
}
private String formatValue(int operand) {
if(showHex){
return Integer.toHexString(operand).toUpperCase();
}
return Integer.toString(operand);
}
private String formatValue(Object operand) {
if(showHex){
if(operand instanceof Integer) {
return Integer.toHexString(((Integer)operand).intValue()).toUpperCase();
} else if(operand instanceof Long) {
return Long.toHexString(((Long)operand).longValue()).toUpperCase();
} else if(operand instanceof Double) {
return Double.toHexString(((Double)operand).doubleValue()).toUpperCase();
} else if(operand instanceof Float) {
return Float.toHexString(((Float)operand).floatValue()).toUpperCase();
} else {
return operand.toString();
}
}
return operand.toString();
}
public void visitLocalVariable(final String name, final String desc,
final String signature, final Label start, final Label end,
final int index) {
......@@ -273,6 +317,24 @@ public class CommentedClassVisitor extends TraceClassVisitor {
}
}
public void visitLdcInsn(Object cst) {
buf.setLength(0);
buf.append(tab2).append("LDC ");
if (cst instanceof String) {
AbstractVisitor.appendString(buf, (String) cst);
} else if (cst instanceof Type) {
buf.append(((Type) cst).getDescriptor() + ".class");
} else {
buf.append(formatValue(cst));
}
buf.append('\n');
text.add(buf.toString());
if (mv != null) {
mv.visitLdcInsn(cst);
}
}
public void visitLineNumber(final int line, final Label start) {
if (showLines) {
super.visitLineNumber(line, start);
......
......@@ -8,6 +8,9 @@
*******************************************************************************/
package de.loskutov.bco.preferences;
import java.util.HashMap;
import java.util.Map;
/**
* Keys for preferences store used in BCO
......@@ -53,7 +56,7 @@ public interface BCOConstants {
* expand stackmap frames
*/
String EXPAND_STACKMAP = "expandStackmap";
/**
* recalculate stackmap (to see computed frames, works for all classes even before MUSTANG)
*/
......@@ -64,6 +67,10 @@ public interface BCOConstants {
*/
String SHOW_ANALYZER = "showAnalyzer";
/**
* Show non decimal values for numeric constants in the bytecode
*/
String SHOW_HEX_VALUES = "showHexValues";
int F_LINK_VIEW_TO_EDITOR = 0;
int F_SHOW_ONLY_SELECTED_ELEMENT = 1;
......@@ -75,5 +82,30 @@ public interface BCOConstants {
int F_EXPAND_STACKMAP = 7;
int F_SHOW_ANALYZER = 8;
int F_SHOW_STACKMAP = 9;
int F_SHOW_HEX_VALUES = 10;
/**
* Key is Integer value from one of F_* constants, value is the String value of one of corresponding
* preference keys. It is not intended that the map would be modified by clients.
*/
Map/*<Integer,String>*/ FLAG_TO_NAME_MAP = new ConstantsMap();
final class ConstantsMap extends HashMap {
private static final long serialVersionUID = 1L;
private ConstantsMap() {
super();
put(Integer.valueOf(F_EXPAND_STACKMAP), EXPAND_STACKMAP);
put(Integer.valueOf(F_LINK_VIEW_TO_EDITOR), LINK_VIEW_TO_EDITOR);
put(Integer.valueOf(F_RECALCULATE_STACKMAP), RECALCULATE_STACKMAP);
put(Integer.valueOf(F_SHOW_ANALYZER), SHOW_ANALYZER);
put(Integer.valueOf(F_SHOW_ASMIFIER_CODE), SHOW_ASMIFIER_CODE);
put(Integer.valueOf(F_SHOW_HEX_VALUES), SHOW_HEX_VALUES);
put(Integer.valueOf(F_SHOW_LINE_INFO), SHOW_LINE_INFO);
put(Integer.valueOf(F_SHOW_ONLY_SELECTED_ELEMENT), SHOW_ONLY_SELECTED_ELEMENT);
put(Integer.valueOf(F_SHOW_RAW_BYTECODE), SHOW_RAW_BYTECODE);
put(Integer.valueOf(F_SHOW_STACKMAP), SHOW_STACKMAP);
put(Integer.valueOf(F_SHOW_VARIABLES), SHOW_VARIABLES);
}
}
}
......@@ -38,6 +38,7 @@ public class BCOPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(BCOConstants.SHOW_STACKMAP, true);
store.setDefault(BCOConstants.EXPAND_STACKMAP, false);
store.setDefault(BCOConstants.RECALCULATE_STACKMAP, false);
store.setDefault(BCOConstants.SHOW_HEX_VALUES, false);
}
}
......@@ -152,6 +152,7 @@ public class BytecodeOutlineView extends ViewPart {
protected Action hideLineInfoAction;
protected Action hideLocalsAction;
protected Action hideStackMapAction;
protected Action showHexValuesAction;
protected Action expandStackMapAction;
protected Action toggleVerifierAction;
protected StatusLineManager statusLineManager;
......@@ -236,6 +237,7 @@ public class BytecodeOutlineView extends ViewPart {
hideLocalsAction.setEnabled(on);
hideLineInfoAction.setEnabled(on);
hideStackMapAction.setEnabled(on);
showHexValuesAction.setEnabled(on);
toggleASMifierModeAction.setEnabled(on);
setRawModeAction.setEnabled(on && !toggleASMifierModeAction.isChecked());
boolean showAnalyzer = on && toggleVerifierAction.isChecked();
......@@ -398,6 +400,7 @@ public class BytecodeOutlineView extends ViewPart {
modes.set(BCOConstants.F_EXPAND_STACKMAP, store.getBoolean(BCOConstants.EXPAND_STACKMAP));
modes.set(BCOConstants.F_SHOW_ASMIFIER_CODE, store.getBoolean(BCOConstants.SHOW_ASMIFIER_CODE));
modes.set(BCOConstants.F_SHOW_ANALYZER, store.getBoolean(BCOConstants.SHOW_ANALYZER));
modes.set(BCOConstants.F_SHOW_HEX_VALUES, store.getBoolean(BCOConstants.SHOW_HEX_VALUES));
}
private void createToolbarActions() {
......@@ -425,7 +428,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_LINK_VIEW_TO_EDITOR, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_LINK_VIEW_TO_EDITOR, Boolean.TRUE == event.getNewValue());
if(modes.get(BCOConstants.F_LINK_VIEW_TO_EDITOR)) {
showSelectedOnlyAction.setEnabled(true);
toggleVerifierAction.setEnabled(true);
......@@ -446,7 +449,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_SHOW_ONLY_SELECTED_ELEMENT, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_SHOW_ONLY_SELECTED_ELEMENT, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -457,7 +460,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_SHOW_RAW_BYTECODE, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_SHOW_RAW_BYTECODE, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -468,7 +471,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_SHOW_LINE_INFO, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_SHOW_LINE_INFO, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -479,7 +482,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_SHOW_VARIABLES, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_SHOW_VARIABLES, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -490,7 +493,7 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_SHOW_STACKMAP, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_SHOW_STACKMAP, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -501,7 +504,18 @@ public class BytecodeOutlineView extends ViewPart {
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
modes.set(BCOConstants.F_EXPAND_STACKMAP, Boolean.TRUE == event.getNewValue());
setMode(BCOConstants.F_EXPAND_STACKMAP, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
}
});
showHexValuesAction = new DefaultToggleAction(BCOConstants.SHOW_HEX_VALUES,
new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
setMode(BCOConstants.F_SHOW_HEX_VALUES, Boolean.TRUE == event.getNewValue());
inputChanged = true;
refreshView();
}
......@@ -513,9 +527,9 @@ public class BytecodeOutlineView extends ViewPart {
public void propertyChange(PropertyChangeEvent event) {
if (IAction.CHECKED.equals(event.getProperty())) {
boolean checked = Boolean.TRUE == event.getNewValue();
modes.set(BCOConstants.F_SHOW_ASMIFIER_CODE, checked);
setMode(BCOConstants.F_SHOW_ASMIFIER_CODE, checked);
if(checked) {
modes.set(BCOConstants.F_SHOW_RAW_BYTECODE, true);
setMode(BCOConstants.F_SHOW_RAW_BYTECODE, true);
setRawModeAction.setEnabled(false);
} else {
setRawModeAction.setEnabled(true);
......@@ -543,6 +557,7 @@ public class BytecodeOutlineView extends ViewPart {
mmanager.add(setRawModeAction);
mmanager.add(hideLineInfoAction);
mmanager.add(hideLocalsAction);
mmanager.add(showHexValuesAction);
mmanager.add(hideStackMapAction);
mmanager.add(expandStackMapAction);
mmanager.add(toggleASMifierModeAction);
......@@ -749,6 +764,7 @@ public class BytecodeOutlineView extends ViewPart {
hideLineInfoAction = null;
hideLocalsAction = null;
hideStackMapAction = null;
showHexValuesAction = null;
expandStackMapAction = null;
toggleVerifierAction = null;
lastDecompiledResult = null;
......@@ -1461,8 +1477,22 @@ public class BytecodeOutlineView extends ViewPart {
}
}
/**
* Set the bit with given index to given value and remembers it in the preferences
* @param bitIndex
* @param value
*/
protected void setMode(int bitIndex, boolean value) {
modes.set(bitIndex, value);
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore();
String key = (String) BCOConstants.FLAG_TO_NAME_MAP.get(Integer.valueOf(bitIndex));
if(key != null) {
store.setValue(key, value);
}
}
protected void toggleVerifyMode(final IMenuManager mmanager, boolean showAnalyzer) {
modes.set(BCOConstants.F_SHOW_ANALYZER, showAnalyzer);
setMode(BCOConstants.F_SHOW_ANALYZER, showAnalyzer);
if(modes.get(BCOConstants.F_SHOW_ANALYZER)) {
((StackLayout) stackComposite.getLayout()).topControl = verifyControl;
viewSelectionProvider.setCurrentSelectionProvider(tableControlViewer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment