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