Commit 71cbd63e authored by ekuleshov's avatar ekuleshov
Browse files

make dump output easier to read

parent 18f3da9d
......@@ -106,6 +106,12 @@ public class CheckClassAdapter extends ClassAdapter {
verify(cr, false);
}
/**
* Checks a given class
*
* @param cr a <code>ClassReader</code> that contains bytecode for the analysis.
* @param dump true if bytecode should be printed out not only when errors are found.
*/
public static void verify(ClassReader cr, boolean dump) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn), true);
......@@ -130,17 +136,29 @@ public class CheckClassAdapter extends ClassAdapter {
TraceMethodVisitor mv = new TraceMethodVisitor();
method.accept(mv);
System.err.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
String s = frames[j] == null
? "null"
: frames[j].toString();
while (s.length() < method.maxStack + method.maxLocals + 1) {
s += " ";
StringBuffer s = new StringBuffer();
Frame f = frames[j];
if (f == null) {
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString()))
.append(' ');
}
s.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString()))
.append(' ');
}
}
System.err.print(Integer.toString(j + 100000)
.substring(1));
while (s.length() < method.maxStack + method.maxLocals + 1)
{
s.append(' ');
}
System.err.print(Integer.toString(j + 100000).substring(1));
System.err.print(" " + s + " : " + mv.text.get(j));
}
System.err.println();
......@@ -148,6 +166,13 @@ public class CheckClassAdapter extends ClassAdapter {
}
}
private static String getShortName(String name) {
int n = name.lastIndexOf('/');
int k = name.length();
if(name.charAt(k-1)==';') k--;
return n==-1 ? name : name.substring(n+1, k);
}
/**
* Constructs a new {@link CheckClassAdapter}.
*
......
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