[m-dev.] for review: runtime fixes
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Aug 9 15:20:01 AEST 1999
runtime/mercury_label.c:
Guard against some functions being given bad data. This can happen
when the code generator has a bug that stomps on data and the debugger
calls these functions on garbage values.
runtime/mercury_misc.[ch]:
Fix some software rot, and add a capability for printing the values
of some stack slots as labels. This is useful when a code generator
bug stomps on the return address of a stack frame.
Zoltan.
cvs diff: Diffing runtime
Index: runtime/mercury_label.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_label.c,v
retrieving revision 1.13
diff -u -b -r1.13 mercury_label.c
--- mercury_label.c 1999/04/26 03:34:35 1.13
+++ mercury_label.c 1999/08/06 08:11:14
@@ -177,6 +177,10 @@
lo = 0;
hi = entry_array_next-1;
+ if (addr < entry_array[lo].e_addr) {
+ return NULL;
+ }
+
while (lo <= hi) {
mid = (lo + hi) / 2;
if (entry_array[mid].e_addr == addr) {
@@ -250,7 +254,12 @@
static const void *
internal_addr(const void *internal)
{
- return (const void *) (((const MR_Internal *) internal)->i_addr);
+ if (internal == NULL) {
+ return NULL;
+ } else {
+ return (const void *)
+ (((const MR_Internal *) internal)->i_addr);
+ }
}
static bool
Index: runtime/mercury_misc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.c,v
retrieving revision 1.18
diff -u -b -r1.18 mercury_misc.c
--- mercury_misc.c 1999/04/30 04:25:40 1.18
+++ mercury_misc.c 1999/08/06 07:30:13
@@ -17,6 +17,7 @@
/*--------------------------------------------------------------------*/
static void print_ordinary_regs(void);
+static void MR_printdetslot_as_label(const Integer offset);
/* debugging messages */
@@ -27,7 +28,7 @@
{
restore_transient_registers();
- printf("\nnew choice point %s for procedure %s\n", predname);
+ printf("\nnew choice point for procedure %s\n", predname);
printf("new fr: "); printnondstack(MR_curfr);
printf("prev fr: "); printnondstack(MR_prevfr_slot(MR_curfr));
printf("succ fr: "); printnondstack(MR_succfr_slot(MR_curfr));
@@ -77,7 +78,7 @@
printf("\nfailing from procedure\n");
printf("curr fr: "); printnondstack(MR_curfr);
printf("fail fr: "); printnondstack(MR_prevfr_slot(MR_curfr));
- printf("fail ip: "); printlabel(MR_redoip_slot(curprevfr_slot(MR_curfr)));
+ printf("fail ip: "); printlabel(MR_redoip_slot(MR_prevfr_slot(MR_curfr)));
}
void
@@ -135,7 +136,7 @@
incr_hp_debug_msg(Word val, const Word *addr)
{
#ifdef CONSERVATIVE_GC
- printf("allocated %ld words at %lu\n", (unsigned long) val, addr);
+ printf("allocated %ld words at %p\n", (unsigned long) val, addr);
#else
printf("increment hp by %ld from ", (long) (Integer) val);
printheap(addr);
@@ -309,10 +310,24 @@
#endif /* defined(MR_DEBUG_GOTOS) */
+static void
+MR_printdetslot_as_label(const Integer offset)
+{
+ MR_printdetstackptr(&MR_CONTEXT(detstack_zone)->min[offset]);
+ printf(" ");
+ printlabel((Code *) (MR_CONTEXT(detstack_zone)->min[offset]));
+}
+
void
MR_printdetstackptr(const Word *s)
{
@@ -358,30 +373,53 @@
}
void
-printlabel(/* const */ Code *w)
+MR_print_heapptr(FILE *fp, const Word *s)
+{
+#ifdef CONSERVATIVE_GC
+ fprintf(fp, "heap %ld (%p)",
+ (long) s, (const void *) s);
+#else
+ fprintf(fp, "heap %3ld (%p)",
+ (long) (Integer) (s - MR_ENGINE(heap_zone)->min),
+ (const void *) s);
+#endif
+}
+
+void
+MR_print_label(FILE *fp, /* const */ Code *w)
{
MR_Internal *internal;
internal = MR_lookup_internal_by_addr(w);
if (internal != NULL) {
if (internal->i_name != NULL) {
- printf("label %s (%p)\n", internal->i_name, w);
+ fprintf(fp, "label %s (%p)", internal->i_name, w);
} else {
- printf("label (%p)\n", w);
+ fprintf(fp, "label (%p)", w);
}
} else {
#ifdef MR_DEBUG_GOTOS
MR_Entry *entry;
+
entry = MR_prev_entry_by_addr(w);
- if (entry->e_addr == w && entry->e_name != NULL) {
- printf("label %s (%p)\n", entry->e_name, w);
+ if (entry != NULL && entry->e_addr == w
+ && entry->e_name != NULL)
+ {
+ fprintf(fp, "label %s (%p)", entry->e_name, w);
} else {
- printf("label UNKNOWN (%p)\n", w);
+ fprintf(fp, "label UNKNOWN (%p)", w);
}
#else
- printf("label UNKNOWN (%p)\n", w);
+ fprintf(fp, "label UNKNOWN (%p)", w);
#endif /* not MR_DEBUG_GOTOS */
}
+}
+
+void
+printlabel(/* const */ Code *w)
+{
+ MR_print_label(stdout, w);
+ fprintf(stdout, "\n");
}
void *
Index: runtime/mercury_misc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.h,v
retrieving revision 1.15
diff -u -b -r1.15 mercury_misc.h
--- mercury_misc.h 1999/04/30 04:25:40 1.15
+++ mercury_misc.h 1999/08/04 02:29:58
@@ -59,6 +59,8 @@
extern void printnondstack(const Word *s);
extern void MR_printnondstackptr(const Word *s);
extern void MR_print_nondstackptr(FILE *fp, const Word *s);
+extern void MR_print_heapptr(FILE *fp, const Word *s);
+extern void MR_print_label(FILE *fp, /* const */ Code *w);
extern void printlabel(/* const */ Code *w);
#if __GNUC__
--------------------------------------------------------------------------
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