/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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"
/**
* This SourceDebugExtension code does not
* allow concurrent translation - due to caching method.
* A separate thread setting the default stratum ID
* is, however, fine.
*/
#define true JNI_TRUE
#define false JNI_FALSE
#define String char *
#define private static
typedef struct {
int fileId;
int isConverted;
typedef struct {
int jplsStart;
int jplsEnd;
int jplsLineInc;
int njplsStart;
int njplsEnd;
int fileId;
typedef struct {
int fileIndex;
int lineIndex;
/* back-end wide value for default stratum */
/* reference type default */
/* mangled in parse, cannot be parsed. Must be kept. */
private void ignoreWhite(void);
private void
/* Not the same - swap out the info */
/* Delete existing info */
if ( cachedClass != null ) {
cachedClass = null;
}
if ( sourceDebugExtension!=null ) {
}
/* Init info */
stratumTable = null;
lineTableSize = 0;
fileTableSize = 0;
stratumTableSize = 0;
fileIndex = 0;
lineIndex = 0;
stratumIndex = 0;
currentFileId = 0;
defaultStratumIndex = -1;
sourceMapIsValid = false;
if (setjmp(jmp_buf_env) == 0) {
/* this is the initial (non-error) case, do parse */
decode();
}
}
cachedClass = null;
}
}
/* Return 1 if match, 0 if no match */
private int
int pattLen;
int compLen;
char *start;
int offset;
return 0;
}
}
if (offset < 0) {
return 0;
}
if (pattern[0] == '*') {
pattern++;
} else {
}
}
/**
* Return 1 if p1 is a SourceName for stratum sti,
* else, return 0.
*/
private int
/* one past end */
int ii;
return 1;
}
}
return 0;
}
/**
* Return 1 if p1 is a SourceName for any stratum
* else, return 0.
*/
char *p1) {
int ii;
if (!isValid()) {
return 0; /* no SDE or not SourceMap */
}
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
int lastLn = 0;
int sti;
if (!isValid()) {
return; /* no SDE or not SourceMap - return unchanged */
}
if (sti == baseStratumIndex) {
return; /* Java stratum - return unchanged */
}
LOG_MISC(("SDE is re-ordering the line table"));
if (lti >= 0) {
++toEntry;
}
}
}
/*LINTED*/
}
/**
* Set back-end wide default stratum ID .
*/
void
}
"bad SourceDebugExtension syntax - position %d - %s\n",
/*LINTED*/
(int)(sdePos-sourceDebugExtension),
msg);
}
if (*sdePos == 0) {
syntax("unexpected EOF");
}
return *sdePos;
}
if (*sdePos == 0) {
syntax("unexpected EOF");
}
return *sdePos++;
}
sdePos++;
}
if (lineIndex >= lineTableSize) {
int new_lineTableSize;
new_lineTableSize = lineTableSize == 0?
lineTableSize * 2;
if ( new_lineTable == NULL ) {
}
lineTableSize * (int)sizeof(LineTableRecord));
}
}
}
if (fileIndex >= fileTableSize) {
int new_fileTableSize;
new_fileTableSize = fileTableSize == 0?
fileTableSize * 2;
if ( new_fileTable == NULL ) {
}
fileTableSize * (int)sizeof(FileTableRecord));
}
}
}
if (stratumIndex >= stratumTableSize) {
int new_stratumTableSize;
new_stratumTableSize = stratumTableSize == 0?
stratumTableSize * 2;
if ( new_stratumTable == NULL ) {
}
if ( stratumTable!=NULL ) {
stratumTableSize * (int)sizeof(StratumTableRecord));
}
}
}
char *initialPos;
char ch;
ignoreWhite();
initialPos = sdePos;
if (ch == 0) {
syntax("unexpected EOF");
}
++sdePos;
}
*sdePos++ = 0; /* null terminate string - mangles SDE */
/* check for CR LF */
++sdePos;
}
ignoreWhite(); /* leading white */
return initialPos;
}
}
return defaultStratumIndex;
}
int i;
return defaultStratumTableIndex();
}
for (i = 0; i < (stratumIndex-1); ++i) {
return i;
}
}
return defaultStratumTableIndex();
}
/*****************************
*
* Needed support functions:
* sdePeek()
* sdeRead()
* sdeAdvance()
* readLine()
* assureLineTableSize()
* assureFileTableSize()
* assureStratumTableSize()
* syntax(String)
*
* stratumTableIndex(String)
*
* Needed support variables:
* lineTable
* lineIndex
* fileTable
* fileIndex
* currentFileId
*
* Needed types:
* String
*
* Needed constants:
* NullString
*/
char ch;
sdeAdvance();
}
}
char ch;
do {
/* check for CR LF */
sdeAdvance();
}
ignoreWhite(); /* leading white */
}
int value = 0;
char ch;
ignoreWhite();
sdeAdvance();
}
ignoreWhite();
return value;
}
++fileIndex;
}
int fileId;
/* is there an absolute filename? */
if (sdePeek() == '+') {
sdeAdvance();
hasAbsolute = 1;
}
fileId = readNumber();
sourceName = readLine();
if (hasAbsolute == 1) {
sourcePath = readLine();
}
}
++lineIndex;
}
/**
* Parse line translation info. Syntax is
* <NJ-start-line> [ # <file-id> ] [ , <line-count> ] :
* <J-start-line> [ , <line-increment> ] CR
*/
int njplsStart;
int jplsStart;
njplsStart = readNumber();
/* is there a fileID? */
if (sdePeek() == '#') {
sdeAdvance();
currentFileId = readNumber();
}
/* is there a line count? */
if (sdePeek() == ',') {
sdeAdvance();
lineCount = readNumber();
}
if (sdeRead() != ':') {
syntax("expected ':'");
}
jplsStart = readNumber();
if (sdePeek() == ',') {
sdeAdvance();
lineIncrement = readNumber();
}
ignoreLine(); /* flush the rest */
}
/**
* Until the next stratum section, everything after this
* is in stratumId - so, store the current indicies.
*/
/* remove redundant strata */
if (stratumIndex > 0) {
== fileIndex) &&
== lineIndex)) {
/* nothing changed overwrite it */
--stratumIndex;
}
}
/* store the results */
++stratumIndex;
currentFileId = 0;
}
/**
* The beginning of a stratum's info
*/
storeStratum(readLine());
}
ignoreLine();
while (sdePeek() != '*') {
fileLine();
}
}
ignoreLine();
while (sdePeek() != '*') {
lineLine();
}
}
/**
* Ignore a section we don't know about.
*/
ignoreLine();
while (sdePeek() != '*') {
ignoreLine();
}
}
/**
* A base "Java" stratum is always available, though
* it is not in the SourceDebugExtension.
* Create the base stratum.
*/
/* JPL line numbers cannot exceed 65535 */
}
/**
* Decode a SourceDebugExtension which is in SourceMap format.
* This is the entry point into the recursive descent parser.
*/
/* check for "SMAP" - allow EOF if not ours */
(sdeRead() != 'S') ||
(sdeRead() != 'M') ||
(sdeRead() != 'A') ||
(sdeRead() != 'P')) {
return; /* not our info */
}
ignoreLine(); /* flush the rest */
jplsFilename = readLine();
defaultStratumId = readLine();
while (true) {
if (sdeRead() != '*') {
syntax("expected '*'");
}
switch (sdeRead()) {
case 'S':
break;
case 'F':
fileSection();
break;
case 'L':
lineSection();
break;
case 'E':
/* set end points */
storeStratum("*terminator*");
sourceMapIsValid = true;
return;
default:
}
}
}
/***************** query functions ***********************/
int i;
int lineIndexStart;
int lineIndexEnd;
/* one past end */
for (i = lineIndexStart; i < lineIndexEnd; ++i) {
return i;
}
}
return -1;
}
}
int i;
/* one past end */
for (i = fileIndexStart; i < fileIndexEnd; ++i) {
return i;
}
}
return -1;
}
}
return sourceMapIsValid;
}