fixes for ir generation

This commit is contained in:
Julian Dolby 2014-10-10 17:48:37 -04:00
parent 0e55cd2eec
commit e3dfc5afe5
8 changed files with 85 additions and 26 deletions

View File

@ -0,0 +1,22 @@
package com.ibm.wala.dalvik.drivers;
import java.io.IOException;
import com.ibm.wala.dalvik.test.callGraph.DalvikCallGraphTestBase;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.util.CancelException;
public class APKCallGraphDriver {
public static void main(String[] args) throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {
CallGraph CG = DalvikCallGraphTestBase.makeAPKCallGraph(args[0]).fst;
System.err.println(CG);
for(CGNode n : CG) {
System.err.println(n);
System.err.println(n.getIR());
}
}
}

View File

@ -33,7 +33,6 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.properties.WalaProperties;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.MethodReference;

View File

@ -14,8 +14,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Set;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
@ -28,6 +27,7 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ipa.cha.ClassHierarchy;
@ -36,6 +36,7 @@ import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.OrdinalSet;
public class JVMLDalvikComparison extends DalvikCallGraphTestBase {
@ -83,17 +84,32 @@ public class JVMLDalvikComparison extends DalvikCallGraphTestBase {
Set<MethodReference> androidMethods = applicationMethods(android.fst);
Set<MethodReference> javaMethods = applicationMethods(java.fst);
Set<MethodReference> androidExtra = HashSetFactory.make(androidMethods);
androidExtra.removeAll(javaMethods);
System.err.println(androidExtra);
Set<MethodReference> javaExtra = HashSetFactory.make(javaMethods);
javaExtra.removeAll(androidMethods);
System.err.println(javaExtra);
System.err.println(edgeDiff(android.fst, java.fst));
System.err.println(edgeDiff(java.fst, android.fst));
if (!androidMethods.containsAll(javaMethods)) {
Set<MethodReference> androidExtra = HashSetFactory.make(androidMethods);
androidExtra.removeAll(javaMethods);
Set<MethodReference> javaExtra = HashSetFactory.make(javaMethods);
javaExtra.removeAll(androidMethods);
System.err.println(edgeDiff(java.fst, android.fst));
System.err.println(javaExtra);
System.err.println(android.fst);
for(CGNode n : android.fst) {
System.err.println("### " + n);
if (n.getIR() != null) {
System.err.println(n.getIR());
for(int i = 1; i < n.getIR().getSymbolTable().getMaxValueNumber(); i++) {
LocalPointerKey x = new LocalPointerKey(n, i);
OrdinalSet<InstanceKey> s = android.snd.getPointsToSet(x);
if (s != null && !s.isEmpty()) {
System.err.println(i + ": " + s);
}
}
}
}
}
Assert.assertTrue(androidMethods.containsAll(javaMethods));
}

View File

@ -984,7 +984,7 @@ public class DexIMethod implements IBytecodeMethod {
break;
case MOVE_EXCEPTION:
instructions.add(new UnaryOperation(instLoc,
UnaryOperation.OpID.MOVE, ((Instruction11x)inst).getRegisterA(),
UnaryOperation.OpID.MOVE_EXCEPTION, ((Instruction11x)inst).getRegisterA(),
getExceptionReg(), inst.opcode, this));
break;
case RETURN_VOID:

View File

@ -57,7 +57,7 @@ import com.ibm.wala.shrikeBT.IUnaryOpInstruction.IOperator;
public class UnaryOperation extends Instruction {
public static enum OpID {MOVE, MOVE_WIDE, NOT, NEGINT, NOTINT, NEGLONG, NOTLONG, NEGFLOAT, NEGDOUBLE, DOUBLETOLONG, DOUBLETOFLOAT, INTTOBYTE, INTTOCHAR, INTTOSHORT, DOUBLETOINT, FLOATTODOUBLE, FLOATTOLONG, FLOATTOINT, LONGTODOUBLE, LONGTOFLOAT, LONGTOINT, INTTODOUBLE, INTTOFLOAT, INTTOLONG};
public static enum OpID {MOVE, MOVE_WIDE, MOVE_EXCEPTION, NOT, NEGINT, NOTINT, NEGLONG, NOTLONG, NEGFLOAT, NEGDOUBLE, DOUBLETOLONG, DOUBLETOFLOAT, INTTOBYTE, INTTOCHAR, INTTOSHORT, DOUBLETOINT, FLOATTODOUBLE, FLOATTOLONG, FLOATTOINT, LONGTODOUBLE, LONGTOFLOAT, LONGTOINT, INTTODOUBLE, INTTOFLOAT, INTTOLONG};
public final OpID op;
public final int source;

View File

@ -289,7 +289,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
@Override
public boolean isUnaryNoOp() {
return true;
return false;
}
@Override
@ -299,9 +299,14 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
// Exception e = new Exception("evaluating a MeetOperator");
// e.printStackTrace();
// return NOT_CHANGED;
if (cfg.getDexMethod().getReference().toString().equals("< Application, Lcom/google/android/gms/tagmanager/v$a, onOpen(Landroid/database/sqlite/SQLiteDatabase;)V >")) {
System.err.println("got here");
}
if (!bb.isCatchBlock()) {
return meet(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
} else {
} else {
return meetForCatchBlock(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
}
}
@ -418,6 +423,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
// not already allocated.
if (L.locals == null) {
L.allocateLocals();
changed = true;
}
DexIMethod dMethod = (DexIMethod)L.getBasicBlock().getMethod();
@ -428,10 +434,8 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
int meet = meeter.meetStackAtCatchBlock(bb);
if (L.locals[dMethod.getExceptionReg()] == TOP) {
if (meet != TOP) {
changed = true;
L.locals[dMethod.getExceptionReg()] = meet;
}
changed = true;
L.locals[dMethod.getExceptionReg()] = meet;
} else if (meet != L.locals[dMethod.getExceptionReg()]) {
changed = true;
L.locals[dMethod.getExceptionReg()] = meet;
@ -543,6 +547,7 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
int nLocals = computeMeetNLocals(rhs);
if (nLocals > -1 && L.locals == null) {
L.allocateLocals();
changed = true;
}
// evaluate the element-wise meet over the locals.

View File

@ -71,6 +71,7 @@ import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.ssa.PhiValue;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.ssa.SSACFG;
import com.ibm.wala.ssa.SSACFG.ExceptionHandlerBasicBlock;
import com.ibm.wala.ssa.SSAConditionalBranchInstruction;
import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction;
import com.ibm.wala.ssa.SSAInstruction;
@ -271,8 +272,11 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) cfg.getNode(bbNumber);
SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction();
int exceptionValue;
if (cfg.getMethod().getReference().toString().equals("< Application, Lcom/google/android/gms/tagmanager/v$a, onOpen(Landroid/database/sqlite/SQLiteDatabase;)V >")) {
System.err.println("got here");
}
if (s == null) {
exceptionValue = symbolTable.newSymbol();
exceptionValue = symbolTable.newSymbol();
s = insts.GetCaughtExceptionInstruction(bb.getLastInstructionIndex(), bbNumber, exceptionValue);
newBB.setCatchInstruction(s);
} else {
@ -387,7 +391,7 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
this.symbolTable = symbolTable;
this.loader = dexCFG.getMethod().getDeclaringClass().getClassLoader().getReference();
// this.localMap = localMap;
init(this.new NodeVisitor(), this.new EdgeVisitor());
init(this.new NodeVisitor(cfg), this.new EdgeVisitor());
}
@Override
@ -449,7 +453,13 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
* Update the machine state to account for an instruction
*/
class NodeVisitor extends BasicRegisterMachineVisitor {
// TODO: make sure all visit functions are overridden
private final SSACFG cfg;
public NodeVisitor(SSACFG cfg) {
this.cfg = cfg;
}
// TODO: make sure all visit functions are overridden
/**
* @see com.ibm.wala.shrikeBT.Instruction.Visitor#visitArrayLength(ArrayLengthInstruction)
@ -1229,6 +1239,11 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
}
emitInstruction(insts.ConversionInstruction(getCurrentInstructionIndex(), result, val, fromType, toType, overflows));
}
else if (instruction.op == UnaryOperation.OpID.MOVE_EXCEPTION) {
int source = ((DexIMethod)dexCFG.getMethod()).getExceptionReg();
workingState.setLocal(instruction.destination, source);
}
else
{
emitInstruction(insts.UnaryOpInstruction(getCurrentInstructionIndex(), instruction.getOperator(), result, val));
@ -1243,7 +1258,6 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
else
workingState.setLocal(instruction.destination+1, workingState.getLocal(instruction.source+1));
}
}
}

View File

@ -352,6 +352,9 @@ nextMethod:
final Collection<IMethod> ifMethods = iFace.getDeclaredMethods();
for (final IMethod ifMethod : ifMethods) {
final IMethod method = appClass.getMethod(ifMethod.getSelector());
if (method == null || method.isAbstract()) {
continue;
}
if (method.getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application)) {
// The function is overridden
final AndroidEntryPoint ep = new AndroidEntryPoint(selectPositionForHeuristic(method), method, cha);