jdk/src/share/back/EventRequestImpl.c
author lana
Fri, 23 Dec 2011 16:36:33 -0800
changeset 11304 5d3d2bd1dfd1
parent 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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 "EventRequestImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "inStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "outStream.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "stepControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Take JDWP "modifiers" (which are JDI explicit filters, like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * addCountFilter(), and implicit filters, like the LocationOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * filter that goes with breakpoints) and add them as filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * (eventFilter) to the HandlerNode (eventHandler).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static jdwpError
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
readAndSetFilters(JNIEnv *env, PacketInputStream *in, HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                  jint filterCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    jdwpError serror = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    for (i = 0; i < filterCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        jbyte modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        modifier = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        switch (modifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            case JDWP_REQUEST_MODIFIER(Conditional): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                jint exprID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                exprID = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                        eventFilter_setConditionalFilter(node, i, exprID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            case JDWP_REQUEST_MODIFIER(Count): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                count = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        eventFilter_setCountFilter(node, i, count));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            case JDWP_REQUEST_MODIFIER(ThreadOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                        eventFilter_setThreadOnlyFilter(node, i, thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            case JDWP_REQUEST_MODIFIER(LocationOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                jbyte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                tag = inStream_readByte(in); /* not currently used */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                tag = tag; /* To shut up lint */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                method = inStream_readMethodID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                location = inStream_readLocation(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        eventFilter_setLocationOnlyFilter(node, i, clazz, method, location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            case JDWP_REQUEST_MODIFIER(FieldOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                jfieldID field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                field = inStream_readFieldID(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        eventFilter_setFieldOnlyFilter(node, i, clazz, field));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            case JDWP_REQUEST_MODIFIER(ClassOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                clazz = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        eventFilter_setClassOnlyFilter(node, i, clazz));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            case JDWP_REQUEST_MODIFIER(ExceptionOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                jclass exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                jboolean caught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                jboolean uncaught;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                exception = inStream_readClassRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                caught = inStream_readBoolean(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                uncaught = inStream_readBoolean(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        eventFilter_setExceptionOnlyFilter(node, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                             exception, caught, uncaught));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            case JDWP_REQUEST_MODIFIER(InstanceOnly): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                jobject instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                instance = inStream_readObjectRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        eventFilter_setInstanceOnlyFilter(node, i, instance));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            case JDWP_REQUEST_MODIFIER(ClassMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                char *pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                pattern = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        eventFilter_setClassMatchFilter(node, i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                                                pattern));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            case JDWP_REQUEST_MODIFIER(ClassExclude): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                char *pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                pattern = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        eventFilter_setClassExcludeFilter(node, i, pattern));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            case JDWP_REQUEST_MODIFIER(Step): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                jint depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                thread = inStream_readThreadRef(env, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                size = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                depth = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                      eventFilter_setStepFilter(node, i, thread, size, depth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            case JDWP_REQUEST_MODIFIER(SourceNameMatch): {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                char *sourceNamePattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                sourceNamePattern = inStream_readString(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                serror = map2jdwpError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        eventFilter_setSourceNameMatchFilter(node, i, sourceNamePattern));
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                serror = JDWP_ERROR(ILLEGAL_ARGUMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if ( serror != JDWP_ERROR(NONE) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    return serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * This is the back-end implementation for enabling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * (what are at the JDI level) EventRequests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * Allocate the event request handler (eventHandler).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * Add any filters (explicit or implicit).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * Install the handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * Return the handlerID which is used to map subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * events to the EventRequest that created it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
setCommand(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    HandlerNode *node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    HandlerID requestID = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    jdwpEvent eventType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    jbyte suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    jint filterCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    EventIndex ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    node = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    eventType = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    suspendPolicy = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (inStream_error(in)) {
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
    filterCount = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    ei = jdwp2EventIndex(eventType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    if (ei == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (ei == EI_VM_INIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * VM is already initialized so there's no need to install a handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * for this event. However we need to allocate a requestID to send in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * the reply to the debugger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        serror = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        requestID = eventHandler_allocHandlerID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        node = eventHandler_alloc(filterCount, ei, suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (node == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (eventType == JDWP_EVENT(METHOD_EXIT_WITH_RETURN_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            node->needReturnValue = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            node->needReturnValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        serror = readAndSetFilters(getEnv(), in, node, filterCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (serror == JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            error = eventHandler_installExternal(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            serror = map2jdwpError(error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (serror == JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                requestID = node->handlerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    if (serror == JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        (void)outStream_writeInt(out, requestID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        (void)eventHandler_free(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        outStream_setError(out, serror);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * This is the back-end implementation for disabling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * (what are at the JDI level) EventRequests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
clearCommand(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    jdwpEvent eventType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    HandlerID handlerID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    EventIndex ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    eventType = inStream_readByte(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    handlerID = inStream_readInt(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    if (inStream_error(in)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    ei = jdwp2EventIndex(eventType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    if (ei == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        /* NOTE: Clear command not yet spec'ed to return INVALID_EVENT_TYPE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    error = eventHandler_freeByID(ei, handlerID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        outStream_setError(out, map2jdwpError(error));
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
clearAllBreakpoints(PacketInputStream *in, PacketOutputStream *out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    error = eventHandler_freeAll(EI_BREAKPOINT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        outStream_setError(out, map2jdwpError(error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
void *EventRequest_Cmds[] = { (void *)0x3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    ,(void *)setCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    ,(void *)clearCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    ,(void *)clearAllBreakpoints};