Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can javac supply a class' "source debug extension information" attribute?

A Java class file format supports an attribute called "source debug extension" (see Java language specification §4.7.11 "TheSourceDebugExtension attribute").

In JVMs that support this aspect of JVMTI, you can query for this string using jvmtiError GetSourceDebugExtension(jvmtiEnv *, jclass, char **).

My question is whether there's a way to use ordinary javac and the Java language to embed "source debug extension" information in a .class file. There doesn't appear to be an annotation in the core Java language that would do this (no obvious candidates in the "All Known Implementing Classes" list in the javadoc for java.lang.Annotation).

like image 464
0xbe5077ed Avatar asked Aug 26 '14 23:08

0xbe5077ed


1 Answers

That attribute was added by JSR 45 to support debugging in non-Java languages. The JVM itself doesn't use the value of the attribute; it's meant for debugging tools. The final release of that JSR describes the motivation for the SourceDebugExtension attribute as follows:

SourceDebugExtension Support

Debugger applications frequently need debugging information about the source that exceeds what is delivered by the existing JavaTM Virtual Machine class file attributes (SourceFile, LineNumber, and LocalVariable). This is particularly true for debugging the source of other languages. In a distributed environment side files may not be accessible, the information must be directly associated with the class.

The solution is the addition of a class file attribute which holds a string; The string contains debugging information in a standardized format which allows for evolution and vendor extension.

Given that purpose, it's unlikely that javac would put anything in to that field. There is another StackOverflow question asking what JVM languages use the SMAP attribute.

like image 163
Esko Luontola Avatar answered Oct 13 '22 01:10

Esko Luontola