[m-dev.] Suggestion: ^C throws an exception

Ralph Becket rbeck at microsoft.com
Mon Nov 22 20:54:19 AEDT 1999


> > It occurred to me when using the debugger, after I'd 
> accidentally printed
> > out a huge term for the second time,
> 
> How did you print the term out?  Do you mean with io__write 
> or the like in the code being debugged?

No, this was in the term browser in the debugger.  I'm happy to admit that
I haven't really got to grips with mdb, but when you do make a mistake like
the above it's nice to have some way of cancelling without losing the entire
debugging session.

> > that some way to catch ^C signals would be
> > very useful (all the Prolog debuggers I've used have this facility).
> > 
> > Would it be possible to put in a signal handler that caught 
> ^C and issued an
> > exception in the context of the main thread?
> 
> In general that would be unsafe, since the code which you're executing
> when you happen to get the ^C may not be re-entrant.  For example,
> GC_malloc() is not re-entrant.  Likewise functions in the C library
> such as printf(), malloc(), fopen(), etc. may not be re-entrant.
> If you interrupt them, then they may leave crucial data structures
> in an inconsistent state, resulting in strange errors at some later
> point in the program.

Rats.

> However, I think it would be possible to put in a signal handler that
> caught ^C and set a global variable to tell the debugger to 
> stop at the
> next trace event.  So you could interrupt a `continue' 
> command, for example.
> The user would get control whenever execution next reached code
> that was compiled with debugging enabled.  In fact that would not be
> very hard to implement at all.  [... a couple of hours pass ...]
> Hmm, perhaps a little harder than I first thought, but anyway
> easy enough.  See the diff that I posted in a separate mail.

That's just what I was after!  Fast work.

> Currently we disable the debugger when executing interactive queries,
> to avoid potential problems that might arise because our current
> debugger is not re-entrant.  The diff I just posted doesn't 
> change that.  So it won't yet let you interrupt interactive queries.

So far that hasn't been a problem - I was just searching around for other
motivating examples.

Thanks again for the speedy response.

Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list