jdk/src/share/back/StackFrameImpl.c
author ohair
Fri, 22 Aug 2008 12:24:27 -0700
changeset 1090 c5805b1672a6
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6732421: Removed old javavm and Classic VM files from the jdk7 sources Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "StackFrameImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "FrameID.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
validateThreadFrame(jthread thread, FrameID frame)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    jdwpError  serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    error = threadControl_suspendCount(thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    if ( error == JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        if ( count > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            serror = validateFrameID(thread, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            serror = JDWP_ERROR(THREAD_NOT_SUSPENDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        serror =  map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    return serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
writeVariableValue(JNIEnv *env, PacketOutputStream *out, jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                   FrameNumber fnum, jint slot, jbyte typeKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    jvalue value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                        (gdata->jvmti, thread, fnum, slot, &value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                (void)outStream_writeByte(out, specificTypeKey(env, value.l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                (void)outStream_writeObjectRef(env, out, value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         * For primitive types, the type key is bounced back as is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        (void)outStream_writeByte(out, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            case JDWP_TAG(BYTE): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    jint intValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                (gdata->jvmti, thread, fnum, slot, &intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    (void)outStream_writeByte(out, (jbyte)intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            case JDWP_TAG(CHAR): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    jint intValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                (gdata->jvmti, thread, fnum, slot, &intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    (void)outStream_writeChar(out, (jchar)intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalFloat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                (gdata->jvmti, thread, fnum, slot, &value.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                (void)outStream_writeFloat(out, value.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalDouble)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                (gdata->jvmti, thread, fnum, slot, &value.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                (void)outStream_writeDouble(out, value.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                (gdata->jvmti, thread, fnum, slot, &value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                (void)outStream_writeInt(out, value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalLong)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                (gdata->jvmti, thread, fnum, slot, &value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                (void)outStream_writeLong(out, value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            case JDWP_TAG(SHORT): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                jint intValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                (gdata->jvmti, thread, fnum, slot, &intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                (void)outStream_writeShort(out, (jshort)intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            case JDWP_TAG(BOOLEAN):{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                jint intValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                (gdata->jvmti, thread, fnum, slot, &intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                (void)outStream_writeBoolean(out, (jboolean)intValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                return JDWP_ERROR(INVALID_TAG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    return map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
readVariableValue(JNIEnv *env, PacketInputStream *in, jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                  FrameNumber fnum, jint slot, jbyte typeKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    jvalue value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    if (isObjectTag(typeKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        value.l = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        (gdata->jvmti, thread, fnum, slot, value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        switch (typeKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            case JDWP_TAG(BYTE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                value.b = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                (gdata->jvmti, thread, fnum, slot, value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            case JDWP_TAG(CHAR):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                value.c = inStream_readChar(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                (gdata->jvmti, thread, fnum, slot, value.c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            case JDWP_TAG(FLOAT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                value.f = inStream_readFloat(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalFloat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                (gdata->jvmti, thread, fnum, slot, value.f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            case JDWP_TAG(DOUBLE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                value.d = inStream_readDouble(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalDouble)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                (gdata->jvmti, thread, fnum, slot, value.d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            case JDWP_TAG(INT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                value.i = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                (gdata->jvmti, thread, fnum, slot, value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            case JDWP_TAG(LONG):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                value.j = inStream_readLong(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalLong)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                (gdata->jvmti, thread, fnum, slot, value.j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            case JDWP_TAG(SHORT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                value.s = inStream_readShort(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                (gdata->jvmti, thread, fnum, slot, value.s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            case JDWP_TAG(BOOLEAN):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                value.z = inStream_readBoolean(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                (gdata->jvmti, thread, fnum, slot, value.z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                return JDWP_ERROR(INVALID_TAG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    return map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
getValues(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    FrameID frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    jint variableCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    frame = inStream_readFrameID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    variableCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Validate the frame id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    serror = validateThreadFrame(thread, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    (void)outStream_writeInt(out, variableCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    for (i = 0; (i < variableCount) && !outStream_error(out); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        jint slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        FrameNumber fnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        slot = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (inStream_error(in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        typeKey = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (inStream_error(in))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        fnum = getFrameNumber(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        serror = writeVariableValue(env, out, thread, fnum, slot, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
setValues(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    FrameID frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    jint variableCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    frame = inStream_readFrameID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    variableCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Validate the frame id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    serror = validateThreadFrame(thread, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    for (i = 0; (i < variableCount) && !inStream_error(in); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        jint slot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        jbyte typeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        FrameNumber fnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        slot = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        typeKey = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        fnum = getFrameNumber(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        serror = readVariableValue(env, in, thread, fnum, slot, typeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (serror != JDWP_ERROR(NONE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
thisObject(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    FrameID frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    frame = inStream_readFrameID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Validate the frame id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    serror = validateThreadFrame(thread, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    WITH_LOCAL_REFS(env, 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        FrameNumber fnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * Find out if the given frame is for a static or native method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        fnum = getFrameNumber(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                (gdata->jvmti, thread, fnum, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            jint modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            error = methodModifiers(method, &modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                jobject this_object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                 * Return null for static or native methods; otherwise, the JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                 * spec guarantees that "this" is in slot 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                if (modifiers & (MOD_STATIC | MOD_NATIVE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    this_object = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    (void)outStream_writeByte(out, specificTypeKey(env, this_object));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    (void)outStream_writeObjectRef(env, out, this_object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                (gdata->jvmti, thread, fnum, 0, &this_object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        (void)outStream_writeByte(out, specificTypeKey(env, this_object));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                        (void)outStream_writeObjectRef(env, out, this_object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        serror = map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    if (serror != JDWP_ERROR(NONE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
popFrames(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    FrameID frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    FrameNumber fnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    thread = inStream_readThreadRef(getEnv(), in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    frame = inStream_readFrameID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Validate the frame id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    serror = validateThreadFrame(thread, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    if (threadControl_isDebugThread(thread)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        outStream_setError(out, JDWP_ERROR(INVALID_THREAD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    fnum = getFrameNumber(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    error = threadControl_popFrames(thread, fnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        serror = map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
void *StackFrame_Cmds[] = { (void *)0x4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    ,(void *)getValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    ,(void *)setValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    ,(void *)thisObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    ,(void *)popFrames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
};