ComputeServerDebuggerImpl.mesa
The Compute Server side of the Summoner.
Last Edited by: Bob Hagmann, November 26, 1985 2:33:13 pm PST
Copyright © 1984 by Xerox Corporation. All rights reserved.
DIRECTORY
AMBridge,
AMEvents,
AMEventsBackdoor,
AMEventsBackdoorExtra,
AMModel,
AMModelBridge,
AMTypes,
AMViewerOps,
Basics,
Commander,
ComputeServerClient,
ComputeServer,
ComputeServerControl,
ComputeServerDebugger,
ComputeServerDebuggerRpcControl,
ComputeServerInternal,
EvalQuote,
FS,
Interpreter,
InterpreterOps,
InterpreterToolPrivate,
IO,
MBQueue,
PrincOps,
PrincOpsUtils,
Process,
PupDefs,
PupErrors,
PupStream,
PupTypes,
SymTab,
Rope,
RPC,
RuntimeError,
WorldVM;
ComputeServerDebuggerImpl: CEDAR PROGRAM
IMPORTS AMBridge, AMEvents, AMEventsBackdoor, AMEventsBackdoorExtra, AMModel, AMModelBridge, AMTypes, AMViewerOps, ComputeServerDebuggerRpcControl, ComputeServerInternal, EvalQuote, FS, Interpreter, InterpreterOps, IO, MBQueue, PrincOpsUtils, Process, PupDefs, PupErrors, PupStream, Rope, RPC, RuntimeError, SymTab, WorldVM
= BEGIN
Variable Declarations
STREAM: TYPE = IO.STREAM;
ROPE: TYPE = Rope.ROPE;
ActiveServicesItem: TYPE = ComputeServerInternal.ActiveServicesItem;
ActiveServicesPointer: TYPE = ComputeServerInternal.ActiveServicesPointer;
PupListener: TYPE = ComputeServerInternal.PupListener;
BufStreamData: TYPE = ComputeServerInternal.BufStreamData;
BufStreamDataObject: TYPE = ComputeServerInternal.BufStreamDataObject;
Uncaught Signals
guestLocalEvent: PROC[event: AMEvents.Event, f: PrincOps.FrameHandle,
stack: POINTER TO PrincOps.StateVector, return: BOOLFALSE] RETURNS[debugLocally: BOOLFALSE] = TRUSTED BEGIN
 modified from AMEventsImpl.LocalEvent
