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

1

7

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).

Eddo answered 26/8, 2014 at 23:44 Comment(3)
I'm not sure how this is used in practice, but is this the information provided by -g:source?Longhand
@chrylis, I don't believe so. Looking at the javac manpage where it describes the -g option, I think that just embeds the source file name. That seems to be what happened when I ran a test using $ javac -g:source Test.java && javap -v Test.class.Eddo
I don't know what information is supposed to be in that SourceDebugExtension, though, and I thought that might have been it.Longhand
B
2

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.

Blintz answered 28/12, 2017 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.