[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Printing Jimple
>>>>> "vranganath" == Venkatesh Prasad Ranganath <vranganath@cox.net> writes:
vranganath> Can anybody enlighten me how does one print a
vranganath> JimpleBody in Soot? Also, is there a way to
vranganath> print only the selected methods instead of
vranganath> printing the whole class?
I don't have any clues about why your attempt to print the whole
class prints nothing at all. But I have appended a debugging
routine that does successfully print individual Bodies for me.
I call it out of Transform.apply(Body), to dump the internal
representation as selected phases run (the "alreadyDumping" flag
avoids a Heisenberg effect when I also dump CFGs as they are
built). You could use similar code to print the bodies of
selected methods from a class.
// soot.Printer itself needs to create a BriefUnitGraph in order
// to format the text for a method's instructions, so this flag is
// a hack to avoid dumping graphs that we create in the course of
// dumping bodies or other graphs.
private boolean alreadyDumping = false;
private void dumpBody(Body b, String baseName) {
alreadyDumping = true;
try {
java.io.PrintWriter out = openBodyFile(b, baseName);
soot.Printer.v().setOption(Printer.USE_ABBREVIATIONS);
soot.Printer.v().printTo(b, out);
out.close();
} catch (java.io.IOException e) {
// Don't abort execution because of an I/O error, but let
// the user know.
G.v().out.println("PhaseDumper.dumpBody() caught: " + e.toString());
e.printStackTrace(G.v().out);
}
alreadyDumping = false;
}
--
John Jorgensen jjorge1@cs.mcgill.ca