javap可以显示与字节码混合的原始源代码行,如objdump -S吗? [英] Can javap show the original source code lines intermingled with the bytecode like objdump -S?

查看:342
本文介绍了javap可以显示与字节码混合的原始源代码行,如objdump -S吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在使用以下代码编译
时,此.class文件中包含此调试信息:

I know this debug information is contained in the .class file when compiling with:

javac -g Main.java

并且可以从 LineNumberTable手动观察:部分:

javap -c -constants -private -verbose '$<' > '$@'

我想要的是制作 javap 在字节码的中间显示源。

What I want is to make javap display the source in the middle of the bytecode.

示例输入:

public class New {
    public static void main(String[] args) {
        System.out.println(new Integer(1));
    }
}

实际 javap 输出:

   0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
   3: new           #3                  // class java/lang/Integer
   6: dup
   7: iconst_1
   8: invokespecial #4                  // Method java/lang/Integer."<init>":(I)V
  11: invokevirtual #5                  // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
  14: return
LineNumberTable:
  line 3: 0
  line 4: 14

所需的javap输出:

Desired javap output:

       System.out.println(new Integer(1));
   0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
   3: new           #3                  // class java/lang/Integer
   6: dup
   7: iconst_1
   8: invokespecial #4                  // Method java/lang/Integer."<init>":(I)V
  11: invokevirtual #5                  // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
    }
  14: return
LineNumberTable:
  line 3: 0
  line 4: 14

这样可以更容易地解释 javap 输出。

That would make it much easier to interpret javap output.

类似但更通用的问题:如何使用javap来查看字节码的哪些行对应于Java代码中的行?

Similar but more generic question: How to use javap to see what lines of bytecode correspond to lines in the Java code?

我试过:

  • create a feature request at: http://bugreport.java.com/submit_intro.do
  • send an email to the mailing list: jdk9-dev@openjdk.java.net

但没有回复,我的消息甚至没有出现在这些网站上。不是一个非常开放的项目。

but there was no reply, and my messages don't even appear on those websites. Not a very open project.

推荐答案

我不认为 javap 支持这个用例,但是过去几天我一直在使用一些类文件解析代码,到目前为止,它能够将源代码与汇编代码混合在一起。有关详细信息和源代码,请参见 https://github.com/gagern/classfile

I don't think javap supports this use case, but I've been toying with some class file parsing code these past few days, and as of today it's capable of mixing source code with assembly code. See https://github.com/gagern/classfile for details and source code.

这篇关于javap可以显示与字节码混合的原始源代码行,如objdump -S吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