This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] JDWP implement VMVM::getFrame


Hi,

The GNU Classpath changes for this patch have now gone in (see cp-commits as of this morning), this is part 2 of 3 of the large patch from before.

This patch implements the JDWP method getFrame from
natVMVirtualMachine.cc. This method calls jvmti-GetStackTrace to get info about 1 particular frame, then creates a new VMFrame and returns it. This was changed to now take a jlong, which saves having to pack a ByteBuffer to use this method from getFrames. VMFrame has also been augmented since it was intentionally left unfinshed until the specifics of stack tracing were determined.


Changelog

2007-02-02 Kyle Galloway <kgallowa@redhat.com>

    * classpath/gnu/classpath/jdwp/processor/
    StackFrameCommandSet.java (executeGetValues): Pass jlong instead
    of ByteBuffer.
    (executeSetValues): Ditto.
    (executeThisObject): Ditto.
    * classpath/gnu/classpath/jdwp/processor/
    StackFrameCommandSet.class: Rebuilt.
    * classpath/lib/gnu/classpath/jdwp/VMVirtualMachine.class:
    Rebuilt.
    * classpath/lib/gnu/classpath/jdwp/VMFrame.class: Rebuilt.
    * classpath/lib/gnu/classpath/jdwp/exception/
    InvalidFrameException.java: New file.
    * gnu/classpath/jdwp/VMFrame.java: Added field for thread of
    frame.
    (Constructor): New method.
    * gnu/classpath/jdwp/VMFrame.h: Regenerated.
    * gnu/classpath/jdwp/VMVirtualMachine.java
    (getFrame): Changed ByteBuffer to jlong.
    * gnu/classpath/jdwp/natVMVirtualMachine.cc
    (getFrame): Implment.
    * gnu/classpath/jdwp/VMVirtualMachine.h: Regenerated.


Comments?


- Kyle


Index: libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java
===================================================================
--- libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java	(revision 121296)
+++ libjava/classpath/gnu/classpath/jdwp/processor/StackFrameCommandSet.java	(working copy)
@@ -1,5 +1,5 @@
 /* StackFrameCommandSet.java -- class to implement the StackFrame Command Set
-   Copyright (C) 2005 Free Software Foundation
+   Copyright (C) 2005, 2007 Free Software Foundation
  
 This file is part of GNU Classpath.
 
@@ -107,7 +107,8 @@
     // has a reference to them. Furthermore they are not ReferenceTypeIds since
     // these are held permanently and we want these to be held only as long as
     // the Thread is suspended.
-    VMFrame frame = VMVirtualMachine.getFrame(thread, bb);
+    long frameID = bb.getLong();
+    VMFrame frame = VMVirtualMachine.getFrame(thread, frameID);
     int slots = bb.getInt();
     os.writeInt(slots); // Looks pointless but this is the protocol
     for (int i = 0; i < slots; i++)
@@ -125,7 +126,8 @@
     ObjectId tId = idMan.readObjectId(bb);
     Thread thread = (Thread) tId.getObject();
 
-    VMFrame frame = VMVirtualMachine.getFrame(thread, bb);
+    long frameID = bb.getLong();
+    VMFrame frame = VMVirtualMachine.getFrame(thread, frameID);
 
     int slots = bb.getInt();
     for (int i = 0; i < slots; i++)
@@ -142,7 +144,8 @@
     ObjectId tId = idMan.readObjectId(bb);
     Thread thread = (Thread) tId.getObject();
 
-    VMFrame frame = VMVirtualMachine.getFrame(thread, bb);
+    long frameID = bb.getLong();
+    VMFrame frame = VMVirtualMachine.getFrame(thread, frameID);
 
     Object thisObject = frame.getObject();
     Value.writeTaggedValue(os, thisObject);
Index: libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java
===================================================================
--- libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java	(revision 0)
+++ libjava/classpath/gnu/classpath/jdwp/exception/InvalidFrameException.java	(revision 0)
@@ -0,0 +1,63 @@
+/* InvalidFrameException.java -- invalid jframeid
+   Copyright (C) 2007 Free Software Foundation
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.jdwp.exception;
+
+import gnu.classpath.jdwp.JdwpConstants;
+
+/**
+ * An exception thrown when the debugger requests an invalid frame in the call
+ * stack.
+ *
+ * @author Kyle Galloway  (kgallowa@redhat.com)
+ */
+public class InvalidFrameException
+  extends JdwpException
+{
+  public InvalidFrameException(long id)
+  {
+    super(JdwpConstants.Error.INVALID_FRAMEID, 
+		  "invalid frame id (" + id + ")");
+  }
+
+  public InvalidFrameException(String msg)
+  {
+    super(JdwpConstants.Error.INVALID_FRAMEID, msg);
+  }
+}
Index: libjava/gnu/classpath/jdwp/VMFrame.java
===================================================================
--- libjava/gnu/classpath/jdwp/VMFrame.java	(revision 121464)
+++ libjava/gnu/classpath/jdwp/VMFrame.java	(working copy)
@@ -1,5 +1,5 @@
 /* VMFrame.java -- Reference implementation of VM hooks for JDWP Frame access.
-   Copyright (C) 2005, 2006 Free Software Foundation
+   Copyright (C) 2005, 2006, 2007 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -54,7 +54,10 @@
    */
   public static final int SIZE = 8;
 
