[m-rev.] diff: minor agc debugging improvements

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 30 20:51:23 AEDT 2003


Estimated hours taken: 0.5
Branches: main

Some minor improvements to the infrastructure used to debug accurate GC.

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.

runtime/mercury_agc_debug.c:
runtime/mercury_debug.c:
        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 -r1.23 mercury_agc_debug.c
--- runtime/mercury_agc_debug.c	18 Nov 2003 07:05:01 -0000	1.23
+++ runtime/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,32 +50,34 @@
 	fflush(NULL);
 	fprintf(stderr, "Dumping roots\n");
 
-  #ifdef MR_DEBUG_AGC_PRINT_VARS
-	while (roots != NULL) {
+  	if (MR_debug_agc_print_vars) {
+		while (roots != NULL) {
 
 
-		/*
-		** Restore the registers, because we need to save them
-		** to a more permanent backing store (we are going to
-		** call Mercury soon, and we don't want it messing with
-		** the saved registers).
-		*/
-		MR_restore_registers();
-		MR_copy_regs_to_saved_regs(MR_MAX_FAKE_REG - 1, saved_regs);
+			/*
+			** Restore the registers, because we need to save them
+			** to a more permanent backing store (we are going to
+			** call Mercury soon, and we don't want it messing with
+			** the saved registers).
+			*/
+			MR_restore_registers();
+			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);
+			MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
+			MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
 
-		fflush(NULL);
-		MR_write_variable(roots->type_info, *roots->root);
-		fflush(NULL);
-		fprintf(stderr, "\n");
+			fflush(NULL);
+			MR_write_variable(roots->type_info, *roots->root);
+			fflush(NULL);
+			fprintf(stderr, "\n");
 
-		MR_copy_saved_regs_to_regs(MR_MAX_FAKE_REG - 1, saved_regs);
-		MR_save_registers();
-		roots = roots->next;
+			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,26 +283,25 @@
 		fprintf(stderr, "\n");
 		fflush(NULL);
 
-#ifdef MR_DEBUG_AGC_PRINT_VARS
-		/*
-		** Call Mercury but use the debugging heap.
-		*/
-
-		MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
-		MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
+		if (MR_debug_agc_print_vars) {
+			/*
+			** Call Mercury but use the debugging heap.
+			*/
 
-		if (MR_get_type_and_value_base(label_layout, i,
-				current_regs, stack_pointer,
-				current_frame, type_params,
-				&type_info, &value)) {
-			printf("\t");
-			MR_write_variable(type_info, value);
-			printf("\n");
-		}
+			MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
+			MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
 
-#endif	/* MR_DEBUG_AGC_PRINT_VARS */
+			if (MR_get_type_and_value_base(label_layout, i,
+					current_regs, stack_pointer,
+					current_frame, type_params,
+					&type_info, &value)) {
+				printf("\t");
+				MR_write_variable(type_info, value);
+				printf("\n");
+			}
 
-		fflush(NULL);
+			fflush(NULL);
+		}
 	}
 
 	for (; i < short_var_count; i++) {
@@ -303,26 +315,25 @@
 		fprintf(stderr, "\n");
 		fflush(NULL);
 
-#ifdef MR_DEBUG_AGC_PRINT_VARS
-		/*
-		** Call Mercury but use the debugging heap.
-		*/
-
-		MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
-		MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
+		if (MR_debug_agc_print_vars) {
+			/*
+			** Call Mercury but use the debugging heap.
+			*/
 
-		if (MR_get_type_and_value_base(label_layout, i,
-				current_regs, stack_pointer,
-				current_frame, type_params,
-				&type_info, &value)) {
-			printf("\t");
-			MR_write_variable(type_info, value);
-			printf("\n");
-		}
+			MR_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
+			MR_virtual_hp = MR_ENGINE(MR_eng_debug_heap_zone->min);
 
-#endif	/* MR_DEBUG_AGC_PRINT_VARS */
+			if (MR_get_type_and_value_base(label_layout, i,
+					current_regs, stack_pointer,
+					current_frame, type_params,
+					&type_info, &value)) {
+				printf("\t");
+				MR_write_variable(type_info, value);
+				printf("\n");
+			}
 
-		fflush(NULL);
+			fflush(NULL);
+		}
 	}
 
 
Index: runtime/mercury_debug.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_debug.c,v
retrieving revision 1.18
diff -u -d -r1.18 mercury_debug.c
--- runtime/mercury_debug.c	20 Oct 2003 07:29:31 -0000	1.18
+++ runtime/mercury_debug.c	30 Dec 2003 05:28:53 -0000
@@ -881,7 +881,7 @@
 		if (internal->i_name != NULL) {
 			fprintf(fp, "label %s", internal->i_name);
 		} else {
-			fprintf(fp, "unnamed label");
+			fprintf(fp, "unnamed label %p", internal->i_addr);
 		}
 	} else {
 #ifdef	MR_NEED_ENTRY_LABEL_ARRAY
@@ -892,13 +892,14 @@
 			if (entry->e_name != NULL) {
 				fprintf(fp, "entry label %s", entry->e_name);
 			} else {
-				fprintf(fp, "unnamed entry label");
+				fprintf(fp, "unnamed entry label %p",
+					entry->e_addr);
 			}
 		} else {
-			fprintf(fp, "label UNKNOWN");
+			fprintf(fp, "label UNKNOWN %p", w);
 		}
 #else
-		fprintf(fp, "label UNKNOWN");
+		fprintf(fp, "label UNKNOWN %p", w);
 #endif	/* not MR_NEED_ENTRY_LABEL_ARRAY */
 	}
 

-- 
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