允许轻松打印字节码指令*包括*参数的库
我正在寻找一个库,它可以轻松地让我查看方法的给定字节码。示例:
ALOAD 0
INVOKEVIRTUAL ns/c.m ()I
IRETURN
我已经尝试了两种方法:
- ASM :我实际上可以让它打印指令和参数,但是我很难理解它的整个访问者范例,也就是说,我所做的最好的就是漂亮地打印一个全班。
- BCEL:可以让它打印指令,但没有参数。
- JavaAssist:可以让它打印指令,但没有参数。
I am looking for a library that will easily allow me to see a method's given bytecode. Example:
ALOAD 0
INVOKEVIRTUAL ns/c.m ()I
IRETURN
I've tried both:
- ASM : I could actually get it to print instructions plus parameters, but I'm having difficulties wrapping my head around its whole visitors paradigm, that is to say, the best I did was to pretty print a whole class.
- BCEL : Could get it to print the instructions, but no parameters.
- JavaAssist : Could get it to print the instructions, but no parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 ASM 源代码
TraceClassVisitor
和TraceMethodVisitor
查看打印字节码详细信息的示例。这是一个简单的测试类:
输出(当作为参数传递
Main.class
时):Take a look at the ASM source for
TraceClassVisitor
andTraceMethodVisitor
for an example of printing bytecode details.Here's a simple test class:
Which outputs (when passed
Main.class
as an argument):其中,ASM 是唯一支持最新 Java 版本的。对于访问者,您可能需要阅读本教程。它是为旧版本的 ASM API 编写的,但访问者概念仍然相同。
Out of those, ASM is the only one supporting the latest Java version. In regards to visitors, you may want to read this tutorial. It been written for an older version of ASM API, but visitor concepts are still the same.