serverPupAddress: PupDefs.PupAddress;
outcome: AMEvents.Outcome;
interface: ComputeServerDebuggerRpcControl.InterfaceRecord ← NIL;
serviceItemPointer: ActiveServicesPointer;
IF ~PrincOpsUtils.IsBound[LOOPHOLE[AMEventsBackdoorExtra.PSBIToTV]] THEN RETURN[TRUE]; -- skip if the interface isn't exported
procPSBIToTV: PROC [psbi: CARDINAL, world: WorldVM.World] RETURNS [p: AMTypes.TV];
serviceItemPointer ← LOOPHOLE[ComputeServerInternal.GetGuestProcessData[LOOPHOLE[Process.GetCurrent[]]]];
IF serviceItemPointer = NIL THEN RETURN[TRUE];
interface ← ComputeServerDebuggerRpcControl.ImportNewInterface[
interfaceName: [ type: "ComputeServerDebugger.summoner", instance: serviceItemPointer.clientNetAddressRope, version: [1,1]]
! RPC.ImportFailed => {
CONTINUE;
};
];
IF interface = NIL THEN RETURN[TRUE];
event.world ← AMEventsBackdoorExtra.LocalActor.world;
event.session ← AMEventsBackdoorExtra.LocalActor.bootCount;
event.process ←
AMEventsBackdoorExtra.PSBIToTV[PrincOpsUtils.PsbHandleToIndex[PrincOpsUtils.ReadPSB[]], AMEventsBackdoorExtra.LocalActor.world];
procPSBIToTV← LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate["AMEventsImpl.PSBIToTV"].result]];
event.process ←
procPSBIToTV[PrincOpsUtils.PsbHandleToIndex[PrincOpsUtils.ReadPSB[]], AMEventsBackdoorExtra.LocalActor.world];
event.frame ← AMBridge.TVForFrame[f, stack, return, event.type = break];
event.worry ← FALSE;
IF AMEventsBackdoorExtra.Informing THEN RuntimeError.InformationalSignal[AMEvents.Debugging];
[outcome, serverPupAddress, debugLocally] ← remoteEventHandler[event, interface, serviceItemPointer]; --used to call InvokeEvent who called InterpreterToolImpl.EventHandler
[] ← ComputeServerInternal.DeletePupAddress[serverPupAddress];
IF AMEventsBackdoorExtra.Informing THEN RuntimeError.InformationalSignal[AMEvents.Debugged];
IF ~debugLocally THEN {
WITH o: outcome SELECT FROM
proceed => NULL;
quit => ERROR ABORTED -- I don't like it, but that's the convention for now --;
retry, returnFrom => ERROR AMEventsBackdoorExtra.NotImplemented[];
ENDCASE => ERROR;
};
END;
remoteEventHandler: PROC[event: AMEvents.Event,
interface: ComputeServerDebuggerRpcControl.InterfaceRecord,
serviceItemPointer: ActiveServicesPointer]
RETURNS[outcome: AMEvents.Outcome, serverPupAddress: PupDefs.PupAddress, debugLocally: BOOLFALSE] = TRUSTED {
InterpreterToolImpl.EventHandler basically calls InterpreterToolImpl.CreateTool if it can't find a suitable window to nest the call in. CreateTool is copied below, less the dormant Event window finding stuff.
h: InterpreterToolPrivate.Handle;
context: AMModel.Context =
IF event = NIL THEN AMModel.RootContext[WorldVM.LocalWorld[]] ELSE AMModelBridge.ContextForFrame[event.frame];
remoteWorld: WorldVM.World ← NIL;
oldPriority: Process.Priority ← Process.GetPriority[];
listener: PupListener;
debugServicesItem: ActiveServicesItem ← NIL;
byteStreamOK: BOOL;
name: ROPENIL;
in, out: STREAM;
inData, outData: BufStreamData ;
copyProcess: PROCESS;
procMainLoop: PROC [h: InterpreterToolPrivate.Handle] RETURNS [outcome: AMEvents.Outcome ];
serverPupAddress ← PupDefs.AnyLocalPupAddress[PupDefs.UniqueLocalPupSocketID[]];
Process.SetPriority[Process.priorityNormal];
IF context = NIL THEN ERROR;
IF WorldVM.LocalWorld[] # AMModel.ContextWorld[context]
THEN remoteWorld ← AMModel.ContextWorld[context];
h ← NEW[
InterpreterToolPrivate.InterpreterObject
← [remoteWorld: remoteWorld,
context: context,
event: event,
menuHitQueue: MBQueue.Create[],
symTab: SymTab.Create[],
readEvalPrintProcess: LOOPHOLE[Process.GetCurrent[]]]]; -- LOOPHOLE should not be needed, but the compiler give a bogus type error
name ← NewViewer[h];
glue the streams together and wake up remote window
listener ← ComputeServerInternal.CreatePupByteStreamListener[local: serverPupAddress.socket, proc: ComputeServerInternal.ListenerProcess, ticks: PupStream.SecondsToTocks[1], filter: ComputeServerInternal.DontReject];
debugServicesItem ← ComputeServerInternal.AddPupAddress[serverPupAddress, NIL, listener];
debugServicesItem.debugItem ← TRUE;
debugServicesItem.h ← h;
debugServicesItem.debuggerInterface ← interface;
debugServicesItem.originalListenerPupAddress ← serviceItemPointer.listenerPupAddress;
byteStreamOK ← interface.OpenDebugStream[listenerPupAddress: serviceItemPointer.listenerPupAddress, newListenerPupAddress: serverPupAddress, name: name, serverMachine: ComputeServerInternal.myHostName ! RPC.CallFailed => {
byteStreamOK ← FALSE;
};
];
IF byteStreamOK THEN {
WHILE debugServicesItem.remoteStream = NIL DO
Process.Pause[5];
ENDLOOP;
in ← IO.CreateStream[streamProcs: ComputeServerInternal.inStreamProcs,
streamData: inData ← NEW[BufStreamDataObject ← [listenerItem: debugServicesItem]]];
out ← IO.CreateStream[streamProcs: ComputeServerInternal.outStreamProcs,
streamData: outData ← NEW[BufStreamDataObject ← [listenerItem: debugServicesItem]]];
debugServicesItem.remoteStream.PutRope[Rope.Cat[name, "\n"]];
debugServicesItem.remoteStream.Flush[];
h.tsInStream ← in;
h.tsOutStream ← out;
TRUSTED { Process.Detach[copyProcess ← FORK DebugStreamCopy[debugServicesItem, in, out, inData, outData]]};
streams connected: start up the interpreter
procMainLoop ← LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.MainLoop"].result]];
outcome ← procMainLoop[h];
}
ELSE {
outcome ← [quit[]];
};
out.Close[];
debugServicesItem.remoteStream.Close[! IO.Error => CONTINUE;] ;
debugServicesItem.callOver ← TRUE;
[] ← ComputeServerInternal.DeletePupAddress[serverPupAddress];
Process.SetPriority[oldPriority];
};
DebugStreamCopy: PROC[debugServicesItem: ActiveServicesItem, in, out: STREAM, inData, outData: BufStreamData] = {
lastLoop: BOOLFALSE;
WHILE ~debugServicesItem.inEOF OR debugServicesItem.outEOF ~= true DO
doneSomething: BOOLFALSE;
copy from the internal stream to the remote stream
IF debugServicesItem.outEOF ~= true AND ComputeServerInternal.inCharsAvail[out, FALSE] > 0 THEN {
WHILE ComputeServerInternal.inCharsAvail[out, FALSE] > 0 AND debugServicesItem.outEOF = false DO
debugServicesItem.remoteStream.PutChar[ComputeServerInternal.inBufGetChar[out ! IO.EndOfStream => {debugServicesItem.outEOF ← pending; CONTINUE;}]];
ENDLOOP;
debugServicesItem.remoteStream.Flush[ ! PupErrors.StreamClosing => {debugServicesItem.outEOF ← true; CONTINUE;}; ];
IF debugServicesItem.outEOF = pending THEN {
PupStream.SendMark[debugServicesItem.remoteStream, 27B
! PupErrors.StreamClosing => CONTINUE];
debugServicesItem.outEOF ← true;
};
doneSomething ← TRUE;
};
copy from the remote stream to the internal stream
WHILE debugServicesItem.remoteStream.CharsAvail[] > 0 AND ~debugServicesItem.inEOF AND (inData.inPointer - (inData.outPointer + 1)) MOD ComputeServerInternal.BufStreamBufferSize # 0 DO
doneSomething ← TRUE;
ComputeServerInternal.outBufPutChar[in, debugServicesItem.remoteStream.GetChar[
! IO.EndOfStream => {
FOR i:INT IN [0..5) DO ComputeServerInternal.outBufPutChar[in, '\n]; ENDLOOP;
TRUSTED {abort[debugServicesItem.h]; };
inData.EOF ← pending;
debugServicesItem.inEOF ← TRUE;
CONTINUE;
}
]];
ENDLOOP;
IF lastLoop THEN EXIT;
IF debugServicesItem.callOver THEN { lastLoop ← TRUE; LOOP;};
IF ~doneSomething THEN Process.Pause[5];
ENDLOOP;
PupStream.SendMark[debugServicesItem.remoteStream, 26B
! PupErrors.StreamClosing => CONTINUE];
debugServicesItem.remoteStream.Close[! IO.Error => CONTINUE;] ;
};
NewViewer: PROC[h: InterpreterToolPrivate.Handle] RETURNS[name: ROPENIL] = TRUSTED {
LocalRegister: PROC [name: ROPE, ref: REF, help: ROPE] = TRUSTED {
ENABLE AMTypes.Error => GO TO err;
InterpreterOps.RegisterTV[
name: name, tv: AMBridge.TVForReferent[ref], help: help, symTab: h.symTab
];
EXITS err => {
IO.PutF[h.tsOutStream, "** Failed to register %g\n", [rope[name]]];
};
};
IF h.event # NIL THEN {
procEventToName: PROC [event: AMEvents.Event] RETURNS [name: ROPE ];
procEventToName ← LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.EventToName"].result]];
IF h.event.world # WorldVM.LocalWorld[] THEN name ← "WORLDSWAP ";
name ← Rope.Cat[name, "Event: ", procEventToName[h.event]];
}
ELSE name ← Rope.Cat["Interp: ", AMModel.ContextName[h.context]];
LocalRegister[
"&H", NEW[InterpreterToolPrivate.Handle ← h], "this interpretertool's handle"];
LocalRegister[
"&depth", NEW[INT ← 4], "printing depth for this interpretertool"];
LocalRegister[
"&width", NEW[INT ← 32], "printing width for this interpretertool"];
LocalRegister[
"&WalkStack",
NEW[UNSAFE PROC[nFrames: INT ← 1, h: InterpreterToolPrivate.Handle ← NIL] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.WalkStack"].result]] ],
"set a local frame context (eventhandler)"];
LocalRegister[
"&slf",
NEW[UNSAFE PROC[nFrames: INT ← 1, h: InterpreterToolPrivate.Handle ← NIL] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.WalkStack"].result]] ],
"set a local frame context (eventhandler)"];
LocalRegister[
"&ShowFrame",
NEW[UNSAFE PROC[h: InterpreterToolPrivate.Handle ← NIL] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.ShowFrame"].result]] ],
"show the current lf context (eventhandler)"];
LocalRegister[
"&Source", NEW[UNSAFE PROC[h: InterpreterToolPrivate.Handle ← NIL] ← Source],
"show source loc of current lf context (eventhandler)"];
EvalQuote.Register["&sgf", LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.SetGlobalFrameHelper"].result]], h.symTab, h];
LocalRegister[
"&sgf",
NEW[UNSAFE PROC[progName: ROPE, h: InterpreterToolPrivate.Handle ← NIL] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.SetGlobalFrameContext"].result]] ],
"&sgf[rope]\tset context to be that for the given module"];
EvalQuote.Register["&gf", LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.GlobalFrameHelper"].result]], h.symTab, h];
LocalRegister[
"&gf",
NEW[UNSAFE PROC[progName: ROPE, h: InterpreterToolPrivate.Handle ← NIL] RETURNS [AMTypes.TV] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.GlobalFrameContext"].result]] ],
"&gf[rope]\tget the given module's context"];
EvalQuote.Register["&sir", LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.SetIRHelper"].result]], h.symTab, h];
LocalRegister[
"&sir",
NEW[UNSAFE PROC[interfaceName: ROPE, h: InterpreterToolPrivate.Handle ← NIL] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.SetIRContext"].result]] ],
"&sir[rope]\tset context to be that for the given IR"];
EvalQuote.Register["&type", LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.TypeHelper"].result]], h.symTab, h];
LocalRegister[
"&type",
NEW[UNSAFE PROC[expr: ROPE, h: InterpreterToolPrivate.Handle ← NIL] RETURNS[AMTypes.Type] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.TypeGetter"].result]] ],
"&type[expr]\tget the type of the given expr"];
EvalQuote.Register["&ir", LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.IRHelper"].result]], h.symTab, h];
LocalRegister[
"&ir",
NEW[UNSAFE PROC[interfaceName: ROPE, h: InterpreterToolPrivate.Handle ← NIL] RETURNS[AMTypes.TV] ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate[ "InterpreterToolImpl.IRContext"].result]] ],
"&ir[rope]\tget the given IR"];
LocalRegister[
"&ABORT", NEW[UNSAFE PROC[h: InterpreterToolPrivate.Handle ← NIL] ← abort],
"abort button hit"];};
abort: UNSAFE PROC[h: InterpreterToolPrivate.Handle ← NIL] = TRUSTED {
giveFinalCR: BOOLTRUE;
procSetAbortRequested: PROC[h: InterpreterToolPrivate.Handle];
procSetAbortRequested ← LOOPHOLE[ AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.SetAbortRequested"].result]];
procSetAbortRequested[h];
Process.Abort[h.readEvalPrintProcess ! Process.InvalidProcess => {giveFinalCR ← FALSE; CONTINUE;}; ]; -- ERROR possible due to timing error, but the Process.Abort is only being used to wake up the interperter and the timeing error is that the interperter woke up, so it is ok.
IF giveFinalCR THEN StuffIt[h, "\n"];
};
Source: PROC [h: InterpreterToolPrivate.Handle ← NIL] = {
name: ROPE;
index: INT;
fName: ROPENIL;
report: AMViewerOps.ReportProc = -- [msg: ROPE, severity: Severity]
TRUSTED {h.tsOutStream.PutRope[msg]};
TRUSTED {
IF h = NIL THEN {
procGetHandlePlease: PROC RETURNS [InterpreterToolPrivate.Handle];
procGetHandlePlease ← LOOPHOLE[AMBridge.TVToProc[Interpreter.Evaluate["InterpreterToolImpl.GetHandlePlease"].result]];
h ← procGetHandlePlease[];
};
};
[name, index] ← AMViewerOps.SourceFromTV[h.context, report];
IF name # NIL THEN {
fName ← FS.FileInfo[name: name, remoteCheck: FALSE ! FS.Error => CONTINUE;].attachedTo;
};
IF fName # NIL THEN {
interface: ComputeServerDebuggerRpcControl.InterfaceRecord ← NIL;
debuggerItem: ActiveServicesItem ← ComputeServerInternal.findDebuggerItemFromInterpreterHandle[h].item;
IF debuggerItem # NIL THEN
debuggerItem.debuggerInterface.OpenSourceViewer[debuggerItem.originalListenerPupAddress, fName, index ! RPC.CallFailed => CONTINUE];
};
};
StuffIt: PROC [h: InterpreterToolPrivate.Handle, rope: ROPE] = {
h.tsOutStream.PutRope[rope];
};
disableGuest: PROC [localFS: BOOL] = {
process: PROCESS = LOOPHOLE[Process.GetCurrent[]];
IF localFS THEN ComputeServerInternal.MarkProcessNotGuest[process]
ELSE ComputeServerInternal.RemoveMarkProcessNotGuest[process];
};
Initialization
newProcs: REF AMEventsBackdoor.GuestProcsRec ← NEW[AMEventsBackdoor.GuestProcsRec ← [
IsGuestProcess: ComputeServerInternal.IsGuestProcess,
disableGuest: disableGuest,
guestLocalEvent: guestLocalEvent
]];
TRUSTED {AMEventsBackdoor.RegisterGuestProcs[newProcs];};
END.
Bob Hagmann May 3, 1985 8:05:30 am PDT
changes to: remoteEventHandler
Bob Hagmann July 5, 1985 9:01:47 am PDT
use Interpreter to find procedures inside of AMEventsImpl and InterpreterToolImpl