mirror of https://github.com/mchr3k/org.intrace
- Add "onlyjar" target to skip UTs in build
- Allow tracing of Test classes - Add exception tracing - UTs are currently broken!!
This commit is contained in:
parent
53128e9653
commit
e0a0bd3079
|
|
@ -122,9 +122,10 @@
|
|||
</emma>
|
||||
</target>
|
||||
|
||||
<target name="jar" description="Create Jars" depends="build, test, onlyjar" >
|
||||
</target>
|
||||
|
||||
|
||||
<target name="jar" description="Create Jars" depends="build, test" >
|
||||
<target name="onlyjar" >
|
||||
|
||||
<mkdir dir="./build/jars/" />
|
||||
|
||||
|
|
@ -192,8 +193,8 @@
|
|||
<target name="findbugs" depends="jar">
|
||||
|
||||
<mkdir dir="./reports/findbugs" />
|
||||
|
||||
<!-- Build Findbugs Trace Agent (Don't include ASM classes) -->
|
||||
|
||||
<!-- Build Findbugs Trace Agent (Don't include ASM classes) -->
|
||||
<jar destfile="./reports/findbugs/traceagent_findbugs.jar" compress="false" manifest="conf/META-INF/MANIFEST.MF">
|
||||
<fileset dir="./build/classes" includes="**/agent/**/*.class" />
|
||||
<fileset dir="./build/classes" includes="**/output/**/*.class" />
|
||||
|
|
@ -211,7 +212,7 @@
|
|||
<sourcePath path="./src" />
|
||||
<class location="./reports/findbugs/traceagent_findbugs.jar" />
|
||||
</findbugs>
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -141,12 +141,12 @@ public class ClassTransformer implements ClassFileTransformer
|
|||
|
||||
// Don't modify self
|
||||
if (className.startsWith("org.intrace")
|
||||
|| className.startsWith("org.objectweb.asm"))
|
||||
|| className.contains("objectweb.asm"))
|
||||
{
|
||||
if (settings.isVerboseMode())
|
||||
{
|
||||
System.out
|
||||
.println("Ignoring class in org.intrace or org.objectweb.asm package: "
|
||||
.println("Ignoring class in org.intrace or objectweb.asm package: "
|
||||
+ className);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -162,18 +162,6 @@ public class ClassTransformer implements ClassFileTransformer
|
|||
return false;
|
||||
}
|
||||
|
||||
// Don't modify test classes
|
||||
int p = className.lastIndexOf('$');
|
||||
if (className.endsWith("Test") || p > 0
|
||||
&& className.substring(0, p).endsWith("Test"))
|
||||
{
|
||||
if (settings.isVerboseMode())
|
||||
{
|
||||
System.out.println("Ignoring class name ending in Test: " + className);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't modify classes which fail to match the regex
|
||||
if ((settings.getClassRegex() == null)
|
||||
|| !settings.getClassRegex().matcher(className).matches())
|
||||
|
|
|
|||
|
|
@ -71,13 +71,14 @@ public class InstrumentedClassWriter extends ClassWriter
|
|||
// Final method fields
|
||||
private final String methodName;
|
||||
private final String methodDescriptor;
|
||||
private final int methodAccess;
|
||||
private final Map<Label, Integer> labelLineNos = new HashMap<Label, Integer>();
|
||||
private final Set<Label> traceLabels = new HashSet<Label>();
|
||||
private final int methodAccess;
|
||||
|
||||
// Analysis data
|
||||
private final Set<Integer> reverseGOTOLines;
|
||||
private final Integer entryLine;
|
||||
private final Map<Label, Integer> labelLineNos = new HashMap<Label, Integer>();
|
||||
private final Set<Label> traceLabels = new HashSet<Label>();
|
||||
private final Set<Label> exceptionHandlerLabels = new HashSet<Label>();
|
||||
|
||||
// State
|
||||
private boolean writeTraceLine = false;
|
||||
|
|
@ -249,6 +250,25 @@ public class InstrumentedClassWriter extends ClassWriter
|
|||
writeTraceLine = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exceptionHandlerLabels.contains(label))
|
||||
{
|
||||
// Top of the stack contains an exception - generate code to trace it
|
||||
// Duplicate the exception
|
||||
mv.visitInsn(Opcodes.DUP);
|
||||
|
||||
// Load args
|
||||
mv.visitLdcInsn("Caught exception");
|
||||
mv.visitInsn(Opcodes.SWAP);
|
||||
mv.visitLdcInsn(className);
|
||||
mv.visitInsn(Opcodes.SWAP);
|
||||
mv.visitLdcInsn(methodName);
|
||||
mv.visitInsn(Opcodes.SWAP);
|
||||
|
||||
// Generate call to trace exception
|
||||
mv.visitMethodInsn(INVOKESTATIC, HELPER_CLASS, "val",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V");
|
||||
}
|
||||
|
||||
numBranchesOnLine = 0;
|
||||
super.visitLineNumber(xiLineNumber, label);
|
||||
|
|
@ -387,7 +407,7 @@ public class InstrumentedClassWriter extends ClassWriter
|
|||
public void visitTryCatchBlock(Label start, Label end, Label handler,
|
||||
String type)
|
||||
{
|
||||
traceLabels.add(handler);
|
||||
exceptionHandlerLabels.add(handler);
|
||||
super.visitTryCatchBlock(start, end, handler, type);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -360,6 +360,16 @@ public class AgentHelper
|
|||
outputHandler.val(desc, className, methodName, objArrayArg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void val(String desc, String className, String methodName,
|
||||
Throwable throwable)
|
||||
{
|
||||
for (IInstrumentationHandler outputHandler : instrumentationHandlers
|
||||
.keySet())
|
||||
{
|
||||
outputHandler.val(desc, className, methodName, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void branch(String className, String methodName, int lineNo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ public interface IInstrumentationHandler
|
|||
public void val(String desc, String className, String methodName, Object objArg);
|
||||
|
||||
public void val(String desc, String className, String methodName, Object[] objArrayArg);
|
||||
|
||||
public void val(String desc, String className, String methodName, Throwable throwable);
|
||||
|
||||
public void branch(String className, String methodName, int lineNo);
|
||||
|
||||
|
|
|
|||
|
|
@ -113,6 +113,12 @@ public class IInstrumentationHandlerAdapter implements IInstrumentationHandler
|
|||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void val(String desc, String className, String methodName, Throwable throwable)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void branch(String className, String methodName, int lineNo)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.intrace.output.trace;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -49,7 +51,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ byteArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,7 +60,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(byteArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +70,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ shortArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +79,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(shortArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +90,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
if (argTrace)
|
||||
{
|
||||
AgentHelper
|
||||
.writeOutput(className + ":" + methodName + ": " + desc + ":" + intArg);
|
||||
.writeOutput(className + ":" + methodName + ": " + desc + ": " + intArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +99,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(intArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +109,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ longArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +119,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(longArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +129,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ floatArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -137,7 +139,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(floatArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +149,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ doubleArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +159,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(doubleArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +169,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ boolArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +179,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(boolArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -187,7 +189,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ charArg);
|
||||
}
|
||||
}
|
||||
|
|
@ -197,7 +199,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.toString(charArrayArg));
|
||||
}
|
||||
}
|
||||
|
|
@ -213,7 +215,7 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
String objStr = Arrays.deepToString(new Object[] {objArg});
|
||||
objStr = objStr.substring(1, objStr.length() - 1);
|
||||
AgentHelper
|
||||
.writeOutput(className + ":" + methodName + ": " + desc + ":" + objStr);
|
||||
.writeOutput(className + ":" + methodName + ": " + desc + ": " + objStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,10 +223,36 @@ public class TraceHandler implements IInstrumentationHandler
|
|||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ":"
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ Arrays.deepToString(objArrayArg));
|
||||
}
|
||||
}
|
||||
|
||||
public void val(String desc, String className, String methodName, Throwable throwable)
|
||||
{
|
||||
if (argTrace)
|
||||
{
|
||||
AgentHelper.writeOutput(className + ":" + methodName + ": " + desc + ": "
|
||||
+ throwableToString(throwable));
|
||||
}
|
||||
}
|
||||
|
||||
private String throwableToString(Throwable throwable)
|
||||
{
|
||||
StringBuilder throwToStr = new StringBuilder();
|
||||
if (throwable == null)
|
||||
{
|
||||
throwToStr.append("null");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringWriter strWriter = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(strWriter);
|
||||
throwable.printStackTrace(writer);
|
||||
throwToStr.append(strWriter.toString());
|
||||
}
|
||||
return throwToStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void branch(String className, String methodName, int lineNo)
|
||||
|
|
|
|||
|
|
@ -187,6 +187,8 @@ public class AgentTest extends TestCase
|
|||
EasyMock.expectLastCall().anyTimes();
|
||||
testHandler.val(isA(String.class), isA(String.class), isA(String.class), EasyMock.anyInt());
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
testHandler.val(isA(String.class), isA(String.class), isA(String.class), isA(Throwable.class));
|
||||
EasyMock.expectLastCall().anyTimes();
|
||||
|
||||
EasyMock.replay(testHandler);
|
||||
AgentHelper.instrumentationHandlers.put(testHandler, new Object());
|
||||
|
|
|
|||
|
|
@ -135,6 +135,12 @@ public class ArgCapture implements IInstrumentationHandler
|
|||
addArg(desc + ":##:[" + className + ", " + methodName + ", "
|
||||
+ Arrays.deepToString(objArrayArg) + "]");
|
||||
}
|
||||
|
||||
public void val(String desc, String className, String methodName, Throwable th)
|
||||
{
|
||||
addArg(desc + ":##:[" + className + ", " + methodName + ", "
|
||||
+ th + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void branch(String className, String methodName, int lineNo)
|
||||
|
|
|
|||
Loading…
Reference in New Issue