Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

$STACK VS $ESTACK QUESTION

33 views
Skip to first unread message

Kevin Toppenberg

unread,
Jan 9, 2025, 10:13:54 AMJan 9
to Everything MUMPS

I am trying to figure out how to use $STACK vs $ESTACK.

I know that there is a FUNCTION $STACK(), which is different from the VARIABLE $STACK, which holds the size of the stack array. 

I have been working on my TMGIDE debugger, trying to improve the stack display. 

In my debugger, I am stepping through this test code:
...
 +23 NEW i,JDX,k
 +24 for i=1:1:10 do  write "+"
 +25 .for JDX=1:1:10 do  write "^"
 +26 ..WRITE !,JDX,!
 +27 ..for k=1:1:10 do  write "%"
 +28 ...write "*"
>+29 ...write "^"
 +30 ...write "%"

when on line 29, I ask for display of stack.   I use this code to display the stack.

  NEW STACKSZ SET STACKSZ=$STACK
  write !,"$STACK:",!
  for IDX=0:1:STACKSZ do
  . NEW ENTRY SET ENTRY=$STACK(IDX)
  . NEW POS SET POS=$STACK(IDX,"PLACE")
  . NEW CODE SET CODE=$STACK(IDX,"MCODE")
  . write IDX,") ",ENTRY," -- ",POS,":  ",CODE,! 
  WRITE !,"$ESTACK=",$ESTACK,!
  DO PRESS2GO^TMGUSRI2

This gives me this output:

$STACK:
0) -dir -- +1^GTM$DMOD:
1) DO -- MENUDONE+6^TMGIDE:    DO PROMPT("AllInOne")
2) DO -- PPT2+39^TMGIDE:    XECUTE tmgDbgLine

3) XECUTE -- @:  do ^TMGTEST
4) DO -- TMGTEST+23^TMGTEST:   for i=1:1:10 do  write "+"
5) DO -- TMGTEST+24^TMGTEST:   .for JDX=1:1:10 do  write "^"
6) DO -- TMGTEST+26^TMGTEST:   ..for k=1:1:10 do  write "%"
7) DO -- TMGTEST+28^TMGTEST:   ...write "^"

8) $$ -- SP2+45^TMGIDE2:    IF tmgRunMode'=2 DO  ;"2=Don't show code
9) DO -- SP2+46^TMGIDE2:    . DO CMDPROMPT ;"display prompt and interact with user
10) DO -- CMDPROMPT+8^TMGIDE2:    FOR  DO  QUIT:tmgDone=1
11) DO -- CMDPROMPT+58^TMGIDE2:    . IF tmgAction["STACK" DO HndlStack^TMGIDE2C(.tmgIDEPos,.tmgViewOffset) QUIT
12) DO -- HndlStack+7^TMGIDE2C:    NEW Stack DO GetStackInfo(.Stack,tmgOrigIDEPos)
13) DO -- GetStackInfo+11^TMGIDE2C:    for IDX=0:1:STACKSZ do

$ESTACK=5
----- Press Key To Continue -----

Notice that the lines in green (1,2 ) are indicative of my entry into my debugger ^TMGIDE.  Line 3 in blue is where I tell the debugger to launch ^TMGTEST and lines 8-12 in white are where my debugger is handling my request for stack display, entered at a command prompt.

Now step-by-step debugging is achieved by using ZBREAK and ZSTEP's so that yottadb will execute just 1 command at a time.  After each line is executed, a function in my code, STEPTRAP^TMGIDE2 is called.  And a that code starts like this:

STEPTRAP(tmgIDEPos,tmgMsg)  ;
...
  NEW $ESTACK  ;"Any entries into $ESTACK will be related to debugger, for filtering $STACK
  NEW tmgdbgTruth SET tmgdbgTruth=$TEST   ;"save initial value of $TEST

Notice that as soon as I start the STEPTRAP, is NEW $ESTACK.   The idea being that any additional items added to stack should not be related to running program, so shouldn't be shown. 

What does value of $ESTACK=5 mean in this context? 

CONCLUSIONS:

The stack level seems to be 8 when STEPTRAP is called (SP2 is in STEPTRAP).  Since I NEW $ESTACK, this is apparently set this to 0 (not 1).  We therefore have the following values as the program progresses
  • $STACK        $ESTACK
  •    8     --      0
  •    9     --      1
  •   10     --      2
  •   11     --      3
  •   12     --      4
  •   13     --      5

Therefore, to know how to filter out stack entries that apply to the inner working of TMGIDE, I would use $ESTACK (e.g. 5) - $STACK (e.g. 13) - 1 =  8.  And all stack entries for values 8 and greater should not be shown. 

Furthermore, entries 0,1,2 should also not be shown. 

Thanks for listening.  It helps me type these posts out, and I often can figure it out along the way, "rubber ducky" style.

Kevin

Sam Habiel

unread,
Jan 9, 2025, 10:18:38 AMJan 9
to Kevin Toppenberg, Everything MUMPS
$ESTACK is used in Error trapping with $ETRAP for you to unwind the stack when you get an error. Look at UNWIND^%ZTER for an example implementation; the XWB broker also has an implementation.

--sam

--
You received this message because you are subscribed to the Google Groups "Everything MUMPS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to everythingmum...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/everythingmumps/ad8ba280-e8a1-4804-842b-35e7d9a17bdfn%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Wicksell

unread,
Jan 9, 2025, 1:55:32 PMJan 9
to Everything MUMPS
Hi Kevin.

 You said, "Now step-by-step debugging is achieved by using ZBREAK and ZSTEP's so that yottadb will execute just 1 command at a time."
I have one small correction for you. A ZSTEP will not execute just one command at a time, rather it will execute one _line_ at a time,
regardless of how many commands are on that line. Good luck.

David Wicksell
Fourth Watch Software LC

Kevin Toppenberg

unread,
Jan 10, 2025, 10:05:08 AMJan 10
to Everything MUMPS
David,

Good correction.  I would love for yottadb to allow command by command stepping, but has Bhaskar once told my, this change would be "non-trivial."  :-)

Kevin
Reply all
Reply to author
Forward
0 new messages