本文来自 Adding profiling instructions to applications with Soot ,描述了如何实现用 goto 指令的计数器来 annotates JimpleBody 的BodyTransformer。
文中的例子来自 ashes,代码位于 ashes.examples.countgotos 包中。也可 http://www.sable.mcgill.ca/soot/tutorial/profiler/Main.java 下载代码。
目标
具体的会完成下述工作:
- 根据方法的 signature 从 Scene 中将其检索。
- 为类添加 field
- 区分不同类型的 Jimple statement
- 在确定的位置插入 Jimple 指令
本例示范了如何打印出应用中 goto 指令的运行次数。
创建 GotoInstrumenter
- 在 main class 中添加一个 static field :gotoCount
- 在每个 goto 指令之前,增加 gotoCount的值
- 在main方法的每个 return 指令前添加打印 gotoCount 的语句
- 在每个 System.exit() 调用点之前打