WALA
WALA copied to clipboard
How to add source files and what is the entrypoint?
I want to add all the files in a directory to the Scope and then slice the program.
But I have encountered a lot of problems.
- First, I added a directory, but only a
.java
in the directory was added. - Second, I don't know what
entrypoint
means.
So, I used com.ibm.wala.ipa.callgraph.impl.AllApplicationEntrypoints;
, but it shows Number of EntryPoints: 0
.
Immediately caused makeCallGraph
to fail. “Could not create a entrypoint callsites:” problems.
Thanks.
ref1 - source dir call graph, ref2 - sdg for java,ref3 - entrypoint callsites,ref4 - addToScope
And, this is my code.
public static void doSlice() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException, InvalidClassFileException {
String sourceDir = "/Users/qingdujun/home/whole/test/tomcat";
AnalysisScope scope = new JavaSourceAnalysisScope();
String[] stdlibs = WalaProperties.getJ2SEJarFiles();
for (String s : stdlibs) {
// System.out.println(s);
scope.addToScope(ClassLoaderReference.Primordial, new JarFile(s));
}
scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));
// scope.addSourceFileToScope(ClassLoaderReference.Application, new File(sourceDir+"/Sliceme.java"), sourceDir+"/Sliceme.java");
// scope.setExclusions(new FileOfClasses(new ByteArrayInputStream(EXCLUSIONS.getBytes("UTF-8"))));
IClassHierarchy cha = ClassHierarchyFactory.make(scope, new ECJClassLoaderFactory(scope.getExclusions()));
// IClassHierarchy cha = ClassHierarchyFactory.make(scope);
System.out.println(cha.getNumberOfClasses()+" classed");
// System.out.println(Warnings.asString());
// Warnings.clear();
AnalysisOptions options = new AnalysisOptions();
// Iterable<? extends Entrypoint> entrypoints = Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE, cha, new String[] {"mainClass"});
Iterable<? extends Entrypoint> entrypoints = new AllApplicationEntrypoints2(scope, cha);
options.setEntrypoints(entrypoints);
// options.setReflectionOptions(ReflectionOptions.NONE);
AnalysisCache cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
CallGraphBuilder<InstanceKey> builder = new ZeroCFABuilderFactory().make(options, cache, cha, scope);
System.out.println("building call graph...");
CallGraph cg = builder.makeCallGraph(options, null);
// PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
// DataDependenceOptions dOptions = DataDependenceOptions.NO_BASE_NO_EXCEPTIONS;
// ControlDependenceOptions cOptions = ControlDependenceOptions.NONE;
// SDG<InstanceKey> sdg = new SDG<InstanceKey>(cg, pointerAnalysis, new AstJavaModRef<InstanceKey>(), dOptions, cOptions);
// CGNode call = findMethod(cg, "main",null);
// Statement ss = findCallTo(call, "append");//readByte
// Collection<Statement> collection = Slicer.computeBackwardSlice(sdg, ss);
// dumpSlice(collection);
}
i encountered the same problem,did you solved this issue?
AllApplicationEntrypoints looks for classes from the Application loader. What does AllApplicationEntrypoints2 do?
On Mon, Oct 21, 2019 at 9:48 AM Jiawei Qin [email protected] wrote:
i encountered the same problem,did you solved this issue?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wala/WALA/issues/520?email_source=notifications&email_token=AAMTO7UR2NZE74H4OJNI3V3QPWXLFA5CNFSM4HSHE6OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEB2MHEA#issuecomment-544523152, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMTO7XAT267H2SA3JPBBSTQPWXLFANCNFSM4HSHE6OA .
I write this;
String sourceDir = "/tmp/test_data/SpringBootDemo/SpringBootDemo/src/main/java/";
AnalysisScope scope = new JavaSourceAnalysisScope();
// add standard libraries to scope
String[] stdlibs = WalaProperties.getJ2SEJarFiles();
for (String stdlib : stdlibs) {
scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib));
}
ExampleUtil.addDefaultExclusions(scope);
// ExampleUtil.addTailExclusions(scope);
// add the source directory
scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));
// build the class hierarchy
IClassHierarchy cha = ClassHierarchyFactory.make(scope, new ECJClassLoaderFactory(scope.getExclusions()));
but issue is factory getloader is null
Exception in thread "main" com.ibm.wala.ipa.cha.ClassHierarchyException: factory.getLoader failed java.lang.NullPointerException
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:291)
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:203)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:81)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:67)
at com.ibm.wala.examples.analysis.SourceDirCallGraph.main(SourceDirCallGraph.java:80)
@liberatorqjw , I got the same exception. Have you solved this?
Does the SourceDirCallGraph
driver work for people having this issue?
https://github.com/wala/WALA/blob/master/com.ibm.wala.cast.java.ecj/src/com/ibm/wala/cast/java/ecj/util/SourceDirCallGraph.java
I have tested that before. If it doesn't work, can you provide a small example that shows the crash?
@msridhar Thank you for the quick reply. I wrote a simple example in https://github.com/Anemone95/wala-demo/blob/master/wala-code/src/main/java/top/anemone/walaDemo/MySourceDirCallGraph.java. After mvn clean package
, using the following commands to reproduce this issue:
$ java -cp wala-code/target/lib/:wala-code/target/wala-code-1.0-SNAPSHOT.jar top.anemone.walaDemo.MySourceDirCallGraph -sourceDir wala-target/src/main/java -mainClass Ltop/anemone/walaTarget/Main
Exception in thread "main" com.ibm.wala.ipa.cha.ClassHierarchyException: factory.getLoader failed java.lang.NullPointerException
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:291)
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:203)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:81)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:67)
at com.ibm.wala.cast.java.ecj.util.SourceDirCallGraph.main(SourceDirCallGraph.java:63)
at top.anemone.walaDemo.MySourceDirCallGraph.main(MySourceDirCallGraph.java:11)
Yes, I write as follows:
scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));
// build the class hierarchy
IClassHierarchy cha = ClassHierarchyFactory.make(scope, new com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory(scope.getExclusions()));
.......
IAnalysisCacheView cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
I think the key poinr is this
IAnalysisCacheView cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
Looked into this a bit. It looks like there are a couple of issues going on with WALA master. But regarding the factory.getLoader failed java.lang.NullPointerException
issue, I think this is because the source front-end is crashing when there is a missing third-party jar file. @Anemone95 I think if you add the jar with the Gson
class to your AnalysisScope
then things might work; can you try?
I will try to work on fixing these issues soon.
On WALA master the example from @Anemone95 fails as follows:
Exception in thread "main" com.ibm.wala.ipa.cha.ClassHierarchyException: factory.getLoader failed
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:291)
at com.ibm.wala.ipa.cha.ClassHierarchy.<init>(ClassHierarchy.java:203)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:81)
at com.ibm.wala.ipa.cha.ClassHierarchyFactory.make(ClassHierarchyFactory.java:67)
at com.ibm.wala.cast.java.ecj.util.SourceDirCallGraph.main(SourceDirCallGraph.java:63)
Caused by: java.lang.NullPointerException
at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator$ProcedureEntity.<init>(JDTJava2CAstTranslator.java:1088)
at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator$ProcedureEntity.<init>(JDTJava2CAstTranslator.java:1011)
at com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator$ProcedureEntity.<init>(JDTJava2CAstTranslator.java:956)
The NullPointerException
comes because the JDT frontend tries to resolve Gson
and fails.
@juliandolby do you know if the JDT / ECJ frontend is supposed to be robust to source files referencing classes that are missing from the analysis scope?
I can confirm from my experience that the frontend is absolutely not robust to classes missing from the analysis scope. The JDT/ECJ Java2CAstTranslator runs into a myriad of NPEs if you don't provide the classes or implement an alternative (I hacked together the latter and it was quite an undertaking)
see #99