de.hdu.pvs.crashfinder.instrument.StmtTracer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crashFinder Show documentation
Show all versions of crashFinder Show documentation
A tool for localizing the software regression errors
The newest version!
package de.hdu.pvs.crashfinder.instrument;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import de.hdu.pvs.crashfinder.util.Files;
import de.hdu.pvs.crashfinder.util.Globals;
/**
* This tracer is used to trace every executed bytecode statements
* */
public class StmtTracer {
public static StmtTracer tracer = new StmtTracer();
private StmtTracer() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("------- dump stmts to file -------");
synchronized (stmts) {
StringBuilder sb = new StringBuilder();
for (String stmt : stmts) {
sb.append(stmt);
sb.append(Globals.lineSep);
}
try {
long currTime = System.currentTimeMillis();
String fileName = "./stmts_dump_" + currTime + ".txt";
System.out.println("Write to file: " + fileName);
Files.writeToFile(sb.toString(), fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
private static Set stmts = new LinkedHashSet();
// record the statements that get executed
public void trace(String input) {
synchronized (stmts) {
stmts.add(input);
}
}
}