jdk/src/share/back/stepControl.c
author ohair
Fri, 22 Aug 2008 12:24:27 -0700
changeset 1090 c5805b1672a6
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6732421: Removed old javavm and Classic VM files from the jdk7 sources Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "stepControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "eventHandler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "eventHelper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "threadControl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "SDE.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
static jrawMonitorID stepLock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
getFrameCount(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    jint count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                    (gdata->jvmti, thread, &count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        EXIT_ERROR(error, "getting frame count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Most enabling/disabling of JVMTI events happens implicitly through
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the inserting and freeing of handlers for those events. Stepping is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * different because requested steps are usually not identical to JVMTI steps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * They usually require multiple events step, and otherwise, before they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * complete. While a step request is pending, we may need to temporarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * disable and re-enable stepping, but we can't just remove the handlers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * because that would break the application's ability to remove the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * events. So, for step events only, we directly enable and disable stepping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * This is safe because there can only ever be one pending step request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * per thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
enableStepping(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    LOG_STEP(("enableStepping: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    error = threadControl_setEventMode(JVMTI_ENABLE, EI_SINGLE_STEP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                            thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        EXIT_ERROR(error, "enabling single step");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
disableStepping(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    LOG_STEP(("disableStepping: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    error = threadControl_setEventMode(JVMTI_DISABLE, EI_SINGLE_STEP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                            thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        EXIT_ERROR(error, "disabling single step");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
getFrameLocation(jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        jclass *pclazz, jmethodID *pmethod, jlocation *plocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    *pclazz = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    *pmethod = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    *plocation = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            (gdata->jvmti, thread, 0, pmethod, plocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    if (error == JVMTI_ERROR_NONE && *pmethod!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        /* This also serves to verify that the methodID is valid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        error = methodClass(*pmethod, pclazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
getLineNumberTable(jmethodID method, jint *pcount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                jvmtiLineNumberEntry **ptable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    *pcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    *ptable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /* If the method is native or obsolete, don't even ask for the line table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    if ( isMethodObsolete(method) || isMethodNative(method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLineNumberTable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                (gdata->jvmti, method, pcount, ptable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        *pcount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
static jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
findLineNumber(jthread thread, jlocation location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
               jvmtiLineNumberEntry *lines, jint count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    jint line = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (location != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            jint i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            /* any preface before first line is assigned to first line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            for (i=1; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (location < lines[i].start_location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            line = lines[i-1].line_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    return line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
hasLineNumbers(jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    jint count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    jvmtiLineNumberEntry *table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    getLineNumberTable(method, &count, &table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if ( count == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        jvmtiDeallocate(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
static jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
initState(JNIEnv *env, jthread thread, StepRequest *step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Initial values that may be changed below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    step->fromLine = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    step->fromNative = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    step->frameExited = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    step->fromStackDepth = getFrameCount(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (step->fromStackDepth <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * If there are no stack frames, treat the step as though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * from a native frame. This is most likely to occur at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * beginning of a debug session, right after the VM_INIT event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * so we need to do something intelligent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        step->fromNative = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Try to get a notification on frame pop. If we're in an opaque frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * we won't be able to, but we can use other methods to detect that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * a native frame has exited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * TO DO: explain the need for this notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    error = JVMTI_FUNC_PTR(gdata->jvmti,NotifyFramePop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                (gdata->jvmti, thread, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    if (error == JVMTI_ERROR_OPAQUE_FRAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        step->fromNative = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        /* continue without error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    } else if (error == JVMTI_ERROR_DUPLICATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        /* Already being notified, continue without error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    } else if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    LOG_STEP(("initState(): frame=%d", step->fromStackDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Note: we can't undo the frame pop notify, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * we'll just have to let the handler ignore it if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * there are any errors below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (step->granularity == JDWP_STEP_SIZE(LINE) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        LOG_STEP(("initState(): Begin line step"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            error = getFrameLocation(thread, &clazz, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                /* Clear out previous line table only if we changed methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                if ( method != step->method ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    step->lineEntryCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    if (step->lineEntries != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        jvmtiDeallocate(step->lineEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        step->lineEntries = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    step->method = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    getLineNumberTable(step->method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                 &step->lineEntryCount, &step->lineEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    if (step->lineEntryCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        convertLineNumberTable(env, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                &step->lineEntryCount, &step->lineEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                step->fromLine = findLineNumber(thread, location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                     step->lineEntries, step->lineEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * TO DO: The step handlers (handleFrameChange and handleStep can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * be broken down and made simpler now that we can install and de-install event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
handleFramePopEvent(JNIEnv *env, EventInfo *evinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    jthread thread = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if (step == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting step request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (step->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * Note: current depth is reported as *before* the pending frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         * pop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        jint currentDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        jint fromDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        jint afterPopDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        currentDepth = getFrameCount(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        fromDepth = step->fromStackDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        afterPopDepth = currentDepth-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        LOG_STEP(("handleFramePopEvent: BEGIN fromDepth=%d, currentDepth=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        fromDepth, currentDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * If we are exiting the original stepping frame, record that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         * fact here. Once the next step event comes in, we can safely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         * stop stepping there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (fromDepth > afterPopDepth ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            step->frameExited = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (step->depth == JDWP_STEP_DEPTH(OVER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
             * Either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
             * 1) the original stepping frame is about to be popped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
             *    [fromDepth == currentDepth]. Re-enable stepping to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
             *    reach a point where we can stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
             * 2) a method called from the stepping frame has returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
             *    (during which we had stepping disabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
             *    [fromDepth == currentDepth - 1]. Re-enable stepping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
             *    so that we can continue instructions steps in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             *    original stepping frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
             * 3) a method further down the call chain has notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
             *    of a frame pop [fromDepth < currentDepth - 1]. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             *    *might* represent case (2) above if the stepping frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
             *    was calling a native method which in turn called a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             *    java method. If so, we must enable stepping to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
             *    ensure that we get control back after the intervening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
             *    native frame is popped (you can't get frame pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             *    notifications on native frames). If the native caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
             *    calls another Java method before returning,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
             *    stepping will be diabled again and another frame pop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
             *    will be awaited.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
             *    If it turns out that this is not case (2) with native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
             *    methods, then the enabled stepping is benign and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
             *    will be disabled again on the next step event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
             * Note that the condition not covered above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
             * [fromDepth > currentDepth] shouldn't happen since it means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
             * that too many frames have been popped. For robustness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
             * we enable stepping in that case too, so that the errant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
             * step-over can be stopped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            LOG_STEP(("handleFramePopEvent: starting singlestep, depth==OVER"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        } else if (step->depth == JDWP_STEP_DEPTH(OUT) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                   fromDepth > afterPopDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
             * The original stepping frame is about to be popped. Step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
             * until we reach the next safe place to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            LOG_STEP(("handleFramePopEvent: starting singlestep, depth==OUT && fromDepth > afterPopDepth (%d>%d)",fromDepth, afterPopDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        } else if (step->methodEnterHandlerNode != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                   fromDepth >= afterPopDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
             * We installed a method entry event handler as part of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
             * step into operation. We've popped back to the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
             * stepping frame without finding a place to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
             * Resume stepping in the original frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            LOG_STEP(("handleFramePopEvent: starting singlestep, have methodEnter handler && depth==OUT && fromDepth >= afterPopDepth (%d>%d)",fromDepth, afterPopDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            (void)eventHandler_free(step->methodEnterHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        LOG_STEP(("handleFramePopEvent: finished"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
handleExceptionCatchEvent(JNIEnv *env, EventInfo *evinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                          HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                          struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    jthread thread = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    if (step == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting step request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    if (step->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         *  Determine where we are on the call stack relative to where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         *  we started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        jint currentDepth = getFrameCount(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        jint fromDepth = step->fromStackDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        LOG_STEP(("handleExceptionCatchEvent: fromDepth=%d, currentDepth=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        fromDepth, currentDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * If we are exiting the original stepping frame, record that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * fact here. Once the next step event comes in, we can safely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * stop stepping there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (fromDepth > currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            step->frameExited = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (step->depth == JDWP_STEP_DEPTH(OVER) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            fromDepth >= currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
             * Either the original stepping frame is done,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
             * or a called method has returned (during which we had stepping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
             * disabled). In either case we must resume stepping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } else if (step->depth == JDWP_STEP_DEPTH(OUT) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                   fromDepth > currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
             * The original stepping frame is done. Step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
             * until we reach the next safe place to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } else if (step->methodEnterHandlerNode != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                   fromDepth >= currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
             * We installed a method entry event handler as part of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
             * step into operation. We've popped back to the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
             * stepping frame or higher without finding a place to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             * Resume stepping in the original frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            (void)eventHandler_free(step->methodEnterHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
handleMethodEnterEvent(JNIEnv *env, EventInfo *evinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                       HandlerNode *node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                       struct bag *eventBag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    jthread thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    thread = evinfo->thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    if (step == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting step request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    if (step->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        jclass    clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        char     *classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        LOG_STEP(("handleMethodEnterEvent: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        clazz     = evinfo->clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        method    = evinfo->method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        classname = getClassname(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * This handler is relevant only to step into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        JDI_ASSERT(step->depth == JDWP_STEP_DEPTH(INTO));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (    (!eventFilter_predictFiltering(step->stepHandlerNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                               clazz, classname))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
             && (   step->granularity != JDWP_STEP_SIZE(LINE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                 || hasLineNumbers(method) ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
             * We've found a suitable method in which to stop. Step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
             * until we reach the next safe location to complete the step->,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
             * and we can get rid of the method entry handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if ( step->methodEnterHandlerNode != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                (void)eventHandler_free(step->methodEnterHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        jvmtiDeallocate(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        classname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
completeStep(JNIEnv *env, jthread thread, StepRequest *step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * We've completed a step; reset state for the next one, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    LOG_STEP(("completeStep: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    if (step->methodEnterHandlerNode != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        (void)eventHandler_free(step->methodEnterHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    error = initState(env, thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         * None of the initState errors should happen after one step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * has successfully completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        EXIT_ERROR(error, "initializing step state");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
stepControl_handleStep(JNIEnv *env, jthread thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                       jclass clazz, jmethodID method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    jboolean completed = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    jint currentDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    jint fromDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    char *classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    classname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    if (step == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting step request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * If no step is currently pending, ignore the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    if (!step->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    LOG_STEP(("stepControl_handleStep: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * We never filter step into instruction. It's always over on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * first step event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    if (step->depth == JDWP_STEP_DEPTH(INTO) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        step->granularity == JDWP_STEP_SIZE(MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        LOG_STEP(("stepControl_handleStep: completed, into min"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        goto done;
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
     * If we have left the method in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * stepping started, the step is always complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    if (step->frameExited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        LOG_STEP(("stepControl_handleStep: completed, frame exited"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        goto done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *  Determine where we are on the call stack relative to where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *  we started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    currentDepth = getFrameCount(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    fromDepth = step->fromStackDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    if (fromDepth > currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         * We have returned from the caller. There are cases where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
         * we don't get frame pop notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * (e.g. stepping from opaque frames), and that's when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * this code will be reached. Complete the step->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        LOG_STEP(("stepControl_handleStep: completed, fromDepth>currentDepth(%d>%d)", fromDepth, currentDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    } else if (fromDepth < currentDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        /* We have dropped into a called method. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (   step->depth == JDWP_STEP_DEPTH(INTO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            && (!eventFilter_predictFiltering(step->stepHandlerNode, clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                          (classname = getClassname(clazz))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            && hasLineNumbers(method) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            /* Stepped into a method with lines, so we're done */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            LOG_STEP(("stepControl_handleStep: completed, fromDepth<currentDepth(%d<%d) and into method with lines", fromDepth, currentDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
             * We need to continue, but don't want the overhead of step
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
             * events from this method. So, we disable stepping and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
             * enable a frame pop. If we're stepping into, we also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
             * enable method enter events because a called frame may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
             * where we want to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            disableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if (step->depth == JDWP_STEP_DEPTH(INTO)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                step->methodEnterHandlerNode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    eventHandler_createInternalThreadOnly(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                       EI_METHOD_ENTRY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                       handleMethodEnterEvent, thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                if (step->methodEnterHandlerNode == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                                "installing event method enter handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            error = JVMTI_FUNC_PTR(gdata->jvmti,NotifyFramePop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        (gdata->jvmti, thread, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            if (error == JVMTI_ERROR_DUPLICATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            } else if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                EXIT_ERROR(error, "setting up notify frame pop");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        jvmtiDeallocate(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        classname = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         * We are at the same stack depth where stepping started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * Instruction steps are complete at this point. For line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * steps we must check to see whether we've moved to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * different line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (step->granularity == JDWP_STEP_SIZE(MIN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            LOG_STEP(("stepControl_handleStep: completed, fromDepth==currentDepth(%d) and min", fromDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            if (step->fromLine != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                jint line = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                jlocation location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                jmethodID method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                WITH_LOCAL_REFS(env, 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    error = getFrameLocation(thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                        &clazz, &method, &location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                    if ( isMethodObsolete(method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        method = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        location = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    if (error != JVMTI_ERROR_NONE || location == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                        EXIT_ERROR(error, "getting frame location");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    if ( method == step->method ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                        LOG_STEP(("stepControl_handleStep: checking line location"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                        log_debugee_location("stepControl_handleStep: checking line loc",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                thread, method, location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                        line = findLineNumber(thread, location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                                      step->lineEntries, step->lineEntryCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    if (line != step->fromLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                        completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        LOG_STEP(("stepControl_handleStep: completed, fromDepth==currentDepth(%d) and different line", fromDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                } END_WITH_LOCAL_REFS(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                 * This is a rare case. We have stepped from a location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                 * inside a native method to a location within a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                 * method at the same stack depth. This means that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                 * the original native method returned to another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                 * native method which, in turn, invoked a Java method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                 * Since the original frame was  native, we were unable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                 * to ask for a frame pop event, and, thus, could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                 * set the step->frameExited flag when the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                 * method was done. Instead we end up here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                 * and act just as though the frameExited flag was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                 * and complete the step immediately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                completed = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                LOG_STEP(("stepControl_handleStep: completed, fromDepth==currentDepth(%d) and no line", fromDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        LOG_STEP(("stepControl_handleStep: finished"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
done:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    if (completed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        completeStep(env, thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    return completed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
stepControl_initialize(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    stepLock = debugMonitorCreate("JDWP Step Handler Lock");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
stepControl_reset(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 * Reset step control request stack depth and line number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
stepControl_resetRequest(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    LOG_STEP(("stepControl_resetRequest: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    if (step != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        env = getEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        error = initState(env, thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        if (error != JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            EXIT_ERROR(error, "initializing step state");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        EXIT_ERROR(AGENT_ERROR_INVALID_THREAD, "getting step request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
initEvents(jthread thread, StepRequest *step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /* Need to install frame pop handler and exception catch handler when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * single-stepping is enabled (i.e. step-into or step-over/step-out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * when fromStackDepth > 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    if (step->depth == JDWP_STEP_DEPTH(INTO) || step->fromStackDepth > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         * TO DO: These might be able to applied more selectively to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
         * boost performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        step->catchHandlerNode = eventHandler_createInternalThreadOnly(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                                     EI_EXCEPTION_CATCH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                     handleExceptionCatchEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                     thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        step->framePopHandlerNode = eventHandler_createInternalThreadOnly(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                        EI_FRAME_POP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                        handleFramePopEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                                        thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        if (step->catchHandlerNode == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            step->framePopHandlerNode == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                        "installing step event handlers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Initially enable stepping:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * 1) For step into, always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * 2) For step over, unless right after the VM_INIT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *    Enable stepping for STEP_MIN or STEP_LINE with or without line numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *    If the class is redefined then non EMCP methods may not have line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *    number info. So enable line stepping for non line number so that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *    behaves like STEP_MIN/STEP_OVER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * 3) For step out, only if stepping from native, except right after VM_INIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * (right after VM_INIT, a step->over or out is identical to running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * forever)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    switch (step->depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        case JDWP_STEP_DEPTH(INTO):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        case JDWP_STEP_DEPTH(OVER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            if (step->fromStackDepth > 0 && !step->fromNative ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
              enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        case JDWP_STEP_DEPTH(OUT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            if (step->fromNative &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                (step->fromStackDepth > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                enableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            JDI_ASSERT(JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
stepControl_beginStep(JNIEnv *env, jthread thread, jint size, jint depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                      HandlerNode *node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    jvmtiError error2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    LOG_STEP(("stepControl_beginStep: thread=%p,size=%d,depth=%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        thread, size, depth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    eventHandler_lock(); /* for proper lock order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    if (step == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        error = AGENT_ERROR_INVALID_THREAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        /* Normally not getting a StepRequest struct pointer is a fatal error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         *   but on a beginStep, we just return an error code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         * In case the thread isn't already suspended, do it again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        error = threadControl_suspendThread(thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
             * Overwrite any currently executing step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            step->granularity = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            step->depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            step->catchHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            step->framePopHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            step->stepHandlerNode = node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            error = initState(env, thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                initEvents(thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            /* false means it is not okay to unblock the commandLoop thread */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            error2 = threadControl_resumeThread(thread, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            if (error2 != JVMTI_ERROR_NONE && error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                error = error2;
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
             * If everything went ok, indicate a step is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            if (error == JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                step->pending = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            EXIT_ERROR(error, "stepControl_beginStep: cannot suspend thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    eventHandler_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
clearStep(jthread thread, StepRequest *step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    if (step->pending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        disableStepping(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        if ( step->catchHandlerNode != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            (void)eventHandler_free(step->catchHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            step->catchHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        if ( step->framePopHandlerNode!= NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            (void)eventHandler_free(step->framePopHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            step->framePopHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if ( step->methodEnterHandlerNode != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            (void)eventHandler_free(step->methodEnterHandlerNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            step->methodEnterHandlerNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        step->pending = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * Warning: Do not clear step->method, step->lineEntryCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         *          or step->lineEntries here, they will likely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         *          be needed on the next step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
jvmtiError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
stepControl_endStep(jthread thread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    StepRequest *step;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    jvmtiError error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    LOG_STEP(("stepControl_endStep: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    eventHandler_lock(); /* for proper lock order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    stepControl_lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    step = threadControl_getStepRequest(thread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    if (step != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        clearStep(thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        /* If the stepRequest can't be gotten, then this thread no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         *   exists, just return, don't die here, this is normal at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         *   termination time. Return JVMTI_ERROR_NONE so the thread Ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         *   can be tossed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         error = JVMTI_ERROR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    stepControl_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    eventHandler_unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    return error;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
stepControl_clearRequest(jthread thread, StepRequest *step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    LOG_STEP(("stepControl_clearRequest: thread=%p", thread));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    clearStep(thread, step);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
stepControl_lock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    debugMonitorEnter(stepLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
stepControl_unlock(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    debugMonitorExit(stepLock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
}