[m-rev.] for review: speed up the declarative debugger

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Aug 2 16:11:54 AEST 2005


For review and benchmarking by Ian.

Zoltan.

Reduce the overhead of gathering the annotated trace by specializing the code
paths that lead there.

trace/mercury_trace.[ch]:
	Provide a new function MR_trace_real_decl, which combines the
	functionality of MR_trace_real and MR_trace_event and then discards
	several tests not needed when building the annotated trace. These
	tests include checking what the current mdb command is and whether a
	spypoint applies to the current event.

	Export MR_trace_ctrl for use by mercury_trace_declarative.c. This
	allows us to avoid the overhead of passing it around on every event,
	even though it is needed only for the final event.

trace/mercury_trace_internal.[ch]:
	Delete the old type MR_Trace_Mode and the global variable
	MR_trace_decl_mode, which used to indicate whether we are gathering
	the annotated trace or doing something else. This binary choice is
	now encoded in whether MR_selected_trace_func_ptr points to
	MR_trace_real_decl or to MR_trace_real.

	Factor out some duplicate code.

trace/mercury_trace_declarative.[ch]:
	Replace the old type MR_Trace_Mode with MR_Decl_Mode, which now says
	whether we are dumping the gathered annotated trace.

	Use the new method of switching from annotated trace gathering to
	other event processing and vice versa.

cvs diff: Diffing .
cvs diff: Diffing analysis
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/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
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/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
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/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
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 samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
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.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.83
diff -u -r1.83 mercury_trace.c
--- trace/mercury_trace.c	1 Aug 2005 02:26:25 -0000	1.83
+++ trace/mercury_trace.c	1 Aug 2005 09:08:19 -0000
@@ -49,13 +49,14 @@
 #include "mercury_trace.h"
 #include "mercury_trace_internal.h"
 #include "mercury_trace_external.h"
+#include "mercury_trace_declarative.h"
 #include "mercury_trace_spy.h"
 #include "mercury_trace_util.h"
 #include "mercury_trace_vars.h"
 
 #include <stdio.h>
 
-static  MR_Trace_Cmd_Info   MR_trace_ctrl = {
+MR_Trace_Cmd_Info   MR_trace_ctrl = {
     MR_CMD_GOTO,
     0,                      /* stop depth */
     0,                      /* stop event */
@@ -119,8 +120,51 @@
 ** MR_trace_real() is called via a function pointer from MR_trace()
 ** in runtime/mercury_trace_base.c, which in turn is called from
 ** compiled code whenever an event to be traced occurs.
+**
+** The initial part, MR_TRACE_REAL_SETUP_CODE, is shared by MR_trace_real and
+** MR_trace_real_decl.
 */
 
+#if defined(MR_USE_MINIMAL_MODEL_STACK_COPY) && defined(MR_MINIMAL_MODEL_DEBUG)
+  #define MR_TRACE_SETUP_MAYBE_SAVE_SUBGOAL_CUR_PROC                          \
+        if ((MR_Trace_Port) layout->MR_sll_port == MR_PORT_CALL) {            \
+            MR_subgoal_debug_cur_proc = layout->MR_sll_entry;                 \
+        }
+#else
+  #define MR_TRACE_SETUP_MAYBE_SAVE_SUBGOAL_CUR_PROC
+#endif
+
+#define MR_TRACE_REAL_SETUP_CODE()                                            \
+    do {                                                                      \
+        /* In case MR_sp or MR_curfr is transient. */                         \
+        MR_restore_transient_registers();                                     \
+                                                                              \
+        maybe_from_full = layout->MR_sll_entry->MR_sle_maybe_from_full;       \
+        if (MR_DETISM_DET_STACK(layout->MR_sll_entry->MR_sle_detism)) {       \
+            if (maybe_from_full > 0 && ! MR_stackvar(maybe_from_full)) {      \
+                return NULL;                                                  \
+            }                                                                 \
+                                                                              \
+            seqno = (MR_Unsigned) MR_call_num_stackvar(MR_sp);                \
+            depth = (MR_Unsigned) MR_call_depth_stackvar(MR_sp);              \
+        } else {                                                              \
+            if (maybe_from_full > 0 && ! MR_framevar(maybe_from_full)) {      \
+                return NULL;                                                  \
+            }                                                                 \
+                                                                              \
+            seqno = (MR_Unsigned) MR_call_num_framevar(MR_curfr);             \
+            depth = (MR_Unsigned) MR_call_depth_framevar(MR_curfr);           \
+        }                                                                     \
+                                                                              \
+        MR_TRACE_SETUP_MAYBE_SAVE_SUBGOAL_CUR_PROC                            \
+                                                                              \
+        if (layout->MR_sll_hidden && !MR_trace_unhide_events) {               \
+            return NULL;                                                      \
+        }                                                                     \
+                                                                              \
+        MR_trace_event_number++;                                              \
+    } while (0)
+
 MR_Code *
 MR_trace_real(const MR_Label_Layout *layout)
 {
@@ -131,37 +175,7 @@
     MR_bool             match;
     MR_Trace_Port       port;
 
-    /* in case MR_sp or MR_curfr is transient */
-    MR_restore_transient_registers();
-
-    maybe_from_full = layout->MR_sll_entry->MR_sle_maybe_from_full;
-    if (MR_DETISM_DET_STACK(layout->MR_sll_entry->MR_sle_detism)) {
-        if (maybe_from_full > 0 && ! MR_stackvar(maybe_from_full)) {
-            return NULL;
-        }
-
-        seqno = (MR_Unsigned) MR_call_num_stackvar(MR_sp);
-        depth = (MR_Unsigned) MR_call_depth_stackvar(MR_sp);
-    } else {
-        if (maybe_from_full > 0 && ! MR_framevar(maybe_from_full)) {
-            return NULL;
-        }
-
-        seqno = (MR_Unsigned) MR_call_num_framevar(MR_curfr);
-        depth = (MR_Unsigned) MR_call_depth_framevar(MR_curfr);
-    }
-
-#if defined(MR_USE_MINIMAL_MODEL_STACK_COPY) && defined(MR_MINIMAL_MODEL_DEBUG)
-    if ((MR_Trace_Port) layout->MR_sll_port == MR_PORT_CALL) {
-        MR_subgoal_debug_cur_proc = layout->MR_sll_entry;
-    }
-#endif
-
-    if (layout->MR_sll_hidden && !MR_trace_unhide_events) {
-        return NULL;
-    }
-
-    MR_trace_event_number++;
+    MR_TRACE_REAL_SETUP_CODE();
 
 #ifdef  MR_TRACE_HISTOGRAM
 
@@ -426,10 +440,9 @@
         seqno = (MR_Unsigned) MR_call_num_framevar(MR_curfr);
         depth = (MR_Unsigned) MR_call_depth_framevar(MR_curfr);
     }
-    port = (MR_Trace_Port) layout->MR_sll_port;
 
+    port = (MR_Trace_Port) layout->MR_sll_port;
     MR_trace_event_number++;
-
     return MR_trace_event(&MR_trace_ctrl, MR_TRUE, layout, port, seqno, depth);
 }
 
@@ -446,25 +459,59 @@
     MR_selected_trace_func_ptr = MR_trace_interrupt;
 }
 
+/*
+** The MR_TRACE_EVENT_DECL_AND_SETUP macro is the initial part of
+** MR_trace_event, shared also by MR_trace_real_decl.
+**
+** It must be included in a context that defines layout, port, seqno and depth.
+*/
+
+#define MR_TRACE_EVENT_DECL_AND_SETUP                                         \
+    MR_Code         *jumpaddr;                                                \
+    MR_Event_Info   event_info;                                               \
+    MR_Word         *saved_regs = event_info.MR_saved_regs;                   \
+                                                                              \
+    event_info.MR_event_number = MR_trace_event_number;                       \
+    event_info.MR_call_seqno = seqno;                                         \
+    event_info.MR_call_depth = depth;                                         \
+    event_info.MR_trace_port = port;                                          \
+    event_info.MR_event_sll = layout;                                         \
+    event_info.MR_event_path = MR_label_goal_path(layout);                    \
+                                                                              \
+    MR_compute_max_mr_num(event_info.MR_max_mr_num, layout);                  \
+    /* This also saves the regs in MR_fake_regs. */                           \
+    MR_copy_regs_to_saved_regs(event_info.MR_max_mr_num, saved_regs);
+
+/*
+** The MR_TRACE_EVENT_TEARDOWN macro is the final part of
+** MR_trace_event, shared also by MR_trace_real_decl.
+**
+** It must be included in a context that defines jumpaddr, saved_regs and
+** event_info.
+**
+** Whenever the debugger changes the flow of control, e.g. by
+** executing a retry command, it also sets up the saved registers
+** to the state that is appropriate for the label at which execution
+** will resume. There may be more registers live at that point than
+** at the point at which MR_trace was called. Therefore max_mr_num
+** should also be set appropriately when executing a retry command.
+**
+** For the treatment of MR_global_hp, see the top of this file.
+*/
+
+#define MR_TRACE_EVENT_TEARDOWN                                               \
+    /* In case MR_global_hp is transient. */                                  \
+    MR_restore_transient_registers();                                         \
+    MR_saved_global_hp_word(saved_regs) = (MR_Word) MR_global_hp;             \
+    MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, saved_regs);         \
+    return jumpaddr;
+
 static MR_Code *
 MR_trace_event(MR_Trace_Cmd_Info *cmd, MR_bool interactive,
     const MR_Label_Layout *layout, MR_Trace_Port port,
     MR_Unsigned seqno, MR_Unsigned depth)
 {
-    MR_Code         *jumpaddr;
-    MR_Event_Info   event_info;
-    MR_Word         *saved_regs = event_info.MR_saved_regs;
-
-    event_info.MR_event_number = MR_trace_event_number;
-    event_info.MR_call_seqno = seqno;
-    event_info.MR_call_depth = depth;
-    event_info.MR_trace_port = port;
-    event_info.MR_event_sll = layout;
-    event_info.MR_event_path = MR_label_goal_path(layout);
-
-    MR_compute_max_mr_num(event_info.MR_max_mr_num, layout);
-    /* This also saves the regs in MR_fake_regs. */
-    MR_copy_regs_to_saved_regs(event_info.MR_max_mr_num, saved_regs);
+    MR_TRACE_EVENT_DECL_AND_SETUP
 
 #ifdef MR_USE_EXTERNAL_DEBUGGER
     if (MR_trace_handler == MR_TRACE_EXTERNAL) {
@@ -486,26 +533,36 @@
     ** We should get here only if MR_trace_handler == MR_TRACE_INTERNAL.
     ** This is enforced by mercury_wrapper.c.
     */
+    {
+        MR_Spy_Action       action;         /* ignored */
+        MR_Spy_Print_List   print_list;
 
-    jumpaddr = MR_trace_event_internal(cmd, interactive, &event_info);
+        (void) MR_event_matches_spy_point(layout, port, &action, &print_list);
+        jumpaddr = MR_trace_event_internal(cmd, interactive, print_list,
+            &event_info);
+    }
 #endif
 
-    /*
-    ** Whenever the debugger changes the flow of control, e.g. by
-    ** executing a retry command, it also sets up the saved registers
-    ** to the state that is appropriate for the label at which execution
-    ** will resume. There may be more registers live at that point than
-    ** at the point at which MR_trace was called. Therefore max_mr_num
-    ** should also be set appropriately when executing a retry command.
-    **
-    ** For the treatment of MR_global_hp, see the top of this file.
-    */
+    MR_TRACE_EVENT_TEARDOWN
+}
 
-        /* in case MR_global_hp is transient */
-    MR_restore_transient_registers();
-    MR_saved_global_hp_word(saved_regs) = (MR_Word) MR_global_hp;
-    MR_copy_saved_regs_to_regs(event_info.MR_max_mr_num, saved_regs);
-    return jumpaddr;
+MR_Code *
+MR_trace_real_decl(const MR_Label_Layout *layout)
+{
+    MR_Integer          maybe_from_full;
+    MR_Unsigned         seqno;
+    MR_Unsigned         depth;
+    MR_Trace_Port       port;
+
+    MR_TRACE_REAL_SETUP_CODE();
+
+    port = (MR_Trace_Port) layout->MR_sll_port;
+
+    {
+        MR_TRACE_EVENT_DECL_AND_SETUP
+        jumpaddr = MR_trace_decl_debug(&event_info);
+        MR_TRACE_EVENT_TEARDOWN
+    }
 }
 
 /*****************************************************************************/
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.29
diff -u -r1.29 mercury_trace.h
--- trace/mercury_trace.h	6 Apr 2005 01:11:32 -0000	1.29
+++ trace/mercury_trace.h	1 Aug 2005 09:07:22 -0000
@@ -63,8 +63,13 @@
 ** MR_trace_real may be taken in automatically generated <main>_init.c files,
 ** and we do not want to include mercury_trace.h in such files; we don't want
 ** them to refer to the trace directory at all unless debugging is enabled.
+**
+** MR_trace_real_decl is the version of MR_trace_real we use when gathering
+** events for the annotated trace.
 */
 
+extern  MR_Code *MR_trace_real_decl(const MR_Label_Layout *);
+
 /*
 ** Ideally, MR_trace_retry works by resetting the state of the stacks and
 ** registers to the state appropriate for the call to the selected ancestor,
@@ -254,6 +259,13 @@
 				*/
 	MR_FilterFuncPtr	MR_filter_ptr;
 } MR_Trace_Cmd_Info;
