Commit 3b279c4a authored by Lukáš Marek's avatar Lukáš Marek
Browse files

Improved debug support, package rename for testtools

parent 46bfb5af
package ch.usi.dag.disl;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
......@@ -386,6 +387,14 @@ public class DiSL implements Instrumentation {
public byte[] instrument(byte[] classAsBytes) throws Exception {
// output bytes into the file
if(debug) {
String errFile = "err.class";
FileOutputStream fos = new FileOutputStream(errFile);
fos.write(classAsBytes);
fos.close();
}
ClassReader cr = new ClassReader(classAsBytes);
return instrument(cr);
......
......@@ -33,7 +33,7 @@
<mkdir dir="build"/>
<jar jarfile="build/agent-light.jar">
<manifest>
<attribute name="Premain-Class" value="ch.usi.dag.disl.test.agent.Agent"/>
<attribute name="Premain-Class" value="ch.usi.dag.disl.testtools.agent.Agent"/>
</manifest>
</jar>
</target>
......
package ch.usi.dag.disl.test.agent;
package ch.usi.dag.disl.testtools.agent;
import java.lang.instrument.Instrumentation;
......
package ch.usi.dag.disl.test.agent;
package ch.usi.dag.disl.testtools.agent;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
......
package ch.usi.dag.disl.test.jarrewriter;
package ch.usi.dag.disl.testtools.jarrewriter;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
......
package ch.usi.dag.disl.test;
package ch.usi.dag.disl.testtools.onplace;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;
import ch.usi.dag.disl.DiSL;
......@@ -10,19 +15,37 @@ public class OnPlaceTransformer {
public static void main(String[] args) throws Exception {
// INSTRUCTIONS: Under Eclipse call me with these jvm params (example)
// -Dtest.class=/ch/usi/dag/disl/test/bodymarker/TargetClass.class
// -Ddisltest.transform=bin/ch/usi/dag/disl/test/bodymarker/TargetClass.class
// -Ddisl.classes=bin/ch/usi/dag/disl/test/bodymarker/DiSLClass.class
DiSL disl = new DiSL();
disl.initialize();
byte[] instrOut = disl.instrument(OnPlaceTransformer.class
.getResourceAsStream(System.getProperty("test.class")));
String classToTransform = null;
if(args.length == 1) {
classToTransform = args[0];
}
if(classToTransform == null) {
classToTransform = System.getProperty("disltest.transform");
}
if(classToTransform == null) {
System.err.println("No class to transform...");
System.exit(1);
}
// check class first
ClassReader cr = new ClassReader(new FileInputStream(classToTransform));
cr.accept(new CheckClassAdapter(
new TraceClassVisitor(new PrintWriter(System.out))), 0);
byte[] instrOut = disl.instrument(new FileInputStream(classToTransform));
if(instrOut != null) {
File f = new File("ModifiedClass.class");
FileOutputStream fos = new FileOutputStream(f);
FileOutputStream fos = new FileOutputStream("ModifiedClass.class");
fos.write(instrOut);
fos.flush();
fos.close();
......
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