Reply to topic  [ 4 posts ] 
keeping debug mode with after_error 
Author Message
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post keeping debug mode with after_error
When an error occurs, any scheduled "after" events are canceled. This is documented in "after_error". The documentation says that if you want to reschedule an after event, you can do so in an after_error handler. And I was able to do that. However, I am then unable to enter debug mode when I do that.

What I want to do is make sure a periodic "after" event gets rescheduled after an error, but still be able to enter debug mode if I want. How can I do that?


Thu Apr 04, 2013 3:52 pm
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post Re: keeping debug mode with after_error
By the time the after_error function is invoked, the virtual machine stack has long been cleared, so the state at the time of the error, which would have been preserved in debug mode, is long gone. There's no going back.

You want your after function running and resetting itself during the time you're trying to debug? Seriously?? That sounds like crazy talk to me...

If you want to automatically resume your after function setup when you exit debug mode, you can simply write your own "dbexit" function that calls the true "dbexit" after resetting your after function. You wouldn't install your after_error in this debugging scenario; the after handling would be suspended while you poke around trying to figure out the state after the error by hand, then resume when you want to continue. But having an after function silently changing the state while you are trying to debug doesn't make any sense to me...

If you have known places in your interpreted code that produce errors you want to handle, use the catch function. Unlike after_error, catch gives you the state you would have in debug mode. The idea of after_error is that you can pick up as if you had not entered debug mode.


Sun Apr 07, 2013 8:44 am
Profile
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post Re: keeping debug mode with after_error
For us, the consequences of the after function halting are more severe than the consequences of it running during debug mode. So yes, I want this after function to continue running during debug time. I'd rather it only abort if it encountered its own error. Ideally, I'd love to see an option to configure whether after functions are canceled on errors (perhaps as a keyword option to the after function).

The state that this particular after function is changing in the background is restricted to its own internal object contents, with side effects in Tcl. So it would almost never have any impact on what we're debugging.

We don't always use debug mode when an error occurs. We use it with auto mode turned off (so that you have to hit "enter" to enter it). Sometimes, the user will issue another command and keep working and debug mode never even gets entered. Sometimes, debug mode is inadvertently entered and they don't realize it (because a lot of it is GUI-driven) and they don't notice it for some time. And sometimes, we do enter debug mode to troubleshoot the source of the error. Any of those possibilities could happen at any time. Since we're not guaranteed to enter debug mode, wrapping dbexit always wouldn't work reliably. Plus, you can exit from debug mode from other functions as well: dbcont and dbret. So I'd have to wrap all three.

I think for now I'll try having Tcl watch for "ERROR" using Expect and let it restart the background process. That seems like the most resilient manner of handling this so far, even if it's somewhat more indirect than I'd like.


Mon Apr 08, 2013 6:18 am
Profile
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post Re: keeping debug mode with after_error
Here's something that works:

Code:
func my_idler {
  set_idler, my_idler, 4;
  tksync, check;
  maybe_prompt;
}
set_idler, my_idler, 4;

func my_after_error {
  set_idler, my_idler, 4;
}
after_error = my_after_error;


The "set_idler" function lets you specify how to treat errors when they are encountered. Flag 4 specifies that any after_error function should be called in debug mode rather than clearing the stack. So the above makes sure my idler gets rescheduled, and then lets me proceed with debug mode like normal.

One side effect of the above is that I automatically enter debug (as with dbauto,1) instead of being prompted (as with dbauto,0), but that's tolerable.

Another side effect of the above is that because it runs in a tight loop, Yorick now uses 100% CPU. It doesn't seem to impact Yorick's responsiveness, but I don't love that it's wasting so many CPU cycles. So I'll probably stick with using Expect to monitor it for now instead of this technique.

I tried this instead:
Code:
func my_idler {
  set_idler, my_idler, 4;
  maybe_prompt;
}
set_idler, my_idler, 4;

func my_after_error {
  set_idler, my_idler, 4;
  tksync, background;
}
after_error = my_after_error;


Unfortunately, that still uses 100% CPU (as I figured it would). However, it also doesn't work as I expected/hoped. While I'm in debug mode, the tksync,background command continues running and re-installing itself. However, when I exit debug mode, it stops running.

If that had worked, then I was hoping there'd be a way to set the errflag 4 without installing a custom idler function. Then I could have after_error re-install the after function while keeping debug mode. But since the after function gets canceled when I leave debug mode, that won't work at all.

So I then tried wrapping dbexit like you suggested.

Code:
dbauto, 1;

func my_dbexit(orig, n) {
  tksync, background;
  if(is_integer(n)) {
    orig, n;
  } else {
    orig;
   }
}
dbexit = closure(my_dbexit, dbexit);


Unfortunately, this has the same issue the previous iteration had: the after event doesn't run after debug mode is exited. It appears that dbexit also clears any existing after calls.


Mon Apr 08, 2013 8:03 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.