OSDN Git Service

* include/jvmti-int.h (_Jv_GetJDWP_JVMTIEnv): Declare.
[pf3gnuchains/gcc-fork.git] / libjava / gnu / classpath / jdwp / natVMMethod.cc
1 // natVMMethod.cc -- native support for VMMethod
2
3 /* Copyright (C) 2006, 2007 Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 #include <config.h>
12 #include <gcj/cni.h>
13 #include <java-interp.h>
14 #include <jvmti.h>
15 #include "jvmti-int.h"
16
17 #include <gnu/classpath/jdwp/VMMethod.h>
18 #include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h>
19 #include <gnu/classpath/jdwp/util/LineTable.h>
20 #include <gnu/classpath/jdwp/util/VariableTable.h>
21
22 jstring
23 gnu::classpath::jdwp::VMMethod::getName ()
24 {
25   jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
26   jmethodID method = reinterpret_cast<jmethodID> (_methodId);
27   char *name;
28   env->GetMethodName (method, &name, NULL, NULL);
29   jstring string = JvNewStringUTF (name);
30   env->Deallocate (reinterpret_cast<unsigned char *> (name));
31   return string;
32 }
33
34 jstring
35 gnu::classpath::jdwp::VMMethod::getSignature ()
36 {
37   jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
38   jmethodID method = reinterpret_cast<jmethodID> (_methodId);
39   char *signature;
40   env->GetMethodName (method, NULL, &signature, NULL);
41   jstring string = JvNewStringUTF (signature);
42   env->Deallocate (reinterpret_cast<unsigned char *> (signature));
43   return string;
44 }
45
46 jint
47 gnu::classpath::jdwp::VMMethod::getModifiers ()
48 {
49   jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
50   jmethodID method = reinterpret_cast<jmethodID> (_methodId);
51   jint flags;
52   env->GetMethodModifiers (method, &flags);
53   return flags;
54 }
55
56 gnu::classpath::jdwp::util::LineTable *
57 gnu::classpath::jdwp::VMMethod::getLineTable ()
58 {
59   if (!_Jv_IsInterpretedClass (getDeclaringClass ()))
60     {
61       // this should not happen
62       ::java::lang::String *msg = JvNewStringLatin1 ("native class");
63       throw new exception::JdwpInternalErrorException (msg);
64     }
65
66   jmethodID desired_method = reinterpret_cast<jmethodID> (_methodId);
67
68   _Jv_MethodBase *theMethod
69     = _Jv_FindInterpreterMethod (getDeclaringClass (), desired_method);
70
71   if (theMethod == NULL)
72     {
73       // this should not happen
74       ::java::lang::String *msg
75         = JvNewStringLatin1 ("could not find method in class");
76       throw new exception::JdwpInternalErrorException (msg);
77     }
78
79   if (::java::lang::reflect::Modifier::isNative (desired_method->accflags))
80     {
81       jintArray lines = JvNewIntArray (0);
82       jlongArray indices = JvNewLongArray (0);
83       return new util::LineTable (-1, -1, lines, indices);
84     }
85
86   // get the linetable
87   _Jv_InterpMethod *imeth = reinterpret_cast<_Jv_InterpMethod *> (theMethod);
88   jlong start;
89   jlong end;
90   jintArray lines;
91   jlongArray indices;
92   imeth->get_line_table (start, end, lines, indices);
93   return new util::LineTable (start, end, lines, indices);
94 }
95
96
97 gnu::classpath::jdwp::util::VariableTable*
98 gnu::classpath::jdwp::VMMethod::getVariableTable ()
99 {
100   return NULL;
101 }