jdk/src/share/back/SDE.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 2001-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 <setjmp.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 "SDE.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This SourceDebugExtension code does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * allow concurrent translation - due to caching method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A separate thread setting the default stratum ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * is, however, fine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define INIT_SIZE_FILE 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define INIT_SIZE_LINE 100
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define INIT_SIZE_STRATUM 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define BASE_STRATUM_NAME "Java"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define null NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define true JNI_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define false JNI_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define String char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define private static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  String sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  String sourcePath; // do not read - use accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  int isConverted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
} FileTableRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    int jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int jplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int jplsLineInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    int njplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int njplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
} LineTableRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    int fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    int lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
} StratumTableRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/* back-end wide value for default stratum */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
private String globalDefaultStratumId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/* reference type default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
private String defaultStratumId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
private jclass cachedClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
private FileTableRecord* fileTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
private LineTableRecord* lineTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
private StratumTableRecord* stratumTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
private int fileTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
private int lineTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
private int stratumTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
private int fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
private int lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
private int stratumIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
private int currentFileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
private int defaultStratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
private int baseStratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
private char* sdePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
private char* jplsFilename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
private char* NullString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/* mangled in parse, cannot be parsed.  Must be kept. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
private String sourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
private jboolean sourceMapIsValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
private jmp_buf jmp_buf_env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
private int stratumTableIndex(String stratumId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
private int stiLineTableIndex(int sti, int jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
private int stiLineNumber(int sti, int lti, int jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
private void decode(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
private void ignoreWhite(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
private jboolean isValid(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    loadDebugInfo(JNIEnv *env, jclass clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (!isSameObject(env, clazz, cachedClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            /* Not the same - swap out the info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            /* Delete existing info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if ( cachedClass != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                tossGlobalRef(env, &cachedClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                cachedClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if ( sourceDebugExtension!=null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                jvmtiDeallocate(sourceDebugExtension);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            sourceDebugExtension = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            /* Init info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            lineTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            fileTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            stratumTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            lineTableSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            fileTableSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            stratumTableSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            fileIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            lineIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            stratumIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            currentFileId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            defaultStratumId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            defaultStratumIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            baseStratumIndex = -2; /* so as not to match -1 above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            sourceMapIsValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (getSourceDebugExtension(clazz, &sourceDebugExtension) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                JVMTI_ERROR_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                sdePos = sourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                if (setjmp(jmp_buf_env) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    /* this is the initial (non-error) case, do parse */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            cachedClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            saveGlobalRef(env, clazz, &cachedClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /* Return 1 if match, 0 if no match */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    patternMatch(char *classname, const char *pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int pattLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int compLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        char *start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (pattern == NULL || classname == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        pattLen = (int)strlen(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if ((pattern[0] != '*') && (pattern[pattLen-1] != '*')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return strcmp(pattern, classname) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        compLen = pattLen - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        offset = (int)strlen(classname) - compLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (offset < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (pattern[0] == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            pattern++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            start = classname + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            start = classname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return strncmp(pattern, start, compLen) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Return 1 if p1 is a SourceName for stratum sti,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * else, return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    searchOneSourceName(int sti, char *p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        int fileIndexStart = stratumTable[sti].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int fileIndexEnd = stratumTable[sti+1].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int ii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        for (ii = fileIndexStart; ii < fileIndexEnd; ++ii) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (patternMatch(fileTable[ii].sourceName, p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
              return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Return 1 if p1 is a SourceName for any stratum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * else, return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    int searchAllSourceNames(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                             jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                             char *p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int ii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        loadDebugInfo(env, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
          return 0; /* no SDE or not SourceMap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        for (ii = 0; ii < stratumIndex - 1; ++ii) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (searchOneSourceName(ii, p1) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Convert a line number table, as returned by the JVMTI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * function GetLineNumberTable, to one for another stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Conversion is by overwrite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Actual line numbers are not returned - just a unique
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * number (file ID in top 16 bits, line number in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * bottom 16 bits) - this is all stepping needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    convertLineNumberTable(JNIEnv *env, jclass clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                           jint *entryCountPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                           jvmtiLineNumberEntry **tablePtr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        jvmtiLineNumberEntry *fromEntry = *tablePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        jvmtiLineNumberEntry *toEntry = *tablePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int cnt = *entryCountPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int lastLn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int sti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        loadDebugInfo(env, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return; /* no SDE or not SourceMap - return unchanged */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        sti = stratumTableIndex(globalDefaultStratumId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (sti == baseStratumIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return; /* Java stratum - return unchanged */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        LOG_MISC(("SDE is re-ordering the line table"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        for (; cnt-->0; ++fromEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            int jplsLine = fromEntry->line_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            int lti = stiLineTableIndex(sti, jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            if (lti >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                int fileId = lineTable[lti].fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                int ln = stiLineNumber(sti, lti, jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                ln += (fileId << 16); /* create line hash */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if (ln != lastLn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    lastLn = ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    toEntry->start_location = fromEntry->start_location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    toEntry->line_number = ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    ++toEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        *entryCountPtr = (int)(toEntry - *tablePtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Set back-end wide default stratum ID .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    setGlobalStratumId(char *id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        globalDefaultStratumId = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private void syntax(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        char buf[200];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        (void)snprintf(buf, sizeof(buf),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                "bad SourceDebugExtension syntax - position %d - %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                /*LINTED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                (int)(sdePos-sourceDebugExtension),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        JDI_ASSERT_FAILED(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        longjmp(jmp_buf_env, 1);  /* abort parse */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private char sdePeek(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (*sdePos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            syntax("unexpected EOF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return *sdePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private char sdeRead(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (*sdePos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            syntax("unexpected EOF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return *sdePos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private void sdeAdvance(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        sdePos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private void assureLineTableSize(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (lineIndex >= lineTableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            size_t allocSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            LineTableRecord* new_lineTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            int new_lineTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            new_lineTableSize = lineTableSize == 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                  INIT_SIZE_LINE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                  lineTableSize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            allocSize = new_lineTableSize * (int)sizeof(LineTableRecord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            new_lineTable = jvmtiAllocate((jint)allocSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if ( new_lineTable == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY, "SDE line table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if ( lineTable!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                (void)memcpy(new_lineTable, lineTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        lineTableSize * (int)sizeof(LineTableRecord));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                jvmtiDeallocate(lineTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            lineTable     = new_lineTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            lineTableSize = new_lineTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private void assureFileTableSize(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (fileIndex >= fileTableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            size_t allocSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            FileTableRecord* new_fileTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            int new_fileTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            new_fileTableSize = fileTableSize == 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                  INIT_SIZE_FILE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                  fileTableSize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            allocSize = new_fileTableSize * (int)sizeof(FileTableRecord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            new_fileTable = jvmtiAllocate((jint)allocSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if ( new_fileTable == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY, "SDE file table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if ( fileTable!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                (void)memcpy(new_fileTable, fileTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        fileTableSize * (int)sizeof(FileTableRecord));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                jvmtiDeallocate(fileTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            fileTable     = new_fileTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            fileTableSize = new_fileTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    private void assureStratumTableSize(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (stratumIndex >= stratumTableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            size_t allocSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            StratumTableRecord* new_stratumTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            int new_stratumTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            new_stratumTableSize = stratumTableSize == 0?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                  INIT_SIZE_STRATUM :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                  stratumTableSize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            allocSize = new_stratumTableSize * (int)sizeof(StratumTableRecord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            new_stratumTable = jvmtiAllocate((jint)allocSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if ( new_stratumTable == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY, "SDE stratum table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if ( stratumTable!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                (void)memcpy(new_stratumTable, stratumTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                        stratumTableSize * (int)sizeof(StratumTableRecord));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                jvmtiDeallocate(stratumTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            stratumTable     = new_stratumTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            stratumTableSize = new_stratumTableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private String readLine(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        char *initialPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        initialPos = sdePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        while (((ch = *sdePos) != '\n') && (ch != '\r')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (ch == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                syntax("unexpected EOF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            ++sdePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        *sdePos++ = 0; /* null terminate string - mangles SDE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        /* check for CR LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if ((ch == '\r') && (*sdePos == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            ++sdePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        ignoreWhite(); /* leading white */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return initialPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private int defaultStratumTableIndex(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if ((defaultStratumIndex == -1) && (defaultStratumId != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            defaultStratumIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                stratumTableIndex(defaultStratumId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return defaultStratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private int stratumTableIndex(String stratumId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (stratumId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return defaultStratumTableIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        for (i = 0; i < (stratumIndex-1); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (strcmp(stratumTable[i].id, stratumId) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return defaultStratumTableIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
/*****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 * below functions/methods are written to compile under either Java or C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 * Needed support functions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 *   sdePeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
 *   sdeRead()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
 *   sdeAdvance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
 *   readLine()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
 *   assureLineTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 *   assureFileTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 *   assureStratumTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 *   syntax(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 *   stratumTableIndex(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
 * Needed support variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
 *   lineTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
 *   lineIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
 *   fileTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 *   fileIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 *   currentFileId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
 * Needed types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
 *   String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
 * Needed constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
 *   NullString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private void ignoreWhite(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        while (((ch = sdePeek()) == ' ') || (ch == '\t')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    private void ignoreLine(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
           ch = sdeRead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } while ((ch != '\n') && (ch != '\r'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        /* check for CR LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if ((ch == '\r') && (sdePeek() == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        ignoreWhite(); /* leading white */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    private int readNumber(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        while (((ch = sdePeek()) >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            value = (value * 10) + ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    private void storeFile(int fileId, String sourceName, String sourcePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        assureFileTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        fileTable[fileIndex].fileId = fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        fileTable[fileIndex].sourceName = sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        fileTable[fileIndex].sourcePath = sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        ++fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    private void fileLine(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int hasAbsolute = 0; /* acts as boolean */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        String sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        String sourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        /* is there an absolute filename? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (sdePeek() == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            hasAbsolute = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        fileId = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        sourceName = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (hasAbsolute == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            sourcePath = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        storeFile(fileId, sourceName, sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private void storeLine(int jplsStart, int jplsEnd, int jplsLineInc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                  int njplsStart, int njplsEnd, int fileId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        assureLineTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        lineTable[lineIndex].jplsStart = jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        lineTable[lineIndex].jplsEnd = jplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        lineTable[lineIndex].jplsLineInc = jplsLineInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        lineTable[lineIndex].njplsStart = njplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        lineTable[lineIndex].njplsEnd = njplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        lineTable[lineIndex].fileId = fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        ++lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Parse line translation info.  Syntax is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *     <NJ-start-line> [ # <file-id> ] [ , <line-count> ] :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *                 <J-start-line> [ , <line-increment> ] CR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    private void lineLine(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int lineCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int lineIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        int njplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        int jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        njplsStart = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        /* is there a fileID? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (sdePeek() == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            currentFileId = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        /* is there a line count? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (sdePeek() == ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            lineCount = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (sdeRead() != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            syntax("expected ':'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        jplsStart = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (sdePeek() == ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            lineIncrement = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        ignoreLine(); /* flush the rest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        storeLine(jplsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                  jplsStart + (lineCount * lineIncrement) -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                  lineIncrement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                  njplsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                  njplsStart + lineCount -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                  currentFileId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Until the next stratum section, everything after this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * is in stratumId - so, store the current indicies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    private void storeStratum(String stratumId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        /* remove redundant strata */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (stratumIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            if ((stratumTable[stratumIndex-1].fileIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                            == fileIndex) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                (stratumTable[stratumIndex-1].lineIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                            == lineIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                /* nothing changed overwrite it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                --stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        /* store the results */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        assureStratumTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        stratumTable[stratumIndex].id = stratumId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        stratumTable[stratumIndex].fileIndex = fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        stratumTable[stratumIndex].lineIndex = lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        ++stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        currentFileId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * The beginning of a stratum's info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    private void stratumSection(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        storeStratum(readLine());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    private void fileSection(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            fileLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    private void lineSection(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            lineLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Ignore a section we don't know about.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    private void ignoreSection(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * A base "Java" stratum is always available, though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * it is not in the SourceDebugExtension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Create the base stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private void createJavaStratum(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        baseStratumIndex = stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        storeStratum(BASE_STRATUM_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        storeFile(1, jplsFilename, NullString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        /* JPL line numbers cannot exceed 65535 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        storeLine(1, 65536, 1, 1, 65536, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        storeStratum("Aux"); /* in case they don't declare */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Decode a SourceDebugExtension which is in SourceMap format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * This is the entry point into the recursive descent parser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    private void decode(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        /* check for "SMAP" - allow EOF if not ours */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (strlen(sourceDebugExtension) <= 4 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            (sdeRead() != 'S') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            (sdeRead() != 'M') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            (sdeRead() != 'A') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            (sdeRead() != 'P')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return; /* not our info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        ignoreLine(); /* flush the rest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        jplsFilename = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        defaultStratumId = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        createJavaStratum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (sdeRead() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                syntax("expected '*'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            switch (sdeRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                case 'S':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    stratumSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    fileSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    lineSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    /* set end points */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    storeStratum("*terminator*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    sourceMapIsValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    ignoreSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /***************** query functions ***********************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    private int stiLineTableIndex(int sti, int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        int lineIndexStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        int lineIndexEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        lineIndexStart = stratumTable[sti].lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        lineIndexEnd = stratumTable[sti+1].lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        for (i = lineIndexStart; i < lineIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if ((jplsLine >= lineTable[i].jplsStart) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                            (jplsLine <= lineTable[i].jplsEnd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    private int stiLineNumber(int sti, int lti, int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        return lineTable[lti].njplsStart +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                (((jplsLine - lineTable[lti].jplsStart) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                                   lineTable[lti].jplsLineInc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    private int fileTableIndex(int sti, int fileId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        int fileIndexStart = stratumTable[sti].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        int fileIndexEnd = stratumTable[sti+1].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        for (i = fileIndexStart; i < fileIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            if (fileTable[i].fileId == fileId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    private int stiFileTableIndex(int sti, int lti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        return fileTableIndex(sti, lineTable[lti].fileId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private jboolean isValid(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        return sourceMapIsValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }