/* * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
#include <setjmp.h>
#include"util.h" #include"SDE.h"
#ifdef __APPLE__ /* use setjmp/longjmp versions that do not save/restore the signal mask */ #define setjmp _setjmp #define longjmp _longjmp #endif
/** * This SourceDebugExtension code does not * allow concurrent translation - due to caching method. * A separate thread setting the default stratum ID * is, however, fine.
*/
if (!isSameObject(env, clazz, cachedClass)) { /* Not the same - swap out the info */
/* Delete existing info */ if ( cachedClass != null ) {
tossGlobalRef(env, &cachedClass);
cachedClass = null;
} if ( sourceDebugExtension!=null ) {
jvmtiDeallocate(sourceDebugExtension);
}
sourceDebugExtension = null;
/* Init info */
lineTable = null;
fileTable = null;
stratumTable = null;
lineTableSize = 0;
fileTableSize = 0;
stratumTableSize = 0;
fileIndex = 0;
lineIndex = 0;
stratumIndex = 0;
currentFileId = 0;
defaultStratumId = null;
defaultStratumIndex = -1;
baseStratumIndex = -2; /* so as not to match -1 above */
sourceMapIsValid = JNI_FALSE;
if (getSourceDebugExtension(clazz, &sourceDebugExtension) ==
JVMTI_ERROR_NONE) {
sdePos = sourceDebugExtension; if (setjmp(jmp_buf_env) == 0) { /* this is the initial (non-error) case, do parse */
decode();
}
}
/* Return 1 if match, 0 if no match */ privateint
patternMatch(char *classname, constchar *pattern) { int pattLen; int compLen; char *start; int offset;
/** * Return 1 if p1 is a SourceName for stratum sti, * else, return 0.
*/ privateint
searchOneSourceName(int sti, char *p1) { int fileIndexStart = stratumTable[sti].fileIndex; /* one past end */ int fileIndexEnd = stratumTable[sti+1].fileIndex; int ii; for (ii = fileIndexStart; ii < fileIndexEnd; ++ii) { if (patternMatch(fileTable[ii].sourceName, p1)) { return 1;
}
} return 0;
}
/** * Return 1 if p1 is a SourceName for any stratum * else, return 0.
*/ int searchAllSourceNames(JNIEnv *env,
jclass clazz, char *p1) { int ii;
loadDebugInfo(env, clazz); if (!isValid()) { return 0; /* no SDE or not SourceMap */
}
for (ii = 0; ii < stratumIndex - 1; ++ii) { if (searchOneSourceName(ii, p1) == 1) { return 1;
}
} return 0;
}
/** * Convert a line number table, as returned by the JVMTI * function GetLineNumberTable, to one for another stratum. * Conversion is by overwrite. * Actual line numbers are not returned - just a unique * number (file ID in top 16 bits, line number in * bottom 16 bits) - this is all stepping needs.
*/ void
convertLineNumberTable(JNIEnv *env, jclass clazz,
jint *entryCountPtr,
jvmtiLineNumberEntry **tablePtr) {
jvmtiLineNumberEntry *fromEntry = *tablePtr;
jvmtiLineNumberEntry *toEntry = *tablePtr; int cnt = *entryCountPtr; int lastLn = 0; int sti;
if (cnt < 0) { return;
}
loadDebugInfo(env, clazz); if (!isValid()) { return; /* no SDE or not SourceMap - return unchanged */
}
sti = stratumTableIndex(globalDefaultStratumId); if (sti == baseStratumIndex || sti < 0) { return; /* Java stratum - return unchanged */
}
LOG_MISC(("SDE is re-ordering the line table")); for (; cnt-- > 0; ++fromEntry) { int jplsLine = fromEntry->line_number; int lti = stiLineTableIndex(sti, jplsLine); if (lti >= 0) { int fileId = lineTable[lti].fileId; int ln = stiLineNumber(sti, lti, jplsLine);
ln += (fileId << 16); /* create line hash */ if (ln != lastLn) {
lastLn = ln;
toEntry->start_location = fromEntry->start_location;
toEntry->line_number = ln;
++toEntry;
}
}
} /*LINTED*/
*entryCountPtr = (int)(toEntry - *tablePtr);
}
/** * Set back-end wide default stratum ID .
*/ void
setGlobalStratumId(char *id) {
globalDefaultStratumId = id;
}
/** * Until the next stratum section, everything after this * is in stratumId - so, store the current indices.
*/ privatevoid storeStratum(String stratumId) { /* remove redundant strata */ if (stratumIndex > 0) { if ((stratumTable[stratumIndex-1].fileIndex
== fileIndex) &&
(stratumTable[stratumIndex-1].lineIndex
== lineIndex)) { /* nothing changed overwrite it */
--stratumIndex;
}
} /* store the results */
assureStratumTableSize();
stratumTable[stratumIndex].id = stratumId;
stratumTable[stratumIndex].fileIndex = fileIndex;
stratumTable[stratumIndex].lineIndex = lineIndex;
++stratumIndex;
currentFileId = 0;
}
/** * The beginning of a stratum's info
*/ privatevoid stratumSection(void) {
storeStratum(readLine());
}
/** * Ignore a section we don't know about.
*/ privatevoid ignoreSection(void) {
ignoreLine(); while (sdePeek() != '*') {
ignoreLine();
}
}
/** * A base "Java" stratum is always available, though * it is not in the SourceDebugExtension. * Create the base stratum.
*/ privatevoid createJavaStratum(void) {
baseStratumIndex = stratumIndex;
storeStratum(BASE_STRATUM_NAME);
storeFile(1, jplsFilename, NullString); /* JPL line numbers cannot exceed 65535 */
storeLine(1, 65536, 1, 1, 65536, 1);
storeStratum("Aux"); /* in case they don't declare */
}
/** * Decode a SourceDebugExtension which is in SourceMap format. * This is the entry point into the recursive descent parser.
*/ privatevoid decode(void) { /* check for "SMAP" - allow EOF if not ours */ if (strlen(sourceDebugExtension) <= 4 ||
(sdeRead() != 'S') ||
(sdeRead() != 'M') ||
(sdeRead() != 'A') ||
(sdeRead() != 'P')) { return; /* not our info */
}
ignoreLine(); /* flush the rest */
jplsFilename = readLine();
defaultStratumId = readLine();
createJavaStratum(); while (1) { if (sdeRead() != '*') {
syntax("expected '*'");
} switch (sdeRead()) { case'S':
stratumSection(); break; case'F':
fileSection(); break; case'L':
lineSection(); break; case'E': /* set end points */
storeStratum("*terminator*");
sourceMapIsValid = JNI_TRUE; return; default:
ignoreSection();
}
}
}
privateint stiLineTableIndex(int sti, int jplsLine) { int i; int lineIndexStart; int lineIndexEnd;
lineIndexStart = stratumTable[sti].lineIndex; /* one past end */
lineIndexEnd = stratumTable[sti+1].lineIndex; for (i = lineIndexStart; i < lineIndexEnd; ++i) { if ((jplsLine >= lineTable[i].jplsStart) &&
(jplsLine <= lineTable[i].jplsEnd)) { return i;
}
} return -1;
}
privateint stiLineNumber(int sti, int lti, int jplsLine) { return lineTable[lti].njplsStart +
(((jplsLine - lineTable[lti].jplsStart) /
lineTable[lti].jplsLineInc));
}
privateint fileTableIndex(int sti, int fileId) { int i; int fileIndexStart = stratumTable[sti].fileIndex; /* one past end */ int fileIndexEnd = stratumTable[sti+1].fileIndex; for (i = fileIndexStart; i < fileIndexEnd; ++i) { if (fileTable[i].fileId == fileId) { return i;
}
} return -1;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.