takashi-ishio / selogger

(Near-)omniscient debugging/tracing/logging tool for Java
Other
35 stars 8 forks source link

Incorrect Label recorded? #10

Closed takashi-ishio closed 3 years ago

takashi-ishio commented 3 years ago
int answer;
public void divided(int x) {
  if (x == 0) {
    return;
  }
  answer /= x;
}

weave=LABEL mode records a LABEL event inside the IF-THEN block even if the IF-THEN block is skipped by x!=0.

takashi-ishio commented 3 years ago

This problem is caused by incorrect handling of labels.

if (x == 0) {
    return;
}

is compiled to like this:

  4: (L00004)
  5: (line=6)
  6: ILOAD 1 (x)
  7: IFNE L00011
  8: (L00008)
  9: (line=7)
  10: RETURN
  11: (L00011)
  12: (line=9)

As we can see, a LABEL node is placed before LINE number attribute. The bytecode internally records "line=9" is active from the label L00011.
However, selogger simply uses "line=7" as a line number for L00011. As a result, if a user watches only LABEL events, the execution trace incorrectly reports L00011 at line 7 is executed even if the trace skipped the RETURN instruction.

takashi-ishio commented 3 years ago

The updated version now correctly links L00011 to line 9.
The first LABEL at the beginning of a method also now has a correct line number (the first line of the method).