From c83167c404730d8f9b2a6b9963800ff9e3e62baf Mon Sep 17 00:00:00 2001
From: kseitz <kseitz@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 2 Nov 2006 16:59:04 +0000
Subject: [PATCH]         * jvmti.cc (_Jv_JVMTI_GetLineNumberTable): New
 function.         (_Jv_JVMTI_Interface): Define GetLineNumberTable.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118419 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libjava/ChangeLog |  5 +++++
 libjava/jvmti.cc  | 50 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 8c3d985097a2..e8348a0a9095 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,8 @@
+2006-11-02  Keith Seitz  <keiths@redhat.com>
+
+	* jvmti.cc (_Jv_JVMTI_GetLineNumberTable): New function.
+	(_Jv_JVMTI_Interface): Define GetLineNumberTable.
+
 2006-11-01  Keith Seitz  <keiths@redhat.com>
 
 	* gnu/gcj/jvmti/Location.java: New file.
diff --git a/libjava/jvmti.cc b/libjava/jvmti.cc
index 5569551c2a30..8584c333d6d1 100644
--- a/libjava/jvmti.cc
+++ b/libjava/jvmti.cc
@@ -506,6 +506,54 @@ _Jv_JVMTI_GetMethodModifiers (MAYBE_UNUSED jvmtiEnv *env, jmethodID method,
   return JVMTI_ERROR_NONE;
 }
 
+static jvmtiError JNICALL
+_Jv_JVMTI_GetLineNumberTable (jvmtiEnv *env, jmethodID method,
+			      jint *entry_count_ptr,
+			      jvmtiLineNumberEntry **table_ptr)
+{
+  NULL_CHECK (entry_count_ptr);
+  NULL_CHECK (table_ptr);
+
+  jclass klass;
+  jvmtiError jerr = env->GetMethodDeclaringClass (method, &klass);
+  if (jerr != JVMTI_ERROR_NONE)
+    return jerr;
+
+  _Jv_MethodBase *base = _Jv_FindInterpreterMethod (klass, method);
+  if (base == NULL)
+    return JVMTI_ERROR_INVALID_METHODID;
+
+  if (java::lang::reflect::Modifier::isNative (method->accflags)
+      || !_Jv_IsInterpretedClass (klass))
+    return JVMTI_ERROR_NATIVE_METHOD;
+
+  _Jv_InterpMethod *imeth = reinterpret_cast<_Jv_InterpMethod *> (base);
+  jlong start, end;
+  jintArray lines = NULL;
+  jlongArray indices = NULL;
+  imeth->get_line_table (start, end, lines, indices);
+  if (lines == NULL)
+    return JVMTI_ERROR_ABSENT_INFORMATION;
+
+  jvmtiLineNumberEntry *table;
+  jsize len = lines->length * sizeof (jvmtiLineNumberEntry);
+  table = (jvmtiLineNumberEntry *) _Jv_MallocUnchecked (len);
+  if (table == NULL)
+    return JVMTI_ERROR_OUT_OF_MEMORY;
+  
+  jint *line = elements (lines);
+  jlong *index = elements (indices);
+  for (int i = 0; i < lines->length; ++i)
+    {
+      table[i].start_location = index[i];
+      table[i].line_number = line[i];
+    }
+
+  *table_ptr = table;
+  *entry_count_ptr = lines->length;
+  return JVMTI_ERROR_NONE;
+}
+
 static jvmtiError JNICALL
 _Jv_JVMTI_IsMethodNative (MAYBE_UNUSED jvmtiEnv *env, jmethodID method,
 			  jboolean *result)
@@ -1380,7 +1428,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
   RESERVED,			// reserved67
   UNIMPLEMENTED,		// GetMaxLocals
   UNIMPLEMENTED,		// GetArgumentsSize
-  UNIMPLEMENTED,		// GetLineNumberTable
+  _Jv_JVMTI_GetLineNumberTable,	// GetLineNumberTable
   UNIMPLEMENTED,		// GetMethodLocation
   UNIMPLEMENTED,		// GetLocalVariableTable
   RESERVED,			// reserved73
-- 
GitLab