Error processing question

17 views
Skip to first unread message

Kevin Toppenberg

unread,
Jan 17, 2025, 5:12:08 PMJan 17
to Everything MUMPS
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





Kevin Toppenberg

unread,
Jan 17, 2025, 5:38:18 PMJan 17
to Everything MUMPS
I figured it out.

Before DO block, I add this line:
 NEW tmgINITZLEVEL SET tmgINITZLEVEL=$ZLEVEL

And in
TOPERRHNDL();
  ;"NOTE:  This function gets called repeatedly, apparently as it repeatitively pops off levels of stack.  
  SET tmgUserAborting=+$GET(tmgUserAborting)
  ;"WRITE !,"In TOPERRHNDL^TMGIDE",!
  ;"WRITE ",$ESTACK=",$ESTACK," vs tmgINITESTACK=",$GET(tmgINITESTACK),!
  ;"NEW % FOR %=0:1:$STACK DO
  ;". W (%+1),".  ",$STACK(%)," -- ",$STACK(%,"PLACE"),": ",$STACK(%,"MCODE")," - ",$STACK(%,"ECODE"),!
  SET tmgERR("tmgDbgLine")=$GET(tmgDbgLine)
  SET tmgERR("Aborting")=tmgUserAborting
  NEW tmgResult set tmgResult=0
  IF tmgUserAborting=1 DO
  . SET tmgResult=1
  . IF $GET(tmgINITZLEVEL)>0 DO
  . . SET $ECODE=""   ;"will prevent ERRTRAP^TMGIDE2A from being called  
  . . SET $ETRAP=""
  . . KILL tmgUserQuitting
  . . ZGOTO tmgINITZLEVEL
  QUIT tmgResult
  ;

The ZGOTO tmgINITZLEVEL will return execution to the $ZLEVEL from just before the DO block.  This gives me opportunity to exit gracefully.

Rubber ducky programming again to the rescue!

Kevin
Reply all
Reply to author
Forward
0 new messages