-- BBDisableBreaksImpl.mesa
-- Russ Atkinson, November 1, 1982 10:07 pm

DIRECTORY
BBDisableBreaks USING [],
BBZones USING [GetPrefixedZone],
ProcessOperations USING [HandleToIndex, ReadPSB];

BBDisableBreaksImpl: CEDAR PROGRAM
IMPORTS BBZones, ProcessOperations
EXPORTS BBDisableBreaks
= BEGIN

Index: TYPE = CARDINAL [0..1024); -- shadows PSB.PsbIndex
ProcessBitVector: TYPE = PACKED ARRAY Index OF BOOL;

z: ZONE ← BBZones.GetPrefixedZone[];
disabled: REF ProcessBitVector ← z.NEW[ProcessBitVector ← ALL[FALSE]];
disabling: BOOLTRUE;

DisableBreakPoints: PUBLIC PROC [inner: PROC] = {
-- calls the inner proc with breakpoints disabled for the current process
-- ABORTED or UNWIND will restore the old state
me: Index ← Me[];
old: BOOL ← disabled[me];
disabled[me] ← disabling;
inner[! ABORTED => {disabled[me] ← old; GO TO abort};
UNWIND => disabled[me] ← old];
disabled[me] ← old;
EXITS abort => ERROR ABORTED;
};

EnableBreakPoints: PUBLIC PROC [inner: PROC] = {
-- calls the inner proc with breakpoints enabled for the current process
-- ABORTED or UNWIND will restore the old state
me: Index ← Me[];
old: BOOL ← disabled[me];
disabled[me] ← FALSE;
inner[! ABORTED => {disabled[me] ← old; GO TO abort};
UNWIND => disabled[me] ← old];
disabled[me] ← old;
EXITS abort => ERROR ABORTED;
};

Enabled: PUBLIC PROC RETURNS [BOOL] = {
-- test to see if the current process has breakpoints for the current process
me: Index ← Me[];
RETURN [NOT disabled[me]];
};

Me: PROC RETURNS [Index] = TRUSTED INLINE {
RETURN [LOOPHOLE[ProcessOperations.HandleToIndex[ProcessOperations.ReadPSB[]]]]};

END.