pascal-lab/Tai-e

How to obtain the results of CFGBuilder while writing PTA Plugin code?

Spr1n9T1me opened this issue · 2 comments

Description

Description

In my PTA plugin, I override onNewMethod() as below:

    @Override
    public void onNewMethod(JMethod method) {
        CFG<Stmt> cfg = method.getIR().getResult(CFGBuilder.ID);
        for (Stmt stmt : cfg) {
            if (stmt instanceof If ifStmt){
                /* some code*/
            }
        }
    }

In this code, i want to filter all IF stmt in new method while PTA running, before that i need to get the result of CFGBuilder, but finally I got the error:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "pascal.taie.analysis.graph.cfg.CFG.iterator()" because "cfg" is null at net.pecker.entry.AnnotationEntryHandler.onNewMethod(AnnotationEntryHandler.java:133)
which might indicate the cfg analysis did not run correctly so that the result of method.getIR().getResult(CFGBuilder.ID) is empty.
So how can i obtain the results of CFGBuilder(or relevant data flow analysis) while writing PTA Plugin code?

Option File

here is my options file:

optionsFile: null
printHelp: false
classPath: [my-code-1.0.0.jar]
appClassPath:
#  - benchmarks/tomcat/javax.servlet-api-4.0.1.jar
#  - benchmarks/tomcat
  -  my-code\target\classes
mainClass:
inputClasses: []
javaVersion: 8
prependJVM: false
allowPhantom: true
worldBuilderClass: pascal.taie.frontend.soot.SootWorldBuilder
outputDir: output
preBuildIR: false
worldCacheMode: false
scope: REACHABLE
nativeModel: true
planFile: null
analyses:
  throw: "exception:explicit;algorithm:intra;"
  cfg: "exception:explicit;dump:false"
  pta: cs:ci;plugins:[net.pecker.entry.AnnotationEntryHandler];
  process-result: "analyses:[ cfg ]"
onlyGenPlan: false
keepResult:
  - $KEEP-ALL

Specify -scope to ALL to analyze more methods in CFGBuilder.

Problem solved, thanks!