ProcessWatchPrintingImpl.Mesa
Spreitzer, April 22, 1986 9:09:39 pm PST
DIRECTORY AMBridge, AMModel, AMModelBridge, AMModelPrivate, AMTypes, BackStop, IO, PrincOps, PrintTV, ProcessWatch, ProcessWatchPrinting, Rope, RTSymbolDefs, RTSymbols, RuntimeError, ViewerIO;
ProcessWatchPrintingImpl:
CEDAR
MONITOR
IMPORTS AMBridge, AMModel, AMModelBridge, BackStop, IO, ProcessWatch, Rope, ViewerIO
EXPORTS ProcessWatchPrinting
= {OPEN ProcessWatch;
ROPE: TYPE = Rope.ROPE;
ShowTop:
PUBLIC
PROC [pi: UsefulPsbIndex] = {
ph: ProcessHistory = GetHistory[pi];
pName: ROPE = IO.PutFR["Process %g (%bB, %xH)", [cardinal[pi]], [cardinal[pi]], [cardinal[pi]]];
PrintIt:
PROC [to:
IO.
STREAM] = {
IF ph.lastStack.end = 0
THEN to.PutF["\n%g was never seen to execute.\n", [rope[pName]]]
ELSE {
fi: FrameIndex ← 0;
to.PutF["\n%g, Priority %g: ", [rope[pName]], [cardinal[ph.lastPriority]]];
PrintFrame[to, ph.lastStack.frames[0]];
to.PutRope["\n"];
};
};
LetPrint[PrintIt];
};
ShowStack:
PUBLIC
PROC [pi: UsefulPsbIndex] = {
ph: ProcessHistory = GetHistory[pi];
pName: ROPE = IO.PutFR["Process %g (%bB, %xH)", [cardinal[pi]], [cardinal[pi]], [cardinal[pi]]];
PrintIt:
PROC [to:
IO.
STREAM] = {
IF ph.lastStack.end = 0
THEN to.PutF["\n%g was never seen to execute.\n", [rope[pName]]]
ELSE {
fi: FrameIndex ← 0;
to.PutF["\n%g, Priority %g:", [rope[pName]], [cardinal[ph.lastPriority]]];
DO
glitch: BOOL ← FALSE;
to.PutRope["\n\t"];
PrintFrame[to, ph.lastStack.frames[fi]];
fi ← IF fi IN [0 .. warmFrames-1) THEN fi + 1
ELSE IF fi = warmFrames-1 THEN (IF glitch ← ph.lastStack.wrapped THEN ph.lastStack.end ELSE warmFrames)
ELSE IF fi = LAST[FrameIndex] THEN warmFrames ELSE (fi+1);
IF fi = ph.lastStack.end AND NOT glitch THEN EXIT;
IF glitch THEN to.PutRope["\n\t..."];
ENDLOOP;
to.PutF["\n\t~~~ End of stack ~~~\n"];
};
};
LetPrint[PrintIt];
};
PrintFrame:
PROC [to:
IO.
STREAM, mf: Frame] = {
Partly cloned from SpyPrintImpl of March 8, 1985 7:06:56 pm PST.
ReallyPrintFrame:
PROC =
TRUSTED {
gfTV: AMTypes.TV = AMBridge.TVForGFHReferent[mf.gf];
gfContext: AMModel.Context = AMModelBridge.ContextForFrame[gfTV];
ls: AMModelBridge.LoadedSection = AMModelBridge.LoadedSectionForProgPC[gfContext, mf.pc];
source: AMModel.Source = AMModel.SectionSource[ls.section];
procSection, progSection: AMModel.Section;
FOR procSection ← ls.section, AMModel.ParentSection[procSection] UNTIL AMModel.SectionClass[procSection] = proc DO NULL ENDLOOP;
progSection ← AMModel.ParentSection[procSection];
to.PutRope[AMModel.SectionName[progSection]];
to.PutRope["."];
to.PutRope[AMModel.SectionName[procSection]];
IF mf.repeat # 1 THEN to.PutF["*%g", [cardinal[mf.repeat]]];
WITH source
SELECT
FROM
x: REF AMModel.SourceObj.field => to.PutF["[%g]", [integer[x.firstCharIndex]]];
ENDCASE;
};
errorMessage: ROPE = BackStop.Call[ReallyPrintFrame];
IF errorMessage.Length[] # 0 THEN to.PutF["Aack! %g", [rope[errorMessage]]];
};
LetPrint:
ENTRY
PROC [
Print:
PROC [
IO.
STREAM]] = {
ENABLE UNWIND => NULL;
DO
thisLog: IO.STREAM = log;
ok: BOOL ← thisLog # NIL;
IF ok
THEN Print[thisLog !
IO.EndOfStream => IF stream = thisLog THEN {ok ← FALSE; CONTINUE};
IO.Error => IF stream = thisLog AND ec = StreamClosed THEN {ok ← FALSE; CONTINUE}
];
IF ok THEN EXIT;
log ← ViewerIO.CreateViewerStreams["Process Watcher Log"].out;
ENDLOOP;
};
log: IO.STREAM ← NIL;
}.