How to generate a control flow graph for any piece of java program?

453 views Asked by At

I want to generate a control flow graph directly from the java source code. I have tried to use soot to generate a control flow graph, but soot will check for syntax errors, as shown below.

D:\isoot>java -cp sootclasses-trunk-jar-with-dependencies.jar soot.tools.CFGViewer --soot-classpath .;"D:\isoot\Java\jre1.8.0_221\lib\rt.jar" --graph=BriefBlockGraph A -src-prec  java
Soot started on Tue Apr 20 11:21:41 CST 2021
D:\isoot\A.java:6,22:
  Semantic Error: no visible type named Cache2kBuilder
D:\isoot\A.java:6,46:
  Semantic Error: no visible type named Cache2kConfiguration
D:\isoot\A.java:7,3:
  Semantic Error: no visible type named Cache2kBuilder
D:\isoot\A.java:7:
  Semantic Error: can not instantiate Unknown no matching constructor found in Unknown
D:\isoot\A.java:7,32:
  Semantic Error: no visible type named Cache2kBuilder
soot.CompilationDeathException: there were errors during parsing and/or type checking (JastAdd frontend)
        at soot.JastAddInitialResolver.formAst(JastAddInitialResolver.java:63)
        at soot.JavaClassSource.resolve(JavaClassSource.java:54)
        at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:235)
        at soot.SootResolver.bringToHierarchy(SootResolver.java:208)
        at soot.SootResolver.bringToSignatures(SootResolver.java:266)
        at soot.SootResolver.processResolveWorklist(SootResolver.java:170)
        at soot.SootResolver.resolveClass(SootResolver.java:133)
        at soot.Scene.loadClass(Scene.java:853)
        at soot.Scene.loadClassAndSupport(Scene.java:839)
        at soot.Scene.loadNecessaryClass(Scene.java:1569)
        at soot.Scene.loadNecessaryClasses(Scene.java:1582)
        at soot.Main.run(Main.java:250)
        at soot.Main.main(Main.java:147)
        at soot.tools.CFGViewer.main(CFGViewer.java:101)


Ouuups... something went wrong! Sorry about that.
Follow these steps to fix the problem:
1.) Are you sure you used the right command line?
    Click here to double-check:
    https://soot-build.cs.uni-paderborn.de/doc/sootoptions/

2.) Not sure whether it's a bug? Feel free to discuss
    the issue on the Soot mailing list:
    https://github.com/Sable/soot/wiki/Getting-help

3.) Sure it's a bug? Click this link to report it.
    https://github.com/Sable/soot/issues/new?title=soot.CompilationDeathException+when+...&body=Steps+to+reproduce%3A%0A1.%29+...%0A%0AFiles+used+to+reproduce%3A+%0A...%0A%0ASoot+version%3A+%3Cpre%3Etrunk%3C%2Fpre%3E%0A%0ACommand+line%3A%0A%3Cpre%3E--soot-classpath+.%3BD%3A%5Cisoot%5CJava%5Cjre1.8.0_221%5Clib%5Crt.jar+-p+jtp.printcfg+graph-type%3ABriefBlockGraph+A+-src-prec+java%3C%2Fpre%3E%0A%0AMax+Memory%3A%0A%3Cpre%3E1799MB%3C%2Fpre%3E%0A%0AStack+trace%3A%0A%3Cpre%3Esoot.CompilationDeathException%3A+there+were+errors+during+parsing+and%2For+type+checking+%28JastAdd+frontend%29%0D%0A%09at+soot.JastAddInitialResolver.formAst%28JastAddInitialResolver.java%3A63%29%0D%0A%09at+soot.JavaClassSource.resolve%28JavaClassSource.java%3A54%29%0D%0A%09at+soot.SootResolver.bringToHierarchyUnchecked%28SootResolver.java%3A235%29%0D%0A%09at+soot.SootResolver.bringToHierarchy%28SootResolver.java%3A208%29%0D%0A%09at+soot.SootResolver.bringToSignatures%28SootResolver.java%3A266%29%0D%0A%09at+soot.SootResolver.processResolveWorklist%28SootResolver.java%3A170%29%0D%0A%09at+soot.SootResolver.resolveClass%28SootResolver.java%3A133%29%0D%0A%09at+soot.Scene.loadClass%28Scene.java%3A853%29%0D%0A%09at+soot.Scene.loadClassAndSupport%28Scene.java%3A839%29%0D%0A%09at+soot.Scene.loadNecessaryClass%28Scene.java%3A1569%29%0D%0A%09at+soot.Scene.loadNecessaryClasses%28Scene.java%3A1582%29%0D%0A%09at+soot.Main.run%28Main.java%3A250%29%0D%0A%09at+soot.Main.main%28Main.java%3A147%29%0D%0A%09at+soot.tools.CFGViewer.main%28CFGViewer.java%3A101%29%0D%0A%3C%2Fpre%3E
    Please be as precise as possible when giving us
    information on how to reproduce the problem. Thanks!

I know that soot can generate control flow graphs from .class files, but soot has strict requirements on the java version, that is, it can only use the 1.7 version of jdk, otherwise it will easily report errors. This is a fatal shortcoming for me, because I have 100 java projects waiting to generate control flow graphs, and it is difficult to compile these projects with only 1.7 jdk.

I have found that some software for software testing can easily generate control flow graphs directly from source code, such as visutin. How does this kind of software generate control flow graphs? Is there any open source code?

visustin

0

There are 0 answers