for review: improved low-level debugging messages

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Mar 17 08:38:45 AEDT 1999


Estimated hours taken: 0.5

runtime/mercury_misc.[ch]:
	Improve the facilities for printing pointers into the det and nondet
	stacks for diagnostic purposes.

runtime/mercury_stack_trace.c:
	Use the improved facilities in mercury_misc to improve the output.

trace/mercury_trace_internal.c:
	Use the improved facilties in mercury_misc to improve the
	formatting of the output of the stack_regs command.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/mercury_misc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.c,v
retrieving revision 1.14
diff -u -b -u -r1.14 mercury_misc.c
--- mercury_misc.c	1998/11/11 02:14:18	1.14
+++ mercury_misc.c	1999/03/16 01:19:16
@@ -156,7 +156,7 @@
 incr_hp_debug_msg(Word val, const Word *addr)
 {
 #ifdef CONSERVATIVE_GC
-	printf("allocated %ld words at 0x%p\n", (long) (Integer) val, addr);
+	printf("allocated %ld words at %p\n", (long) (Integer) val, addr);
 #else
 	printf("increment hp by %ld from ", (long) (Integer) val);
 	printheap(addr);
@@ -251,7 +251,7 @@
 void 
 printstring(const char *s)
 {
-	printf("string 0x%p %s\n", (const void *) s, s);
+	printf("string %p %s\n", (const void *) s, s);
 
 	return;
 }
@@ -260,59 +260,22 @@
 printheap(const Word *h)
 {
 #ifndef CONSERVATIVE_GC
-	printf("ptr 0x%p, offset %3ld words\n",
+	printf("ptr %p, offset %3ld words\n",
 		(const void *) h,
 		(long) (Integer) (h - MR_ENGINE(heap_zone)->min));
 #else
-	printf("ptr 0x%p\n",
+	printf("ptr %p\n",
 		(const void *) h);
 #endif
 	return;
 }
 
 void 
-printdetstack(const Word *s)
-{
-	printf("ptr 0x%p, offset %3ld words\n",
-		(const void *) s,
-		(long) (Integer) (s - MR_CONTEXT(detstack_zone)->min));
-	return;
-}
-
-void 
-printnondstack(const Word *s)
-{
-#ifndef	MR_DEBUG_NONDET_STACK
-	printf("ptr 0x%p, offset %3ld words\n",
-		(const void *) s,
-		(long) (Integer) (s - MR_CONTEXT(nondetstack_zone)->min));
-#else
-	if (s > MR_CONTEXT(nondetstack_zone)->min) {
-		printf("ptr 0x%p, offset %3ld words, procedure %s\n",
-			(const void *) s, 
-			(long) (Integer)
-				(s - MR_CONTEXT(nondetstack_zone)->min),
-			(const char *) s[PREDNM]);
-	} else {
-		/*
-		** This handles the case where the prevfr of the first frame
-		** is being printed.
-		*/
-		printf("ptr 0x%p, offset %3ld words\n",
-			(const void *) s, 
-			(long) (Integer)
-				(s - MR_CONTEXT(nondetstack_zone)->min));
-	}
-#endif
-	return;
-}
-
-void 
 dumpframe(/* const */ Word *fr)
 {
 	reg	int	i;
 
-	printf("frame at ptr 0x%p, offset %3ld words\n",
+	printf("frame at ptr %p, offset %3ld words\n",
 		(const void *) fr, 
 		(long) (Integer) (fr - MR_CONTEXT(nondetstack_zone)->min));
 #ifdef	MR_DEBUG_NONDET_STACK
@@ -324,7 +287,7 @@
 	printf("\t prevfr    "); printnondstack(MR_prevfr_slot(fr));
 
 	for (i = 1; &MR_based_framevar(fr,i) > MR_prevfr_slot(fr); i++) {
-		printf("\t framevar(%d)  %ld 0x%lx\n",
+		printf("\t framevar(%d)  %ld %lx\n",
 			i, (long) (Integer) MR_based_framevar(fr,i),
 			(unsigned long) MR_based_framevar(fr,i));
 	}
@@ -396,24 +359,93 @@
 #endif /* defined(MR_DEBUG_GOTOS) */
 
 void 
+printdetstackptr(const Word *s)
+{
+	print_detstackptr(stdout, s);
+	return;
+}
+
+void 
+print_detstackptr(FILE *fp, const Word *s)
+{
+	fprintf(fp, "det %3ld (%p)",
+		(long) (Integer) (s - MR_CONTEXT(detstack_zone)->min),
+		(const void *) s);
+	return;
+}
+
+void 
+printdetstack(const Word *s)
+{
+	printf("ptr %p, offset %3ld words\n",
+		(const void *) s,
+		(long) (Integer) (s - MR_CONTEXT(detstack_zone)->min));
+	return;
+}
+
+void 
+printnondstackptr(const Word *s)
+{
+	print_nondstackptr(stdout, s);
+	return;
+}
+
+void 
+print_nondstackptr(FILE *fp, const Word *s)
+{
+	fprintf(fp, "non %3ld (%p)",
+		(long) (Integer) (s - MR_CONTEXT(nondetstack_zone)->min),
+		(const void *) s);
+	return;
+}
+
+void 
+printnondstack(const Word *s)
+{
+#ifndef	MR_DEBUG_NONDET_STACK
+	printf("ptr %p, offset %3ld words\n",
+		(const void *) s,
+		(long) (Integer) (s - MR_CONTEXT(nondetstack_zone)->min));
+#else
+	if (s > MR_CONTEXT(nondetstack_zone)->min) {
+		printf("ptr %p, offset %3ld words, procedure %s\n",
+			(const void *) s, 
+			(long) (Integer)
+				(s - MR_CONTEXT(nondetstack_zone)->min),
+			(const char *) s[PREDNM]);
+	} else {
+		/*
+		** This handles the case where the prevfr of the first frame
+		** is being printed.
+		*/
+		printf("ptr %p, offset %3ld words\n",
+			(const void *) s, 
+			(long) (Integer)
+				(s - MR_CONTEXT(nondetstack_zone)->min));
+	}
+#endif
+	return;
+}
+
+void 
 printlabel(/* const */ Code *w)
 {
 	MR_Internal	*internal;
 
 	internal = MR_lookup_internal_by_addr(w);
 	if (internal != NULL) {
-		printf("label %s (0x%p)\n", internal->i_name, w);
+		printf("label %s (%p)\n", internal->i_name, w);
 	} else {
 #ifdef	MR_DEBUG_GOTOS
 		MR_Entry	*entry;
 		entry = MR_prev_entry_by_addr(w);
 		if (entry->e_addr == w) {
-			printf("label %s (0x%p)\n", entry->e_name, w);
+			printf("label %s (%p)\n", entry->e_name, w);
 		} else {
-			printf("label UNKNOWN (0x%p)\n", w);
+			printf("label UNKNOWN (%p)\n", w);
 		}
 #else
-		printf("label UNKNOWN (0x%p)\n", w);
+		printf("label UNKNOWN (%p)\n", w);
 #endif	/* not MR_DEBUG_GOTOS */
 	}
 }
Index: runtime/mercury_misc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.h,v
retrieving revision 1.12
diff -u -b -u -r1.12 mercury_misc.h
--- mercury_misc.h	1998/12/15 00:22:22	1.12
+++ mercury_misc.h	1999/03/16 01:19:16
@@ -46,8 +46,6 @@
 extern	void	printint(Word n);
 extern	void	printstring(const char *s);
 extern	void	printheap(const Word *h);
-extern	void	printdetstack(const Word *s);
-extern	void	printnondstack(const Word *s);
 extern	void	dumpframe(/* const */ Word *);
 extern	void	dumpnondstack(void);
 extern	void	printlist(Word p);
@@ -55,6 +53,12 @@
 extern	void	printregs(const char *msg);
 #endif
 
+extern	void	printdetstack(const Word *s);
+extern	void	printdetstackptr(const Word *s);
+extern	void	print_detstackptr(FILE *fp, const Word *s);
+extern	void	printnondstack(const Word *s);
+extern	void	printnondstackptr(const Word *s);
+extern	void	print_nondstackptr(FILE *fp, const Word *s);
 extern	void	printlabel(/* const */ Code *w);
 
 #if __GNUC__
Index: runtime/mercury_stack_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_trace.c,v
retrieving revision 1.29
diff -u -b -u -r1.29 mercury_stack_trace.c
--- mercury_stack_trace.c	1999/02/28 02:09:02	1.29
+++ mercury_stack_trace.c	1999/03/16 01:19:24
@@ -225,40 +225,48 @@
 	do_init_modules();
 
 	/*
-	** Change the >= below to > if you don't want the trace to include
-	** the bottom frame created by mercury_wrapper.c (whose redoip/redofr
-	** field can be hijacked by other code).
+	** The comparison operator in the condition of the while loop
+	** should be >= if you want the trace to include the bottom frame
+	** created by mercury_wrapper.c (whose redoip/redofr field can be
+	** hijacked by other code), and > if you don't want the bottom
+	** frame to be included.
 	*/
 
 	while (base_maxfr >= MR_nondet_stack_trace_bottom) {
 		frame_size = base_maxfr - MR_prevfr_slot(base_maxfr);
 		if (frame_size == MR_NONDET_TEMP_SIZE) {
-			fprintf(fp, "%p: nondet temp, %d words\n",
-				base_maxfr, frame_size);
+			print_nondstackptr(fp, base_maxfr);
+			fprintf(fp, ": temp\n");
 			fprintf(fp, " redoip: ");
 			printlabel(MR_redoip_slot(base_maxfr));
-			fprintf(fp, " redofr: %p\n",
-				MR_redofr_slot(base_maxfr));
+			fprintf(fp, " redofr: ");
+			print_nondstackptr(fp, MR_redofr_slot(base_maxfr));
+			fprintf(fp, " \n");
 		} else if (frame_size == MR_DET_TEMP_SIZE) {
-			fprintf(fp, "%p: nondet temp, %d words\n",
-				base_maxfr, frame_size);
+			print_nondstackptr(fp, base_maxfr);
+			fprintf(fp, ": temp\n");
 			fprintf(fp, " redoip: ");
 			printlabel(MR_redoip_slot(base_maxfr));
-			fprintf(fp, " redofr: %p\n",
-				MR_redofr_slot(base_maxfr));
-			fprintf(fp, " detfr:  %p\n",
-				MR_detfr_slot(base_maxfr));
+			fprintf(fp, " redofr: ");
+			print_nondstackptr(fp, MR_redofr_slot(base_maxfr));
+			fprintf(fp, " \n");
+			fprintf(fp, " detfr: ");
+			print_detstackptr(fp, MR_detfr_slot(base_maxfr));
+			fprintf(fp, " \n");
 		} else {
-			fprintf(fp, "%p: ordinary, %d words\n",
-				base_maxfr, frame_size);
+			print_nondstackptr(fp, base_maxfr);
+			fprintf(fp, ": ordinary, %d words\n",
+				frame_size);
 			fprintf(fp, " redoip: ");
 			printlabel(MR_redoip_slot(base_maxfr));
-			fprintf(fp, " redofr: %p\n",
-				MR_redofr_slot(base_maxfr));
+			fprintf(fp, " redofr: ");
+			print_nondstackptr(fp, MR_redofr_slot(base_maxfr));
+			fprintf(fp, " \n");
 			fprintf(fp, " succip: ");
 			printlabel(MR_succip_slot(base_maxfr));
-			fprintf(fp, " succfr: %p\n",
-				MR_succfr_slot(base_maxfr));
+			fprintf(fp, " succfr: ");
+			print_nondstackptr(fp, MR_succfr_slot(base_maxfr));
+			fprintf(fp, " \n");
 		}
 
 		base_maxfr = MR_prevfr_slot(base_maxfr);
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.31
diff -u -b -u -r1.31 mercury_trace_internal.c
--- mercury_trace_internal.c	1999/03/05 12:52:34	1.31
+++ mercury_trace_internal.c	1999/03/16 05:23:40
@@ -1226,11 +1226,16 @@
 		}
 	} else if (streq(words[0], "stack_regs")) {
 		if (word_count == 1) {
-			fprintf(MR_mdb_out,
-				"sp = %p, curfr = %p, maxfr = %p\n",
-				MR_saved_sp(saved_regs),
-				MR_saved_curfr(saved_regs),
+			fprintf(MR_mdb_out, "sp = ");
+			print_detstackptr(MR_mdb_out,
+				MR_saved_sp(saved_regs));
+			fprintf(MR_mdb_out, ", curfr = ");
+			print_nondstackptr(MR_mdb_out,
+				MR_saved_curfr(saved_regs));
+			fprintf(MR_mdb_out, ", maxfr = ");
+			print_nondstackptr(MR_mdb_out,
 				MR_saved_maxfr(saved_regs));
+			fprintf(MR_mdb_out, "\n");
 		} else {
 			MR_trace_usage("developer", "stack_regs");
 		}
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list