[Soot-list] Def Use analysis on Groovy Classes (Bytecode)
Pauline Anthonysamy
anthonys at comp.lancs.ac.uk
Tue Sep 11 14:29:14 EDT 2012
Hello Everyone,
I implemented a method which generates def - use chain for a method.
Below is my method:
private HashMap<Integer, HashSet<Integer>> getDUChains(SootMethod m) {
HashMap<Integer, HashSet<Integer>> duChains = new
HashMap<Integer, HashSet<Integer>>();
Body b = m.retrieveActiveBody();
UnitGraph graph = new CompleteUnitGraph(b);
SimpleLiveLocals s = new SimpleLiveLocals(graph);
Iterator<Unit> gIt = graph.iterator();
// generate du-pairs
while (gIt.hasNext()) {
Unit defUnit = gIt.next();
SmartLocalDefs des = new SmartLocalDefs(graph, s); // defs
of local variables
SimpleLocalUses uses = new SimpleLocalUses(graph, des);
List<UnitValueBoxPair> ul = uses.getUsesOf(defUnit);
if (ul != null && ul.size() != 0) {
// defs in this unit have some uses
*int defLine =
Integer.parseInt(defUnit.getTag("LineNumberTag").toString());*
HashSet<Integer> useLines = duChains.get(defLine); //
save my use lines
if (useLines == null) {
useLines = new HashSet<Integer>();
}
// all uses lines here
for (UnitValueBoxPair vbp : ul) {
String use =
vbp.getUnit().getTag("LineNumberTag").toString(); //
useLines.add(Integer.parseInt(use));
}
duChains.put(defLine, useLines);
}
}
return duChains;
}
The method works for Java classes but not on Groovy as the
"defUnit.getTag("LineNumberTag").toString()" throws a
NullPointerException. I remember reading somewhere that Groovy Bytecode
does not keep the source code line numbers. Is this true? If yes, is
there a way to get pass this? I am not sure how I can proceed from here.
Any help would be very much appreciated!
Many Thanks,
-Pauline
--
Pauline Anthonysamy
PhD Candidate
Lancaster University
Lancaster, United Kingdom
Email: anthonys at comp.lancs.ac.uk
Phone: +44 (01524) 510346
WWW: http://www.comp.lancs.ac.uk/~anthonys
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120911/b841b991/attachment.html
More information about the Soot-list
mailing list