[m-rev.] for review: integrity checks
Zoltan Somogyi
zs at cs.mu.OZ.AU
Thu Jun 12 21:20:10 AEST 2003
On 12-Jun-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> The option should be documented in runtime/mercury_conf_param.h,
> if not elsewhere.
Done.
> > +MR_trace_check_integrity_on_cur_level(void)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < MR_point.MR_point_var_count; i++) {
> > + (void) MR_trace_browse_var(stdout, &MR_point.MR_point_vars[i],
> > + (MR_String) (MR_Integer) "", MR_trace_print,
> > + MR_BROWSE_CALLER_PRINT, MR_BROWSE_DEFAULT_FORMAT);
> > + }
> > +}
>
> A comment there would be helpful, e.g. explaining how calling
> MR_trace_browse_var() serves to check integrity.
I added
/*
** Printing the variable will fail if any part of the variable's value
** that is printed has been constructed incorrectly. The default print
** command will print only the top few levels of the variable, but
** since the construction of a memory cell is usually followed very
** closely by a call or an exit, this should be sufficient to catch
** most misconstructed terms.
*/
> > +static int MR_check_max_mr_num;
> > +static MR_Word MR_check_saved_regs[MR_MAX_FAKE_REG];
>
> Why are those variables static globals, rather than being
> local to the MR_trace_check_integrity() function and having
> automatic storage duration?
I made them automatic.
> > +static int MR_check_integrity_seq_num = 0;
>
> Likewise, why is that one global rather than being a static variable
> local to the function?
I made it local.
> > + do {
> > + MR_check_integrity_seq_num++;
> > +#if 0
> > + /* enable this code if necessary for debugging */
> > + sprintf(buf, "integrity check at event %d, level %d, seq %d\n",
> > + MR_trace_event_number, level, MR_check_integrity_seq_num);
> > +#endif
> > + MR_trace_report_msg = buf;
> > + fprintf(stdout, "%s", buf);
> > + fflush(stdout);
>
> "buf" is uninitialized at this point, due to the `#if 0'.
> Perhaps the "#endif" is in the wrong place??
You are right, it should be around the fprintf, not the sprintf.
> Also, this diff refers to MR_trace_report_msg, which is not defined.
I forgot to bring that part of the diff over. Here it is.
runtime/mercury_trace_base.[ch]:
Add a mechanism that allows a message to be printed by the debugger
when a program being run under mdb crashes.
Zoltan.
Index: mercury_trace_base.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.50
diff -u -b -r1.50 mercury_trace_base.c
--- mercury_trace_base.c 8 Nov 2002 08:48:21 -0000 1.50
+++ mercury_trace_base.c 14 Apr 2003 05:03:25 -0000
@@ -318,6 +319,8 @@
&MR_init_call_num_hash, &MR_next_std_call_num);
}
+char *MR_trace_report_msg = NULL;
+
void
MR_trace_report(FILE *fp)
{
@@ -327,6 +330,10 @@
** which implies that the user wants trace info on abort.
*/
+ if (MR_trace_report_msg != NULL) {
+ fprintf(fp, "%s\n", MR_trace_report_msg);
+ }
+
if (MR_standardize_event_details) {
fprintf(fp, "Last trace event was event #E%ld.\n",
(long) MR_standardize_event_num(
@@ -376,6 +383,11 @@
** which implies that the user wants trace info on abort.
*/
+ if (MR_trace_report_msg != NULL) {
+ write(fd, MR_trace_report_msg,
+ strlen(MR_trace_report_msg));
+ }
+
if (MR_standardize_event_details) {
sprintf(buf, "Last trace event was event #E%ld.\n",
(long) MR_standardize_event_num(
Index: mercury_trace_base.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.h,v
retrieving revision 1.32
diff -u -b -r1.32 mercury_trace_base.h
--- mercury_trace_base.h 18 Mar 2003 16:38:13 -0000 1.32
+++ mercury_trace_base.h 14 Apr 2003 05:01:19 -0000
@@ -287,6 +287,12 @@
extern void MR_trace_report_raw(int fd);
/*
+** If MR_trace_report_msg is not NULL, it will be included in messages
+** from MR_trace_report.
+*/
+extern char *MR_trace_report_msg;
+
+/*
** This function prints an error message and aborts. It should be
** called in situations where tracing is required, but `--trace' was
** not passed to c2init.
--------------------------------------------------------------------------
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