我刚开始使用Wala Java切片器来做一些源代码分析任务。我对图书馆的正确使用有一个疑问。假设我有以下示例代码:Wala Java切片器 - 从切片丢失的语句
public void main(String[] args) {
...
UserType ut = userType;
int i = ut.getInt();
...
System.out.println(i);
}
计算为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
的代码我使用的创建与瓦剌切片如下图所示:
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.getInt()
ut = userType
,包括在片 - 从
getInt()
实施的任何声明都包括在内。是否有激活“程序间”切片的选项?我在这里应该提到.class文件包含在用于创建AnalysisScope
的路径中。
正如你所看到的,我使用的依赖选项DataDependenceOptions.NO_BASE_NO_HEAP
和ControlDependenceOptions.NONE
。但即使当我使用FULL
时,问题仍然存在。
我在做什么错?
谢谢!我完全错过了Wala页面上的警告。这是否意味着如果我需要这些语句,那么我必须分析源代码而不是字节码? – Rizkallah
我想这取决于你想要达到的目标;在大多数情况下,分析这种分配并不重要,因为它是调用对象的方法,而不是参考的存储位置。跟踪引用可能会成为你和编译器之间的战斗,这是一场艰苦的战斗。祝你好运! – StuPointerException
我想跟踪哪个引用被用来执行方法调用,而不仅仅是方法调用自己。这就是为什么分配对我很重要。我想我需要对这个话题做更多的研究。再次感谢你! – Rizkallah