Aug 03

You know how you’re debugging, and you reach a method call that looks like methodCall(anotherMethod()) and you want to step over the call to anotherMethod but step into the call to methodCall? That’s where column-level debugger information could come handy.

And there are other cases as well:

  • Chained boolean evaluations: Imagine being able to tell which boolean evaluation is taking place now in the next code: if ((a.equals(b) || b.size() > 5) && a.size() != 0). Most of us just have to press F8 (or whatever key we use for “next step”) and determine later why the boolean failed or succeeded.
  • Conditional assignments: Being able to separating the steps in the ?: operator, such as a = condition ? b : c. Again, most of the time it’s just stepping through the condition and checking what was assigned to a.
  • As mentioned before, for loops (both classic or foreach style).

This doesn’t only help for separating the steps in a debugging session: Imagine being able to set a breakpoint on the second condition on a for loop, so for the following code: for (int i = 0; i < arr.size() && i < n; i++) the breakpoint would occur only when i is bigger than arr.size(), and not (as it is today) whenever the code reaches any of the three parts of the statement definition.

Another great benefit is code coverage, where tools today cannot tell whether an if statement was reached through all possible conditions – Information which could be of great help when analysing code through code coverage utilities.

And the change to make this work? Well, it requires modification to the JVM, I can tell you that. But it can be deemed as an optional change. The current specification of LineNumberTable specifies that a Code attribute of a method, which is used by debuggers to determine which line in the source code is attached to which part of bytecode sequence. What is needed is an extension to the LineNumberTable structure to include the column-start and column-end of the code at that line. For example, the structure might become like the following (changes from origin are bolded):


    NewLineNumberTable_attribute {
    	u2 attribute_name_index;
    	u4 attribute_length;
    	u2 line_number_table_length;
    	{  u2 start_pc;
    	   u2 line_number;
    	   u2 col_start;	     
    	   u2 col_end;	     
    	} line_number_table[line_number_table_length];
    }
Related Posts with Thumbnails
Share

One Response to “Column Debug Information”

  1. Alex Says:

    You are absolutely right and it’s a lack in the JVM spec which really hurts if you are in the bytecode business. The smallest atomic (source code) instruction does not always (actually most often ) have to be complete source code line. Wonder who came up with that (insane) idea. I’d like to see an enhancement to the JVM spec as soon as possible. Have not yet looked into existing JSRs but I guess it’s not included :(