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

问题描述

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

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

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.

类似但更通用的问题:

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

我试过:


  • 在以下位置创建功能请求:

  • 发送电子邮件至邮件列表: [email protected]

  • create a feature request at: http://bugreport.java.com/submit_intro.do
  • send an email to the mailing list: [email protected]

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

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

推荐答案

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

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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 10:29