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

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Nov 20 06:49:13 AEDT 1999


On 19-Nov-1999, Ralph Becket <rbeck at microsoft.com> wrote:
> 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?

> 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.

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.

> This could then be used e.g.
> in the debugger to terminate printing of large terms (I suspect that turning
> paging on would be another good solution, but that doesn't solve the case
> when you want to interrupt, say, an interactive query).

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.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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