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

sun.tools.debug.RemoteThread.getCurrentFrame() does not return correct result

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.4
    • 1.1.2
    • core-svc
    • None
    • 1.1.4
    • x86
    • windows_nt
    • Not verified



      Name: joT67522 Date: 08/26/97


      sun.tools.debug.RemoteThread.getCurrentFrame does not reliably
      return the correct stack frame information unless
      RemoteThread.dumpStack has been called.

      ----- TEST CASE:
      Run the following Java program, Mdbg:

      -------
      // Sample code to illustrate use of RemoteDebugger APIs
      // Author: Malcom Zung 1997

      import sun.tools.debug.*;
      import java.io.*;

      class Mdbg implements DebuggerCallback {

        // Data Members

        protected RemoteDebugger debugger_;
        protected RemoteThread currentThread_;
        private final String debuggeeName = "howdy";
        private final boolean consoleOutput = false;

        // Mdbg methods

        public Mdbg() {
        }

        protected synchronized void debug() {
          int i = 0;

          try {
            debugOutput("Creating new debugger...");
            debugger_ = new RemoteDebugger("", this, true);

            debugOutput("Looking up start class...");
            RemoteClass startClass = debugger_.findClass(debuggeeName);
            debugOutput("startClass = " + startClass);

            debugOutput("Looking up main method...");
            RemoteField mainMethod = startClass.getMethod("main");
            debugOutput("mainMethod = " + mainMethod);

            debugOutput("Set breakpoint in main method...");
            startClass.setBreakpointMethod(mainMethod);

            debugOutput("Go...");
            String[] parms = { debuggeeName, "parm1" };
            debugger_.run(1, parms);
            wait();
            printStackFrame(currentThread_);

            /*
            debugOutput("Getting threadgroups...");
            RemoteThreadGroup[] threadGroups = debugger_.listThreadGroups(null);
            for (i=0; i<threadGroups.length; ++i)
      debugOutput("threadGroups[" + i + "] = " + threadGroups[i]);
            */

            debugOutput("Stepping over...");
            currentThread_.next();
            wait();
            printStackFrame(currentThread_);
            printStackFrame(currentThread_);


            debugOutput("Closing debugger...");
            debugger_.close();
          }
          catch(Exception excp) {
            handleException(excp);
          }
        }

        static public void main(String[] args) {
          Mdbg mdb = new Mdbg();
          mdb.debug();
        }

        protected void printStackFrame(RemoteThread thd) {
          try {
            debugOutput("Thread = " + thd);
            RemoteStackFrame currentStackFrame = thd.getCurrentFrame();
            debugOutput("StackFrame (getCurrentFrame) = " + currentStackFrame);

            RemoteStackFrame[] currentStackFrame1 = thd.dumpStack();
            debugOutput("StackFrame (dumpStack) = " + currentStackFrame1[0]);
          }
          catch(Exception excp) {
            handleException(excp);
          }
        }

        protected void handleException(Exception excp) {
          System.out.println("*** Error: exception thrown." + excp);
          System.out.println(excp.getMessage());
          excp.printStackTrace();
          debugger_.close();
          System.exit(1);
        }

        protected void debugOutput(String msg) {
          System.out.println("Mdbg> " + msg);
        }

        // Debugger Callback methods

        public void printToConsole(String msg) {
          if (consoleOutput)
            System.out.println("Console> " + msg);
        }

        public synchronized void breakpointEvent(RemoteThread thd) {
          debugOutput("breakpointEvent() called.");
          currentThread_ = thd;
          notify();
        }

        public void exceptionEvent(RemoteThread thd, String err) {
          debugOutput("exceptionEvent() called.");
        }

        public void threadDeathEvent(RemoteThread thd) {
          debugOutput("threadDeathEvent() called.");
        }

        public void quitEvent() {
          debugOutput("quitEvent() called.");
        }
      }
      -------

      This program looks for a class called "howdy" to debug.
      I used the following program:

      ------
      class howdy
      {
        public static void
        main( String argv[] )
        {
          int i = 0;
          ++i;
          ++i;

          System.out.println( "Howdy there yall!" );
          System.out.println( "The value of i is: " + i );
          System.out.println( "I don't have anything more to say!" );
        }
      }

      --------

      When this is run, the following output is produced:

      D:\java\dbgtest>java Mdbg
      Mdbg> Creating new debugger...
      [debugger: starting child: D:\JDK1.1.2\BIN\..\bin\java_g -debug sun.tools.debug
      .EmptyApp]
      [debugger: password returned: 5kf6mb]
      Mdbg> Looking up start class...
      Mdbg> startClass = 0xf709a0:class(howdy)
      Mdbg> Looking up main method...
      Mdbg> mainMethod = ([Ljava/lang/String;)V main
      Mdbg> Set breakpoint in main method...
      Mdbg> Go...
      Mdbg> breakpointEvent() called.
      Mdbg> Thread = Thread[main,5,howdy.main]
      Mdbg> StackFrame (getCurrentFrame) = howdy.main (howdy:8)
      Mdbg> StackFrame (dumpStack) = howdy.main (howdy:8)
      Mdbg> Stepping over...
      Mdbg> breakpointEvent() called.
      Mdbg> Thread = Thread[main,5,howdy.main]
      Mdbg> StackFrame (getCurrentFrame) = howdy.main (howdy:8) ***
      Mdbg> StackFrame (dumpStack) = howdy.main (howdy:9)
      Mdbg> Thread = Thread[main,5,howdy.main]
      Mdbg> StackFrame (getCurrentFrame) = howdy.main (howdy:9)
      Mdbg> StackFrame (dumpStack) = howdy.main (howdy:9)
      Mdbg> Closing debugger...

      Notice that the line number information on the line marked with
      *** is not correct. getCurrentFrame does not return the correct
      information until after dumpStack has been called.

      company - IBM Canada , email - ###@###.###
      ======================================================================

            rfield Robert Field (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: