我想使用烟尘创建一个调用图,它可以将lambda实体标识为可到达。
更准确地说,我想为下面的示例绘制调用图。
public class TestLambda3 {
public static void main(String[] args) {
method1();
}
public static void method1() {
List<TestLambda3> list = Arrays.asList(new TestLambda3(), new TestLambda3());
list.stream().forEach(x -> x.foo());
}
public void foo() {
bar();
}
public void bar() {
System.out.println("hi1");
}
}
在这里,我期望调用图将包含来自的路径 main
一直到 foo
然后 bar
,与 lambda
中间调用。我不知道为什么没有这条路。我可以想象这是因为 accept
方法,但我不想分析整个java.util,有没有简单的方法可以在不分析jdk的情况下处理这个问题?
我的烟灰配置是
G.reset();
Options options = Options.v();
options.set_whole_program(true);
options.set_verbose(true);
options.setPhaseOption("jb", "use-original-names:true");
options.set_keep_line_number(true);
options.setPhaseOption("cg.cha", "enabled:true");
options.set_allow_phantom_refs(true);
options.set_no_bodies_for_excluded(true);
options.set_soot_classpath(String.join(":", Arrays.asList(Objects.requireNonNull(config.getTargetJar()))));
options.set_process_dir(Arrays.asList(config.getTargetJar()));
options.set_prepend_classpath(true);
Scene.v().loadNecessaryClasses();
SootClass c = Scene.v().forceResolve("TestLambda3",SootClass.BODIES);
c.setApplicationClass();
SootMethod method = c.getMethod("void main(java.lang.String[])");
List entryPoints = new ArrayList();
entryPoints.add(method);
Scene.v().setEntryPoints(entryPoints);
PackManager.v().getPack("wjpp").apply();
PackManager.v().getPack("cg").apply();
生成的调用图是:
STATIC edge: staticinvoke <TestLambda3: void method1()>() in <TestLambda3: void main(java.lang.String[])> ==> <TestLambda3: void method1()>
CLINIT edge: list = staticinvoke <java.util.Arrays: java.util.List asList(java.lang.Object[])>($stack1) in <TestLambda3: void method1()> ==> <java.util.Arrays: void <clinit>()>
STATIC edge: $stack8 = staticinvoke <TestLambda3$lambda_method1_0__1: java.util.function.Consumer bootstrap$()>() in <TestLambda3: void method1()> ==> <TestLambda3$lambda_method1_0__1: java.util.function.Consumer bootstrap$()>
STATIC edge: list = staticinvoke <java.util.Arrays: java.util.List asList(java.lang.Object[])>($stack1) in <TestLambda3: void method1()> ==> <java.util.Arrays: java.util.List asList(java.lang.Object[])>
CLINIT edge: list = staticinvoke <java.util.Arrays: java.util.List asList(java.lang.Object[])>($stack1) in <TestLambda3: void method1()> ==> <java.lang.Object: void <clinit>()>
CLINIT edge: staticinvoke <java.lang.Object: void registerNatives()>() in <java.lang.Object: void <clinit>()> ==> <java.lang.Object: void <clinit>()>
STATIC edge: staticinvoke <java.lang.Object: void registerNatives()>() in <java.lang.Object: void <clinit>()> ==> <java.lang.Object: void registerNatives()>
SPECIAL edge: specialinvoke $stack2.<TestLambda3: void <init>()>() in <TestLambda3: void method1()> ==> <TestLambda3: void <init>()>
SPECIAL edge: specialinvoke $stack4.<TestLambda3: void <init>()>() in <TestLambda3: void method1()> ==> <TestLambda3: void <init>()>
SPECIAL edge: specialinvoke $r0.<TestLambda3$lambda_method1_0__1: void <init>()>() in <TestLambda3$lambda_method1_0__1: java.util.function.Consumer bootstrap$()> ==> <TestLambda3$lambda_method1_0__1: void <init>()>
SPECIAL edge: specialinvoke this.<java.lang.Object: void <init>()>() in <TestLambda3: void <init>()> ==> <java.lang.Object: void <init>()>
FINALIZE edge: null in <java.lang.Object: void <init>()> ==> <java.lang.Object: void finalize()>
SPECIAL edge: specialinvoke $r0.<java.lang.Object: void <init>()>() in <TestLambda3$lambda_method1_0__1: void <init>()> ==> <java.lang.Object: void <init>()>
有没有关于如何解决这个问题的建议?谢谢
暂无答案!
目前还没有任何答案,快来回答吧!