Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/back/EventRequestImpl.c
38765 views
/*1* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "util.h"26#include "EventRequestImpl.h"27#include "eventHandler.h"28#include "inStream.h"29#include "outStream.h"30#include "stepControl.h"3132/**33* Take JDWP "modifiers" (which are JDI explicit filters, like34* addCountFilter(), and implicit filters, like the LocationOnly35* filter that goes with breakpoints) and add them as filters36* (eventFilter) to the HandlerNode (eventHandler).37*/38static jdwpError39readAndSetFilters(JNIEnv *env, PacketInputStream *in, HandlerNode *node,40jint filterCount)41{42int i;43jdwpError serror = JDWP_ERROR(NONE);4445for (i = 0; i < filterCount; ++i) {4647jbyte modifier;4849modifier = inStream_readByte(in);50if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )51break;5253switch (modifier) {5455case JDWP_REQUEST_MODIFIER(Conditional): {56jint exprID;57exprID = inStream_readInt(in);58if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )59break;60serror = map2jdwpError(61eventFilter_setConditionalFilter(node, i, exprID));62break;63}6465case JDWP_REQUEST_MODIFIER(Count): {66jint count;67count = inStream_readInt(in);68if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )69break;70serror = map2jdwpError(71eventFilter_setCountFilter(node, i, count));72break;73}7475case JDWP_REQUEST_MODIFIER(ThreadOnly): {76jthread thread;77thread = inStream_readThreadRef(env, in);78if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )79break;80serror = map2jdwpError(81eventFilter_setThreadOnlyFilter(node, i, thread));82break;83}8485case JDWP_REQUEST_MODIFIER(LocationOnly): {86jbyte tag;87jclass clazz;88jmethodID method;89jlocation location;90tag = inStream_readByte(in); /* not currently used */91tag = tag; /* To shut up lint */92if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )93break;94clazz = inStream_readClassRef(env, in);95if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )96break;97method = inStream_readMethodID(in);98if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )99break;100location = inStream_readLocation(in);101if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )102break;103serror = map2jdwpError(104eventFilter_setLocationOnlyFilter(node, i, clazz, method, location));105break;106}107108case JDWP_REQUEST_MODIFIER(FieldOnly): {109jclass clazz;110jfieldID field;111clazz = inStream_readClassRef(env, in);112if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )113break;114field = inStream_readFieldID(in);115if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )116break;117serror = map2jdwpError(118eventFilter_setFieldOnlyFilter(node, i, clazz, field));119break;120}121122case JDWP_REQUEST_MODIFIER(ClassOnly): {123jclass clazz;124clazz = inStream_readClassRef(env, in);125if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )126break;127serror = map2jdwpError(128eventFilter_setClassOnlyFilter(node, i, clazz));129break;130}131132case JDWP_REQUEST_MODIFIER(ExceptionOnly): {133jclass exception;134jboolean caught;135jboolean uncaught;136exception = inStream_readClassRef(env, in);137if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )138break;139caught = inStream_readBoolean(in);140if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )141break;142uncaught = inStream_readBoolean(in);143if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )144break;145serror = map2jdwpError(146eventFilter_setExceptionOnlyFilter(node, i,147exception, caught, uncaught));148break;149}150151case JDWP_REQUEST_MODIFIER(InstanceOnly): {152jobject instance;153instance = inStream_readObjectRef(env, in);154if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )155break;156serror = map2jdwpError(157eventFilter_setInstanceOnlyFilter(node, i, instance));158break;159}160161case JDWP_REQUEST_MODIFIER(ClassMatch): {162char *pattern;163pattern = inStream_readString(in);164if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )165break;166serror = map2jdwpError(167eventFilter_setClassMatchFilter(node, i,168pattern));169break;170}171172case JDWP_REQUEST_MODIFIER(ClassExclude): {173char *pattern;174pattern = inStream_readString(in);175if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )176break;177serror = map2jdwpError(178eventFilter_setClassExcludeFilter(node, i, pattern));179break;180}181case JDWP_REQUEST_MODIFIER(Step): {182jthread thread;183jint size;184jint depth;185thread = inStream_readThreadRef(env, in);186if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )187break;188size = inStream_readInt(in);189if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )190break;191depth = inStream_readInt(in);192if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )193break;194serror = map2jdwpError(195eventFilter_setStepFilter(node, i, thread, size, depth));196break;197}198case JDWP_REQUEST_MODIFIER(SourceNameMatch): {199char *sourceNamePattern;200sourceNamePattern = inStream_readString(in);201if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) ) {202break;203}204serror = map2jdwpError(205eventFilter_setSourceNameMatchFilter(node, i, sourceNamePattern));206break;207}208209default:210serror = JDWP_ERROR(ILLEGAL_ARGUMENT);211break;212}213if ( serror != JDWP_ERROR(NONE) )214break;215}216return serror;217}218219/**220* This is the back-end implementation for enabling221* (what are at the JDI level) EventRequests.222*223* Allocate the event request handler (eventHandler).224* Add any filters (explicit or implicit).225* Install the handler.226* Return the handlerID which is used to map subsequent227* events to the EventRequest that created it.228*/229static jboolean230setCommand(PacketInputStream *in, PacketOutputStream *out)231{232jdwpError serror;233HandlerNode *node;234HandlerID requestID = -1;235jdwpEvent eventType;236jbyte suspendPolicy;237jint filterCount;238EventIndex ei;239240node = NULL;241eventType = inStream_readByte(in);242if (inStream_error(in)) {243return JNI_TRUE;244}245suspendPolicy = inStream_readByte(in);246if (inStream_error(in)) {247return JNI_TRUE;248}249filterCount = inStream_readInt(in);250if (inStream_error(in)) {251return JNI_TRUE;252}253254ei = jdwp2EventIndex(eventType);255if (ei == 0) {256outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));257return JNI_TRUE;258}259260if (ei == EI_VM_INIT) {261/*262* VM is already initialized so there's no need to install a handler263* for this event. However we need to allocate a requestID to send in264* the reply to the debugger.265*/266serror = JDWP_ERROR(NONE);267requestID = eventHandler_allocHandlerID();268} else {269node = eventHandler_alloc(filterCount, ei, suspendPolicy);270if (node == NULL) {271outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));272return JNI_TRUE;273}274if (eventType == JDWP_EVENT(METHOD_EXIT_WITH_RETURN_VALUE)) {275node->needReturnValue = 1;276} else {277node->needReturnValue = 0;278}279serror = readAndSetFilters(getEnv(), in, node, filterCount);280if (serror == JDWP_ERROR(NONE)) {281jvmtiError error;282error = eventHandler_installExternal(node);283serror = map2jdwpError(error);284if (serror == JDWP_ERROR(NONE)) {285requestID = node->handlerID;286}287}288}289290if (serror == JDWP_ERROR(NONE)) {291(void)outStream_writeInt(out, requestID);292} else {293(void)eventHandler_free(node);294outStream_setError(out, serror);295}296297return JNI_TRUE;298}299300/**301* This is the back-end implementation for disabling302* (what are at the JDI level) EventRequests.303*/304static jboolean305clearCommand(PacketInputStream *in, PacketOutputStream *out)306{307jvmtiError error;308jdwpEvent eventType;309HandlerID handlerID;310EventIndex ei;311312eventType = inStream_readByte(in);313if (inStream_error(in)) {314return JNI_TRUE;315}316handlerID = inStream_readInt(in);317if (inStream_error(in)) {318return JNI_TRUE;319}320321ei = jdwp2EventIndex(eventType);322if (ei == 0) {323/* NOTE: Clear command not yet spec'ed to return INVALID_EVENT_TYPE */324outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));325return JNI_TRUE;326}327328error = eventHandler_freeByID(ei, handlerID);329if (error != JVMTI_ERROR_NONE) {330outStream_setError(out, map2jdwpError(error));331}332333return JNI_TRUE;334}335336static jboolean337clearAllBreakpoints(PacketInputStream *in, PacketOutputStream *out)338{339jvmtiError error;340341error = eventHandler_freeAll(EI_BREAKPOINT);342if (error != JVMTI_ERROR_NONE) {343outStream_setError(out, map2jdwpError(error));344}345return JNI_TRUE;346}347348void *EventRequest_Cmds[] = { (void *)0x3349,(void *)setCommand350,(void *)clearCommand351,(void *)clearAllBreakpoints};352353354