-  // The object this frame resides in
+  // The thread this frame resides in
+  private Thread thread;
+   
+  //The object of this frame
   private Object obj;
   
   // The current location of this frame
@@ -64,6 +67,20 @@
   private long id;
   
   /**
+   * Create a new VMFrame object.
+   * 
+   * @param thr a Thread, the thread this frame is in
+   * @param frame_id a long, the jframeID of this frame
+   * @param frame_loc a Location, the location of this frame
+   */
+  public VMFrame(Thread thr, long frame_id, Location frame_loc)
+  {
+    thread = thr;
+    id = frame_id;
+    loc = frame_loc;
+  }
+  
+  /**
    * Gets the current location of the frame.
    */
   public Location getLocation()
@@ -84,6 +101,14 @@
    * @param value The value to assign the variable to
    */
   public native void setValue(int slot, Object value);
+  
+  /**
+   * Get the thread this frame is in.
+   */
+  public Thread getThread()
+  {
+    return thread;
+  }
 
   /**
    * Get the object which is represented by 'this' in the context of the frame,
Index: libjava/gnu/classpath/jdwp/VMVirtualMachine.java
===================================================================
--- libjava/gnu/classpath/jdwp/VMVirtualMachine.java	(revision 121464)
+++ libjava/gnu/classpath/jdwp/VMVirtualMachine.java	(working copy)
@@ -1,7 +1,7 @@
 /* VMVirtualMachine.java -- A reference implementation of a JDWP virtual
    machine
 
-   Copyright (C) 2005, 2006 Free Software Foundation
+   Copyright (C) 2005, 2006, 2007 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -243,7 +243,7 @@
    * @param  bb      buffer containing the frame's ID
    * @return the desired frame
    */
-  public static native VMFrame getFrame (Thread thread, ByteBuffer bb)
+  public static native VMFrame getFrame (Thread thread, long frameID)
     throws JdwpException;
 
   /**
Index: libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc
===================================================================
--- libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc	(revision 121504)
+++ libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc	(working copy)
@@ -13,6 +13,8 @@
 #include <jvm.h>
 #include <jvmti.h>
 
+#include <java-interp.h>
+
 #include <java/lang/Class.h>
 #include <java/lang/ClassLoader.h>
 #include <java/lang/Integer.h>
@@ -20,6 +22,7 @@
 #include <java/lang/StringBuilder.h>
 #include <java/lang/Thread.h>
 #include <java/nio/ByteBuffer.h>
+#include <java/nio/ByteBufferImpl.h>
 #include <java/util/ArrayList.h>
 #include <java/util/Hashtable.h>
 #include <java/util/Iterator.h>
@@ -34,8 +37,10 @@
 #include <gnu/classpath/jdwp/event/ThreadStartEvent.h>
 #include <gnu/classpath/jdwp/event/VmDeathEvent.h>
 #include <gnu/classpath/jdwp/event/VmInitEvent.h>
+#include <gnu/classpath/jdwp/exception/InvalidFrameException.h>
 #include <gnu/classpath/jdwp/exception/InvalidMethodException.h>
 #include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h>
+#include <gnu/classpath/jdwp/util/Location.h>
 #include <gnu/classpath/jdwp/util/MethodResult.h>
 
 using namespace java::lang;
@@ -360,9 +365,50 @@
 
 gnu::classpath::jdwp::VMFrame *
 gnu::classpath::jdwp::VMVirtualMachine::
-getFrame (MAYBE_UNUSED Thread *thread, MAYBE_UNUSED::java::nio::ByteBuffer *bb)
+getFrame (Thread *thread, jlong frameID)
 {
-  return NULL;
+  using namespace gnu::classpath::jdwp::exception;
+  
+  _Jv_Frame *vm_frame = (_Jv_Frame *) thread->frame;
+  jint depth = 0;
+  _Jv_Frame *frame = reinterpret_cast<_Jv_Frame *> (frameID); 
+  
+  // We need to find the stack depth of the frame, so search through the call
+  // stack to find it.  This also checks for a valid frameID.
+  while (vm_frame != frame)
+    {
+      vm_frame = vm_frame->next;
+      depth++;
+      if (vm_frame == NULL)
+        throw new InvalidFrameException (frameID);
+    }
+  
+  Location *loc = NULL;
+  jvmtiFrameInfo info;
+  jvmtiError jerr;
+  jint num_frames;
+  jclass klass;
+  
+  // Get the info for the frame of interest
+  jerr = _jdwp_jvmtiEnv->GetStackTrace (thread, depth, 1, &info, &num_frames);
+   
+  if (jerr != JVMTI_ERROR_NONE)
+    throw_jvmti_error (jerr);
+  
+  jerr = _jdwp_jvmtiEnv->GetMethodDeclaringClass (info.method, &klass);
+      
+  if (jerr != JVMTI_ERROR_NONE)
+    throw_jvmti_error (jerr);
+
+  VMMethod *meth 
+    = getClassMethod (klass, reinterpret_cast<jlong> (info.method));
+  
+  if (info.location == -1)
+    loc = new Location (meth, 0);
+  else
+    loc = new Location (meth, static_cast<jlong> (info.location));
+  
+  return new VMFrame (thread, reinterpret_cast<jlong> (vm_frame), loc); 
 }
 
 jint

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]