/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
#include "util.h"
#include "transport.h"
#include "debugLoop.h"
#include "sys.h"
/*
* data structure used for passing transport info from thread to thread
*/
typedef struct TransportInfo {
char *name;
char *address;
long timeout;
/*
* Print the last transport error
*/
static void
{
char *msg;
int len;
int maxlen;
/* Convert this string to UTF8 */
}
if (rv == JDWPTRANSPORT_ERROR_NONE) {
} else {
}
}
/* Find OnLoad symbol */
static jdwpTransport_OnLoad_t
{
return onLoad;
}
return onLoad;
}
/* Load transport library (directory=="" means do system search) */
static void *
{
void *handle;
char *plibdir;
/* Convert libdir from UTF-8 to platform encoding */
int len;
}
/* Construct library name (simple name or full path) */
/* dlopen (unix) / LoadLibrary (windows) the transport library */
return handle;
}
/*
* loadTransport() is adapted from loadJVMHelperLib() in
* JDK 1.2 javai.c v1.61
*/
static jdwpError
{
void *handle;
char *libdir;
/* Make sure library name is not empty */
ERROR_MESSAGE(("library name is empty"));
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.
*/
ERROR_MESSAGE(("Java property sun.boot.library.path is not set"));
return JDWP_ERROR(TRANSPORT_LOAD);
}
/* 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
*/
}
/* See if a library was found with this name */
return JDWP_ERROR(TRANSPORT_LOAD);
}
/* Find the onLoad address */
return JDWP_ERROR(TRANSPORT_LOAD);
}
/* Get transport interface */
jdwpTransportEnv *t;
switch (ver) {
case JNI_ENOMEM :
ERROR_MESSAGE(("insufficient memory to complete initialization"));
break;
case JNI_EVERSION :
ERROR_MESSAGE(("transport doesn't recognize version %x",
break;
case JNI_EEXIST :
ERROR_MESSAGE(("transport doesn't support multiple environments"));
break;
default:
break;
}
return JDWP_ERROR(TRANSPORT_INIT);
}
*transportPtr = t;
} else {
return JDWP_ERROR(TRANSPORT_LOAD);
}
return JDWP_ERROR(NONE);
}
static void
{
/*
* Don't allow a connection until initialization is complete
*/
/* Are we the first transport to get a connection? */
transport = t;
} else {
if (transport == t) {
/* connected with the same transport as before */
} else {
/*
* Another transport got a connection - multiple transports
* not fully supported yet so shouldn't get here.
*/
(*t)->Close(t);
}
}
if (isValid) {
}
if (isValid) {
}
}
/*
* Set the transport property (sun.jdwp.listenerAddress) to the
* specified value.
*/
static void
}
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()) {
}
}
}
static void JNICALL
{
jdwpTransportEnv *t;
LOG_MISC(("Begin accept thread"));
/* System property no longer needed */
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);
} else {
(*t)->StopListening(t);
}
LOG_MISC(("End accept thread"));
}
static void JNICALL
{
LOG_MISC(("Begin attach thread"));
LOG_MISC(("End attach thread"));
}
void
transport_initialize(void)
{
}
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.
*/
}
}
static jdwpError
{
char *buf;
char *commandLine;
int len;
/* Construct complete command line (all in UTF-8) */
if (commandLine == NULL) {
return JDWP_ERROR(OUT_OF_MEMORY);
}
/* Convert commandLine from UTF-8 to platform encoding */
/* Exec commandLine */
/* Free up buffers */
/* And non-zero exit status means we had an error */
return JDWP_ERROR(TRANSPORT_INIT);
}
return JDWP_ERROR(NONE);
}
long timeout)
{
/*
* 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.
*/
} else {
return serror;
}
}
if (isServer) {
char *retAddress;
char *launchCommand;
int len;
char* prop_value;
return JDWP_ERROR(OUT_OF_MEMORY);
}
goto handleError;
}
goto handleError;
}
}
if (err != JDWPTRANSPORT_ERROR_NONE) {
goto handleError;
}
/*
* Record listener address in a system property
*/
func = &acceptThread;
if (error != JVMTI_ERROR_NONE) {
goto handleError;
}
if (launchCommand != NULL) {
goto handleError;
}
} else {
TTY_MESSAGE(("Listening for transport %s at address: %s",
name, retAddress));
}
}
return JDWP_ERROR(NONE);
} 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.
*/
if (err != JDWPTRANSPORT_ERROR_NONE) {
return serror;
}
/*
* Start the transport loop in a separate thread
*/
func = &attachThread;
}
return serror;
}
void
transport_close(void)
{
}
}
transport_is_open(void)
{
}
return is_open;
}
{
}
if (err != JDWPTRANSPORT_ERROR_NONE) {
}
/*
* The users of transport_sendPacket except 0 for
* success; non-0 otherwise.
*/
}
} /* else, bit bucket */
return rc;
}
{
if (err != JDWPTRANSPORT_ERROR_NONE) {
/*
* If transport has been closed return EOF
*/
return 0;
}
/*
* Users of transport_receivePacket expect 0 for success,
* non-0 otherwise.
*/
return (jint)-1;
}
return 0;
}