[Soot-list] Can soot generate LocalVariableTable in the output class files?

Saswat Anand saswat at cc.gatech.edu
Tue Dec 4 02:12:09 EST 2007


Hi,

I am wondering if there was any further suggestions on how to 
make soot generate Local variable tables in the output classes.

Since I needed the feature badly, I attempted to implement it.
It seems to work fine for me so far. Can anybody please check 
if its the right way to do it. I will be happy to create a patch
to add the feature to soot if it is correct.

I added the following code to soot.baf.JasminClass right before 
emiting the code (around line 214). I also had to make minor 
changes to soot.baf.internal.BafLocal and soot.baf.BafBody to 
create a mapping from a BafLocal to the type of its corresponding 
JimpleLocal (used in getJasminTypeDescriptor() below).

if(!unitToLabel.containsKey(instList.getFirst()))
    unitToLabel.put(instList.getFirst(), "label" + labelCount++);
if(!unitToLabel.containsKey(instList.getLast()))
    unitToLabel.put(instList.getLast(), "label" + labelCount++);
String fromLabel = (String) unitToLabel.get(instList.getFirst());
String toLabel = (String) unitToLabel.get(instList.getLast());

localIt = body.getLocals().iterator();
while(localIt.hasNext()){
    Local local = (Local) localIt.next();
    emit("    .var " + localToSlot.get(local) + " is " + 
	 local.getName() + " " + 
	 ((soot.baf.internal.BafLocal) local).getJasminTypeDescriptor() + 
	 " from " + fromLabel + " to " + toLabel);
}

Saswat


More information about the Soot-list mailing list