[m-rev.] diff: agc debugging improvements

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 30 16:27:18 AEDT 2003


Estimated hours taken: 0.5
Branches: main

runtime/mercury_agc_debug.c:
	Use a run-time test rather than #ifdef for deciding whether
	to print out the values of variables.  This is better because
	it reduces the likelihood that the debugging code will rot
	because it never gets compiled, and because it makes it easier
	to modify the setting at runtime (in gdb), without needing to
	recompile.

	The time overhead of the run-time check is negligable, so
	the only real cost is a very small increase in code size
	(and only when NATIVE_GC is defined), which is well worth it.

	Also, print out the numerical value of unknown labels.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: runtime/mercury_agc_debug.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_agc_debug.c,v
retrieving revision 1.23
diff -u -d -u -b -r1.23 mercury_agc_debug.c
--- mercury_agc_debug.c	18 Nov 2003 07:05:01 -0000	1.23
+++ mercury_agc_debug.c	30 Dec 2003 05:21:02 -0000
@@ -30,6 +30,16 @@
 
 /*---------------------------------------------------------------------------*/
 
+/*
+** Currently this variable is never modified by the Mercury runtime code,
+** but it can be modified manually in gdb.
+** XXX it would be nicer to set it based on a runtime option setting.
+*/
+#ifdef MR_DEBUG_AGC_PRINT_VARS
+  static MR_bool MR_debug_agc_print_vars = MR_TRUE;
+#else
+  static MR_bool MR_debug_agc_print_vars = MR_FALSE;
+#endif
 
 void
 MR_agc_dump_roots(MR_RootList roots)
@@ -40,7 +50,7 @@
 	fflush(NULL);
 	fprintf(stderr, "Dumping roots\n");
 
-  #ifdef MR_DEBUG_AGC_PRINT_VARS
+  	if (MR_debug_agc_print_vars) {
 	while (roots != NULL) {
 
 
@@ -51,7 +61,8 @@
 		** the saved registers).
 		*/
 		MR_restore_registers();
-		MR_copy_regs_to_saved_regs(MR_MAX_FAKE_REG - 1, saved_regs);
+			MR_copy_regs_to_saved_regs(MR_MAX_FAKE_REG - 1,
+				saved_regs);
 
 		MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
 		MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
@@ -61,11 +72,12 @@
 		fflush(NULL);
 		fprintf(stderr, "\n");
 
-		MR_copy_saved_regs_to_regs(MR_MAX_FAKE_REG - 1, saved_regs);
+			MR_copy_saved_regs_to_regs(MR_MAX_FAKE_REG - 1,
+				saved_regs);
 		MR_save_registers();
 		roots = roots->next;
 	}
-  #endif /* MR_DEBUG_AGC_PRINT_VARS */
+	}
 #endif /* MR_NATIVE_GC */
 }
 
@@ -148,7 +160,8 @@
 				dump_live_variables(label->i_layout, heap_zone,
 					registers_valid, stack_pointer,
 					MR_redofr_slot(max_frame));
-				fprintf(stderr, " this label: %s\n", label->i_name);
+				fprintf(stderr, " this label: %s\n",
+					label->i_name);
 			}
 		}
 
@@ -187,7 +200,7 @@
 		if (label->i_name != NULL) {
 			fprintf(stderr, "    label: %s\n", label->i_name);
 		} else {
-			fprintf(stderr, "    label: unknown\n");
+			fprintf(stderr, "    label: %p\n", label->i_addr);
 		}
 
 		if (success_ip == MR_stack_trace_bottom) {
@@ -270,7 +283,7 @@
 		fprintf(stderr, "\n");
 		fflush(NULL);
 
-#ifdef MR_DEBUG_AGC_PRINT_VARS
+		if (MR_debug_agc_print_vars) {
 		/*
 		** Call Mercury but use the debugging heap.
 		*/
@@ -287,10 +300,9 @@
 			printf("\n");
 		}
 
-#endif	/* MR_DEBUG_AGC_PRINT_VARS */
-
 		fflush(NULL);
 	}
+	}
 
 	for (; i < short_var_count; i++) {
 		fprintf(stderr, "%-12s\t", "");
@@ -303,7 +315,7 @@
 		fprintf(stderr, "\n");
 		fflush(NULL);
 
-#ifdef MR_DEBUG_AGC_PRINT_VARS
+		if (MR_debug_agc_print_vars) {
 		/*
 		** Call Mercury but use the debugging heap.
 		*/
@@ -320,9 +332,8 @@
 			printf("\n");
 		}
 
-#endif	/* MR_DEBUG_AGC_PRINT_VARS */
-
 		fflush(NULL);
+		}
 	}
 
 

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