+
+/*
+** The data structure that tells MR_trace_real and MR_trace_real_decl
+** what to do. Exported only for use by mercury_trace_declarative.c.
+*/
+
+extern	MR_Trace_Cmd_Info   	MR_trace_ctrl;
 
 #ifdef	MR_TRACE_CHECK_INTEGRITY
   #define MR_init_trace_check_integrity(cmd)	\
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.93
diff -u -r1.93 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	1 Aug 2005 02:26:25 -0000	1.93
+++ trace/mercury_trace_declarative.c	1 Aug 2005 09:07:43 -0000
@@ -108,6 +108,7 @@
 #include "mercury_imp.h"
 #include "mercury_trace_declarative.h"
 
+#include "mercury_init.h"               /* for MR_trace_real */
 #include "mercury_trace.h"
 #include "mercury_trace_browse.h"
 #include "mercury_trace_help.h"
@@ -177,17 +178,17 @@
 
 #ifdef MR_DD_PRINT_EDT_STATS
 
-static    MR_Unsigned    MR_edt_stats_total_constructed_nodes = 0;
-static    MR_Unsigned    MR_edt_stats_constructed_nodes_this_time = 0;
-static    MR_Unsigned    MR_edt_stats_total_reexecutions = 0;
+static  MR_Unsigned         MR_edt_stats_total_constructed_nodes = 0;
+static  MR_Unsigned         MR_edt_stats_constructed_nodes_this_time = 0;
+static  MR_Unsigned         MR_edt_stats_total_reexecutions = 0;
 
-#define   MR_decl_maybe_print_edt_stats() MR_decl_print_edt_stats()
-#define   MR_decl_maybe_inc_constructed_nodes() MR_decl_inc_constructed_nodes()
+#define MR_decl_maybe_print_edt_stats()         MR_decl_print_edt_stats()
+#define MR_decl_maybe_inc_constructed_nodes()   MR_decl_inc_constructed_nodes()
 
 #else /* MR_DD_PRINT_EDT_STATS */
 
-#define    MR_decl_maybe_print_edt_stats()
-#define    MR_decl_maybe_inc_constructed_nodes()
+#define MR_decl_maybe_print_edt_stats()
+#define MR_decl_maybe_inc_constructed_nodes()
 
 #endif /* MR_DD_PRINT_EDT_STATS */
 
@@ -199,6 +200,8 @@
 ** take for a particular trace event.
 */
 
+static  MR_Decl_Mode        MR_decl_mode = MR_DECL_NODUMP;
+
 /*
 ** If we are building a subtree then reaching this event will cause the
 ** declarative debugger to continue its analysis.  Reaching this event means
@@ -206,7 +209,7 @@
 ** when building a new explicit supertree.
 */
 
-static    MR_Unsigned   MR_edt_last_event;
+static  MR_Unsigned         MR_edt_last_event;
 
 /*
 ** If we are materializing a new subtree then MR_edt_start_seqno is the
@@ -216,7 +219,7 @@
 ** materialized portion of the annotated trace.
 */
 
-static    MR_Unsigned   MR_edt_start_seqno;
+static  MR_Unsigned         MR_edt_start_seqno;
 
 /*
 ** This tells MR_trace_decl_debug whether it is inside a portion of the
@@ -229,7 +232,7 @@
 ** materialized).
 */
 
-static    MR_bool       MR_edt_inside;
+static  MR_bool             MR_edt_inside;
 
 /*
 ** The initial event at which the `dd' command was given.  This is used when
@@ -237,14 +240,14 @@
 ** the declarative debugging session.
 */
 
-static    MR_Unsigned   MR_edt_initial_event;
+static  MR_Unsigned         MR_edt_initial_event;
 
 /*
 ** This variable indicates whether we are building a supertree above a
 ** given event or a subtree rooted at a given event.
 */
 
-static    MR_bool       MR_edt_building_supertree;
+static  MR_bool             MR_edt_building_supertree;
 
 /*
 ** The node returned to the front end once a subtree or supertree has been
@@ -253,7 +256,7 @@
 ** the root of the new explicit subtree is returned.
 */
 
-static    MR_Trace_Node MR_edt_return_node;
+static  MR_Trace_Node       MR_edt_return_node;
 
 /*
 ** The depth of the EDT is different from the call depth of the events, since
@@ -264,14 +267,14 @@
 ** for the root of the tree we are materializing.
 */
 
-static    MR_Integer    MR_edt_depth;
+static  MR_Integer          MR_edt_depth;
 
 /*
 ** Events where the value of MR_edt_depth above is greater than the value of
 ** MR_edt_max_depth will not be included in tha annotated trace.
 */
 
-static    MR_Unsigned   MR_edt_max_depth;
+static  MR_Unsigned         MR_edt_max_depth;
 
 /*
 ** The time (in milliseconds since the start of the program) when collection of
@@ -279,29 +282,30 @@
 ** started.
 */
 
-static    MR_Unsigned   MR_edt_start_time;
+static  MR_Unsigned         MR_edt_start_time;
 
 /*
 ** This global keeps track of how many ticks have been printed so far in
 ** the progress message.
 */
 
-static    MR_Unsigned   MR_edt_progress_last_tick = 0;
+static  MR_Unsigned         MR_edt_progress_last_tick = 0;
 
 /*
 ** The first event executed during the current re-execution.
 */
-static    MR_Unsigned   MR_edt_first_event;
+
+static  MR_Unsigned         MR_edt_first_event;
 
 /*
-** This global points to an array that records the number of
-** events at different depths in implicit subtrees.  These
-** are used to determine what depth an implicit subtree should
+** MR_edt_implicit_subtree_counters points to an array that records
+** the number of events at different depths in implicit subtrees.
+** These are used to determine what depth an implicit subtree should
 ** be materialized to.
 */
 
-static    MR_Unsigned   *MR_edt_implicit_subtree_counters;
-static    MR_Unsigned   MR_edt_implicit_subtree_num_counters;
+static  MR_Unsigned         *MR_edt_implicit_subtree_counters;
+static  MR_Unsigned         MR_edt_implicit_subtree_num_counters;
 
 /*
 ** The declarative debugger ignores modules that were not compiled with
@@ -311,7 +315,7 @@
 ** should be printed before calling the front end.
 */
 
-static    MR_bool       MR_edt_compiler_flag_warning;
+static  MR_bool             MR_edt_compiler_flag_warning;
 
 /*
 ** When building a supertree there will be 2 retries.  The first will
@@ -322,7 +326,7 @@
 ** okay then there's no point asking them again for the second retry.
 */
 
-static    MR_bool       MR_edt_unsafe_retry_already_asked;
+static  MR_bool             MR_edt_unsafe_retry_already_asked;
 
 /*
 ** This is used as the abstract map from node identifiers to nodes
@@ -331,24 +335,23 @@
 ** updated, before being passed to Mercury code again.
 */
 
-static    MR_Unsigned   MR_trace_node_store;
+static  MR_Unsigned         MR_trace_node_store;
 
 /*
 ** The front end state is stored here in between calls to it.
 ** MR_trace_decl_ensure_init should be called before using the state.
 */
 
-static    MR_Word       MR_trace_front_end_state;
+static  MR_Word             MR_trace_front_end_state;
 
-static    void
-MR_trace_decl_ensure_init(void);
+static  void                MR_trace_decl_ensure_init(void);
 
 /*
 ** MR_trace_current_node always contains the last node allocated,
 ** or NULL if the collection has just started.
 */
 
-static    MR_Trace_Node MR_trace_current_node;
+static  MR_Trace_Node       MR_trace_current_node;
 
 /*
 ** When in test mode, MR_trace_store_file points to an open file to
@@ -357,7 +360,9 @@
 ** throughout the declarative debugging session.
 */
 
-static    FILE              *MR_trace_store_file;
+static  FILE                *MR_trace_store_file;
+
+/****************************************************************************/
 
 static    MR_Trace_Node     MR_trace_decl_call(MR_Event_Info *event_info,
                                 MR_Trace_Node prev);
@@ -464,18 +469,19 @@
 static    void              MR_trace_free_implicit_subtree_counters(void);
 static    MR_Unsigned       MR_trace_calc_implicit_subtree_ideal_depth(void);
 
-MR_bool    MR_trace_decl_assume_all_io_is_tabled = MR_FALSE;
+MR_bool     MR_trace_decl_assume_all_io_is_tabled = MR_FALSE;
 
 MR_Unsigned MR_edt_desired_nodes_in_subtree = MR_TRACE_DESIRED_SUBTREE_NODES;
 MR_Unsigned MR_edt_default_depth_limit = MR_TRACE_DECL_INITIAL_DEPTH;
 
-MR_bool    MR_trace_decl_in_dd_dd_mode = MR_FALSE;
+MR_bool     MR_trace_decl_in_dd_dd_mode = MR_FALSE;
 
 /*
 ** We filter out events which are deeper than the limit given by
 ** MR_edt_max_depth.  These events are implicitly represented in the structure
 ** being built.
 */
+
 #define MR_TRACE_EVENT_TOO_DEEP(depth) (depth > MR_edt_max_depth)
 
 /*
@@ -485,7 +491,7 @@
 */
 
 MR_Code *
