|JDB (how to generate debug code) email@example.com (2004-09-21)|
|Re: JDB (how to generate debug code) firstname.lastname@example.org (A Pietu Pohjalainen) (2004-09-24)|
|From:||A Pietu Pohjalainen <email@example.com>|
|Date:||24 Sep 2004 00:22:25 -0400|
|Organization:||University of Helsinki|
|Posted-Date:||24 Sep 2004 00:22:25 EDT|
napi <firstname.lastname@example.org> wrote:
> Can anyone direct me to a doc/manual that describes how a compiler could
> generate debug code for the JDB (Java Debugger).
In the Java bytecode, generating debuggable versions of the class files
is done through the attribute mechanism: a classfile consists of some
administration data, such as magic identifier at the beginning
(0xCAFEBABE), minor and major versions of the class file format etc.
Then there are five tables, namely
- Constant pool
- Implemented interfaces
- Fields of the class
- Methods of the class
- Class level attributes
Fields-table and Methods-table can also contain attributes of their own,
I'll talk about them later.
Now, having sanely debuggable code takes part in (at least) three
places: the constant pool and Class-level attributes and attributes
of the Methods-table.
The class-level attributes are relevant to debuggability, as it contains
an attribute named 'SourceFile', which is used to recover the file that
this class was generated from. Most debuggers don't try to decompile the
bytecode to a higher-level form, but rely on the availability of the
Having your constants readable improves debuggability a lot. The
constant pool contains entries to the 'public' interface of the class:
class name, super class name, member variables, etc. An usual
obfuscation technique is to twist the public interface of the class to a
unreadable form. When debugging, it is advisable to have these in their
Then, the Method table contains all the methods defined in the class. It
has two pre-defined attributes: Exceptions and Code. Exceptions contains
all the exception handlers in the method and Code contains the actual
bytecode of the method.
Now, Code contains yet another attributes: LineNumberTable and
LocalVariableTable. These are used to map bytecode ranges to lines in
the original source file and to give meaningful names to local variables
in the method, respectively.
A more thorough document can be found at almost any book that discusses
the Java VM; I used the one published by O'Reilly; 'Java Virtual Machine'
by Jon Meyer & Trow Downing, 1997. Other books on this topic (that I'm
aware of) include 'Inside the Java Virtual Machine' by Bill Venners and
'Programming for the Java(TM) Virtual Machine' by Joshua Engel. I
believe that any of these will do good enough.
Of course, the most accessible text is 'The Structure of the Java
Virtual Machine' by Tim Lindholm and Frank Yellin; It is also available
Return to the
Search the comp.compilers archives again.