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

jdb does not always stop execution at next line with next command

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 1.1.2
    • 1.1.2
    • core-svc
    • b01
    • x86
    • windows_nt
    • Not verified

    Description


      The sun.tools.debug.RemoteThread.next method does not always stop
      execution of the thread at the next line of the method. This can be
      illustrated with jdb and the following
      program:

      public class BugDemo {
          static int NotAnInstanceVar;
          String StringField;
          static BugDemo BUGDEMO;
          public static void main(String argv[]) {
              int i;
              BugDemo bd, bugdemo;
              bd = new BugDemo("foo");
              BUGDEMO = bd;
              i = argv.length;
              if (i > 0)
                  System.out.println("I'm not expecting any trouble...");
              i *= 2;
              try {
                  i = 16/i;
              } catch(Exception e) {
                  System.out.println("That didn't work at all!");
              }
              System.exit(0);
          }
          public BugDemo(String s) {
              StringField = s;
          }
      }

      Start jdb on BugDemo and enter the following commands:

      load BugDemo
      stop in BugDemo.main
      run BugDemo
      next
      next
      next
      next

      The last next should step over line 11. The program runs to
      completion.

      Another similar situation with this sample:

      start jdb and enter the following:

      load BugDemo
      stop at BugDemo:15
      run BugDemo
      next

      The program takes an exception and completes. It should
      stop at the next line - which in this case is in the catch block.

      As we are a commercial licensee and have source, we have
      looked into this problem a bit further:

      The problem is due to the algorithm used in the method
      sun.tools.debug.Agent.stepNextThread(). In order to step over a line of
      code, a breakpoint is placed at the first instruction of the next source
      line. If there is some branching instruction that causes execution to
      avoid the next line, such as in an if clause or in the case of an
      exception, the program runs until it hits some other breakpoint or
      completes. In our sample, a goto instruction in line 11 and an exception
      in line 13 caused the flow of control to avoid the breakpoint.

      Attachments

        Issue Links

          Activity

            People

              rfield Robert Field (Inactive)
              mmma Marvin Ma (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: