jdk/src/share/back/debugInit.c
author dholmes
Sun, 02 Dec 2012 19:16:56 -0500
changeset 14698 9294fcf94c46
parent 9035 1255eb81cc2f
child 24967 582420f5ab6c
permissions -rw-r--r--
7200297: agent code does not handle multiple boot library path elements correctly Summary: When bug 6819213 was fixed it enabled sun.boot.library.path property to contain multiple paths. Code in agents does not handle multiple paths when attempting to find dependent shared libs. Reviewed-by: dholmes, sspitsyn, dsamersoff Contributed-by: Bill Pittore <bill.pittore@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
     2
 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "commonRef.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "debugDispatch.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "eventHelper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "stepControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "transport.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "classTrack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "debugLoop.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "bag.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "invoker.h"
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
    40
#include "sys.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/* How the options get to OnLoad: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define XDEBUG "-Xdebug"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define XRUN "-Xrunjdwp"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define AGENTLIB "-agentlib:jdwp"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/* Debug version defaults */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    #define DEFAULT_ASSERT_ON           JNI_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    #define DEFAULT_ASSERT_FATAL        JNI_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    #define DEFAULT_LOGFILE             "jdwp.log"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    #define DEFAULT_ASSERT_ON           JNI_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    #define DEFAULT_ASSERT_FATAL        JNI_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    #define DEFAULT_LOGFILE             NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static jboolean vmInitialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
static jrawMonitorID initMonitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
static jboolean initComplete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static jbyte currentSessionID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Options set through the OnLoad options string. All of these values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * are set once at VM startup and never reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
static jboolean isServer = JNI_FALSE;     /* Listens for connecting debuggers? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
static jboolean isStrict = JNI_FALSE;     /* Unused */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
static jboolean useStandardAlloc = JNI_FALSE;  /* Use standard malloc/free? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
static struct bag *transports;            /* of TransportSpec */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
static jboolean initOnStartup = JNI_TRUE;   /* init immediately */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
static char *initOnException = NULL;        /* init when this exception thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
static jboolean initOnUncaught = JNI_FALSE; /* init when uncaught exc thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
static char *launchOnInit = NULL;           /* launch this app during init */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static jboolean suspendOnInit = JNI_TRUE;   /* suspend all app threads after init */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static jboolean dopause = JNI_FALSE;        /* pause for debugger attach */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
static jboolean docoredump = JNI_FALSE;     /* core dump on exit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static char *logfile = NULL;                /* Name of logfile (if logging) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
static unsigned logflags = 0;               /* Log flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
static char *names;                         /* strings derived from OnLoad options */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Elements of the transports bag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
typedef struct TransportSpec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    char *address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
} TransportSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * Forward Refs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
static void JNICALL cbEarlyVMInit(jvmtiEnv*, JNIEnv *, jthread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static void JNICALL cbEarlyVMDeath(jvmtiEnv*, JNIEnv *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
static void JNICALL cbEarlyException(jvmtiEnv*, JNIEnv *,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            jthread, jmethodID, jlocation, jobject, jmethodID, jlocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
static void initialize(JNIEnv *env, jthread thread, EventIndex triggering_ei);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static jboolean parseOptions(char *str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * Phase 1: Initial load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * OnLoad is called by the VM immediately after the back-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * library is loaded. We can do very little in this function since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * the VM has not completed initialization. So, we parse the JDWP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * options and set up a simple initial event callbacks for JVMTI events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * When a triggering event occurs, that callback will begin debugger initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
/* Get a static area to hold the Global Data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static BackendGlobalData *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
get_gdata(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    static BackendGlobalData s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    (void)memset(&s, 0, sizeof(BackendGlobalData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    return &s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
set_event_notification(jvmtiEventMode mode, EventIndex ei)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventNotificationMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                (gdata->jvmti, mode, eventIndex2jvmti(ei), NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ERROR_MESSAGE(("JDWP unable to configure initial JVMTI event %s: %s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    eventText(ei), jvmtiErrorText(error), error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
7978
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   137
typedef struct {
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   138
    int major;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   139
    int minor;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   140
} version_type;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   141
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   142
typedef struct {
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   143
    version_type runtime;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   144
    version_type compiletime;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   145
} compatible_versions_type;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   146
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   147
/*
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   148
 * List of explicitly compatible JVMTI versions, specified as
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   149
 * { runtime version, compile-time version } pairs. -1 is a wildcard.
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   150
 */
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   151
static int nof_compatible_versions = 3;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   152
static compatible_versions_type compatible_versions_list[] = {
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   153
    /*
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   154
     * FIXUP: Allow version 0 to be compatible with anything
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   155
     * Special check for FCS of 1.0.
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   156
     */
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   157
    { {  0, -1 }, { -1, -1 } },
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   158
    { { -1, -1 }, {  0, -1 } },
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   159
    /*
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   160
     * 1.2 is runtime compatible with 1.1 -- just make sure to check the
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   161
     * version before using any new 1.2 features
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   162
     */
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   163
    { {  1,  1 }, {  1,  2 } }
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   164
};
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   165
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   166
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
/* Logic to determine JVMTI version compatibility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
compatible_versions(jint major_runtime,     jint minor_runtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    jint major_compiletime, jint minor_compiletime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
{
7978
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   172
    /*
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   173
     * First check to see if versions are explicitly compatible via the
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   174
     * list specified above.
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   175
     */
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   176
    int i;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   177
    for (i = 0; i < nof_compatible_versions; ++i) {
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   178
        version_type runtime = compatible_versions_list[i].runtime;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   179
        version_type comptime = compatible_versions_list[i].compiletime;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   180
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   181
        if ((major_runtime     == runtime.major  || runtime.major  == -1) &&
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   182
            (minor_runtime     == runtime.minor  || runtime.minor  == -1) &&
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   183
            (major_compiletime == comptime.major || comptime.major == -1) &&
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   184
            (minor_compiletime == comptime.minor || comptime.minor == -1)) {
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   185
            return JNI_TRUE;
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   186
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
7978
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   188
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   189
    return major_runtime == major_compiletime &&
120267233d5e 6436034: Instance filter doesn't filter event if it occurs in native method
kamg
parents: 5506
diff changeset
   190
           minor_runtime >= minor_compiletime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
/* OnLoad startup:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *   Returning JNI_ERR will cause the java_g VM to core dump, be careful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    jvmtiCapabilities needed_capabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    jvmtiCapabilities potential_capabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    jint              jvmtiCompileTimeMajorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    jint              jvmtiCompileTimeMinorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    jint              jvmtiCompileTimeMicroVersion;
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   205
    char              *boot_path = NULL;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   206
    char              npt_lib[MAXPATHLEN];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /* See if it's already loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        ERROR_MESSAGE(("Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options."));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /* If gdata is defined and the VM died, why are we here? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    if ( gdata!=NULL && gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        ERROR_MESSAGE(("JDWP unable to load, VM died"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /* Get global data area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    gdata = get_gdata();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    if (gdata == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        ERROR_MESSAGE(("JDWP unable to allocate memory"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    gdata->isLoaded = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /* Start filling in gdata */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    gdata->jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    vmInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    gdata->vmDead = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /* Get the JVMTI Env, IMPORTANT: Do this first! For jvmtiAllocate(). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    error = JVM_FUNC_PTR(vm,GetEnv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                (vm, (void **)&(gdata->jvmti), JVMTI_VERSION_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if (error != JNI_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        ERROR_MESSAGE(("JDWP unable to access JVMTI Version 1 (0x%x),"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                         " is your J2SE a 1.5 or newer version?"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                         " JNIEnv's GetEnv() returned %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                         JVMTI_VERSION_1, error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        forceExit(1); /* Kill entire process, no core dump */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /* Check to make sure the version of jvmti.h we compiled with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *      matches the runtime version we are using.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    jvmtiCompileTimeMajorVersion  = ( JVMTI_VERSION & JVMTI_VERSION_MASK_MAJOR )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                        >> JVMTI_VERSION_SHIFT_MAJOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    jvmtiCompileTimeMinorVersion  = ( JVMTI_VERSION & JVMTI_VERSION_MASK_MINOR )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                        >> JVMTI_VERSION_SHIFT_MINOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    jvmtiCompileTimeMicroVersion  = ( JVMTI_VERSION & JVMTI_VERSION_MASK_MICRO )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                        >> JVMTI_VERSION_SHIFT_MICRO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /* Check for compatibility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if ( !compatible_versions(jvmtiMajorVersion(), jvmtiMinorVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                jvmtiCompileTimeMajorVersion, jvmtiCompileTimeMinorVersion) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        ERROR_MESSAGE(("This jdwp native library will not work with this VM's "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                       "version of JVMTI (%d.%d.%d), it needs JVMTI %d.%d[.%d].",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                       jvmtiMajorVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                       jvmtiMinorVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                       jvmtiMicroVersion(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                       jvmtiCompileTimeMajorVersion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                       jvmtiCompileTimeMinorVersion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                       jvmtiCompileTimeMicroVersion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        /* Do not let VM get a fatal error, we don't want a core dump here. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        forceExit(1); /* Kill entire process, no core dump wanted */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
14698
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   271
    JVMTI_FUNC_PTR(gdata->jvmti, GetSystemProperty)
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   272
        (gdata->jvmti, (const char *)"sun.boot.library.path",
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   273
         &boot_path);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   274
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   275
    dbgsysBuildLibName(npt_lib, sizeof(npt_lib), boot_path, NPT_LIBNAME);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   276
    /* Npt and Utf function init */
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   277
    NPT_INITIALIZE(npt_lib, &(gdata->npt), NPT_VERSION, NULL);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   278
    jvmtiDeallocate(boot_path);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   279
    if (gdata->npt == NULL) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   280
        ERROR_MESSAGE(("JDWP: unable to initialize NPT library"));
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   281
        return JNI_ERR;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   282
    }
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   283
    gdata->npt->utf = (gdata->npt->utfInitialize)(NULL);
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   284
    if (gdata->npt->utf == NULL) {
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   285
        ERROR_MESSAGE(("JDWP: UTF function initialization failed"));
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   286
        return JNI_ERR;
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   287
    }
9294fcf94c46 7200297: agent code does not handle multiple boot library path elements correctly
dholmes
parents: 9035
diff changeset
   288
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /* Parse input options */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if (!parseOptions(options)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /* No message necessary, should have been printed out already */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        /* Do not let VM get a fatal error, we don't want a core dump here. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        forceExit(1); /* Kill entire process, no core dump wanted */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    LOG_MISC(("Onload: %s", options));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* Get potential capabilities */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    (void)memset(&potential_capabilities,0,sizeof(potential_capabilities));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetPotentialCapabilities)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                (gdata->jvmti, &potential_capabilities);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        ERROR_MESSAGE(("JDWP unable to get potential JVMTI capabilities: %s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        jvmtiErrorText(error), error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /* Fill in ones that we must have */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    (void)memset(&needed_capabilities,0,sizeof(needed_capabilities));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    needed_capabilities.can_access_local_variables              = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    needed_capabilities.can_generate_single_step_events         = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    needed_capabilities.can_generate_exception_events           = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    needed_capabilities.can_generate_frame_pop_events           = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    needed_capabilities.can_generate_breakpoint_events          = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    needed_capabilities.can_suspend                             = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    needed_capabilities.can_generate_method_entry_events        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    needed_capabilities.can_generate_method_exit_events         = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    needed_capabilities.can_generate_garbage_collection_events  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    needed_capabilities.can_maintain_original_method_order      = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    needed_capabilities.can_generate_monitor_events             = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    needed_capabilities.can_tag_objects                         = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /* And what potential ones that would be nice to have */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    needed_capabilities.can_force_early_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                = potential_capabilities.can_force_early_return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    needed_capabilities.can_generate_field_modification_events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                = potential_capabilities.can_generate_field_modification_events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    needed_capabilities.can_generate_field_access_events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                = potential_capabilities.can_generate_field_access_events;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    needed_capabilities.can_get_bytecodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                = potential_capabilities.can_get_bytecodes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    needed_capabilities.can_get_synthetic_attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                = potential_capabilities.can_get_synthetic_attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    needed_capabilities.can_get_owned_monitor_info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                = potential_capabilities.can_get_owned_monitor_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    needed_capabilities.can_get_current_contended_monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                = potential_capabilities.can_get_current_contended_monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    needed_capabilities.can_get_monitor_info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                = potential_capabilities.can_get_monitor_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    needed_capabilities.can_pop_frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                = potential_capabilities.can_pop_frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    needed_capabilities.can_redefine_classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                = potential_capabilities.can_redefine_classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    needed_capabilities.can_redefine_any_class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                = potential_capabilities.can_redefine_any_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    needed_capabilities.can_get_owned_monitor_stack_depth_info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        = potential_capabilities.can_get_owned_monitor_stack_depth_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    needed_capabilities.can_get_constant_pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                = potential_capabilities.can_get_constant_pool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        needed_capabilities.can_get_source_debug_extension      = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        needed_capabilities.can_get_source_file_name            = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        needed_capabilities.can_get_line_numbers                = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        needed_capabilities.can_signal_thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                = potential_capabilities.can_signal_thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /* Add the capabilities */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    error = JVMTI_FUNC_PTR(gdata->jvmti,AddCapabilities)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                (gdata->jvmti, &needed_capabilities);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        ERROR_MESSAGE(("JDWP unable to get necessary JVMTI capabilities."));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        forceExit(1); /* Kill entire process, no core dump wanted */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /* Initialize event number mapping tables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    eventIndexInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /* Set the initial JVMTI event notifications */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    error = set_event_notification(JVMTI_ENABLE, EI_VM_DEATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    error = set_event_notification(JVMTI_ENABLE, EI_VM_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    if (initOnUncaught || (initOnException != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        error = set_event_notification(JVMTI_ENABLE, EI_EXCEPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /* Set callbacks just for 3 functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    gdata->callbacks.VMInit             = &cbEarlyVMInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    gdata->callbacks.VMDeath            = &cbEarlyVMDeath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    gdata->callbacks.Exception  = &cbEarlyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        ERROR_MESSAGE(("JDWP unable to set JVMTI event callbacks: %s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        jvmtiErrorText(error), error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return JNI_ERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    LOG_MISC(("OnLoad: DONE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    return JNI_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
Agent_OnUnload(JavaVM *vm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    gdata->isLoaded = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /* Cleanup, but make sure VM is alive before using JNI, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *   make sure JVMTI environment is ok before deallocating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *   memory allocated through JVMTI, which all of it is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Close transport before exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    if (transport_is_open()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        transport_close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 * Phase 2: Initial events. Phase 2 consists of waiting for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 * event that triggers full initialization. Under normal circumstances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 * (initOnStartup == TRUE) this is the JVMTI_EVENT_VM_INIT event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 * Otherwise, we delay initialization until the app throws a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * particular exception. The triggering event invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * the bulk of the initialization, including creation of threads and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * monitors, transport setup, and installation of a new event callback which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 * handles the complete set of events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
 * Since the triggering event comes in on an application thread, some of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 * initialization is difficult to do here. Specifically, this thread along
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 * with all other app threads may need to be suspended until a debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 * connects. These kinds of tasks are left to the third phase which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 * invoked by one of the spawned debugger threads, the event handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
 * Wait for a triggering event; then kick off debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
 * initialization. A different event callback will be installed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 * debugger initialization, and this function will not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 * again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * TO DO: Decide whether we need to protect this code with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * a lock. It might be too early to create a monitor safely (?).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
cbEarlyVMInit(jvmtiEnv *jvmti_env, JNIEnv *env, jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    LOG_CB(("cbEarlyVMInit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"VM dead at VM_INIT time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    if (initOnStartup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        initialize(env, thread, EI_VM_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    vmInitialized = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    LOG_MISC(("END cbEarlyVMInit"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
disposeEnvironment(jvmtiEnv *jvmti_env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    error = JVMTI_FUNC_PTR(jvmti_env,DisposeEnvironment)(jvmti_env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    if ( error == JVMTI_ERROR_MUST_POSSESS_CAPABILITY )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        error = JVMTI_ERROR_NONE;  /* Hack!  FIXUP when JVMTI has disposeEnv */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /* What should error return say? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        ERROR_MESSAGE(("JDWP unable to dispose of JVMTI environment: %s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        jvmtiErrorText(error), error));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    gdata->jvmti = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
cbEarlyVMDeath(jvmtiEnv *jvmti_env, JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    LOG_CB(("cbEarlyVMDeath"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"VM died more than once");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    disposeEnvironment(jvmti_env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    gdata->jvmti = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    gdata->jvm = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    gdata->vmDead = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    LOG_MISC(("END cbEarlyVMDeath"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
static void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
cbEarlyException(jvmtiEnv *jvmti_env, JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        jthread thread, jmethodID method, jlocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        jobject exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        jmethodID catch_method, jlocation catch_location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    jthrowable currentException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    LOG_CB(("cbEarlyException: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"VM dead at initial Exception event");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    if (!vmInitialized)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        LOG_MISC(("VM is not initialized yet"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * We want to preserve any current exception that might get wiped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * out during event handling (e.g. JNI calls). We have to rely on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * space for the local reference on the current frame because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * doing a PushLocalFrame here might itself generate an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    currentException = JNI_FUNC_PTR(env,ExceptionOccurred)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    if (initOnUncaught && catch_method == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        LOG_MISC(("Initializing on uncaught exception"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        initialize(env, thread, EI_EXCEPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    } else if (initOnException != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        /* Get class of exception thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, exception);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if ( clazz != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            char *signature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            /* initing on throw, check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            error = classSignature(clazz, &signature, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            LOG_MISC(("Checking specific exception: looking for %s, got %s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                        initOnException, signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            if ( (error==JVMTI_ERROR_NONE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                (strcmp(signature, initOnException) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                LOG_MISC(("Initializing on specific exception"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                initialize(env, thread, EI_EXCEPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                error = AGENT_ERROR_INTERNAL; /* Just to cause restore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if ( signature != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                jvmtiDeallocate(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            error = AGENT_ERROR_INTERNAL; /* Just to cause restore */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        /* If initialize didn't happen, we need to restore things */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
             * Restore exception state from before callback call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            LOG_MISC(("No initialization, didn't find right exception"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (currentException != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                JNI_FUNC_PTR(env,Throw)(env, currentException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                JNI_FUNC_PTR(env,ExceptionClear)(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    LOG_MISC(("END cbEarlyException"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
typedef struct EnumerateArg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    jboolean isServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    jdwpError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jint startCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
} EnumerateArg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
startTransport(void *item, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    TransportSpec *transport = item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    EnumerateArg *enumArg = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    jdwpError serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    LOG_MISC(("Begin startTransport"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    serror = transport_startTransport(enumArg->isServer, transport->name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                     transport->address, transport->timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if (serror != JDWP_ERROR(NONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        ERROR_MESSAGE(("JDWP Transport %s failed to initialize, %s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                transport->name, jdwpErrorText(serror), serror));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        enumArg->error = serror;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        /* (Don't overwrite any previous error) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        enumArg->startCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    LOG_MISC(("End startTransport"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    return JNI_TRUE;   /* Always continue, even if there was an error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
signalInitComplete(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Initialization is complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    LOG_MISC(("signal initialization complete"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    debugMonitorEnter(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    initComplete = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    debugMonitorNotifyAll(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    debugMonitorExit(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
 * Determine if  initialization is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
debugInit_isInitComplete(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    return initComplete;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 * Wait for all initialization to complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
debugInit_waitInitComplete(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    debugMonitorEnter(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    while (!initComplete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        debugMonitorWait(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    debugMonitorExit(initMonitor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
/* All process exit() calls come from here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
forceExit(int exit_code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /* make sure the transport is closed down before we exit() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    transport_close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    exit(exit_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
/* All JVM fatal error exits lead here (e.g. we need to kill the VM). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
jniFatalError(JNIEnv *env, const char *msg, jvmtiError error, int exit_code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    JavaVM *vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    char buf[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    gdata->vmDead = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    if ( msg==NULL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        msg = "UNKNOWN REASON";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    vm = gdata->jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    if ( env==NULL && vm!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        jint rc = (*((*vm)->GetEnv))(vm, (void **)&env, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (rc != JNI_OK ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            env = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        (void)snprintf(buf, sizeof(buf), "JDWP %s, jvmtiError=%s(%d)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    msg, jvmtiErrorText(error), error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        (void)snprintf(buf, sizeof(buf), "JDWP %s", buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    if (env != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        (*((*env)->FatalError))(env, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        /* Should rarely ever reach here, means VM is really dead */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        print_message(stderr, "ERROR: JDWP: ", "\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                "Can't call JNI FatalError(NULL, \"%s\")", buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    forceExit(exit_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
 * Initialize debugger back end modules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
initialize(JNIEnv *env, jthread thread, EventIndex triggering_ei)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    EnumerateArg arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    jbyte suspendPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    LOG_MISC(("Begin initialize()"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    currentSessionID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    initComplete = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"VM dead at initialize() time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /* Turn off the initial JVMTI event notifications */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    error = set_event_notification(JVMTI_DISABLE, EI_EXCEPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        EXIT_ERROR(error, "unable to disable JVMTI event notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    error = set_event_notification(JVMTI_DISABLE, EI_VM_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        EXIT_ERROR(error, "unable to disable JVMTI event notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    error = set_event_notification(JVMTI_DISABLE, EI_VM_DEATH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        EXIT_ERROR(error, "unable to disable JVMTI event notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /* Remove initial event callbacks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    (void)memset(&(gdata->callbacks),0,sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    error = JVMTI_FUNC_PTR(gdata->jvmti,SetEventCallbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                (gdata->jvmti, &(gdata->callbacks), sizeof(gdata->callbacks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        EXIT_ERROR(error, "unable to clear JVMTI callbacks");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    commonRef_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    util_initialize(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    threadControl_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    stepControl_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    invoker_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    debugDispatch_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    classTrack_initialize(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    debugLoop_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    initMonitor = debugMonitorCreate("JDWP Initialization Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Initialize transports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    arg.isServer = isServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    arg.error = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    arg.startCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    transport_initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    (void)bagEnumerateOver(transports, startTransport, &arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * Exit with an error only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * 1) none of the transports was successfully started, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * 2) the application has not yet started running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    if ((arg.error != JDWP_ERROR(NONE)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        (arg.startCount == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        initOnStartup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        EXIT_ERROR(map2jvmtiError(arg.error), "No transports initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    eventHandler_initialize(currentSessionID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    signalInitComplete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    transport_waitForConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    suspendPolicy = suspendOnInit ? JDWP_SUSPEND_POLICY(ALL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                  : JDWP_SUSPEND_POLICY(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    if (triggering_ei == EI_VM_INIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        LOG_MISC(("triggering_ei == EI_VM_INIT"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        eventHelper_reportVMInit(env, currentSessionID, thread, suspendPolicy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         * TO DO: Kludgy way of getting the triggering event to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         * just-attached debugger. It would be nice to make this a little
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         * cleaner. There is also a race condition where other events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
         * can get in the queue (from other not-yet-suspended threads)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         * before this one does. (Also need to handle allocation error below?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        EventInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        struct bag *initEventBag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        LOG_MISC(("triggering_ei != EI_VM_INIT"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        initEventBag = eventHelper_createEventBag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        (void)memset(&info,0,sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        info.ei = triggering_ei;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        eventHelper_recordEvent(&info, 0, suspendPolicy, initEventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        (void)eventHelper_reportEvents(currentSessionID, initEventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        bagDestroyBag(initEventBag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    if ( gdata->vmDead ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        EXIT_ERROR(AGENT_ERROR_INTERNAL,"VM dead before initialize() completes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    LOG_MISC(("End initialize()"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
 * Restore all static data to the initialized state so that another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
 * debugger can connect properly later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
debugInit_reset(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    EnumerateArg arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    LOG_MISC(("debugInit_reset() beginning"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    currentSessionID++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    initComplete = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    eventHandler_reset(currentSessionID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    transport_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    debugDispatch_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    invoker_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    stepControl_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    threadControl_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    util_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    commonRef_reset(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    classTrack_reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * If this is a server, we are now ready to accept another connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * If it's a client, then we've cleaned up some (more should be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * later) and we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    if (isServer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        arg.isServer = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        arg.error = JDWP_ERROR(NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        arg.startCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        (void)bagEnumerateOver(transports, startTransport, &arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        signalInitComplete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        transport_waitForConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        signalInitComplete(); /* Why? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    LOG_MISC(("debugInit_reset() completed."));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
debugInit_launchOnInit(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    return launchOnInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
debugInit_suspendOnInit(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    return suspendOnInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
 * code below is shamelessly swiped from hprof.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
get_tok(char **src, char *buf, int buflen, char sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    char *p = *src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    for (i = 0; i < buflen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        if (p[i] == 0 || p[i] == sep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            buf[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            if (p[i] == sep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            *src += i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        buf[i] = p[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    /* overflow */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
printUsage(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     TTY_MESSAGE((
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
 "               Java Debugger JDWP Agent Library\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
 "               --------------------------------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
 "  (see http://java.sun.com/products/jpda for more information)\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 "jdwp usage: java " AGENTLIB "=[help]|[<option>=<value>, ...]\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
 "Option Name and Value            Description                       Default\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
 "---------------------            -----------                       -------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 "suspend=y|n                      wait on startup?                  y\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 "transport=<name>                 transport spec                    none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 "address=<listen/attach address>  transport spec                    \"\"\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 "server=y|n                       listen for debugger?              n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
 "launch=<command line>            run debugger on event             none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
 "onthrow=<exception name>         debug on throw                    none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
 "onuncaught=y|n                   debug on any uncaught?            n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
 "timeout=<timeout value>          for listen/attach in milliseconds n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
 "mutf8=y|n                        output modified utf-8             n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
 "quiet=y|n                        control over terminal messages    n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
 "Obsolete Options\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 "----------------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
 "strict=y|n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
 "stdalloc=y|n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
 "Examples\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
 "--------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
 "  - Using sockets connect to a debugger at a specific address:\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
 "    java " AGENTLIB "=transport=dt_socket,address=localhost:8000 ...\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
 "  - Using sockets listen for a debugger to attach:\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
 "    java " AGENTLIB "=transport=dt_socket,server=y,suspend=y ...\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
 "Notes\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
 "-----\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
 "  - A timeout value of 0 (the default) is no timeout.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 "Warnings\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 "--------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 "  - The older " XRUN " interface can still be used, but will be removed in\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 "    a future release, for example:\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 "        java " XDEBUG " " XRUN ":[help]|[<option>=<value>, ...]\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     TTY_MESSAGE((
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
 "Debugging Options            Description                       Default\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
 "-----------------            -----------                       -------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
 "pause=y|n                    pause to debug PID                n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
 "coredump=y|n                 coredump at exit                  n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
 "errorexit=y|n                exit on any error                 n\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
 "logfile=filename             name of log file                  none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
 "logflags=flags               log flags (bitmask)               none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
 "                               JVM calls     = 0x001\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
 "                               JNI calls     = 0x002\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
 "                               JVMTI calls   = 0x004\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 "                               misc events   = 0x008\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 "                               step logs     = 0x010\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
 "                               locations     = 0x020\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
 "                               callbacks     = 0x040\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
 "                               errors        = 0x080\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 "                               everything    = 0xfff\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
 "debugflags=flags             debug flags (bitmask)           none\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
 "                               USE_ITERATE_THROUGH_HEAP 0x01\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
 "\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
 "Environment Variables\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
 "---------------------\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
 "_JAVA_JDWP_OPTIONS\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
 "    Options can be added externally via this environment variable.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 "    Anything contained in it will get a comma prepended to it (if needed),\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 "    then it will be added to the end of the options supplied via the\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
 "    " XRUN " or " AGENTLIB " command line option.\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
static jboolean checkAddress(void *bagItem, void *arg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    TransportSpec *spec = (TransportSpec *)bagItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    if (spec->address == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        ERROR_MESSAGE(("JDWP Non-server transport %s must have a connection "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                "address specified through the 'address=' option",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                spec->name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
static  char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
add_to_options(char *options, char *new_options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    size_t originalLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    char *combinedOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Allocate enough space for both strings and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * comma in between.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    originalLength = strlen(options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    combinedOptions = jvmtiAllocate((jint)originalLength + 1 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                (jint)strlen(new_options) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    if (combinedOptions == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    (void)strcpy(combinedOptions, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    (void)strcat(combinedOptions, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    (void)strcat(combinedOptions, new_options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    return combinedOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
get_boolean(char **pstr, jboolean *answer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    char buf[80];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    *answer = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    if (get_tok(pstr, buf, (int)sizeof(buf), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        if (strcmp(buf, "y") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            *answer = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        } else if (strcmp(buf, "n") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            *answer = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
/* atexit() callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
atexit_finish_logging(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    /* Normal exit(0) (not _exit()) may only reach here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    finish_logging(0);  /* Only first call matters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
parseOptions(char *options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    TransportSpec *currentTransport = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    char *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    char *current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    char *str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    char *errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /* Set defaults */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    gdata->assertOn     = DEFAULT_ASSERT_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    gdata->assertFatal  = DEFAULT_ASSERT_FATAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    logfile             = DEFAULT_LOGFILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /* Options being NULL will end up being an error. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    if (options == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        options = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /* Check for "help" BEFORE we add any environmental settings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    if ((strcmp(options, "help")) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        printUsage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        forceExit(0); /* Kill entire process, no core dump wanted */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    /* These buffers are never freed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        char *envOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * Add environmentally specified options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        envOptions = getenv("_JAVA_JDWP_OPTIONS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        if (envOptions != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            options = add_to_options(options, envOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            if ( options==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
         * Allocate a buffer for names derived from option strings. It should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
         * never be longer than the original options string itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
         * Also keep a copy of the options in gdata->options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        length = (int)strlen(options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        gdata->options = jvmtiAllocate(length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (gdata->options == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        (void)strcpy(gdata->options, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        names = jvmtiAllocate(length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        if (names == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        transports = bagCreateBag(sizeof(TransportSpec), 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        if (transports == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"transports");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    current = names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    end = names + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    str = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    while (*str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        char buf[100];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if (!get_tok(&str, buf, (int)sizeof(buf), '=')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        if (strcmp(buf, "transport") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            currentTransport = bagAdd(transports);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            currentTransport->name = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        } else if (strcmp(buf, "address") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (currentTransport == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                errmsg = "address specified without transport";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            currentTransport->address = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        } else if (strcmp(buf, "timeout") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            if (currentTransport == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                errmsg = "timeout specified without transport";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            currentTransport->timeout = atol(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        } else if (strcmp(buf, "launch") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            launchOnInit = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        } else if (strcmp(buf, "onthrow") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            /* Read class name and convert in place to a signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            *current = 'L';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            if (!get_tok(&str, current + 1, (int)(end - current - 1), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            initOnException = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            while (*current != '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                if (*current == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    *current = '/';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            *current++ = ';';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            *current++ = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        } else if (strcmp(buf, "assert") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            if (strcmp(current, "y") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                gdata->assertOn = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                gdata->assertFatal = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            } else if (strcmp(current, "fatal") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                gdata->assertOn = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                gdata->assertFatal = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            } else if (strcmp(current, "n") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                gdata->assertOn = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                gdata->assertFatal = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        } else if (strcmp(buf, "pause") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            if ( !get_boolean(&str, &dopause) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if ( dopause ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                do_pause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        } else if (strcmp(buf, "coredump") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            if ( !get_boolean(&str, &docoredump) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        } else if (strcmp(buf, "errorexit") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            if ( !get_boolean(&str, &(gdata->doerrorexit)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        } else if (strcmp(buf, "exitpause") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            errmsg = "The exitpause option removed, use -XX:OnError";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        } else if (strcmp(buf, "precrash") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            errmsg = "The precrash option removed, use -XX:OnError";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        } else if (strcmp(buf, "logfile") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            logfile = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            current += strlen(current) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        } else if (strcmp(buf, "logflags") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            logflags = (unsigned)strtol(current, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        } else if (strcmp(buf, "debugflags") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            if (!get_tok(&str, current, (int)(end - current), ',')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            gdata->debugflags = (unsigned)strtol(current, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        } else if ( strcmp(buf, "suspend")==0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            if ( !get_boolean(&str, &suspendOnInit) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        } else if ( strcmp(buf, "server")==0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            if ( !get_boolean(&str, &isServer) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        } else if ( strcmp(buf, "strict")==0 ) { /* Obsolete, but accept it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            if ( !get_boolean(&str, &isStrict) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        } else if ( strcmp(buf, "quiet")==0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            if ( !get_boolean(&str, &(gdata->quiet)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        } else if ( strcmp(buf, "onuncaught")==0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            if ( !get_boolean(&str, &initOnUncaught) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        } else if ( strcmp(buf, "mutf8")==0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            if ( !get_boolean(&str, &(gdata->modifiedUtf8)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        } else if ( strcmp(buf, "stdalloc")==0 ) { /* Obsolete, but accept it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            if ( !get_boolean(&str, &useStandardAlloc) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            goto syntax_error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    /* Setup logging now */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    if ( logfile!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        setup_logging(logfile, logflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        (void)atexit(&atexit_finish_logging);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    if (bagSize(transports) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        errmsg = "no transport specified";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * TO DO: Remove when multiple transports are allowed. (replace with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * check below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    if (bagSize(transports) > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        errmsg = "multiple transports are not supported in this release";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    if (!isServer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        jboolean specified = bagEnumerateOver(transports, checkAddress, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        if (!specified) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            /* message already printed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            goto bad_option_no_msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * The user has selected to wait for an exception before init happens
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    if ((initOnException != NULL) || (initOnUncaught)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        initOnStartup = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        if (launchOnInit == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
             * These rely on the launch=/usr/bin/foo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
             * suboption, so it is an error if user did not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
             * provide one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            errmsg = "Specify launch=<command line> when using onthrow or onuncaught suboption";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            goto bad_option_with_errmsg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
syntax_error:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    ERROR_MESSAGE(("JDWP option syntax error: %s=%s", AGENTLIB, options));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
bad_option_with_errmsg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    ERROR_MESSAGE(("JDWP %s: %s=%s", errmsg, AGENTLIB, options));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
bad_option_no_msg:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    ERROR_MESSAGE(("JDWP %s: %s=%s", "invalid option", AGENTLIB, options));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
/* All normal exit doors lead here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
debugInit_exit(jvmtiError error, const char *msg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    int exit_code = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /* Pick an error code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    if ( error != JVMTI_ERROR_NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        exit_code = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        if ( docoredump ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            finish_logging(exit_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            abort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    if ( msg==NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        msg = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    LOG_MISC(("Exiting with error %s(%d): %s", jvmtiErrorText(error), error, msg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    gdata->vmDead = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    /* Let's try and cleanup the JVMTI, if we even have one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    if ( gdata->jvmti != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        /* Dispose of jvmti (gdata->jvmti becomes NULL) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        disposeEnvironment(gdata->jvmti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    /* Finish up logging. We reach here if JDWP is doing the exiting. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    finish_logging(exit_code);  /* Only first call matters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    /* Let's give the JNI a FatalError if non-exit 0, which is historic way */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    if ( exit_code != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        JNIEnv *env = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        jniFatalError(env, msg, error, exit_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    /* Last chance to die, this kills the entire process. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    forceExit(exit_code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
}