/* * Copyright (c) 1998, 2018, 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.
*/
/* * data structure used for passing transport info from thread to thread
*/ typedefstruct TransportInfo { char *name;
jdwpTransportEnv *transport; char *address; long timeout; char *allowed_peers; unsigned transportVersion;
} TransportInfo;
/* Construct library name (simple name or full path) */
dbgsysBuildLibName(libname, sizeof(libname), plibdir, name); if (strlen(libname) == 0) { return NULL;
}
/* * loadTransport() is adapted from loadJVMHelperLib() in * JDK 1.2 javai.c v1.61
*/ static jdwpError
loadTransport(constchar *name, TransportInfo *info)
{
JNIEnv *env;
jdwpTransport_OnLoad_t onLoad; void *handle; constchar *libdir;
/* Make sure library name is not empty */ if (name == NULL) {
ERROR_MESSAGE(("library name is empty")); return JDWP_ERROR(TRANSPORT_LOAD);
} if (info == NULL) {
ERROR_MESSAGE(("internal error: info should not be NULL")); return JDWP_ERROR(TRANSPORT_LOAD);
}
/* First, look in sun.boot.library.path. This should find the standard * dt_socket and dt_shmem transport libraries, or any library * that was delivered with the J2SE. * Note: Since 6819213 fixed, Java property sun.boot.library.path can * contain multiple paths. Dll_dir is the first entry and * -Dsun.boot.library.path entries are appended.
*/
libdir = gdata->property_sun_boot_library_path; if (libdir == NULL) {
ERROR_MESSAGE(("Java property sun.boot.library.path is not set")); return JDWP_ERROR(TRANSPORT_LOAD);
}
handle = loadTransportLibrary(libdir, name); if (handle == NULL) { /* Second, look along the path used by the native dlopen/LoadLibrary * functions. This should effectively try and load the simple * library name, which will cause the default system library * search technique to happen. * We should only reach here if the transport library wasn't found * in the J2SE directory, e.g. it's a custom transport library * not installed in the J2SE like dt_socket and dt_shmem is. * * Note: Why not use java.library.path? Several reasons: * a) This matches existing agentlib search * b) These are technically not JNI libraries
*/
handle = loadTransportLibrary("", name);
}
/* See if a library was found with this name */ if (handle == NULL) {
ERROR_MESSAGE(("transport library not found: %s", name)); return JDWP_ERROR(TRANSPORT_LOAD);
}
/* Get transport interface */
env = getEnv(); if (env != NULL) {
jdwpTransportEnv *t = NULL;
JavaVM *jvm = NULL;
jint rc;
size_t i; /* If a new version is added here, update 'case JNI_EVERSION' below. */
jint supported_versions[2] = {JDWPTRANSPORT_VERSION_1_1, JDWPTRANSPORT_VERSION_1_0};
JNI_FUNC_PTR(env,GetJavaVM)(env, &jvm);
/* Try version 1.1 first, fallback to 1.0 on error */ for (i = 0; i < sizeof(supported_versions)/sizeof(jint); ++i) {
rc = (*onLoad)(jvm, &callback, supported_versions[i], &t); if (rc != JNI_EVERSION) {
info->transportVersion = supported_versions[i]; break;
}
}
if (rc != JNI_OK) { switch (rc) { case JNI_ENOMEM :
ERROR_MESSAGE(("insufficient memory to complete initialization")); break;
case JNI_EVERSION :
ERROR_MESSAGE(("transport doesn't recognize all supported versions: " "{ 1_1, 1_0 }")); break;
case JNI_EEXIST :
ERROR_MESSAGE(("transport doesn't support multiple environments")); break;
default:
ERROR_MESSAGE(("unrecognized error %d from transport", rc)); break;
}
return JDWP_ERROR(TRANSPORT_INIT);
}
/* Store transport version to global variable to be able to * set correct transport version for subsequent connect, * even if info is already deallocated.
*/
transportVersion = info->transportVersion;
info->transport = t;
} else { return JDWP_ERROR(TRANSPORT_LOAD);
}
/* * Don't allow a connection until initialization is complete
*/
debugInit_waitInitComplete();
/* Are we the first transport to get a connection? */
if (transport == NULL) {
transport = t;
isValid = JNI_TRUE;
} else { if (transport == t) { /* connected with the same transport as before */
isValid = JNI_TRUE;
} else { /* * Another transport got a connection - multiple transports * not fully supported yet so shouldn't get here.
*/
(*t)->Close(t);
JDI_ASSERT(JNI_FALSE);
}
}
if (isValid) {
debugMonitorNotifyAll(listenerLock);
}
debugMonitorExit(listenerLock);
if (isValid) {
debugLoop_run();
}
}
/* * Set the transport property (sun.jdwp.listenerAddress) to the * specified value.
*/ staticvoid
setTransportProperty(JNIEnv* env, char* value) { char* prop_value = (value == NULL) ? "" : value;
setAgentPropertyValue(env, "sun.jdwp.listenerAddress", prop_value);
}
void
transport_waitForConnection(void)
{ /* * If the VM is suspended on debugger initialization, we wait * for a connection before continuing. This ensures that all * events are delivered to the debugger. (We might as well do this * this since the VM won't continue until a remote debugger attaches * and resumes it.) If not suspending on initialization, we must * just drop any packets (i.e. events) so that the VM can continue * to run. The debugger may not attach until much later.
*/ if (debugInit_suspendOnInit()) {
debugMonitorEnter(listenerLock); while (transport == NULL) {
debugMonitorWait(listenerLock);
}
debugMonitorExit(listenerLock);
}
}
info = (TransportInfo*)arg;
t = info->transport;
rc = (*t)->Accept(t, info->timeout, 0);
/* System property no longer needed */
setTransportProperty(jni_env, NULL); /* TransportInfo data no longer needed */
freeTransportInfo(info);
if (rc != JDWPTRANSPORT_ERROR_NONE) { /* * If accept fails it probably means a timeout, or another fatal error * We thus exit the VM after stopping the listener.
*/
printLastError(t, rc);
(*t)->StopListening(t);
EXIT_ERROR(JVMTI_ERROR_NONE, "could not connect, timeout or fatal error");
} else {
(*t)->StopListening(t);
connectionInitiated(t);
}
void
transport_initialize(void)
{
transport = NULL;
listenerLock = debugMonitorCreate("JDWP Transport Listener Monitor");
sendLock = debugMonitorCreate("JDWP Transport Send Monitor");
}
void
transport_reset(void)
{ /* * Reset the transport by closing any listener (will silently fail * with JDWPTRANSPORT_ERROR_ILLEGAL_STATE if not listening), and * closing any connection (will also fail silently if not * connected). * * Note: There's an assumption here that we don't yet support * multiple transports. When we do then we need a clear transition * from the current transport to the new transport.
*/ if (transport != NULL) {
setTransportProperty(getEnv(), NULL);
(*transport)->StopListening(transport);
(*transport)->Close(transport);
}
}
/* * If the transport is already loaded then use it * Note: We're assuming here that we don't support multiple * transports - when we do then we need to handle the case * where the transport library only supports a single environment. * That probably means we have a bag a transport environments * to correspond to the transports bag.
*/ if (info->transport == NULL) {
serror = loadTransport(name, info); if (serror != JDWP_ERROR(NONE)) {
freeTransportInfo(info); return serror;
}
}
// Cache the value
trans = info->transport;
if (isServer) { char *retAddress; char *launchCommand;
jvmtiError error; int len; char* prop_value;
if (info->transportVersion == JDWPTRANSPORT_VERSION_1_0) { if (allowed_peers != NULL) {
ERROR_MESSAGE(("Allow parameter is specified but transport doesn't support it"));
serror = JDWP_ERROR(TRANSPORT_INIT); goto handleError;
}
} else { /* Memory is allocated only for transport versions > 1.0 * as the version 1.0 does not support the 'allow' option.
*/ if (allowed_peers != NULL) {
info->allowed_peers = jvmtiAllocate((int)strlen(allowed_peers) + 1); if (info->allowed_peers == NULL) {
serror = JDWP_ERROR(OUT_OF_MEMORY); goto handleError;
}
(void)strcpy(info->allowed_peers, allowed_peers);
}
cfg.allowed_peers = info->allowed_peers;
err = (*trans)->SetTransportConfiguration(trans, &cfg); if (err != JDWPTRANSPORT_ERROR_NONE) {
printLastError(trans, err);
serror = JDWP_ERROR(TRANSPORT_INIT); goto handleError;
}
}
/* reset info - it will be deallocated by acceptThread */
info = NULL;
launchCommand = debugInit_launchOnInit(); if (launchCommand != NULL) {
serror = launch(launchCommand, name, retAddress); if (serror != JDWP_ERROR(NONE)) { goto handleError;
}
} else { if ( ! gdata->quiet ) {
TTY_MESSAGE(("Listening for transport %s at address: %s",
name, retAddress));
}
} return JDWP_ERROR(NONE);
handleError:
freeTransportInfo(info);
} else { /* * Note that we don't attempt to do a launch here. Launching * is currently supported only in server mode.
*/
/* * If we're connecting to another process, there shouldn't be * any concurrent listens, so its ok if we block here in this * thread, waiting for the attach to finish.
*/
err = (*trans)->Attach(trans, address, timeout, 0); if (err != JDWPTRANSPORT_ERROR_NONE) {
printLastError(trans, err);
serror = JDWP_ERROR(TRANSPORT_INIT); /* The name, address and allowed_peers fields in 'info' * are not allocated in the non-server case so
* they do not need to be freed. */
freeTransportInfo(info); return serror;
}
/* * Start the transport loop in a separate thread
*/
(void)strcpy(threadName, "JDWP Transport Listener: ");
(void)strcat(threadName, name);
err = (*transport)->ReadPacket(transport, packet); if (err != JDWPTRANSPORT_ERROR_NONE) { /* * If transport has been closed return EOF
*/ if (!(*transport)->IsOpen(transport)) {
packet->type.cmd.len = 0; return 0;
}
printLastError(transport, err);
/* * Users of transport_receivePacket expect 0 for success, * non-0 otherwise.
*/ return (jint)-1;
} return 0;
}
¤ Dauer der Verarbeitung: 0.38 Sekunden
(vorverarbeitet)
¤
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.