/* * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* Initialize all statics */ /* We may be starting a new connection after an error */
cmdQueue = NULL;
cmdQueueLock = debugMonitorCreate("JDWP Command Queue Lock");
transportError = JNI_FALSE;
/* Okay, start reading cmds! */ while (shouldListen) { if (!dequeue(&p)) { break;
}
if (p.type.cmd.flags & JDWPTRANSPORT_FLAGS_REPLY) { /* * Its a reply packet.
*/ continue;
} else { /* * Its a cmd packet.
*/
jdwpCmdPacket *cmd = &p.type.cmd;
PacketInputStream in;
PacketOutputStream out;
CommandHandler func; constchar *cmdSetName; constchar *cmdName;
/* Should reply be sent to sender. * For error handling, assume yes, since * only VM/exit does not reply
*/
jboolean replyToSender = JNI_TRUE;
/* * For all commands we hold the vmDeathLock * while executing and replying to the command. This ensures * that a command after VM_DEATH will be allowed to complete * before the thread posting the VM_DEATH continues VM * termination.
*/
debugMonitorEnter(vmDeathLock);
/* Initialize the input and output streams */
inStream_init(&in, p);
outStream_initReply(&out, inStream_id(&in));
func = debugDispatch_getHandler(cmd->cmdSet, cmd->cmd, &cmdSetName, &cmdName);
LOG_MISC(("Command set %s(%d), command %s(%d)",
cmdSetName, cmd->cmdSet, cmdName, cmd->cmd)); if (func == NULL) { /* we've never heard of this, so I guess we * haven't implemented it. * Handle gracefully for future expansion * and platform / vendor expansion.
*/
outStream_setError(&out, JDWP_ERROR(NOT_IMPLEMENTED));
} elseif (gdata->vmDead &&
((cmd->cmdSet) != JDWP_COMMAND_SET(VirtualMachine))) { /* Protect the VM from calls while dead. * VirtualMachine cmdSet quietly ignores some cmds * after VM death, so, it sends it's own errors.
*/
outStream_setError(&out, JDWP_ERROR(VM_DEAD));
} else { /* Call the command handler */
replyToSender = func(&in, &out);
}
/* Reply to the sender */ if (replyToSender) { if (inStream_error(&in)) {
outStream_setError(&out, inStream_error(&in));
}
outStream_sendReply(&out);
}
/* * Release the vmDeathLock as the reply has been posted.
*/
debugMonitorExit(vmDeathLock);
/* * Cut off the transport immediately. This has the effect of * cutting off any events that the eventHelper thread might * be trying to send.
*/
transport_close();
debugMonitorDestroy(cmdQueueLock);
/* Reset for a new connection to this VM if it's still alive */ if ( ! gdata->vmDead ) {
debugInit_reset(getEnv());
}
}
/* I/O error or EOF */ if (rc != 0 || (rc == 0 && packet.type.cmd.len == 0)) {
shouldListen = JNI_FALSE;
notifyTransportError();
} elseif (packet.type.cmd.flags != JDWPTRANSPORT_FLAGS_NONE) { /* * Close the connection when we get a jdwpCmdPacket with an * invalid flags field value. This is a protocol violation * so we drop the connection. Also this could be a web * browser generating an HTTP request that passes the JDWP * handshake. HTTP requests requires that everything be in * the ASCII printable range so a flags value of * JDWPTRANSPORT_FLAGS_NONE(0) cannot be generated via HTTP.
*/
ERROR_MESSAGE(("Received jdwpPacket with flags != 0x%d (actual=0x%x) when a jdwpCmdPacket was expected.",
JDWPTRANSPORT_FLAGS_NONE, packet.type.cmd.flags));
shouldListen = JNI_FALSE;
notifyTransportError();
} else { constchar *cmdSetName; constchar *cmdName;
cmd = &packet.type.cmd;
/* * The current system for queueing packets is highly * inefficient, and should be rewritten! It'd be nice * to avoid any additional memory allocations.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.