When does the JVM skip line information in a stack trace and how can I prevent it?

I have a very confusing situation:

I have a class that is compiled with string information (verified with javap -l ). This class is loaded and managed by ASM. I checked that the correct class was loaded (i.e. not an obsolete class file from another place). And I also made sure that the ASM ClassReader.SKIP_DEBUG flag is not set. Now, if I call Thread.currentThread().getStackTrace() , I get a StackTraceElement relative to this class, which skips row information. When debugging in Eclipse, line information is displayed in the stack trace. I also made sure that the JVM starts with -Xint to make sure that the information is not deleted as an optimization when compiling the JIT code.

And the most confusing: although all classes are loaded and processed the same way, this is true only for some classes, and not for all. This is the main reason why I think this has something to do with the JVM.

So my question is: Does the JVM indicate line information in the stack trace, if so, when and how can I prevent this?

Edit: Just to make everything clear: this is the class file of the source file that I have in front of me, and not a third-party library. And, as it should be clear, I tried to make sure that the information is in the bytecode.

Edit: Now I even found an example where one StackTraceElement contains information about the line number and the other does not, and they are associated with various methods from the same class >!

+4
source share
3 answers

I am wondering if the lines that were reported (or not somehow) in your stack trace were generated when ASM evaluated your classes. Since they were changed after compilation, any line numbers will not be displayed in the class file, therefore they will not be available to the class loader (or will be available for javap report). I don't have much experience generating code at runtime, so this is just a hunch, but perhaps this is what you might think.

+1
source

This is due to how the class file was compiled. Take a look here:

http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html

and find the "debugging information" around the -g flag. If you add -g, your code will contain line numbers (and a lot of other useful information).

This will not retroactively add debugging information to third-party libraries, I'm afraid. You will need to see how to get the source, or get debug builds from the supplier. I found that this is usually not necessary.

+1
source

Not all line numbers are available in the JVM. Some third-party libraries can be compiled without line numbers, in particular non-open-source, and even some Java classes protect source code that performs encryption or some other secure logic. In short, not everyone will always have line numbers.

0
source

Source: https://habr.com/ru/post/1432813/


All Articles