[m-rev.] diff: bug fix for exception.m

Mark Brown dougl at cs.mu.OZ.AU
Thu Oct 10 22:15:24 AEST 2002


On 10-Oct-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 10-Oct-2002, Mark Brown <dougl at cs.mu.OZ.AU> wrote:
> > library/exception.m:
> > 	Ensure that MR_trace_from_full is set correctly before calling a
> > 	Mercury exception handler.  Failing to set this global can lead to
> > 	bogus events being sporadically generated from shallow traced code.
> ...
> > +++ library/exception.m	9 Oct 2002 17:02:11 -0000
> > @@ -2003,6 +2003,13 @@
> >  	MR_r4 = exception;	/* This is our one input argument */
> >  
> >  	/*
> > +	** The handler is effectively being called from try/2 or one of
> > +	** its variants.  Since this caller is in the standard library,
> > +	** it won't be deep traced.
> > +	*/
> > +	MR_trace_from_full = MR_FALSE;
> 
> I think your fix for this is wrong in the case when the Mercury library
> was compiled with deep tracing enabled.  This is the case for `.decldebug'
> grades, or if the library is compiled with `EXTRA_MCFLAGS=--trace deep'
> in Mmake.params.

This won't cause a problem because in this case the handler won't look
at MR_trace_from_full since it won't be shallow traced itself (it is in
the same module).  But, yes, the comment is wrong.

> Probably the right solution is to save the value of MR_trace_from_full
> at the call to builtin_catch and restore it in builtin_throw.
> It can be saved in a new field of MR_Exception_Handler_Frame_struct
> (from runtime/mercury_stacks.h).

This is a more robust solution, so I've followed your suggestion.  I'll
commit the following when it passes all its bootchecks.

Cheers,
Mark.

Estimated hours taken: 0.25
Branches: main

A more robust version of my previous bugfix.

runtime/mercury_stacks.h:
	Save the value of MR_trace_from_full in the exception struct
	when it is created at the start of builtin_catch.

library/exception.m:
	Restore the value of MR_trace_from_full from the exception struct,
	before calling the exception handler.

Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.71
diff -u -r1.71 exception.m
--- library/exception.m	10 Oct 2002 05:58:56 -0000	1.71
+++ library/exception.m	10 Oct 2002 08:15:20 -0000
@@ -1755,6 +1755,7 @@
 	MR_Word				exception;
 	MR_Word				handler;
 	enum MR_HandlerCodeModel	catch_code_model;
+	MR_bool				trace_from_full;
 	MR_Word				*orig_curfr;
 	MR_Unsigned			exception_event_number;
 
@@ -1855,6 +1856,7 @@
 	*/
 	catch_code_model = MR_EXCEPTION_STRUCT->MR_excp_code_model;
 	handler = MR_EXCEPTION_STRUCT->MR_excp_handler;
+	trace_from_full = (MR_bool) MR_EXCEPTION_STRUCT->MR_excp_full_trace;
 
 	/*
 	** Reset the success ip (i.e. return address).
@@ -2003,11 +2005,10 @@
 	MR_r4 = exception;	/* This is our one input argument */
 
 	/*
-	** The handler is effectively being called from try/2 or one of
-	** its variants.  Since this caller is in the standard library,
-	** it won't be deep traced.
+	** Restore the value of MR_trace_from_full that we saved at the
+	** start of builtin_catch.
 	*/
-	MR_trace_from_full = MR_FALSE;
+	MR_trace_from_full = trace_from_full;
 
 	/*
 	** If the catch was semidet, we need to set the success indicator
Index: runtime/mercury_stacks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.h,v
retrieving revision 1.34
diff -u -r1.34 mercury_stacks.h
--- runtime/mercury_stacks.h	19 Aug 2002 07:14:56 -0000	1.34
+++ runtime/mercury_stacks.h	10 Oct 2002 08:14:18 -0000
@@ -345,6 +345,13 @@
 	MR_Word MR_excp_handler;
 
 	/*
+	** The value of MR_trace_from_full, saved at the time the frame was
+	** created.  This holds a value of type MR_bool, but it is declared
+	** to have type MR_Word to ensure that everything remains word-aligned.
+	*/
+	MR_Word MR_excp_full_trace;
+
+	/*
 	** The remaining fields hold stuff that must be saved in order
 	** to unwind the Mercury stacks.
 	*/
@@ -397,6 +404,9 @@
 			(handler_code_model);				      \
 		/* save the handler's closure */			      \
 		MR_EXCEPTION_STRUCT->MR_excp_handler = (handler_closure);     \
+		/* save the full tracing flag */			      \
+		MR_EXCEPTION_STRUCT->MR_excp_full_trace =		      \
+			(MR_Word) MR_trace_from_full;			      \
 		/* save the det stack pointer */			      \
 		MR_EXCEPTION_STRUCT->MR_excp_stack_ptr = MR_sp;		      \
 		MR_IF_NOT_CONSERVATIVE_GC(				      \
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list