Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine whether .class file was compiled with debug info?

How can I determine for any Java .class file if that was compiled with debug info or not?

How can I tell exactly what -g{source|lines|vars} option was used?

like image 296
Atos Avatar asked Oct 02 '09 08:10

Atos


People also ask

How can I tell if a program was compiled with debug symbols?

To check if there's debug info inside the kernel object, you can add the following at the end of the objdump command: | grep debug . If this string is found, you know the kernel object contains debug information. If not, then it's a "clean" kernel object.

Are .class files compiled?

A Java class file is a compiled java file. It is compiled by the Java compiler into bytecode to be executed by the Java Virtual Machine.

How do I debug a .class file?

There are two ways to debug a class file. The first way is to set the decompiler preference, and to realign the line number. The second way is to check the debug mode in the decompiler menu bar. When your Eclipse workspace is in debug perspective, the debug mode becomes the default.

How do I view the contents of a .class file?

A simple way to see what String literals are used in a ". class" file is to use the javap utility in your JDK installation to dump the file using the "-v" option. Then grep for text that looks like <String "..."> where ... is the String you are looking for.


Video Answer


1 Answers

If you're on the command line, then javap -l will display LineNumberTable and LocalVariableTable if present:

peregrino:$ javac -d bin -g:none src/Relation.java  peregrino:$ javap -classpath bin -l Relation  public class Relation extends java.lang.Object{ public Relation();  peregrino:$ javac -d bin -g:lines src/Relation.java  peregrino:$ javap -classpath bin -l Relation  public class Relation extends java.lang.Object{ public Relation();   LineNumberTable:     line 1: 0    line 33: 4  peregrino:$ javac -d bin -g:vars src/Relation.java  peregrino:$ javap -classpath bin -l Relation  public class Relation extends java.lang.Object{ public Relation();    LocalVariableTable:     Start  Length  Slot  Name   Signature    0      5      0    this       LRelation; 

javap -c will display the source file if present at the start of the decompilation:

peregrino:$ javac -d bin -g:none src/Relation.java  peregrino:$ javap -classpath bin -l -c Relation | head public class Relation extends java.lang.Object{   ...  peregrino:$ javac -d bin -g:source src/Relation.java  peregrino:$ javap -classpath bin -l -c Relation | head Compiled from "Relation.java" public class Relation extends java.lang.Object{   ... 

Programmatically, I'd look at ASM rather than writing yet another bytecode reader.

like image 86
Pete Kirkham Avatar answered Oct 10 '22 22:10

Pete Kirkham