문제

I am manipulating a .class file. I am using the InstrutionHandle package to get the instructions one at a time. I have the byte offset of the instruction via getPosition() method , can i get the source line number from the byte offset?

도움이 되었습니까?

해결책

That depends on whether the classfile is compiled with debugging information. Usually, the compiler will insert a LineNumberTable attribute which gives the original source line numbers corresponding to each range of bytecode. However, the LineNumberTable attribute is just metadata, so the author could put anything they want in there with minor constraints or just omit it entirely. (Typically done by compiling with -g: none or by running an obfuscator on it)

Anyway, the format of the attribute is number of entires (2 bytes) followed by (start pc, line number) pairs (both 2 bytes). You can also have multiple LineNumberTable attributes. Of course if you're using a library, it will probably decode these for you already.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top