CDebugCC.mesa, Last Edited by:
Sweet February 5, 1986 11:39:34 am PST
Sweet, 14-Jul-83 17:12:36
Haynes, 29-Nov-82 20:19:55
DIRECTORY
CDebugDefs,
CodeDefs USING [CCIndex, CCInfoType, CCItem, CCNull, codeType, JumpType],
OpTableDefs USING [InstLength],
P5 USING [NumberOfParams],
RESOut USING [
PChar, PCr, PDecimal, PNext, PNextNull, PNextUnsigned, PNull, POctal,
PRope, PUnsigned],
STDebugDefs USING [ShowLinks, TableBase],
Table USING [Base, Limit];
CDebugCC: PROGRAM
IMPORTS CDebugDefs, OpTableDefs, P5, RESOut, STDebugDefs
EXPORTS CDebugDefs =
BEGIN OPEN CodeDefs, CDebugDefs, RESOut;
Handle: TYPE = CDebugDefs.Handle;
Chunk: TYPE = MACHINE DEPENDENT RECORD [ -- copied from AllocImpl
free(0: 0..0): BOOL,
size(0: 1..15): NAT,
fLink(1): CIndex,
bLink(2): CIndex];
CIndex: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO Chunk;
nullChunkIndex: CIndex = CIndex.FIRST;
FCPtr: TYPE = POINTER TO Chunk;
WriteFOpName: PROC [h: Handle, n: CARDINAL] =
BEGIN
PChar[h, 'q];
PRope[h, RopeForFop[n]];
END;
WriteMOpName: PROC [h: Handle, n: CARDINAL] =
BEGIN
PChar[h, 'z];
PRope[h, RopeForMop[n]];
END;
FullCCSize: CARDINAL = MAX[SIZE[CCItem], SIZE[code CCItem]+3];
FullCC: TYPE = ARRAY [0..FullCCSize) OF UNSPECIFIED;
current: CodeDefs.CCIndex ← CodeDefs.CCNull;
PutNextCC: PUBLIC PROC [h: Handle] =
BEGIN
fc: FullCC;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base = STDebugDefs.TableBase[h, CodeDefs.codeType];
next: CodeDefs.CCIndex;
IF h.lastCC = CodeDefs.CCNull THEN RETURN;
CDCopyRead[h: h, to: @fc, from: @cb[h.lastCC], nwords: FullCCSize];
IF cbc.free THEN next ← LOOPHOLE[LOOPHOLE[cbc, FCPtr].fLink]
ELSE next ← cbc.flink;
IF next # CodeDefs.CCNull THEN
PutAsCC[h, next];
END;
PutPrevCC: PUBLIC PROC [h: Handle] =
BEGIN
fc: FullCC;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base = STDebugDefs.TableBase[h, CodeDefs.codeType];
prev: CodeDefs.CCIndex;
IF h.lastCC = CodeDefs.CCNull THEN RETURN;
CDCopyRead[
h: h,
to: @fc,
from: @cb[h.lastCC],
nwords: FullCCSize];
IF cbc.free THEN prev ← LOOPHOLE[LOOPHOLE[cbc, FCPtr].bLink]
ELSE prev ← cbc.blink;
IF prev # CodeDefs.CCNull THEN
PutAsCC[h, prev];
END;
GoFwd: PUBLIC PROC [h: Handle, n: INTEGER] =
BEGIN
fc: FullCC;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base = STDebugDefs.TableBase[h, CodeDefs.codeType];
next: CodeDefs.CCIndex;
IF h.lastCC = CodeDefs.CCNull THEN RETURN;
THROUGH [0..n) DO
CDCopyRead[
h: h,
to: @fc,
from: @cb[h.lastCC],
nwords: FullCCSize];
IF cbc.free THEN next ← LOOPHOLE[LOOPHOLE[cbc, FCPtr].fLink]
ELSE next ← cbc.flink;
IF next = CodeDefs.CCNull THEN EXIT;
PutAsCC[h, next];
ENDLOOP;
END;
CCFirst: PUBLIC PROC [h: Handle] RETURNS [c: CodeDefs.CCIndex] =
BEGIN
fc: FullCC;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base = STDebugDefs.TableBase[h, CodeDefs.codeType];
prev: CodeDefs.CCIndex;
c ← CDebugDefs.CCCur[h];
IF c = CodeDefs.CCNull THEN RETURN;
DO
CDCopyRead[
h: h,
to: @fc,
from: @cb[c],
nwords: FullCCSize];
IF cbc.free THEN RETURN[CCNull]
ELSE prev ← cbc.blink;
IF prev = CodeDefs.CCNull THEN EXIT;
c ← prev;
ENDLOOP;
END;
PutRecentCC: PUBLIC PROC [h: Handle, n: INTEGER] =
BEGIN
fc: FullCC;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base = STDebugDefs.TableBase[h, CodeDefs.codeType];
c: CCIndex ← h.lastCC;
k: CARDINAL ← 0;
prev: CodeDefs.CCIndex;
IF n = 0 OR c = CodeDefs.CCNull THEN RETURN;
THROUGH (0..n) DO
CDCopyRead[
h: h,
to: @fc,
from: @cb[c],
nwords: FullCCSize];
IF cbc.free THEN prev ← LOOPHOLE[LOOPHOLE[cbc, FCPtr].bLink]
ELSE prev ← cbc.blink;
IF prev = CodeDefs.CCNull THEN EXIT;
k ← k+1;
c ← prev;
ENDLOOP;
PutAsCC[h, c];
IF k # 0 THEN GoFwd[h, k];
END;
PutAsCC: PUBLIC PROC [h: Handle, index: CodeDefs.CCIndex] =
BEGIN
fc: FullCC;
ccInfo: CodeDefs.CCInfoType ← h.infoVar^;
cbc: POINTER TO CodeDefs.CCItem = LOOPHOLE[@fc];
cb: Table.Base ← STDebugDefs.TableBase[h, CodeDefs.codeType];
CDCopyRead[
h: h,
to: @fc,
from: @cb[index],
nwords: FullCCSize];
h.lastCC ← index;
PCr[h];
PDecimal[h, LOOPHOLE[index]];
PRope[h, ": "];
IF cbc.free THEN
BEGIN
PRope[h, "FREE - size: "];
PUnsigned[h, LOOPHOLE[cbc, FCPtr].size];
END
ELSE WITH cc:cbc SELECT FROM
label =>
BEGIN
PRope[h, "Lbl - "];
IF cc.labelseen THEN PNext[h, "seen",,10];
WITH cc SELECT ccInfo FROM
generating =>
BEGIN
PRope[h, "jlist: "];
PNull[h, jumplist, CCNull];
IF cc.catch THEN PNext[h, "catch",,10];
END;
binding =>
BEGIN
PRope[h, "minPC: "]; PUnsigned[h, minPC];
PNextUnsigned[h, "maxPC", maxPC, 10];
END;
coding =>
BEGIN
PRope[h, "pc: "]; PUnsigned[h, pc];
END;
ENDCASE;
IF cc.offsetLoaded THEN PNext[h, "offsetLoaded",,10];
END;
jump =>
BEGIN
WriteJumpName[h, cc.jtype];
PChar[h, ' ];
PNull[h, cc.destlabel, CCNull];
IF cc.forward THEN PNext[h, "fwd",,10];
IF cc.fixedup THEN PNext[h, "fixed",,10];
IF cc.completed THEN PNext[h, "complete",,10];
PNextUnsigned[h, "jsize", cc.jsize, 10];
PNextUnsigned[h, "param", cc.jparam, 10];
WITH cc SELECT ccInfo FROM
generating => PNextNull[h, "thread", thread, CCNull, 10];
binding =>
BEGIN
PNextUnsigned[h, "minPC", minPC, 10];
PNextUnsigned[h, "maxPC", maxPC, 10];
END;
coding => PNextUnsigned[h, "pc", pc, 10];
ENDCASE;
END;
code =>
BEGIN
np: CARDINAL = IF ~cc.realinst THEN P5.NumberOfParams[cc.inst]
ELSE MAX[(IF cc.isize # 0 THEN cc.isize
ELSE OpTableDefs.InstLength[cc.inst]), 1]-1;
i: CARDINAL;
IF cc.realinst THEN WriteMOpName[h, cc.inst]
ELSE WriteFOpName[h, cc.inst];
IF np # 0 THEN
BEGIN
PChar[h, ' ];
FOR i IN [1..np] DO
IF i # 1 THEN PRope[h, ", "];
POctal[h, cc.parameters[i]];
ENDLOOP;
END;
IF cc.isize # 0 THEN PNextUnsigned[h, "size", cc.isize, 10];
IF cc.lco THEN PNext[h, "lco",,10];
END;
other => WITH cc SELECT FROM
table =>
BEGIN
PRope[h, "Table - offset: "];
POctal[h, taboffset];
IF btab THEN PNext[h, "btab",,10];
PNextUnsigned[h, "tableSize", tableSize, 10];
END;
markbody =>
BEGIN
PRope[h, IF start THEN "Start" ELSE "End"];
PRope[h, "Body, bti: "];
PUnsigned[h, LOOPHOLE[index]];
END;
markCatch =>
BEGIN
PRope[h, IF start THEN "Start" ELSE "End"];
PRope[h, "Catch, index: "];
PUnsigned[h, LOOPHOLE[index]];
END;
relSource =>
BEGIN
PRope[h, "RelSource: "];
POctal[h, relLoc];
END;
absSource =>
BEGIN
PRope[h, "AbsSource: "];
POctal[h, loc];
END;
ENDCASE;
ENDCASE;
IF STDebugDefs.ShowLinks[h] THEN
BEGIN
PNextNull[h,
"blink",
IF cbc.free THEN LOOPHOLE[cbc, FCPtr].bLink ELSE LOOPHOLE[cbc.blink],
CCNull,
10];
PNextNull[h,
"flink",
IF cbc.free THEN LOOPHOLE[cbc, FCPtr].fLink ELSE LOOPHOLE[cbc.flink],
CCNull,
10];
END;
END;
WriteJumpName: PROC [h: Handle, n: CodeDefs.JumpType] =
BEGIN OPEN CodeDefs;
JumpName: ARRAY JumpType OF ROPE = [
"JumpE", "JumpN", "JumpL", "JumpGE", "JumpG", "JumpLE",
"UJumpL", "UJumpGE", "UJumpG", "UJumpLE", "ZJumpE", "ZJumpN",
"Jump", "JumpA", "JumpC", "JumpCA", "JumpRet",
"NILJumpE", "NILJumpN", "PAIRJumpL", "PAIRJumpG",
"BYTEJumpE", "BYTEJumpN", "BITJumpE", "BITJumpN"];
IF n > LAST[JumpType] THEN
BEGIN PChar[h, 'j]; PDecimal[h, LOOPHOLE[n]] END
ELSE PRope[h, JumpName[n]]; RETURN
END;
END.