Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Dec 18, 2023
1 parent b5f3d51 commit 66c79bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
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.ReturnValueKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ExceptionReturnValueKey;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
Expand All @@ -40,15 +37,12 @@
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.Iterator2Collection;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.intset.IntSetUtil;
import com.ibm.wala.util.intset.MutableIntSet;
import com.ibm.wala.util.intset.OrdinalSet;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -114,13 +108,13 @@ private static void test(String mainClass, String javaScopeFile)
Set<MethodReference> androidMethods = applicationMethods(android.fst);
Set<MethodReference> javaMethods = applicationMethods(java.fst);

Iterator<Pair<CGNode, CGNode>> javaExtraEdges =
edgeDiff(java.fst, android.fst, false).iterator();
assert !checkEdgeDiff(android, androidMethods, javaMethods, javaExtraEdges);
Set<Pair<CGNode, CGNode>> javaExtraEdges =
edgeDiff(java.fst, android.fst, false);
assert !checkEdgeDiff(android, androidMethods, javaMethods, javaExtraEdges) : "found extra edges in Java call graph";

Iterator<Pair<CGNode, CGNode>> androidExtraEdges =
edgeDiff(android.fst, java.fst, true).iterator();
assert !checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges);
Set<Pair<CGNode, CGNode>> androidExtraEdges =
edgeDiff(android.fst, java.fst, true);
assert !checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges) : "found extra edges in Android call graph";

checkSourceLines(java.fst, android.fst);
}
Expand Down Expand Up @@ -176,39 +170,51 @@ private static void checkSourceLines(CallGraph java, CallGraph android) {
: "inconsistent debug info: " + ajlines + " " + aalines;
}

@SuppressWarnings("UnusedVariable")
private static boolean checkEdgeDiff(
Pair<CallGraph, PointerAnalysis<InstanceKey>> android,
Set<MethodReference> androidMethods,
Set<MethodReference> javaMethods,
Iterator<Pair<CGNode, CGNode>> javaExtraEdges) {
Pair<CallGraph, PointerAnalysis<InstanceKey>> firstResult,
Set<MethodReference> methodsInFirst,
Set<MethodReference> methodsInSecond,
Set<Pair<CGNode, CGNode>> extraEdgesInSecond) {
boolean fail = false;
if (javaExtraEdges.hasNext()) {
if (!extraEdgesInSecond.isEmpty()) {
fail = true;
Set<MethodReference> javaExtraNodes = HashSetFactory.make(javaMethods);
javaExtraNodes.removeAll(androidMethods);

System.err.println(Iterator2Collection.toSet(javaExtraEdges));
System.err.println(javaExtraNodes);

System.err.println(android.fst);

for (CGNode n : android.fst) {
System.err.println("### " + n);
if (n.getIR() != null) {
System.err.println(n.getIR());

System.err.println("return: " + android.snd.getPointsToSet(new ReturnValueKey(n)));
System.err.println(
"exceptions: " + android.snd.getPointsToSet(new ExceptionReturnValueKey(n)));
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);
}
}
Set<MethodReference> extraMethodsInSecond = HashSetFactory.make(methodsInSecond);
extraMethodsInSecond.removeAll(methodsInFirst);

System.err.println(extraEdgesInSecond);
System.err.println(extraMethodsInSecond);

CallGraph firstCG = firstResult.fst;
for (Pair<CGNode, CGNode> p : extraEdgesInSecond) {
System.err.println("### " + p.fst);
System.err.println("### " + p.snd);
System.err.println("### " + p.fst.getIR());
System.err.println("====");
Set<CGNode> nodes = firstCG.getNodes(p.fst.getMethod().getReference());
for (CGNode n : nodes) {
System.err.println("### " + n);
System.err.println("### " + n.getIR());
}
}

// for (CGNode n : firstResult.fst) {
// System.err.println("### " + n);
// if (n.getIR() != null) {
// System.err.println(n.getIR());

// System.err.println("return: " + android.snd.getPointsToSet(new ReturnValueKey(n)));
// System.err.println(
// "exceptions: " + android.snd.getPointsToSet(new ExceptionReturnValueKey(n)));
// 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);
// }
// }
// }
// }
}
return fail;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ktfmt = "0.44"
spotless = "6.23.3"

[libraries]
android-tools = "com.android.tools:r8:2.2.42"
android-tools = "com.android.tools:r8:8.2.38"
ant = "org.apache.ant:ant:1.10.14"
assertj-core = "org.assertj:assertj-core:3.24.2"
commons-cli = "commons-cli:commons-cli:1.5.0"
Expand Down

0 comments on commit 66c79bd

Please sign in to comment.