src/jdk.jdi/share/classes/com/sun/tools/jdi/SDE.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/SDE.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
     2
 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    29
import java.util.ArrayList;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
class SDE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private static final int INIT_SIZE_FILE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private static final int INIT_SIZE_LINE = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    private static final int INIT_SIZE_STRATUM = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    static final String BASE_STRATUM_NAME = "Java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /* for C capatibility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static final String NullString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private class FileTableRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        String sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        String sourcePath; // do not read - use accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        boolean isConverted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
         * Return the sourcePath, computing it if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
         * If set, convert '/' in the sourcePath to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
         * local file separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        String getSourcePath(ReferenceTypeImpl refType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            if (!isConverted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                if (sourcePath == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    sourcePath = refType.baseSourceDir() + sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                } else {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
    58
                    StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                    for (int i = 0; i < sourcePath.length(); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                        char ch = sourcePath.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        if (ch == '/') {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
    62
                            sb.append(File.separatorChar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                        } else {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
    64
                            sb.append(ch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
    67
                    sourcePath = sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                isConverted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return sourcePath;
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
    private class LineTableRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        int jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int jplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int jplsLineInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int njplsStart;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    80
        @SuppressWarnings("unused")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int njplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private class StratumTableRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        int fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        int lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    class Stratum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        private final int sti; /* stratum index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        private Stratum(int sti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            this.sti = sti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        String id() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return stratumTable[sti].id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        boolean isJava() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return sti == baseStratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * Return all the sourceNames for this stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * Look from our starting fileIndex upto the starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         * fileIndex of next stratum - can do this since there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * is always a terminator stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         * Default sourceName (the first one) must be first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        List<String> sourceNames(ReferenceTypeImpl refType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            int fileIndexStart = stratumTable[sti].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            int fileIndexEnd = stratumTable[sti+1].fileIndex;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   118
            List<String> result = new ArrayList<>(fileIndexEnd - fileIndexStart);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            for (i = fileIndexStart; i < fileIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                result.add(fileTable[i].sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * Return all the sourcePaths for this stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * Look from our starting fileIndex upto the starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * fileIndex of next stratum - can do this since there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * is always a terminator stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * Default sourcePath (the first one) must be first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        List<String> sourcePaths(ReferenceTypeImpl refType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            int fileIndexStart = stratumTable[sti].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            int fileIndexEnd = stratumTable[sti+1].fileIndex;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   137
            List<String> result = new ArrayList<>(fileIndexEnd - fileIndexStart);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            for (i = fileIndexStart; i < fileIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                result.add(fileTable[i].getSourcePath(refType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        LineStratum lineStratum(ReferenceTypeImpl refType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            int lti = stiLineTableIndex(sti, jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (lti < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                return new LineStratum(sti, lti, refType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                       jplsLine);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    class LineStratum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        private final int sti; /* stratum index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        private final int lti; /* line table index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        private final ReferenceTypeImpl refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        private final int jplsLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        private String sourceName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        private String sourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        private LineStratum(int sti, int lti,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                            ReferenceTypeImpl refType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                            int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            this.sti = sti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            this.lti = lti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            this.refType = refType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            this.jplsLine = jplsLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        public boolean equals(Object obj) {
18292
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   174
            if (obj instanceof LineStratum) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                LineStratum other = (LineStratum)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                return (lti == other.lti) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                       (sti == other.sti) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                       (lineNumber() == other.lineNumber()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                       (refType.equals(other.refType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
18292
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   185
        @Override
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   186
        public int hashCode() {
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   187
            return (lineNumber() * 17) ^ refType.hashCode();
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   188
        }
3d40978f5ff8 8016576: Overrides warnings in jdi and jconsole
khazra
parents: 5506
diff changeset
   189
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int lineNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return stiLineNumber(sti, lti, jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * Fetch the source name and source path for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * this line, converting or constructing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * the source path if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        void getSourceInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (sourceName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                // already done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            int fti = stiFileTableIndex(sti, lti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (fti == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
              "Bad SourceDebugExtension, no matching source id " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
              lineTable[lti].fileId + " jplsLine: " + jplsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            FileTableRecord ftr = fileTable[fti];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            sourceName = ftr.sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            sourcePath = ftr.getSourcePath(refType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        String sourceName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            getSourceInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        String sourcePath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            getSourceInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private FileTableRecord[] fileTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private LineTableRecord[] lineTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private StratumTableRecord[] stratumTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private int fileIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private int lineIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private int stratumIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private int currentFileId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private int defaultStratumIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private int baseStratumIndex = -2; /* so as not to match -1 above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private int sdePos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    final String sourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    String jplsFilename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    String defaultStratumId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    boolean isValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    SDE(String sourceDebugExtension) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        this.sourceDebugExtension = sourceDebugExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    SDE() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        this.sourceDebugExtension = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        createProxyForAbsentSDE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    char sdePeek() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (sdePos >= sourceDebugExtension.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            syntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return sourceDebugExtension.charAt(sdePos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    char sdeRead() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (sdePos >= sourceDebugExtension.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            syntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return sourceDebugExtension.charAt(sdePos++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    void sdeAdvance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        sdePos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    void syntax() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        throw new InternalError("bad SourceDebugExtension syntax - position " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                sdePos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    void syntax(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        throw new InternalError("bad SourceDebugExtension syntax: " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    void assureLineTableSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        int len = lineTable == null? 0 : lineTable.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (lineIndex >= len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            int newLen = len == 0? INIT_SIZE_LINE : len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            LineTableRecord[] newTable = new LineTableRecord[newLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            for (i = 0; i < len; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                newTable[i] = lineTable[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            for (; i < newLen; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                newTable[i] = new LineTableRecord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            lineTable = newTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    void assureFileTableSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        int len = fileTable == null? 0 : fileTable.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (fileIndex >= len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            int newLen = len == 0? INIT_SIZE_FILE : len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            FileTableRecord[] newTable = new FileTableRecord[newLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            for (i = 0; i < len; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                newTable[i] = fileTable[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            for (; i < newLen; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                newTable[i] = new FileTableRecord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            fileTable = newTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    void assureStratumTableSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        int len = stratumTable == null? 0 : stratumTable.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (stratumIndex >= len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            int newLen = len == 0? INIT_SIZE_STRATUM : len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            StratumTableRecord[] newTable = new StratumTableRecord[newLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            for (i = 0; i < len; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                newTable[i] = stratumTable[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            for (; i < newLen; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                newTable[i] = new StratumTableRecord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            stratumTable = newTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    String readLine() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   330
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   335
            sb.append(ch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // check for CR LF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if ((ch == '\r') && (sdePeek() == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            sdeRead();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        ignoreWhite(); // leading white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private int defaultStratumTableIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if ((defaultStratumIndex == -1) && (defaultStratumId != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            defaultStratumIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                stratumTableIndex(defaultStratumId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return defaultStratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    int stratumTableIndex(String stratumId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (stratumId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return defaultStratumTableIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        for (i = 0; i < (stratumIndex-1); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (stratumTable[i].id.equals(stratumId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return defaultStratumTableIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    Stratum stratum(String stratumID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int sti = stratumTableIndex(stratumID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return new Stratum(sti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    List<String> availableStrata() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   373
        List<String> strata = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        for (int i = 0; i < (stratumIndex-1); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            StratumTableRecord rec = stratumTable[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            strata.add(rec.id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return strata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
/*****************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 * below functions/methods are written to compile under either Java or C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 * Needed support functions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 *   sdePeek()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 *   sdeRead()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 *   sdeAdvance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
 *   readLine()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 *   assureLineTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 *   assureFileTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 *   assureStratumTableSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 *   syntax()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 *   stratumTableIndex(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 * Needed support variables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
 *   lineTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
 *   lineIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
 *   fileTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
 *   fileIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
 *   currentFileId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 * Needed types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 *   String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
 * Needed constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
 *   NullString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    void ignoreWhite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        while (((ch = sdePeek()) == ' ') || (ch == '\t')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    void ignoreLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        while (((ch = sdeRead()) != '\n') && (ch != '\r')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        /* check for CR LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if ((ch == '\r') && (sdePeek() == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        ignoreWhite(); /* leading white */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    int readNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        while (((ch = sdePeek()) >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            value = (value * 10) + ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        ignoreWhite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    void storeFile(int fileId, String sourceName, String sourcePath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        assureFileTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        fileTable[fileIndex].fileId = fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        fileTable[fileIndex].sourceName = sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        fileTable[fileIndex].sourcePath = sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        ++fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    void fileLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        int hasAbsolute = 0; /* acts as boolean */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        int fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        String sourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        String sourcePath = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        /* is there an absolute filename? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (sdePeek() == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            hasAbsolute = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        fileId = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        sourceName = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (hasAbsolute == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            sourcePath = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        storeFile(fileId, sourceName, sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    void storeLine(int jplsStart, int jplsEnd, int jplsLineInc,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   473
                   int njplsStart, int njplsEnd, int fileId) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        assureLineTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        lineTable[lineIndex].jplsStart = jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        lineTable[lineIndex].jplsEnd = jplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        lineTable[lineIndex].jplsLineInc = jplsLineInc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        lineTable[lineIndex].njplsStart = njplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        lineTable[lineIndex].njplsEnd = njplsEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        lineTable[lineIndex].fileId = fileId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        ++lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Parse line translation info.  Syntax is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *     <NJ-start-line> [ # <file-id> ] [ , <line-count> ] :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *                 <J-start-line> [ , <line-increment> ] CR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    void lineLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        int lineCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        int lineIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        int njplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        int jplsStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        njplsStart = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        /* is there a fileID? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (sdePeek() == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            currentFileId = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        /* is there a line count? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (sdePeek() == ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            lineCount = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (sdeRead() != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            syntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        jplsStart = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (sdePeek() == ',') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            sdeAdvance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            lineIncrement = readNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        ignoreLine(); /* flush the rest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        storeLine(jplsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                  jplsStart + (lineCount * lineIncrement) -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                  lineIncrement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                  njplsStart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                  njplsStart + lineCount -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                  currentFileId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Until the next stratum section, everything after this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * is in stratumId - so, store the current indicies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    void storeStratum(String stratumId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        /* remove redundant strata */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (stratumIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if ((stratumTable[stratumIndex-1].fileIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                            == fileIndex) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                (stratumTable[stratumIndex-1].lineIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                            == lineIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                /* nothing changed overwrite it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                --stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        /* store the results */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        assureStratumTableSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        stratumTable[stratumIndex].id = stratumId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        stratumTable[stratumIndex].fileIndex = fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        stratumTable[stratumIndex].lineIndex = lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        ++stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        currentFileId = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * The beginning of a stratum's info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    void stratumSection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        storeStratum(readLine());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    void fileSection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            fileLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    void lineSection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            lineLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Ignore a section we don't know about.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    void ignoreSection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        while (sdePeek() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            ignoreLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * A base "Java" stratum is always available, though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * it is not in the SourceDebugExtension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Create the base stratum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    void createJavaStratum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        baseStratumIndex = stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        storeStratum(BASE_STRATUM_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        storeFile(1, jplsFilename, NullString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        /* JPL line numbers cannot exceed 65535 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        storeLine(1, 65536, 1, 1, 65536, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        storeStratum("Aux"); /* in case they don't declare */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Decode a SourceDebugExtension which is in SourceMap format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * This is the entry point into the recursive descent parser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    void decode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        /* check for "SMAP" - allow EOF if not ours */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if ((sourceDebugExtension.length() < 4) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            (sdeRead() != 'S') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            (sdeRead() != 'M') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            (sdeRead() != 'A') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            (sdeRead() != 'P')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            return; /* not our info */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        ignoreLine(); /* flush the rest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        jplsFilename = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        defaultStratumId = readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        createJavaStratum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (sdeRead() != '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                syntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            switch (sdeRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                case 'S':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    stratumSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    fileSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    lineSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                case 'E':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    /* set end points */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    storeStratum("*terminator*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    isValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    ignoreSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    void createProxyForAbsentSDE() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        jplsFilename = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        defaultStratumId = BASE_STRATUM_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        defaultStratumIndex = stratumIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        createJavaStratum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        storeStratum("*terminator*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /***************** query functions ***********************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    private int stiLineTableIndex(int sti, int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        int lineIndexStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        int lineIndexEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        lineIndexStart = stratumTable[sti].lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        lineIndexEnd = stratumTable[sti+1].lineIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        for (i = lineIndexStart; i < lineIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if ((jplsLine >= lineTable[i].jplsStart) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                            (jplsLine <= lineTable[i].jplsEnd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    private int stiLineNumber(int sti, int lti, int jplsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        return lineTable[lti].njplsStart +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                (((jplsLine - lineTable[lti].jplsStart) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                   lineTable[lti].jplsLineInc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    private int fileTableIndex(int sti, int fileId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        int fileIndexStart = stratumTable[sti].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        /* one past end */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        int fileIndexEnd = stratumTable[sti+1].fileIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        for (i = fileIndexStart; i < fileIndexEnd; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            if (fileTable[i].fileId == fileId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private int stiFileTableIndex(int sti, int lti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return fileTableIndex(sti, lineTable[lti].fileId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        return isValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
}