From bb2e47d6039ea3c3f7d282eb2d54cd1ef32efd5f Mon Sep 17 00:00:00 2001
From: kseitz <kseitz@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 24 Aug 2006 18:55:53 +0000
Subject: [PATCH]         * prims.cc (remoteDebug): New global.        
 (jdwpOptions): New global.         (parse_x_arg): Add processing for "X"
 options "debug" and         "runjdwp:"         (_Jv_RunMain): If debugging,
 start up JDWP backend.         Send VM_INIT and VM_DEATH when appropriate.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116383 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libjava/ChangeLog |  9 +++++++++
 libjava/prims.cc  | 50 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 7859422bdcd6..0a694de4a152 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-24  Keith Seitz  <keiths@redhat.com>
+
+	* prims.cc (remoteDebug): New global.
+	(jdwpOptions): New global.
+	(parse_x_arg): Add processing for "X" options "debug" and
+	"runjdwp:"
+	(_Jv_RunMain): If debugging, start up JDWP backend.
+	Send VM_INIT and VM_DEATH when appropriate.
+
 2006-08-23  Keith Seitz  <keiths@redhat.com>
 
 	* gnu/classpath/jdwp/VMVirtualMachine.java
diff --git a/libjava/prims.cc b/libjava/prims.cc
index c216c7f5e35c..33972f3bc7b8 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -64,6 +64,10 @@ details.  */
 #include <gnu/gcj/runtime/ExtensionClassLoader.h>
 #include <gnu/gcj/runtime/FinalizerThread.h>
 #include <execution.h>
+#include <gnu/classpath/jdwp/Jdwp.h>
+#include <gnu/classpath/jdwp/VMVirtualMachine.h>
+#include <gnu/classpath/jdwp/event/VmDeathEvent.h>
+#include <gnu/classpath/jdwp/event/VmInitEvent.h>
 #include <gnu/java/lang/MainThread.h>
 
 #ifdef USE_LTDL
@@ -98,6 +102,10 @@ property_pair *_Jv_Environment_Properties;
 const char **_Jv_argv;
 int _Jv_argc;
 
+// Debugging options
+static bool remoteDebug = false;
+static char *jdwpOptions = "";
+
 // Argument support.
 int
 _Jv_GetNbArgs (void)
@@ -1138,7 +1146,18 @@ parse_x_arg (char* option_string)
     }
   else if (! strcmp (option_string, "debug"))
     {
-      // FIXME: add JDWP/JVMDI support
+      remoteDebug = true;
+    }
+  else if (! strncmp (option_string, "runjdwp:", 8))
+    {
+      if (strlen (option_string) > 8)
+	  jdwpOptions = &option_string[8];
+      else
+	{
+	  fprintf (stderr,
+		   "libgcj: argument required for JDWP options");
+	  return -1;
+	}
     }
   else if (! strncmp (option_string, "bootclasspath:", 14))
     {
@@ -1519,6 +1538,26 @@ _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
       else
 	main_thread = new MainThread (JvNewStringUTF (name),
 				      arg_vec, is_jar);
+      _Jv_AttachCurrentThread (main_thread);
+
+      // Start JDWP
+      if (remoteDebug)
+	{
+	  using namespace gnu::classpath::jdwp;
+	  VMVirtualMachine::initialize ();
+	  Jdwp *jdwp = new Jdwp ();
+	  jdwp->setDaemon (true);
+	  jdwp->configure (JvNewStringLatin1 (jdwpOptions));
+	  jdwp->start ();
+
+	  // Wait for JDWP to initialize and start
+	  jdwp->join ();
+	}
+
+      // Send VmInit
+      gnu::classpath::jdwp::event::VmInitEvent *event;
+      event = new gnu::classpath::jdwp::event::VmInitEvent (main_thread);
+      gnu::classpath::jdwp::Jdwp::notify (event);
     }
   catch (java::lang::Throwable *t)
     {
@@ -1531,9 +1570,16 @@ _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
       ::exit (1);
     }
 
-  _Jv_AttachCurrentThread (main_thread);
   _Jv_ThreadRun (main_thread);
 
+  // Notify debugger of VM's death
+  if (gnu::classpath::jdwp::Jdwp::isDebugging)
+    {
+      using namespace gnu::classpath::jdwp;
+      event::VmDeathEvent *event = new event::VmDeathEvent ();
+      Jdwp::notify (event);
+    }
+
   // If we got here then something went wrong, as MainThread is not
   // supposed to terminate.
   ::exit (1);
-- 
GitLab