我刚开始使用 Wala Java Slicer 做一些源代码分析任务。我对图书馆的正确使用有疑问。假设我有以下示例代码:
public void main(String[] args) {
...
UserType ut = userType;
int i = ut.getInt();
...
System.out.println(i);
}
用 Wala计算语句的切片println
给出以下语句:
NORMAL_RET_CALLER:Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere[15]13 = invokevirtual < Application, LUserType, getInt()I > 11 @27 exception:12
NORMAL main:23 = getstatic < Application, Ljava/lang/System, out, <Application,Ljava/io/PrintStream> > Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere
NORMAL main:invokevirtual < Application, Ljava/io/PrintStream, println(I)V > 23,13 @63 exception:24 Node: < Application, LRTExecutionClass, main([Ljava/lang/String;)V > Context: Everywhere
我使用 Wala 创建切片的代码如下所示:
AnalysisScope scope = AnalysisScopeReader.readJavaScope("...",
null, WalaJavaSlicer.class.getClassLoader());
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha);
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
// Build the call graph
CallGraphBuilder cgb = Util.makeZeroCFABuilder(options, new AnalysisCache(),cha, scope, null, null);
CallGraph cg = cgb.makeCallGraph(options, null);
PointerAnalysis pa = cgb.getPointerAnalysis();
// Find seed statement
Statement statement = findCallTo(findMainMethod(cg), "println");
// Context-sensitive thin slice
Collection<Statement> slice = Slicer.computeBackwardSlice(statement, cg, pa, DataDependenceOptions.NO_BASE_NO_HEAP, ControlDependenceOptions.NONE);
dumpSlice(slice);
我希望在切片中找到许多语句但不存在:
ut = userType
即使从属方法调用ut.getInt()
IS 包含在切片中,assign 语句也不包含在内- 不包括来自实现的语句
getInt()
。是否有激活“程序间”切片的选项?我应该在这里提到 .class 文件包含在用于创建 .class 文件的路径中AnalysisScope
。
如您所见,我使用DataDependenceOptions.NO_BASE_NO_HEAP
andControlDependenceOptions.NONE
作为依赖选项。但即使我同时使用FULL
两者,问题仍然存在。
我究竟做错了什么?