soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
586 stars 77 forks source link

Failing to build FullView #554

Closed will-leeson closed 1 year ago

will-leeson commented 1 year ago

I am attempting to build a FullView as I want to analyze an entire project. When I do so I get an error

Exception in thread "main" java.lang.RuntimeException: StmtGraph of <org.la4j.inversion.GaussJordanInverter: org.la4j.Matrix inverse()> is invalid.

I'm not sure what is causing this, but when I build the view using createOnDemandView, things work fine. I think I need to use an FullView, because when I attempt to build an InterproceduralCallGraph, I get issues with imported functions from other places in the project.

Is there a reason createFullView is failing but createOnDemandView is not? If it helps, here is my code:

public static void BuildGraph(String ProjectPath, String ClassPath){
        AnalysisInputLocation<JavaSootClass> inputLocation =
        new JavaSourcePathAnalysisInputLocation(ProjectPath);

        // Specify the language of the JavaProject. This is especially relevant for Multi-release jars,
        // where classes are loaded depending on the language level of the analysis
        JavaLanguage language = new JavaLanguage(8);

        // Create a new JavaProject and view based on the input location
        JavaProject project =
            JavaProject.builder(language)
                .addInputLocation(inputLocation)
                .build();

        ClassType classVar = project.getIdentifierFactory().getClassType(ClassPath);

        // JavaView view = project.createOnDemandView();  // This Works
        JavaView view = project.createFullView(); // This doesn't
}

Apologies in advanced if this is a simple question. I'm new to SootUp (and Soot).

swissiety commented 1 year ago

Hi @will-leeson, the difference is the FullView loads/resolves every accessible class eagerly - but the ondemandview does not as it uses lazy loading it - so if you try to get the class org.la4j.inversion.GaussJordanInverter via the ondemandview explicitly via view.getClass( theClassType ) i expect you would get the same error. Was there more information available from the stacktrace?

will-leeson commented 1 year ago

That makes sense. Here is the parsed down stack trace:

Exception in thread "main" java.lang.RuntimeException: StmtGraph of <org.la4j.inversion.GaussJordanInverter: org.la4j.Matrix inverse()> is invalid.
    at sootup.core.model.Body$BodyBuilder.build(Body.java:520)
    at sootup.java.sourcecode.frontend.WalaIRToJimpleConverter.createBody(WalaIRToJimpleConverter.java:557)
    at sootup.java.sourcecode.frontend.WalaIRToJimpleConverter.convertMethod(WalaIRToJimpleConverter.java:278)
    at sootup.java.sourcecode.frontend.WalaIRToJimpleConverter.convertToClassSource(WalaIRToJimpleConverter.java:175)
    at sootup.java.sourcecode.frontend.WalaJavaClassProvider.getClassSources(WalaJavaClassProvider.java:236)
    at sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation.getClassSources(JavaSourcePathAnalysisInputLocation.java:153)
    at sootup.java.core.views.JavaView.lambda$resolveAll$3(JavaView.java:163)
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:269)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
    at sootup.java.core.views.JavaView.resolveAll(JavaView.java:164)
    at sootup.java.core.views.JavaView.getClasses(JavaView.java:104)
    at sootup.java.core.JavaProject.createFullView(JavaProject.java:78)
    at com.lesslab.ProgramGraph.GraphBuilder.BuildGraph(GraphBuilder.java:51)
    at com.lesslab.ProgramGraph.App.main(App.java:9)
Caused by: java.lang.IllegalStateException: visualize invalid StmtGraph: [Crazy long link which shows what I assume is the intermediate graphviz]
at sootup.core.graph.StmtGraph.validateStmtConnectionsInGraph(StmtGraph.java:242)
    at sootup.core.model.Body$BodyBuilder.build(Body.java:518)
    ... 19 more
Caused by: java.lang.IllegalStateException: Stmt '$r18 := @caughtexception' which is neither the StartingStmt nor a TrapHandler is missing a predecessor!
    at sootup.core.graph.StmtGraph.validateStmtConnectionsInGraph(StmtGraph.java:188)
    ... 20 more
JonasKlauke commented 1 year ago

Hi @will-leeson You are using the source code frontend. The source code frontend currently does not support Exceptions. Can you try to build the project and use the bytecode frontend.

To use the bytecode frontend you have to use

AnalysisInputLocation<JavaSootClass> inputLocation =
    new JavaClassPathAnalysisInputLocation(ProjectPath);

and the project path needs to point to the built jar.

will-leeson commented 1 year ago

@JonasKlauke That did the trick! Thank you