DIRECTORY
Alloc USING [BaseSeq],
AllocImpl: FROM "InternalAllocImpl" USING [InstanceData, SizeSeq],
AMBridge USING [GFHFromTV],
AMModel USING [Context, MostRecentNamedContext, RootContext],
AMModelBridge USING [FrameFromContext],
AMTypes USING [TV],
Code USING [curctxlvl],
CodeDefs USING [LabelInfoIndex],
ComData USING [bodyIndex, source, table, textIndex],
Expression USING [recentExp],
FileParms USING [ActualId],
Flow USING [labelStack],
LogPack USING [map],
MDebugDefs USING [Handle],
PrincOpsUtils USING [LongCopy],
RESOut
USING [
Complain, PChar, PCr, PDecimal, PLongNumber, PRope, PUnsigned],
Rope USING [ROPE],
Statement USING [recentStmt],
STDebugDefs USING [Handle],
Symbols USING [ContextLevel],
Table USING [Base, chunkType, Selector],
Tree USING [Link],
WorldVM USING [LocalWorld];
MDebugGlobals:
PROGRAM
IMPORTS AMBridge, AMModel, AMModelBridge, PrincOpsUtils, RESOut, WorldVM
EXPORTS MDebugDefs, STDebugDefs
SHARES AllocImpl, Flow, LogPack =
BEGIN OPEN CodeDefs, RESOut, MDebugDefs;
Handle: TYPE = MDebugDefs.Handle;
ROPE: TYPE = Rope.ROPE;
wordlength: CARDINAL = 16;
basesValid: BOOLEAN ← FALSE;
CPtr: POINTER TO FRAME [Code] ← NIL;
expression: POINTER TO FRAME [Expression] ← NIL;
flow: POINTER TO FRAME [Flow] ← NIL;
MPtr: POINTER TO FRAME [ComData] ← NIL;
logPack: POINTER TO FRAME [LogPack] ← NIL;
statement: POINTER TO FRAME [Statement] ← NIL;
AllocTypes: POINTER TO FRAME [AllocImpl] ← NIL;
ClearCachedFrames:
PUBLIC PROC [h: Handle] = {
CPtr ← NIL;
expression ← NIL;
flow ← NIL;
MPtr ← NIL;
logPack ← NIL;
statement ← NIL;
};
CheckFrame:
PROC[h: Handle, atP:
POINTER
TO
POINTER, mod:
ROPE] =
BEGIN
wc, cc, mc: AMModel.Context;
tx: AMTypes.TV;
IF atP^ # NIL THEN RETURN;
wc ← AMModel.RootContext[WorldVM.LocalWorld[]];
cc ← AMModel.MostRecentNamedContext["MCompiler", wc];
IF cc = NIL THEN GO TO notFound;
mc ← AMModel.MostRecentNamedContext[mod, cc];
IF mc = NIL THEN GO TO notFound;
tx ← AMModelBridge.FrameFromContext[mc];
atP^ ← AMBridge.GFHFromTV[tx];
EXITS
notFound => {
RESOut.Complain[h: h, msg: "Base of ", abort: FALSE, clear: TRUE];
RESOut.Complain[h: h, msg: mod, abort: FALSE, clear: FALSE];
RESOut.Complain[h: h, msg: " unknown", abort: TRUE, clear: FALSE]};
END;
TableBase:
PUBLIC
PROCEDURE [h: STDebugDefs.Handle, table: Table.Selector ← Table.chunkType]
RETURNS [b: Table.Base] =
BEGIN
ah: LONG POINTER TO AllocTypes.InstanceData;
bs: LONG POINTER TO Alloc.BaseSeq;
CheckFrame[NARROW[h], @MPtr, "ComData"];
STCopyRead[h: h, to: @ah, from: @MPtr.table, nwords: SIZE[LONG POINTER]];
STCopyRead[h: h, to: @bs, from: @ah.bases, nwords: SIZE[LONG POINTER]];
STCopyRead[h: h, to: @b, from: @bs[table], nwords: SIZE[Table.Base]];
RETURN
END;
TableSize:
PUBLIC
PROCEDURE [h: STDebugDefs.Handle, table: Table.Selector ← Table.chunkType]
RETURNS [CARDINAL] =
BEGIN
ah: LONG POINTER TO AllocTypes.InstanceData;
ts: LONG POINTER TO AllocTypes.SizeSeq;
CheckFrame[NARROW[h], @MPtr, "ComData"];
STCopyRead[h: h, to: @ah, from: @MPtr.table, nwords: SIZE[LONG POINTER]];
STCopyRead[h: h, to: @ts, from: @ah.top, nwords: SIZE[LONG POINTER]];
RETURN [STRead[h, @ts[table]]];
END;
STRead:
PUBLIC
PROCEDURE [h: STDebugDefs.Handle, addr:
LONG
POINTER]
RETURNS [
UNSPECIFIED] =
BEGIN
RETURN [addr^];
END;
CDRead:
PUBLIC
PROCEDURE [h: Handle, addr:
LONG
POINTER]
RETURNS [
UNSPECIFIED] =
BEGIN
RETURN [addr^];
END;
STCopyRead:
PUBLIC
PROCEDURE [h: STDebugDefs.Handle, from:
LONG
POINTER, nwords:
CARDINAL, to:
LONG
POINTER] =
BEGIN
PrincOpsUtils.LongCopy[from: from, nwords: nwords, to: to];
END;
CDCopyRead:
PUBLIC
PROCEDURE [h: Handle, from:
LONG
POINTER, nwords:
CARDINAL, to:
LONG
POINTER] =
BEGIN
PrincOpsUtils.LongCopy[from: from, nwords: nwords, to: to];
END;
CurContext:
PUBLIC
PROCEDURE [h: Handle]
RETURNS [Symbols.ContextLevel] =
BEGIN
CheckFrame[h, @CPtr, "Code"];
RETURN [CDRead[h, @CPtr.curctxlvl]];
END;
LabelStack:
PUBLIC
PROCEDURE [h: Handle]
RETURNS [CodeDefs.LabelInfoIndex] =
BEGIN
CheckFrame[h, @flow, "Flow"];
RETURN [CDRead[h, @flow.labelStack]];
END;
PutCurrentBody:
PUBLIC
PROCEDURE [h: Handle] =
BEGIN
CheckFrame[h, @MPtr, "ComData"];
PCr[h];
PRope[h, "Current body bti = "];
PUnsigned[h, CDRead[h, @MPtr.bodyIndex]];
END;
StmtMapVal:
PUBLIC
PROC[h: Handle, loc:
CARDINAL]
RETURNS[index:
INT] = {
IF loc <= NAT.LAST THEN index ← loc
ELSE {
chunkSize: NAT = 256;
maxChunks: NAT = NAT.LAST/chunkSize + 1;
IndexChunk: TYPE = ARRAY [0..chunkSize) OF INT;
ChunkMap: TYPE = ARRAY [0..maxChunks) OF LONG POINTER TO IndexChunk;
map: LONG POINTER TO ChunkMap;
ch: LONG POINTER TO IndexChunk;
d: NAT = loc - CARDINAL[NAT.LAST+1];
CheckFrame[h, @logPack, "LogPack"];
CDCopyRead[h: h, to: map, from: @logPack.map, nwords: SIZE[LONG POINTER]];
CDCopyRead[h: h, to: @ch, from: @map[d/chunkSize], nwords: SIZE[LONG POINTER]];
CDCopyRead[h: h, to: @index, from: @ch[d MOD chunkSize], nwords: SIZE[INT]]};
RETURN};
PutCurrentSource:
PUBLIC
PROCEDURE [h: Handle] =
BEGIN
index: CARDINAL;
us: FileParms.ActualId;
BEGIN
CheckFrame[h, @MPtr, "ComData"];
CDCopyRead[h: h, to: @us, from: @MPtr.source, nwords: SIZE[FileParms.ActualId]];
index ← CDRead[h, @MPtr.textIndex];
PCr[h];
PRope[h, "Current source: "]; PutUserRope[h, us.locator];
PRope[h, " ["]; PLongNumber[h, StmtMapVal[h, index], []]; PChar[h, ']];
END;
END;
PutUserRope:
PRIVATE
PROCEDURE [h: Handle, r:
ROPE] =
BEGIN
PRope[h, r];
END;
PutCurrentStmt:
PUBLIC
PROCEDURE [h: Handle] =
BEGIN
st: Tree.Link;
CheckFrame[h, @statement, "Statement"];
PCr[h];
PRope[h, "Current stmt tree = "];
CDCopyRead[h: h, from: @statement.recentStmt, to: @st, nwords: SIZE[Tree.Link]];
PDecimalLink[h, st];
END;
PutCurrentExpr:
PUBLIC
PROCEDURE [h: Handle] =
BEGIN
st: Tree.Link;
CheckFrame[h, @expression, "Expression"];
PCr[h];
PRope[h, "Current expr tree = "];
CDCopyRead[h: h, from: @expression.recentExp, to: @st, nwords: SIZE[Tree.Link]];
PDecimalLink[h, st];
END;
PDecimalLink:
PROC [h: Handle, l: Tree.Link] = {
WITH l
SELECT
FROM
subtree => {PRope[h, "[subtree["]; PDecimal[h, LOOPHOLE[index]]};
hash => {PRope[h, "[hash["]; PDecimal[h, LOOPHOLE[index]]};
symbol => {PRope[h, "[symbol["]; PDecimal[h, LOOPHOLE[index]]};
literal => {PRope[h, "[literal["]; PDecimal[h, LOOPHOLE[index]]};
ENDCASE;
PRope[h, "]]"]};
END.