0N/A/*
2362N/A * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include "util.h"
0N/A#include "EventRequestImpl.h"
0N/A#include "eventHandler.h"
0N/A#include "inStream.h"
0N/A#include "outStream.h"
0N/A#include "stepControl.h"
0N/A
0N/A/**
0N/A * Take JDWP "modifiers" (which are JDI explicit filters, like
0N/A * addCountFilter(), and implicit filters, like the LocationOnly
0N/A * filter that goes with breakpoints) and add them as filters
0N/A * (eventFilter) to the HandlerNode (eventHandler).
0N/A */
0N/Astatic jdwpError
0N/AreadAndSetFilters(JNIEnv *env, PacketInputStream *in, HandlerNode *node,
0N/A jint filterCount)
0N/A{
0N/A int i;
0N/A jdwpError serror = JDWP_ERROR(NONE);
0N/A
0N/A for (i = 0; i < filterCount; ++i) {
0N/A
0N/A jbyte modifier;
0N/A
0N/A modifier = inStream_readByte(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A
0N/A switch (modifier) {
0N/A
0N/A case JDWP_REQUEST_MODIFIER(Conditional): {
0N/A jint exprID;
0N/A exprID = inStream_readInt(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setConditionalFilter(node, i, exprID));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(Count): {
0N/A jint count;
0N/A count = inStream_readInt(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setCountFilter(node, i, count));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(ThreadOnly): {
0N/A jthread thread;
0N/A thread = inStream_readThreadRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setThreadOnlyFilter(node, i, thread));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(LocationOnly): {
0N/A jbyte tag;
0N/A jclass clazz;
0N/A jmethodID method;
0N/A jlocation location;
0N/A tag = inStream_readByte(in); /* not currently used */
0N/A tag = tag; /* To shut up lint */
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A clazz = inStream_readClassRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A method = inStream_readMethodID(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A location = inStream_readLocation(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setLocationOnlyFilter(node, i, clazz, method, location));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(FieldOnly): {
0N/A jclass clazz;
0N/A jfieldID field;
0N/A clazz = inStream_readClassRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A field = inStream_readFieldID(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setFieldOnlyFilter(node, i, clazz, field));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(ClassOnly): {
0N/A jclass clazz;
0N/A clazz = inStream_readClassRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setClassOnlyFilter(node, i, clazz));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(ExceptionOnly): {
0N/A jclass exception;
0N/A jboolean caught;
0N/A jboolean uncaught;
0N/A exception = inStream_readClassRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A caught = inStream_readBoolean(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A uncaught = inStream_readBoolean(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setExceptionOnlyFilter(node, i,
0N/A exception, caught, uncaught));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(InstanceOnly): {
0N/A jobject instance;
0N/A instance = inStream_readObjectRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setInstanceOnlyFilter(node, i, instance));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(ClassMatch): {
0N/A char *pattern;
0N/A pattern = inStream_readString(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setClassMatchFilter(node, i,
0N/A pattern));
0N/A break;
0N/A }
0N/A
0N/A case JDWP_REQUEST_MODIFIER(ClassExclude): {
0N/A char *pattern;
0N/A pattern = inStream_readString(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setClassExcludeFilter(node, i, pattern));
0N/A break;
0N/A }
0N/A case JDWP_REQUEST_MODIFIER(Step): {
0N/A jthread thread;
0N/A jint size;
0N/A jint depth;
0N/A thread = inStream_readThreadRef(env, in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A size = inStream_readInt(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A depth = inStream_readInt(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) )
0N/A break;
0N/A serror = map2jdwpError(
0N/A eventFilter_setStepFilter(node, i, thread, size, depth));
0N/A break;
0N/A }
0N/A case JDWP_REQUEST_MODIFIER(SourceNameMatch): {
0N/A char *sourceNamePattern;
0N/A sourceNamePattern = inStream_readString(in);
0N/A if ( (serror = inStream_error(in)) != JDWP_ERROR(NONE) ) {
0N/A break;
0N/A }
0N/A serror = map2jdwpError(
0N/A eventFilter_setSourceNameMatchFilter(node, i, sourceNamePattern));
0N/A break;
0N/A }
0N/A
0N/A default:
0N/A serror = JDWP_ERROR(ILLEGAL_ARGUMENT);
0N/A break;
0N/A }
0N/A if ( serror != JDWP_ERROR(NONE) )
0N/A break;
0N/A }
0N/A return serror;
0N/A}
0N/A
0N/A/**
0N/A * This is the back-end implementation for enabling
0N/A * (what are at the JDI level) EventRequests.
0N/A *
0N/A * Allocate the event request handler (eventHandler).
0N/A * Add any filters (explicit or implicit).
0N/A * Install the handler.
0N/A * Return the handlerID which is used to map subsequent
0N/A * events to the EventRequest that created it.
0N/A */
0N/Astatic jboolean
0N/AsetCommand(PacketInputStream *in, PacketOutputStream *out)
0N/A{
0N/A jdwpError serror;
0N/A HandlerNode *node;
0N/A HandlerID requestID = -1;
0N/A jdwpEvent eventType;
0N/A jbyte suspendPolicy;
0N/A jint filterCount;
0N/A EventIndex ei;
0N/A
0N/A node = NULL;
0N/A eventType = inStream_readByte(in);
0N/A if (inStream_error(in)) {
0N/A return JNI_TRUE;
0N/A }
0N/A suspendPolicy = inStream_readByte(in);
0N/A if (inStream_error(in)) {
0N/A return JNI_TRUE;
0N/A }
0N/A filterCount = inStream_readInt(in);
0N/A if (inStream_error(in)) {
0N/A return JNI_TRUE;
0N/A }
0N/A
0N/A ei = jdwp2EventIndex(eventType);
0N/A if (ei == 0) {
0N/A outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));
0N/A return JNI_TRUE;
0N/A }
0N/A
0N/A if (ei == EI_VM_INIT) {
0N/A /*
0N/A * VM is already initialized so there's no need to install a handler
0N/A * for this event. However we need to allocate a requestID to send in
0N/A * the reply to the debugger.
0N/A */
0N/A serror = JDWP_ERROR(NONE);
0N/A requestID = eventHandler_allocHandlerID();
0N/A } else {
0N/A node = eventHandler_alloc(filterCount, ei, suspendPolicy);
0N/A if (node == NULL) {
0N/A outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
0N/A return JNI_TRUE;
0N/A }
0N/A if (eventType == JDWP_EVENT(METHOD_EXIT_WITH_RETURN_VALUE)) {
0N/A node->needReturnValue = 1;
0N/A } else {
0N/A node->needReturnValue = 0;
0N/A }
0N/A serror = readAndSetFilters(getEnv(), in, node, filterCount);
0N/A if (serror == JDWP_ERROR(NONE)) {
0N/A jvmtiError error;
0N/A error = eventHandler_installExternal(node);
0N/A serror = map2jdwpError(error);
0N/A if (serror == JDWP_ERROR(NONE)) {
0N/A requestID = node->handlerID;
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (serror == JDWP_ERROR(NONE)) {
0N/A (void)outStream_writeInt(out, requestID);
0N/A } else {
0N/A (void)eventHandler_free(node);
0N/A outStream_setError(out, serror);
0N/A }
0N/A
0N/A return JNI_TRUE;
0N/A}
0N/A
0N/A/**
0N/A * This is the back-end implementation for disabling
0N/A * (what are at the JDI level) EventRequests.
0N/A */
0N/Astatic jboolean
0N/AclearCommand(PacketInputStream *in, PacketOutputStream *out)
0N/A{
0N/A jvmtiError error;
0N/A jdwpEvent eventType;
0N/A HandlerID handlerID;
0N/A EventIndex ei;
0N/A
0N/A eventType = inStream_readByte(in);
0N/A if (inStream_error(in)) {
0N/A return JNI_TRUE;
0N/A }
0N/A handlerID = inStream_readInt(in);
0N/A if (inStream_error(in)) {
0N/A return JNI_TRUE;
0N/A }
0N/A
0N/A ei = jdwp2EventIndex(eventType);
0N/A if (ei == 0) {
0N/A /* NOTE: Clear command not yet spec'ed to return INVALID_EVENT_TYPE */
0N/A outStream_setError(out, JDWP_ERROR(INVALID_EVENT_TYPE));
0N/A return JNI_TRUE;
0N/A }
0N/A
0N/A error = eventHandler_freeByID(ei, handlerID);
0N/A if (error != JVMTI_ERROR_NONE) {
0N/A outStream_setError(out, map2jdwpError(error));
0N/A }
0N/A
0N/A return JNI_TRUE;
0N/A}
0N/A
0N/Astatic jboolean
0N/AclearAllBreakpoints(PacketInputStream *in, PacketOutputStream *out)
0N/A{
0N/A jvmtiError error;
0N/A
0N/A error = eventHandler_freeAll(EI_BREAKPOINT);
0N/A if (error != JVMTI_ERROR_NONE) {
0N/A outStream_setError(out, map2jdwpError(error));
0N/A }
0N/A return JNI_TRUE;
0N/A}
0N/A
0N/Avoid *EventRequest_Cmds[] = { (void *)0x3
0N/A ,(void *)setCommand
0N/A ,(void *)clearCommand
0N/A ,(void *)clearAllBreakpoints};