我知道这个调试信息在编译时包含在.class文件中:
javac -g Main.java
Run Code Online (Sandbox Code Playgroud)
并且可以从以下LineNumberTable:部分手动观察:
javap -c -constants -private -verbose '$<' > '$@'
Run Code Online (Sandbox Code Playgroud)
我想要的是javap在字节码的中间显示源.
样本输入:
public class New {
public static void main(String[] args) {
System.out.println(new Integer(1));
}
}
Run Code Online (Sandbox Code Playgroud)
实际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
Run Code Online (Sandbox Code Playgroud)
期望的javap输出:
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
Run Code Online (Sandbox Code Playgroud)
这样可以更容易地解释javap输出.
类似但更通用的问题:如何使用javap查看字节码的哪些行对应于Java代码中的行?
我试过:
jdk9-dev@openjdk.java.net但没有回复,我的消息甚至没有出现在这些网站上.不是一个非常开放的项目.
我不认为javap支持这个用例,但过去几天我一直在研究一些类文件解析代码,截至今天它能够将源代码与汇编代码混合。有关详细信息和源代码,请参阅https://github.com/gagern/classfile 。
| 归档时间: |
|
| 查看次数: |
760 次 |
| 最近记录: |