STDebugMisc.mesa Edited by Bruce, 18-Sep-81 20:01:23
Sweet February 11, 1986 11:15:34 am PST
DIRECTORY
Ascii USING [CR, DEL, ESC, FF, LF, SP, TAB],
CBinary USING [DebugTab],
ConvertUnsafe USING [SubString],
DebugTable USING [CSRptr],
PrincOpsUtils USING [Codebase],
RESOut USING [Handle, Log8, Log10, LongLog10, MakeRoom, PChar, PCr, PLongNumber, PNumber, PRope, PSubString],
STDebugDefs USING [STCopyRead, STRead, TableBase],
Symbols USING [
HTIndex, HTNull, HTRecord, htType, ISEIndex, SERecord, seType, ssType,
TransferMode, TypeClass],
Table USING [Base];
STDebugMisc: PROGRAM
IMPORTS CBinary, PrincOpsUtils, RESOut, STDebugDefs
EXPORTS STDebugDefs =
BEGIN OPEN STDebugDefs, RESOut;
table: LONG POINTER ← PrincOpsUtils.Codebase[LOOPHOLE[CBinary.DebugTab]];
Handle: TYPE = RESOut.Handle;
SubString: TYPE = ConvertUnsafe.SubString;
PutNodeName: PUBLIC PROC [h: Handle, n: UNSPECIFIED] =
BEGIN
csrP: DebugTable.CSRptr ← table;
desc: SubString;
desc.base ← @csrP[csrP.stringOffset];
[offset: desc.offset, length: desc.length] ← csrP.NodePrintName[n];
PSubString[h, desc];
END;
PutTypeName: PUBLIC PROC [h: Handle, n: Symbols.TypeClass] =
BEGIN
csrP: DebugTable.CSRptr ← table;
desc: SubString;
desc.base ← @csrP[csrP.stringOffset];
[offset: desc.offset, length: desc.length] ← csrP.TypePrintName[n];
PSubString[h, desc];
END;
PutModeName: PUBLIC PROC [h: Handle, n: Symbols.TransferMode] =
BEGIN
csrP: DebugTable.CSRptr ← table;
desc: SubString;
desc.base ← @csrP[csrP.stringOffset];
[offset: desc.offset, length: desc.length] ← csrP.ModePrintName[n];
PSubString[h, desc];
END;
HashForSei: PUBLIC PROC [h: Handle, sei: Symbols.ISEIndex]
RETURNS [hti: Symbols.HTIndex] =
BEGIN OPEN Symbols;
ise: id SERecord;
seb: Table.Base ← TableBase[h, seType];
STCopyRead[h: h, to: @ise, from: @seb[sei], nwords: SIZE[id SERecord]];
RETURN[ise.hash];
END;
PutAsChar: PROC [h: Handle, c: [0..128)] =
BEGIN
SELECT LOOPHOLE [c, CHARACTER] FROM
Ascii.CR => PRope[h, "CR"];
Ascii.DEL => PRope[h, "DEL"];
Ascii.ESC => PRope[h, "ESC"];
Ascii.FF => PRope[h, "FF"];
Ascii.LF => PRope[h, "LF"];
Ascii.SP => PRope[h, "SP"];
Ascii.TAB => PRope[h, "TAB"];
< 40C => BEGIN PRope[h, "'^"]; PChar[h, '@+c]; END;
ENDCASE => BEGIN PChar[h, '']; PChar[h, LOOPHOLE[c]]; END;
END;
LengthAsChar: PROC [c: [0..128)] RETURNS [CARDINAL] =
BEGIN
SELECT LOOPHOLE [c, CHARACTER] FROM
Ascii.CR => RETURN [2];
Ascii.DEL => RETURN [3];
Ascii.ESC => RETURN [3];
Ascii.FF => RETURN [2];
Ascii.LF => RETURN [2];
Ascii.SP => RETURN [2];
Ascii.TAB => RETURN [3];
< 40C => BEGIN RETURN [3]; END;
ENDCASE => BEGIN RETURN [2]; END;
END;
PutAsVariousRep: PUBLIC PROC [h: Handle, n: LONG UNSPECIFIED] = {
lc: LONG CARDINALLOOPHOLE[n];
AnotherVal: PROC [len: CARDINAL] =
BEGIN
PRope[h, " ="];
IF MakeRoom[h, len+1, 2] THEN PChar[h, Ascii.SP];
END;
IF lc <= CARDINAL.LAST THEN PutAsShortRep[h, CARDINAL[lc]]
ELSE {
p: RECORD [first, last: CARDINAL] ← LOOPHOLE[n];
PLongNumber[h, n, [base: 8]];
PRope[h, "B = "];
PLongNumber[h, n, []];
IF LOOPHOLE[n, INT] < 0 THEN {
AnotherVal[1+LongLog10[-LOOPHOLE[n, INT]]];
PLongNumber[h, n, [unsigned: FALSE]]};
AnotherVal[Log8[p.first]+Log8[p.last]+4];
PNumber[h, p.first, [base: 8]]; PRope[h, "B,,"];
PNumber[h, p.last, [base: 8]]; PRope[h, "B"];
AnotherVal[Log10[p.first]+Log10[p.last]+4];
PNumber[h, p.first, []]; PRope[h, ",,"];
PNumber[h, p.last, []];
};
};
PutAsShortRep: PROC [h: Handle, n: UNSPECIFIED] =
BEGIN
r: RECORD [ SELECT OVERLAID * FROM
int => [i: INTEGER],
card => [c: CARDINAL],
bytes => [b1, b2: [0..256)],
nibbles => [n1, n2, n3, n4: [0..16)],
bitaddr => [wd: [0..7777B], bd: [0..17B]],
pdesc => [gfi: [0..1777B], entry: [0..37B], tag: BOOLEAN],
ENDCASE] = n;
AnotherVal: PROC [len: CARDINAL] =
BEGIN
PRope[h, " ="];
IF MakeRoom[h, len+1, 2] THEN PChar[h, Ascii.SP];
END;
PCr[h];
BEGIN OPEN r;
PNumber[h, c, [base: 8, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PRope[h, "B = "];
PNumber[h, c, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
IF i < 0 THEN
BEGIN
AnotherVal[1+Log10[-i]];
PNumber[h, c, [base: 10, zerofill: FALSE, unsigned: FALSE, columns: 0]];
END;
IF b1 # 0 THEN
BEGIN
AnotherVal[Log10[b1]+Log10[b2]+2];
PNumber[h, b1, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PRope[h, ",,"];
PNumber[h, b2, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
IF b1 > 15 OR b2 > 15 THEN
BEGIN
chars: CARDINAL ← Log8[b1]+Log8[b2]+2;
IF b1 > 7 THEN chars ← chars+1;
IF b2 > 7 THEN chars ← chars+1;
AnotherVal[chars];
PNumber[h, b1, [base: 8, zerofill: FALSE, unsigned: TRUE, columns: 0]];
IF b1 > 7 THEN PChar[h, 'B];
PRope[h, ",,"];
PNumber[h, b2, [base: 8, zerofill: FALSE, unsigned: TRUE, columns: 0]];
IF b2 > 7 THEN PChar[h, 'B];
END;
IF b1 < 128 AND b2 < 128 THEN
BEGIN
AnotherVal[LengthAsChar[b1]+ LengthAsChar[b2] + 2];
PutAsChar[h, b1]; PRope[h, ",,"]; PutAsChar[h, b2];
END;
END
ELSE IF b2 IN [1..127] THEN
BEGIN AnotherVal[LengthAsChar[b2]]; PutAsChar[h, b2]; END;
IF n1 # 0 OR n3 # 0 THEN
BEGIN
chars: CARDINAL ← Log10[n4];
IF b1 # 0 THEN
BEGIN
IF n1 # 0 THEN chars ← chars + Log10[n1]+1;
chars ← chars + Log10[n2]+2;
END;
IF n3 # 0 THEN chars ← chars + Log10[n3]+1;
AnotherVal[chars];
IF b1 # 0 THEN
BEGIN
IF n1 # 0 THEN
BEGIN
PNumber[h, n1, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PChar[h, ':];
END;
PNumber[h, n2, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PRope[h, ",,"];
END;
IF n3 # 0 THEN
BEGIN
PNumber[h, n3, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PChar[h, ':];
END;
PNumber[h, n4, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
END;
IF gfi # 0 AND tag THEN
BEGIN
AnotherVal[7 + Log10[gfi] + Log10[entry]];
PRope[h, "pd["];
PNumber[h, gfi, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PChar[h, ',];
PNumber[h, entry, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PRope[h, ",1]"];
END;
IF b1 # 0 THEN
BEGIN
AnotherVal[5 + Log10[wd] + Log10[bd]];
PRope[h, "ba["];
PNumber[h, wd, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PChar[h, ',];
PNumber[h, bd, [base: 10, zerofill: FALSE, unsigned: TRUE, columns: 0]];
PChar[h, ']];
END;
END;
END;
SubStringForHash: PUBLIC PROC [
h: Handle, hti: Symbols.HTIndex] RETURNS [ss: SubString] =
BEGIN OPEN Symbols;
ht: LONG POINTER TO ARRAY HTIndex OF HTRecord;
this, next: HTRecord;
ht ← TableBase[h, htType];
ss.base ← TableBase[h, ssType];
STCopyRead[h: h, to: @this, from: @ht[hti-1],
nwords: SIZE[HTRecord]];
STCopyRead[h: h, to: @next, from: @ht[hti],
nwords: SIZE[HTRecord]];
ss.offset ← this.ssIndex;
ss.length ← next.ssIndex - this.ssIndex;
END;
PutHashString: PUBLIC PROC [h: Handle, hti: Symbols.HTIndex] =
BEGIN OPEN Symbols;
desc: SubString;
IF hti = HTNull THEN
BEGIN PRope[h, "Anon"]; RETURN END;
desc ← SubStringForHash[h, hti];
PSTSubString[h, desc];
END;
PSTSubString: PUBLIC PROC [h: Handle, ss: SubString] =
BEGIN
i: CARDINAL;
s: RECORD [SELECT OVERLAID * FROM
word => [w: CARDINAL],
array => [c: PACKED ARRAY [0..1] OF CHARACTER],
ENDCASE];
len: CARDINALMIN[ss.length, 50];
IF ss.offset MOD 2 # 0 THEN
s.w ← STRead[h, @ss.base.text+ss.offset/2];
FOR i IN [ss.offset..ss.offset+len) DO
IF i MOD 2 = 0 THEN s.w ← STRead[h, @ss.base.text+i/2];
PChar[h, s.c[i MOD 2]];
ENDLOOP;
IF ss.length > len THEN PRope[h, "..."];
END;
PSTString: PUBLIC PROC [h: Handle, s: LONG STRING] =
BEGIN
desc: SubString ← [base: s, offset: 0, length: NULL];
desc.length ← STRead[h, @s.length];
PSTSubString[h, desc];
END;
END.