DIRECTORY
CDebugDefs USING [CDCopyRead, Handle, LabelStack],
CodeDefs USING [codeType, LabelInfoIndex, LabelInfoNull, LabelInfoRecord],
ConvertUnsafe USING [SubString],
IO USING [PutF, RopeFromROS, ROS, STREAM],
RESOut
USING [
Log10, PChar, PCr, PDecimal, PNext, PNextNull, PNextUnsigned, PRope,
PUnsigned],
Rope USING [ROPE],
STDebugDefs USING [PSTSubString, ShowLinks, SubStringForHash, TableBase],
Table USING [Base];
CDebugLabels:
PROGRAM
IMPORTS CDebugDefs, IO, RESOut, STDebugDefs
EXPORTS CDebugDefs =
BEGIN OPEN STDebugDefs, CodeDefs, CDebugDefs, RESOut;
ROPE: TYPE = Rope.ROPE;
PutAsLabelInfoIndex:
PUBLIC
PROCEDURE [h: Handle, lii: CodeDefs.LabelInfoIndex] =
BEGIN
lir: LabelInfoRecord;
cb: Table.Base ← TableBase[h, codeType];
CDCopyRead[h: h, to: @lir, from: @cb[lii], nwords: SIZE[LabelInfoRecord]];
PCr[h]; PRope[h, "cb["];
PDecimal[h, LOOPHOLE[lii]];
PRope[h, "] = "];
IF lir.free
THEN
BEGIN
PRope[h, "FREE!"];
RETURN
END;
PRope[h, "level: "]; PUnsigned[h, lir.catchLevel];
WITH li: lir
SELECT
FROM
named =>
BEGIN
desc: ConvertUnsafe.SubString;
desc ← SubStringForHash[h, li.hti];
PNext[h, "hti: ", Log10[li.hti]+3+desc.length];
PUnsigned[h, li.hti]; PRope[h, " ("];
PSTSubString[h, desc]; PChar[h, ')];
PNextUnsigned[h, "cci", li.cci];
END;
stmt =>
BEGIN
PNextUnsigned[h, "RETRY", li.retry];
PNextUnsigned[h, "CONT", li.continue];
END;
loop =>
BEGIN
PNextUnsigned[h, "LOOP", li.loop];
PNextUnsigned[h, "EXIT", li.exit];
END;
ENDCASE;
IF STDebugDefs.ShowLinks[h] THEN PNextNull[h, "thread", lir.thread, LabelInfoNull];
END;
PutLabelState:
PUBLIC
PROCEDURE [h: Handle] =
BEGIN OPEN CodeDefs;
lii: LabelInfoIndex;
lir: LabelInfoRecord;
cb: Table.Base = STDebugDefs.TableBase[h, codeType];
desc: ConvertUnsafe.SubString;
extra: CARDINAL;
first: BOOLEAN ← TRUE;
ros: IO.STREAM ← IO.ROS[];
name: ROPE;
PCr[h];
PRope[h, "labelStack: "];
lii ← LabelStack[h];
IF lii = LabelInfoNull
THEN
BEGIN PRope[h, "empty"]; RETURN END;
WHILE lii # LabelInfoNull
DO
extra ← 0;
CDCopyRead[h: h, to: @lir, from: @cb[lii], nwords: SIZE[LabelInfoRecord]];
ros.PutF["(%d) ", [cardinal[LONG[LOOPHOLE[lii, CARDINAL]]]]];
name ← ros.RopeFromROS[];
WITH li: lir
SELECT
FROM
named =>
BEGIN
desc ← SubStringForHash[h, li.hti];
extra ← desc.length + 2 + Log10[LOOPHOLE[li.hti]];
END;
loop => extra ← 6 + Log10[LOOPHOLE[li.loop]];
stmt => extra ← 7 + Log10[LOOPHOLE[li.retry]];
ENDCASE;
IF first
THEN
BEGIN PRope[h, name]; first ← FALSE; END
ELSE PNext[h, name, extra];
WITH li: lir
SELECT
FROM
named =>
BEGIN
PSTSubString[h, desc];
PRope[h, ": "];
PUnsigned[h, LOOPHOLE[li.cci]];
END;
loop =>
BEGIN
PRope[h, "LOOP: "];
PUnsigned[h, LOOPHOLE[li.loop]];
PNextUnsigned[h, "EXIT", li.exit];
END;
stmt =>
BEGIN
PRope[h, "RETRY: "];
PUnsigned[h, LOOPHOLE[li.retry]];
PNextUnsigned[h, "CONT", li.continue];
END;
ENDCASE;
lii ← lir.thread;
ENDLOOP;
END;