WALA icon indicating copy to clipboard operation
WALA copied to clipboard

Why fail to build the correct CallGraph

Open RaistlinShu opened this issue 3 years ago • 3 comments

I'm using WALA(via maven) to Slice Java source code in my research, and I just followed the WalaWiki: UserGuide:Slicer write my code. But I find that I seem not to build the right CallGraph because I can't find the method I want to slice in the CallGraph. However, I can find it in the Iterable<Entrypoint> entrypoints. I don't know how to solve it.

The following is part of my code(simplified somewhat):

public void doSlicingMultipleMethods(String appJar) throws WalaException, IOException, IllegalArgumentException, CancelException, InvalidClassFileException {
	File exFile = new FileProvider().getFile("Java60RegressionExclusions.txt");
	AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(appJar, exFile);
	ClassHierarchy cha = ClassHierarchyFactory.make(scope);
	Iterable<Entrypoint> entrypoints;
	Queue<String> methodNames=new LinkedList();
	Queue<String> methodIOs=new LinkedList();
	if (className==null) {
		entrypoints = new AllApplicationEntrypoints(scope, cha);
	}else {
		entrypoints = loadEntrypoints(cha, className);
	}
	for(Entrypoint enn:entrypoints) {
		methodNames.add(enn.getMethod().getName().toString());
		methodIOs.add(enn.getMethod().getDescriptor().toString());
	}
	while (!methodNames.isEmpty()) {
		methodName=methodNames.poll();
		methodIO=methodIOs.poll();

		Iterable<Entrypoint> entrypoints1 = makeEntrypoints(entrypoints, methodName);
		AnalysisOptions options1 = new AnalysisOptions(scope, entrypoints1);
		options1.setReflectionOptions(ReflectionOptions.NONE);
		CallGraphBuilder<InstanceKey> cgb = Util.makeZeroCFABuilder(Language.JAVA, options1, new AnalysisCacheImpl(),
					cha, scope);

		
		try {
			cg= cgb.makeCallGraph(options1, null);
		}catch(IllegalStateException e) {
			System.err.println(methodName+" gives a IllegalStateException, could not create entrypoint callsites\n");
			continue;
		}
		Collection<Statement> statement=findCallTo(findMethod(methodName,methodIO,cg),"return");
		
		...
	}
}		

every time I run this method I get the followings:

Exception in thread "main" com.ibm.wala.util.debug.UnimplementedError: failed to find method
	at com.ibm.wala.util.debug.Assertions.UNREACHABLE(Assertions.java:55)
	at test.bslice5.findMethod(...)
	...

I print CallGraphStats.getStats(cg) and cg and got the following:

Call graph stats:
  Nodes: 5
  Edges: 4
  Methods: 5
  Bytecode Bytes: 5
Node: synthetic < Primordial, Lcom/ibm/wala/FakeRootClass, fakeRootMethod()V > Context: Everywhere
 - invokestatic < Primordial, Lcom/ibm/wala/FakeRootClass, fakeWorldClinit()V >@0
     -> Node: synthetic < Primordial, Lcom/ibm/wala/FakeRootClass, fakeWorldClinit()V > Context: Everywhere
 - invokespecial < Primordial, Ljava/lang/Object, <init>()V >@4
     -> Node: < Primordial, Ljava/lang/Object, <init>()V > Context: Everywhere

Node: synthetic < Primordial, Lcom/ibm/wala/FakeRootClass, fakeWorldClinit()V > Context: Everywhere
 - invokestatic < Primordial, Ljava/lang/Object, <clinit>()V >@0
     -> Node: < Primordial, Ljava/lang/Object, <clinit>()V > Context: Everywhere

Node: < Primordial, Ljava/lang/Object, <clinit>()V > Context: Everywhere
 - invokestatic < Primordial, Ljava/lang/Object, registerNatives()V >@0
     -> Node: < Primordial, Ljava/lang/Object, registerNatives()V > Context: Everywhere

Node: < Primordial, Ljava/lang/Object, registerNatives()V > Context: Everywhere

Node: < Primordial, Ljava/lang/Object, <init>()V > Context: Everywhere

By the way, I use IDEA and maven to build my project, and I have already added the wala.properties in the com.ibm.wala.core-1.5.7.jar and added java_runtime_dir = D:/JDK/jdk1.8.0_311/jre/lib. My java version is 15

thx

RaistlinShu avatar Jan 25 '22 10:01 RaistlinShu

@RaistlinShu it looks like your call graph doesn't really have any methods in it other than some basic standard library ones. So I'm guessing something is messed up there. Why do you do this?

Iterable<Entrypoint> entrypoints1 = makeEntrypoints(entrypoints, methodName);

Maybe you can print the entrypoints and make sure they are what you expect?

msridhar avatar Jan 29 '22 02:01 msridhar

@msridhar There do exist some problems in Iterable<Entrypoint> entrypoints1 = makeEntrypoints(entrypoints, methodName);. But when I use entrypoints which do contains the methods I need to build the call graph, the call graph still doesn't contain the method I need.

RaistlinShu avatar Jan 30 '22 09:01 RaistlinShu

@RaistlinShu sorry for my slow response. Unfortunately I can't really help further without some more details. If you can create an example code in a public repo that exposes the problem you are seeing, I could help try to figure out the root cause.

msridhar avatar Apr 19 '22 17:04 msridhar

Closing due to lack of response

msridhar avatar Oct 29 '22 16:10 msridhar