Code Comments
Programming Forum and web based access to our favorite programming groups.Hi: Can anyone direct me to a doc/manual that describes how a compiler could generate debug code for the JDB (Java Debugger). Thanks. Napi
Post Follow-up to this messagenapi <napi@axiomsol.com> 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 source file. 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 unobfuscated form. 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 via web. br, Pietu Pohjalainen
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.