【发布时间】:2017-02-15 11:12:12
【问题描述】:
我正在尝试实施分析(扩展 DefaultOneStepAnalysis)以在 CHA 算法中构建调用图。我的代码分为三部分:
1) method "doAnalyze" to return the "BasicReport"
2) method "analyze" to find call edges for each method in the given project
3) class "AnalysisContext" to store the context and methods using in the analysis.
在 3) 中,我使用方法“callBySignature”来找出与“CHACallGraphExtractor”相同的方法的 cbsMethods,但它不返回预期结果。 虽然我使用原始 OPAL 的方式在 Extractor 中获取 cbsMethods,但结果是一组方法。
能否请您帮我确认问题出在哪里以及如何解决? 非常感谢。
问候, 江
----我的代码的主要部分------------------------- ------------
object CHACGAnalysis extends DefaultOneStepAnalysis {
... ...
override def doAnalyze(
project: Project[URL],
parameters: Seq[String] = List.empty,
isInterrupted: () ⇒ Boolean
): BasicReport = {
... ...
for {
classFile <- project.allProjectClassFiles
method <- classFile.methods
} {
analyze(project, methodToCellCompleter, classFile, method))
}
... ...
}
def analyze(
project: Project[URL],
methodToCellCompleter: Map[(String,Method), CellCompleter[K, Set[Method]]],
classFile: ClassFile,
method: Method
): Unit = {
… …
val context = new AnalysisContext(project, classFile, method)
method.body.get.foreach((pc, instruction) ⇒
instruction.opcode match {
... ...
case INVOKEINTERFACE.opcode ⇒
val INVOKEINTERFACE(declaringClass, name, descriptor) = instruction
context.addCallEdge_VirtualCall(pc, declaringClass, name, descriptor, true,cell1)
... ...
}
… …
}
protected[this] class AnalysisContext(
val project: SomeProject,
val classFile: ClassFile,
val method: Method
) {
val classHierarchy = project.classHierarchy
val cbsIndex = project.get(CallBySignatureResolutionKey)
val statistics = project.get(IntStatisticsKey)
val instantiableClasses = project.get(InstantiableClassesKey)
val cache = new CallGraphCache[MethodSignature, scala.collection.Set[Method]](project)
private[AnalysisContext] def callBySignature(
declaringClassType: ObjectType,
name: String,
descriptor: MethodDescriptor
): Set[Method] = {
val cbsMethods = cbsIndex.findMethods(
name,
descriptor,
declaringClassType
)
cbsMethods
}
def addCallEdge_VirtualCall(
pc: PC,
declaringClassType: ObjectType,
name: String,
descriptor: MethodDescriptor,
isInterfaceInvocation: Boolean = false,
cell1: CellCompleter[K, Set[Method]]
): Unit = {
val cbsCalls =
if (isInterfaceInvocation) {
callBySignature(declaringClassType, name, descriptor)
}
else
Set.empty[Method]
… …
}
… …
}
【问题讨论】:
-
您可以将您的代码添加到问题中吗?这将有助于澄清您的问题。
-
原代码太复杂,我上传了主要部分的代码。我还在 OPAL 中对其进行了调试,以找出“cbsIndex.findMethods”无法按预期找到方法的原因。我发现它来自 CallBySignatureResolution.scala 中的“propertyStore(method, CallBySignature.Key)”。至于这条语句,我的代码的结果是“EP(XXXX,NoCBSTargets)”,原始代码的结果是“EP(XXX,CBSTargets(XXX))”。走得更远
-
您的分析模式是否可能是桌面应用程序?可以使用
project.analysisMode查看