Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8337990

JDWP single stepping sometimes misses first bytecode of catch clause

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 24
    • core-svc

      My colleague Fabien Sanglard observed the following issue.

      The examples below show behaviour when setting a breakpoint at a line that throws an exception, and then executing a step. In the first example the debugging session steps to the line with the catch, as expected. In the second example debugging steps past the line with the catch and advances to the next line. The desired behaviour is for both cases to step to the line with the catch.

      In the first example the step is completed on line 5 (the catch line).

      ```
      $ cat Main5.java
      public class Main5 {
        public static void main(String[] args) {
          try {
            throw new RuntimeException();
          } catch (Exception e) {
            System.out.println();
          }
        }
      }
      ```

      ```
      $ java -fullversion
      openjdk full version "24-ea+9-972"
      $ javac Main5.java
      $ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 -cp . Main5 &
      $ jdb -attach 8000
      main[1] stop at Main5:4
      main[1] resume
      All threads resumed.
      > Set deferred breakpoint Main5:4

      Breakpoint hit: "thread=main", Main5.main(), line=4 bci=0
      4 throw new RuntimeException();

      main[1] next
      >
      Step completed: "thread=main", Main5.main(), line=5 bci=8
      5 } catch (Exception e) {
      ```

      In the second example the step is completed on Line 6. The catch line (5) was skipped.

      ```
      $ cat Main6.java
      public class Main6 {
        public static void main(String[] args) {
          try {
            throwRuntimeException();
          } catch (Exception e) {
            System.out.println();
          }
        }

        static void throwRuntimeException() {
          throw new RuntimeException();
        }
      }
      ```

      ```
      $ javac Main6.java
      $ java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 -cp . Main6 &
      $ jdb -attach 8000
      main[1] stop at Main6:4
      main[1] resume
      All threads resumed.
      > Set deferred breakpoint Main6:4

      Breakpoint hit: "thread=main", Main6.main(), line=4 bci=0
      4 throwRuntimeException();

      main[1] next
      >
      Step completed: "thread=main", Main6.main(), line=6 bci=7
      6 System.out.println();

      ```

            Unassigned Unassigned
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: