I have a question about error processing, for use in my debugger.
==========================================
First a description of how the debugger works.
==========================================
* User launches ^TMGIDE, which asks user for a command to run.
* User enters code to run, e.g. "do LOOPTEST^TMGTEST"
* ^TMGIDE sets ZSTEP mode, e.g. ZSTEP INTO
* $ZSTEP is set to, e.g., "NEW tmgTrap SET tmgTrap=$$STEPTRAP^TMGIDE2($ZPOS) ZSTEP:(tmgTrap=1) INTO "
* User code is launched as below.
DO
. ;"NOTE: $ETRAP gets called repeatedly, apparently as it repetitively pops off levels of stack.
. NEW $ETRAP SET $ETRAP="S %=$O(tmgERR(""ZP"",""""),-1)+1,tmgERR(""ZP"",%)=$ZPOS DO TOPERRHNDL^TMGIDE() QUIT "
. XECUTE tmgDbgLine ;"<---- launch user's mumps command
NOTE: Here is the code for LOOPTEST
LOOPTEST ;
NEW I
FOR I=1:1:100 DO
. NEW Y
. SET Y=I
. WRITE Y,!
QUIT
So after the the code, e.g.
e.g. "do LOOPTEST^TMGTEST, the first command, "LOOPTEST" (a label) will be executed, and then
$$STEPTRAP^TMGIDE2 is called.
* Inside STEPTRAP, the source code is displayed and user is given a command prompt where they can check variables, etc. And when done they can continue stepping through the code.
* To continue execution, the STEPTRAP() function is exited (quit), which will continues the rest of the $ZTEP command, "ZSTEP:(tmgTrap=1) INTO", which will effect the next line in LOOPTEST^TMGTEST to be done, which will be "NEW I", and STEPTRAP() will be called, continuing the loop.
If the entire program is stepped through, eventually the code in
tmgDbgLine will complete, and the DO block will be exited, and ^TMGIDE can quit
==========================================
NOW FOR THE QUESTIONS:
==========================================
Sometimes when stepping through code, the user will want to abort execution and QUIT the run. I have traditionally done this by generating some error, e.g. "SET A=1/0", which will blow the user all the way back to direct mode. The user then has to type ZGOTO to clear out errors. This is awkward and not ideal
I would like to be able to exit gracefully. But how?
As above, I set up an $ETRAP just before launching user code:
DO
. NEW $ETRAP SET $ETRAP="S %=$O(tmgERR(""ZP"",""""),-1)+1,tmgERR(""ZP"",%)=$ZPOS DO TOPERRHNDL^TMGIDE() QUIT "
. XECUTE tmgDbgLine ;"<---- launch user's mumps command
This $ETRAP calls DO TOPERRHNDL^TMGIDE() which will show the current stack and provides a chance to do whatever is needed. So when when the user asks to quit, and the code does "SET A=1/0", the error handler will fire. But the QUIT in the $ETRAP doesn't effect the quit that I want. It just keeps executing the tmgDbgLine command.
So how do I STOP execution gracefully. I want to be able to control exit from the DO block, stopping the XECUTE tmgDbgLine command.
Is this possible?
I know this is complex, and I appreciate any help possible.
Kevin