377150afe52edcf24e730d9112f4d7a8e8a8fa5d
[cacao.git] / src / native / vm / VMMethod.c
1 /* src/native/vm/VMMethod.c - jdwp->jvmti interface
2
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
7
8 This file is part of CACAO.
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301, USA.
24
25 Contact: cacao@cacaojvm.org
26
27 Authors: Samuel Vinson
28 Martin Platter
29          
30
31 Changes: 
32
33
34 $Id: $
35
36 */
37
38 #include "native/jni.h"
39 #include "native/include/gnu_classpath_jdwp_VMMethod.h"
40 #include "native/jvmti/jvmti.h"
41 #include "native/jvmti/VMjdwp.h"
42
43 /*
44  * Class:     gnu/classpath/jdwp/VMMethod
45  * Method:    getName
46  * Signature: ()Ljava/lang/String;
47  */
48 JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getName(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
49 {
50     jvmtiError err;
51     char* errdesc;
52     char *name, *signature, *generic;
53     jstring stringname;
54     
55     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
56                              GetMethodName(jvmtienv, (jmethodID)this->_methodId,
57                                            &name, &signature, &generic))) {
58         (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
59         fprintf(stderr,"jvmti error: %s\n",errdesc);
60         fflush(stderr);
61         (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
62         return NULL;
63     }
64     
65     stringname = (*env)->NewStringUTF(env,name);
66     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
67     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
68     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)generic);
69
70     return stringname;
71 }
72
73
74 /*
75  * Class:     gnu/classpath/jdwp/VMMethod
76  * Method:    getSignature
77  * Signature: ()Ljava/lang/String;
78  */
79 JNIEXPORT struct java_lang_String* JNICALL Java_gnu_classpath_jdwp_VMMethod_getSignature(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
80 {
81     jvmtiError err;
82     char* errdesc;
83     char *name, *signature, *generic;
84     struct java_lang_String* stringsignature;
85     
86     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
87                              GetMethodName(jvmtienv, (jmethodID)this->_methodId,
88                                            &name, &signature, &generic))) {
89         (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
90         fprintf(stderr,"jvmti error: %s\n",errdesc);
91         fflush(stderr);
92         (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
93         return NULL;
94     }
95     
96     stringsignature = (*env)->NewStringUTF(env,signature);
97     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)name);
98     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)signature);
99     (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)generic);
100     
101     return stringsignature;
102 }
103
104
105 /*
106  * Class:     gnu/classpath/jdwp/VMMethod
107  * Method:    getModifiers
108  * Signature: ()I
109  */
110 JNIEXPORT s4 JNICALL Java_gnu_classpath_jdwp_VMMethod_getModifiers(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
111 {
112     jvmtiError err;
113     char* errdesc;
114     jint modifiers;
115         
116     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
117                              GetMethodModifiers(jvmtienv, 
118                                                 (jmethodID) this->_methodId,
119                                                 &modifiers))) {
120         (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
121         fprintf(stderr,"jvmti error: %s\n",errdesc);
122         fflush(stderr);
123         (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
124         return 0;
125     }
126     
127     return modifiers;
128 }
129
130
131 /*
132  * Class:     gnu/classpath/jdwp/VMMethod
133  * Method:    getLineTable
134  * Signature: ()Lgnu/classpath/jdwp/util/LineTable;
135  */
136 JNIEXPORT struct gnu_classpath_jdwp_util_LineTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getLineTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this) 
137 {
138     jclass cl;
139     jmethodID m;
140     jobject ol;
141     jlongArray jlineCI;
142     jintArray jlineNum;
143     jint count = 0, i;
144     int *lineNum;
145     long *lineCI;
146     jvmtiLineNumberEntry *lne;
147     jlocation start,end;
148     
149     jvmtiError err;
150     char* errdesc;
151
152     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
153                              GetLineNumberTable(jvmtienv, 
154                                                 (jmethodID)this->_methodId, 
155                                                 &count, &lne))) {
156         (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
157         fprintf(stderr,"jvmti error: %s\n",errdesc);
158         fflush(stderr);
159         (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
160         return NULL;
161     }
162
163     cl = (*env)->FindClass(env,"gnu.classpath.jdwp.util.LineTable");
164     if (!cl) return NULL;
165
166     m = (*env)->GetMethodID(env, cl, "<init>", "(JJ[I[J)V");
167     if (!m) return NULL;
168         
169     jlineNum = (*env)->NewIntArray(env, count);
170     if (!jlineNum) return NULL;
171     jlineCI = (*env)->NewLongArray(env, count);
172     if (!jlineCI) return NULL;
173     lineNum = (*env)->GetIntArrayElements(env, jlineNum, NULL);
174     lineCI = (*env)->GetLongArrayElements(env, jlineCI, NULL);
175     for (i = 0; i < count; ++i) {
176         lineNum[i] = lne[i].line_number;
177         lineCI[i] = lne[i].start_location;
178     }
179     (*env)->ReleaseLongArrayElements(env, jlineCI, lineCI, 0);
180     (*env)->ReleaseIntArrayElements(env, jlineNum, lineNum, 0);
181     (*jvmtienv)->Deallocate(jvmtienv,lne);
182
183     if (JVMTI_ERROR_NONE != (err= (*jvmtienv)->
184                              GetMethodLocation(jvmtienv, 
185                                                (jmethodID)this->_methodId, 
186                                                 &start, &end))) {
187         (*jvmtienv)->GetErrorName(jvmtienv,err, &errdesc);
188         fprintf(stderr,"jvmti error: %s\n",errdesc);
189         fflush(stderr);
190         (*jvmtienv)->Deallocate(jvmtienv,(unsigned char*)errdesc);
191         return NULL;
192     }
193
194     ol = (*env)->NewObject(env, cl, m, start, 
195                            end, jlineNum, jlineCI);
196
197     return (struct gnu_classpath_jdwp_util_LineTable*)ol;
198  
199 }
200
201
202 /*
203  * Class:     gnu/classpath/jdwp/VMMethod
204  * Method:    getVariableTable
205  * Signature: ()Lgnu/classpath/jdwp/util/VariableTable;
206  */
207 JNIEXPORT struct gnu_classpath_jdwp_util_VariableTable* JNICALL Java_gnu_classpath_jdwp_VMMethod_getVariableTable(JNIEnv *env, struct gnu_classpath_jdwp_VMMethod* this)
208 {
209     fprintf(stderr,"VMMethod_getVariableTable: IMPLEMENT ME!!!");
210     return 0;
211 }
212
213 /*
214  * These are local overrides for various environment variables in Emacs.
215  * Please do not remove this and leave it at the end of the file, where
216  * Emacs will automagically detect them.
217  * ---------------------------------------------------------------------
218  * Local variables:
219  * mode: c
220  * indent-tabs-mode: t
221  * c-basic-offset: 4
222  * tab-width: 4
223  * End:
224  */