-MR_trace_decl_debug(MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info)
+MR_trace_decl_debug(MR_Event_Info *event_info)
 {
     const MR_Proc_Layout    *entry;
     MR_Unsigned             depth;
@@ -547,7 +553,7 @@
         event_details.MR_call_depth = MR_trace_call_depth;
         event_details.MR_event_number = MR_trace_event_number;
 
-        return MR_decl_diagnosis(MR_edt_return_node, cmd,
+        return MR_decl_diagnosis(MR_edt_return_node, &MR_trace_ctrl,
             event_info, &event_details, MR_TRUE);
     }
 
@@ -847,7 +853,7 @@
 
     if (retry_result != MR_RETRY_OK_DIRECT) {
         if (retry_result == MR_RETRY_ERROR) {
-            MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+            MR_selected_trace_func_ptr = MR_trace_real;
             fflush(MR_mdb_out);
             fprintf(MR_mdb_err,
                 "mdb: retry aborted in MR_trace_decl_retry_supertree: %s\n",
@@ -1587,7 +1593,7 @@
 }
 
 MR_bool
-MR_trace_start_decl_debug(MR_Trace_Mode trace_mode, const char *outfile,
+MR_trace_start_decl_debug(MR_Decl_Mode mode, const char *outfile,
     MR_bool new_session, MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
     MR_Event_Details *event_details, MR_Code **jumpaddr)
 {
@@ -1606,7 +1612,8 @@
     ** build a new annotated trace.
     */
     if (!new_session && !first_time) {
-        MR_trace_decl_mode = trace_mode;
+        MR_decl_mode = mode;
+        MR_selected_trace_func_ptr = MR_trace_real_decl;
         *jumpaddr = MR_decl_diagnosis((MR_Trace_Node) NULL, cmd,
             event_info, event_details, MR_FALSE);
         return MR_TRUE;
@@ -1661,7 +1668,7 @@
         return MR_FALSE;
     }
 
-    if (trace_mode == MR_TRACE_DECL_DEBUG_DUMP) {
+    if (mode == MR_DECL_DUMP) {
         out = fopen(outfile, "w");
         if (out == NULL) {
             fflush(MR_mdb_out);
@@ -1673,7 +1680,8 @@
         }
     }
 
-    MR_trace_decl_mode = trace_mode;
+    MR_decl_mode = mode;
+    MR_selected_trace_func_ptr = MR_trace_real_decl;
     MR_trace_decl_ensure_init();
     MR_trace_current_node = (MR_Trace_Node) NULL;
     message = MR_trace_start_collecting(event_info->MR_event_number,
@@ -1693,9 +1701,8 @@
 }
 
 static MR_Code *
-MR_trace_restart_decl_debug(
-    MR_Trace_Node call_preceding, MR_Unsigned event, MR_Unsigned seqno,
-    MR_bool create_supertree, MR_Unsigned depth_limit,
+MR_trace_restart_decl_debug(MR_Trace_Node call_preceding, MR_Unsigned event,
+    MR_Unsigned seqno, MR_bool create_supertree, MR_Unsigned depth_limit,
     MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
     MR_Event_Details *event_details)
 {
@@ -1716,7 +1723,7 @@
     if (message != NULL) {
         fflush(MR_mdb_out);
         fprintf(MR_mdb_err, "mdb: diagnosis aborted:\n%s\n", message);
-        MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+        MR_selected_trace_func_ptr = MR_trace_real;
         MR_debug_enabled = MR_TRUE;
         MR_update_trace_func_enabled();
         return MR_trace_event_internal(cmd, MR_TRUE, NULL, event_info);
@@ -1743,6 +1750,7 @@
     ** call event number corresponding to seqno.  Since we don't have the
     ** call event number for seqno (`event' is the final event number,
     ** not the call event number), we do a retry if:
+    **
     **    a) The call sequence number of the current call is greater than
     **       or equal to seqno, or
     **    b) The current event number is greater than the final event
@@ -1753,7 +1761,7 @@
     ** event is greater than or equal to the call event for seqno and less
     ** than or equal to the final event for seqno.  This means we will do
     ** a retry if the call event for seqno is equal to the current event
-    ** but thats not a problem since the retry will be a no-op.
+    ** but that is not a problem since the retry will be a no-op.
     */
     if (event_info->MR_call_seqno >= seqno ||
         event_info->MR_event_number > event)
@@ -1779,6 +1787,7 @@
                 return "internal error: direct retry impossible";
             }
         }
+
         if (unsafe_retry) {
             MR_edt_unsafe_retry_already_asked = MR_TRUE;
         }
@@ -1859,7 +1868,7 @@
             " the debugging tree.\n");
     }
 
-    if (MR_trace_decl_mode == MR_TRACE_DECL_DEBUG_DUMP && new_tree) {
+    if (MR_decl_mode == MR_DECL_DUMP && new_tree) {
         MR_mercuryfile_init(MR_trace_store_file, 1, &stream);
 
         MR_TRACE_CALL_MERCURY(
@@ -1867,7 +1876,7 @@
         );
 
         fclose(MR_trace_store_file);
-        MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+        MR_selected_trace_func_ptr = MR_trace_real;
         MR_debug_enabled = MR_TRUE;
         MR_update_trace_func_enabled();
         MR_trace_call_seqno = event_details->MR_call_seqno;
@@ -1883,26 +1892,25 @@
         */
         MR_debug_enabled = MR_TRUE;
         MR_update_trace_func_enabled();
-        MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+        MR_selected_trace_func_ptr = MR_trace_real;
     } else {
         MR_debug_enabled = MR_FALSE;
         MR_update_trace_func_enabled();
-        MR_trace_decl_mode = MR_TRACE_DECL_DEBUG;
+        MR_selected_trace_func_ptr = MR_trace_real_decl;
     }
 
     MR_TRACE_CALL_MERCURY(
-        if (new_tree == MR_TRUE) {
+        if (new_tree) {
             MR_DD_decl_diagnosis_new_tree(MR_trace_node_store,
-                root, &response, MR_trace_front_end_state,
-                &MR_trace_front_end_state,
+                root, &response,
+                MR_trace_front_end_state, &MR_trace_front_end_state,
                 MR_trace_browser_persistent_state,
                 &MR_trace_browser_persistent_state
             );
         } else {
-            MR_DD_decl_diagnosis_resume_previous(
-                MR_trace_node_store,
-                &response, MR_trace_front_end_state,
-                &MR_trace_front_end_state,
+            MR_DD_decl_diagnosis_resume_previous(MR_trace_node_store,
+                &response,
+                MR_trace_front_end_state, &MR_trace_front_end_state,
                 MR_trace_browser_persistent_state,
                 &MR_trace_browser_persistent_state
             );
@@ -1928,7 +1936,7 @@
     */
     MR_debug_enabled = MR_FALSE;
     MR_update_trace_func_enabled();
-    MR_trace_decl_mode = MR_TRACE_DECL_DEBUG;
+    MR_selected_trace_func_ptr = MR_trace_real_decl;
 
     MR_trace_call_seqno = event_details->MR_call_seqno;
     MR_trace_call_depth = event_details->MR_call_depth;
@@ -2041,7 +2049,7 @@
                 }
             }
 
-            MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+            MR_selected_trace_func_ptr = MR_trace_real;
             MR_debug_enabled = MR_TRUE;
             MR_update_trace_func_enabled();
             return MR_trace_event_internal(cmd, MR_TRUE, NULL, event_info);
@@ -2060,7 +2068,7 @@
     cmd->MR_trace_print_level = MR_PRINT_LEVEL_NONE;
     cmd->MR_trace_strict = MR_TRUE;
     cmd->MR_trace_must_check = MR_FALSE;
-    MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+    MR_selected_trace_func_ptr = MR_trace_real;
     MR_debug_enabled = MR_TRUE;
     MR_update_trace_func_enabled();
     return jumpaddr;
Index: trace/mercury_trace_declarative.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_declarative.h,v
retrieving revision 1.24
diff -u -r1.24 mercury_trace_declarative.h
--- trace/mercury_trace_declarative.h	20 May 2005 05:40:37 -0000	1.24
+++ trace/mercury_trace_declarative.h	1 Aug 2005 09:08:03 -0000
@@ -16,8 +16,7 @@
 ** MR_trace_decl_debug for each event.  
 */
 
-extern	MR_Code	*MR_trace_decl_debug(MR_Trace_Cmd_Info *cmd,
-			MR_Event_Info *event_info);
+extern	MR_Code	*MR_trace_decl_debug(MR_Event_Info *event_info);
 
 /*
 ** The internal (interactive) debugger calls this function to enter
@@ -26,9 +25,10 @@
 ** being entered.
 */
 
-extern	MR_bool	MR_trace_start_decl_debug(MR_Trace_Mode trace_mode,
-			const char *out, MR_bool new_session,
-			MR_Trace_Cmd_Info *cmd,
+typedef enum { MR_DECL_NODUMP, MR_DECL_DUMP } MR_Decl_Mode;
+
+extern	MR_bool	MR_trace_start_decl_debug(MR_Decl_Mode mode, const char *out,
+			MR_bool new_session, MR_Trace_Cmd_Info *cmd,
 			MR_Event_Info *event_info,
 			MR_Event_Details *event_details, MR_Code **jumpaddr);
 
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.209
diff -u -r1.209 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	1 Aug 2005 02:40:13 -0000	1.209
+++ trace/mercury_trace_internal.c	2 Aug 2005 06:10:05 -0000
@@ -276,8 +276,6 @@
     "MDB INTERNAL ERROR: scope set to MR_SPY_LINENO",
 };
 
-MR_Trace_Mode MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-
 typedef enum {
     MR_MULTIMATCH_ASK, MR_MULTIMATCH_ALL, MR_MULTIMATCH_ONE
 } MR_MultiMatch;
@@ -776,10 +774,6 @@
         return MR_trace_event_internal_report(cmd, print_list, event_info);
     }
 
-    if (MR_trace_decl_mode != MR_TRACE_INTERACTIVE) {
-        return MR_trace_decl_debug(cmd, event_info);
-    }
-
     /*
     ** We want to make sure that the Mercury code used to implement some
     ** of the debugger's commands (a) doesn't generate any trace events,
@@ -5810,13 +5804,13 @@
                 "mdb: dd doesn't work after `unhide_events on'.\n");
             return KEEP_INTERACTING;
         }
-        if (search_mode_was_set) {
-            MR_trace_decl_set_fallback_search_mode(search_mode);
-        } else if (new_session) {
+
+        if (search_mode_was_set || new_session) {
             MR_trace_decl_set_fallback_search_mode(search_mode);
         }
-        if (MR_trace_start_decl_debug(MR_TRACE_DECL_DEBUG,
-            NULL, new_session, cmd, event_info, event_details, jumpaddr))
+
+        if (MR_trace_start_decl_debug(MR_DECL_NODUMP, NULL, new_session, cmd,
+            event_info, event_details, jumpaddr))
         {
             return STOP_INTERACTING;
         }
@@ -5832,7 +5826,7 @@
     MR_Event_Info *event_info, MR_Event_Details *event_details,
     MR_Code **jumpaddr)
 {
-    MR_Trace_Mode       trace_mode;
+    MR_Decl_Mode        mode;
     const char          *filename;
     MR_Decl_Search_Mode search_mode;
     MR_bool             search_mode_was_set = MR_FALSE;
@@ -5851,19 +5845,19 @@
         ; /* the usage message has already been printed */
     } else if (word_count <= 2) {
         if (word_count == 2) {
-            trace_mode = MR_TRACE_DECL_DEBUG_DUMP;
+            mode = MR_DECL_DUMP;
             filename = (const char *) words[1];
         } else {
-            trace_mode = MR_TRACE_DECL_DEBUG;
+            mode = MR_DECL_NODUMP;
             filename = (const char *) NULL;
         }
-        if (search_mode_was_set) {
-            MR_trace_decl_set_fallback_search_mode(search_mode);
-        } else if (new_session) {
+
+        if (search_mode_was_set || new_session) {
             MR_trace_decl_set_fallback_search_mode(search_mode);
         }
-        if (MR_trace_start_decl_debug(trace_mode, filename,
-            new_session, cmd, event_info, event_details, jumpaddr))
+
+        if (MR_trace_start_decl_debug(mode, filename, new_session, cmd,
+            event_info, event_details, jumpaddr))
         {
             return STOP_INTERACTING;
         }
@@ -5902,23 +5896,20 @@
             matches = MR_search_for_matching_procedures(&spec);
             MR_filter_user_preds(&matches);
             if (matches.match_proc_next == 0) {
-                fprintf(MR_mdb_err, "mdb: there is no such "
-                    "module, predicate or function.\n");
+                fprintf(MR_mdb_err,
+                    "mdb: there is no such module, predicate or function.\n");
             } else if (matches.match_proc_next == 1) {
-                MR_decl_add_trusted_pred_or_func(
-                    matches.match_procs[0]);
+                MR_decl_add_trusted_pred_or_func(matches.match_procs[0]);
                 fprintf(MR_mdb_out, "Trusting ");
-                MR_print_pred_id_and_nl(MR_mdb_out,
-                    matches.match_procs[0]);
+                MR_print_pred_id_and_nl(MR_mdb_out, matches.match_procs[0]);
             } else {
-                int i;
-                char buf[80];
-                char *line2;
+                int     i;
+                char    buf[80];
+                char    *line2;
 
                 fprintf(MR_mdb_out, "Ambiguous predicate or function"
                     " specification. The matches are:\n");
-                for (i = 0; i < matches.match_proc_next; i++)
-                {
+                for (i = 0; i < matches.match_proc_next; i++) {
                     fprintf(MR_mdb_out, "%d: ", i);
                     MR_print_pred_id_and_nl(MR_mdb_out,
                         matches.match_procs[i]);
@@ -5937,7 +5928,7 @@
 
                         fprintf(MR_mdb_out, "Trusting ");
                         MR_print_pred_id_and_nl(MR_mdb_out,
-                        matches.match_procs[i]);
+                            matches.match_procs[i]);
                     }
                     MR_free(line2);
                 } else if(MR_trace_is_natural_number(line2, &i)) {
@@ -5947,7 +5938,7 @@
 
                         fprintf(MR_mdb_out, "Trusting ");
                         MR_print_pred_id_and_nl(MR_mdb_out,
-                        matches.match_procs[i]);
+                            matches.match_procs[i]);
                     } else {
                         fprintf(MR_mdb_out, "no such match\n");
                     }
@@ -5967,6 +5958,7 @@
     } else {
         MR_trace_usage("dd", "trust");
     }
+
     return KEEP_INTERACTING;
 }
 
@@ -5977,13 +5969,9 @@
 {
     int i;
 
-    if (word_count == 2) {
-        if (MR_trace_is_natural_number(words[1], &i)) {
-            if (!MR_decl_remove_trusted(i)) {
-                fprintf(MR_mdb_err, "mdb: no such trusted object\n");
-            }
-        } else {
-            MR_trace_usage("dd", "untrust");
+    if (word_count == 2 && MR_trace_is_natural_number(words[1], &i)) {
+        if (!MR_decl_remove_trusted(i)) {
+            fprintf(MR_mdb_err, "mdb: no such trusted object\n");
         }
     } else {
         MR_trace_usage("dd", "untrust");
Index: trace/mercury_trace_internal.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_internal.h,v
retrieving revision 1.19
diff -u -r1.19 mercury_trace_internal.h
--- trace/mercury_trace_internal.h	27 Jan 2005 06:17:41 -0000	1.19
+++ trace/mercury_trace_internal.h	1 Aug 2005 02:46:32 -0000
@@ -7,34 +7,13 @@
 #ifndef	MERCURY_TRACE_INTERNAL_H
 #define	MERCURY_TRACE_INTERNAL_H
 
-#include "mercury_types.h"	/* for MR_Code */
-#include "mercury_trace.h"	/* for MR_Event_Info, etc. */
-#include "mercury_std.h"	/* for MR_bool */
+#include "mercury_types.h"		/* for MR_Code */
+#include "mercury_trace.h"		/* for MR_Event_Info, etc. */
+#include "mercury_std.h"		/* for MR_bool */
 #include "mercury_trace_completion.h"	/* for MR_Make_Completer */
-#include "mercury_trace_spy.h"	/* for MR_Spy_Print_List */
+#include "mercury_trace_spy.h"		/* for MR_Spy_Print_List */
 
-#include <stdio.h>		/* for FILE */
-
-/*
-** The following enum gives the possible modes that the declarative
-** debugger can be in (see trace/mercury_trace_declarative.{c,h}).
-*/
-
-typedef enum {
-	MR_TRACE_INTERACTIVE,	 	/* Use internal debugger. */
-	MR_TRACE_DECL_DEBUG,		/* Normal declarative debugging. */
-	MR_TRACE_DECL_DEBUG_DUMP	/*
-					** Output debugging info to a file
-					** for separate analysis.
-					*/
-} MR_Trace_Mode;
-
-/*
-** This variable is modified whenever we start or stop collecting
-** an execution tree.
-*/
-
-extern	MR_Trace_Mode	MR_trace_decl_mode;
+#include <stdio.h>			/* for FILE */
 
 extern	MR_Code	*MR_trace_event_internal(MR_Trace_Cmd_Info *cmd,
 			MR_bool interactive, MR_Spy_Print_List print_list,
@@ -49,6 +28,7 @@
 ** information messages about conditions which are not errors, should
 ** go to MR_mdb_out, but error messages should go to MR_mdb_err.
 */
+
 extern FILE *MR_mdb_in;
 extern FILE *MR_mdb_out;
 extern FILE *MR_mdb_err;
@@ -57,6 +37,7 @@
 ** This just prints to MR_mdb_out a message telling the user
 ** that the debugger caught an interrupt.
 */
+
 extern	void	MR_trace_interrupt_message(void);
 
 extern	char	*MR_trace_getline(const char *prompt, FILE *mdb_in,
@@ -68,11 +49,15 @@
 ** If word is a valid command, return information about the
 ** completer for the command.
 */
+
 extern	MR_bool	MR_trace_command_completion_info(const char *word,
 				MR_Make_Completer *completer,
 				const char *const **fixed_args);
 
-/* A Readline completer for command names. */
+/*
+** A Readline completer for command names.
+*/
+
 extern  MR_Completer_List *MR_trace_command_completer(const char *word,
 				size_t word_len);
 
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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