[m-rev.] already reviewed: add call/exit events to source to source debugger

Peter Ross pro at missioncriticalit.com
Thu Oct 4 09:48:02 AEST 2007


Hi,

I've already reviewed this code by Olivier.

The next step he will take is to record the procedure name for each
call/exit event.


===================================================================


Estimated hours taken: 20
Branches: main

Initial check-in of the source to source debugger.

In this change we add the ability to print call and exit
events and the call and exit ports of each procedure compiled
with --ssdb.

compiler/.mgnuc_copts:
compiler/COMP_FLAGS.in:
compiler/Mmakefile:
	Allow the mer_ssdb library to be linked into the compiler.

compiler/mercury_compile.m:
compiler/transform_hlds.m:
	Call the new ssdebug module.

compiler/ssdebug.m:
	Add the ssdebug module which does the source to source tranformation
	to place call and exit events in debugged procedures.
	
mdbcomp/prim_data.m:
	Fix a bug of petdr, where he forgot to rename ssdb_builtin to ssdb.


Index: compiler/.mgnuc_copts
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/.mgnuc_copts,v
retrieving revision 1.1
diff -u -r1.1 .mgnuc_copts
--- compiler/.mgnuc_copts	20 May 2005 06:15:08 -0000	1.1
+++ compiler/.mgnuc_copts	3 Oct 2007 23:40:08 -0000
@@ -7,6 +7,8 @@
 -I../mdbcomp/Mercury/mihs
 -I../browser
 -I../browser/Mercury/mihs
+-I../ssdb
+-I../ssdb/Mercury/mihs
 -I../trace
 -I../analysis
 -I../analysis/Mercury/mihs
Index: compiler/COMP_FLAGS.in
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/COMP_FLAGS.in,v
retrieving revision 1.4
diff -u -r1.4 COMP_FLAGS.in
--- compiler/COMP_FLAGS.in	20 Jul 2007 01:22:00 -0000	1.4
+++ compiler/COMP_FLAGS.in	3 Oct 2007 23:40:08 -0000
@@ -5,6 +5,7 @@
 --no-mercury-stdlib-dir
 -I../library
 -I../browser
+-I../ssdb
 -I../mdbcomp
 -I../analysis
 --c-include-directory ../boehm_gc
@@ -16,11 +17,14 @@
 --c-include-directory ../mdbcomp/Mercury/mihs
 --c-include-directory ../browser
 --c-include-directory ../browser/Mercury/mihs
+--c-include-directory ../ssdb
+--c-include-directory ../ssdb/Mercury/mihs
 --c-include-directory ../trace
 --c-include-directory ../analysis
 --c-include-directory ../analysis/Mercury/mihs
 --erlang-include-directory ../library/Mercury/hrls
 --erlang-include-directory ../mdbcomp/Mercury/hrls
 --erlang-include-directory ../analysis/Mercury/hrls
+--erlang-include-directory ../ssdb/Mercury/hrls
 --no-main
 --config-file ../scripts/Mercury.config.bootstrap
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.93
diff -u -r1.93 Mmakefile
--- compiler/Mmakefile	20 Jul 2007 01:22:00 -0000	1.93
+++ compiler/Mmakefile	3 Oct 2007 23:40:08 -0000
@@ -33,7 +33,7 @@
 
 MERCURY_MAIN_MODULES = top_level mlds_to_gcc
 
-VPATH = $(LIBRARY_DIR) $(MDBCOMP_DIR) $(BROWSER_DIR) $(ANALYSIS_DIR)
+VPATH = $(LIBRARY_DIR) $(MDBCOMP_DIR) $(BROWSER_DIR) $(SSDB_DIR) $(ANALYSIS_DIR)
 
 #-----------------------------------------------------------------------------#
 
@@ -60,7 +60,8 @@
 
 MCFLAGS	     += --flags COMP_FLAGS $(CONFIG_OVERRIDE)
 MLOBJS       := ../main.$O ../analysis/lib$(ANALYSIS_LIB_NAME).$A \
-		../trace/lib$(EVENTSPEC_LIB_NAME).$A $(MLOBJS)
+		../trace/lib$(EVENTSPEC_LIB_NAME).$A \
+		../ssdb/lib$(SSDB_LIB_NAME).$A $(MLOBJS)
 ALL_MLLIBS    = $(MLLIBS) $(EXTRA_MLLIBS) $(GCC_BACKEND_LIBS)
 MLFLAGS      += --no-main --shared
 C2INITARGS   += $(ANALYSIS_DIR)/$(ANALYSIS_LIB_NAME).init
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.450
diff -u -r1.450 mercury_compile.m
--- compiler/mercury_compile.m	3 Oct 2007 12:11:54 -0000	1.450
+++ compiler/mercury_compile.m	3 Oct 2007 23:40:09 -0000
@@ -73,6 +73,7 @@
 :- import_module transform_hlds.lambda.
 :- import_module transform_hlds.closure_analysis.
 :- import_module transform_hlds.termination.
+:- import_module transform_hlds.ssdebug.
 :- import_module transform_hlds.term_constr_main.
 :- import_module transform_hlds.exception_analysis.
 :- import_module transform_hlds.trailing_analysis.
@@ -3187,10 +3188,8 @@
         SSDB = yes,
         maybe_write_string(Verbose,
             "% Apply debugging source to source transformation ...\n", !IO),
-        /* XXX for the moment we do nothing.
         process_all_nonimported_procs(
             update_module_io(ssdebug.process_proc), !HLDS, !IO),
-        */
         maybe_write_string(Verbose, "% done.\n", !IO),
         maybe_report_stats(Stats, !IO)
     ;
Index: compiler/ssdebug.m
===================================================================
RCS file: compiler/ssdebug.m
diff -N compiler/ssdebug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ compiler/ssdebug.m	3 Oct 2007 23:40:09 -0000
@@ -0,0 +1,150 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2007 The University of Melbourne.
+% This file may only be copied under the terms of the GNU General
+% Public License - see the file COPYING in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+%
+% Module: transform_hlds.ssdebug.m.
+% Main authors: oannet.
+%
+% The ssdebug module does a source to source tranformation on each procedure
+% which allows the procedure to be debugged.
+% 
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+:- module transform_hlds.ssdebug.
+:- interface.
+
+:- import_module hlds.hlds_module.
+:- import_module hlds.hlds_pred.
+
+:- import_module io.
+
+    %
+    % Place a call/exit event and the beginning/end of each procedure.
+    %
+:- pred ssdebug.process_proc(pred_id::in, proc_id::in,
+    proc_info::in, proc_info::out, module_info::in, module_info::out,
+    io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+:- implementation.
+
+:- import_module check_hlds.mode_util.
+:- import_module hlds.goal_util.
+:- import_module hlds.hlds_goal.
+:- import_module hlds.pred_table.
+:- import_module hlds.quantification.
+:- import_module mdbcomp.prim_data.
+:- import_module parse_tree.prog_data.
+:- import_module parse_tree.prog_type.
+
+:- import_module ssdb.
+
+:- import_module assoc_list.
+:- import_module bool.
+:- import_module list.
+:- import_module maybe.
+:- import_module pair.
+:- import_module string.
+:- import_module svmap.
+:- import_module svvarset.
+:- import_module term.
+
+%-----------------------------------------------------------------------------%
+
+process_proc(_PredId, _ProcId, !ProcInfo, !ModuleInfo, !IO) :-
+    proc_info_get_goal(!.ProcInfo, Goal0),
+
+    some [!Varset, !Vartypes] (
+        proc_info_get_varset(!.ProcInfo, !:Varset),
+        proc_info_get_vartypes(!.ProcInfo, !:Vartypes),
+            
+            %
+            % Build the following two goals
+            %   CallVar = ssdb_call,
+            %   handle_event(CallVar)
+            %
+        make_ssdb_event_type_construction(ssdb_call,
+            CallConstructor, CallVar, !Varset, !Vartypes),
+
+        SSDBModule = mercury_ssdb_builtin_module,
+        Features = [],
+        InstMapSrc = [],
+        Context = term.context_init,
+        goal_util.generate_simple_call(SSDBModule, "handle_event",		
+            pf_predicate, only_mode, detism_det, purity_impure, [CallVar],
+            Features, InstMapSrc, !.ModuleInfo, Context, HandleCallEventGoal),		
+            %
+            % Build the following two goals
+            %   ExitVar = ssdb_exit,
+            %   handle_event(ExitVar)
+            %
+        make_ssdb_event_type_construction(ssdb_exit,
+            ExitConstructor, ExitVar, !Varset, !Vartypes),
+
+        goal_util.generate_simple_call(SSDBModule, "handle_event",		
+            pf_predicate, only_mode, detism_det, purity_impure, [ExitVar],
+            Features, InstMapSrc, !.ModuleInfo, Context, HandleExitEventGoal),		
+            %
+            % Place the call and exit events around the initial goal.
+            % XXX we still need to extend this to handle the other event types
+            %
+        ConjGoals = [CallConstructor, HandleCallEventGoal,
+            Goal0, ExitConstructor, HandleExitEventGoal],
+
+        goal_info_init(GoalInfo),
+        Goal = hlds_goal(conj(plain_conj, ConjGoals), GoalInfo),
+
+        proc_info_set_varset(!.Varset, !ProcInfo),
+        proc_info_set_vartypes(!.Vartypes, !ProcInfo)
+    ),
+
+    proc_info_set_goal(Goal, !ProcInfo),
+
+    requantify_proc(!ProcInfo),
+    recompute_instmap_delta_proc(yes, !ProcInfo, !ModuleInfo).
+
+%-----------------------------------------------------------------------------%
+
+    %
+    % make_ssdb_event_type_construction(EventType,
+    %   Goal, Var, !Varset, !Vartypes)
+    % 
+    % makes a construction unification, Goal, where Var will have the value
+    % EventType, updating the varset and vartypes to reflect this new goal.
+    %
+:- pred make_ssdb_event_type_construction(
+    ssdb_event_type::in, hlds_goal::out, prog_var::out, 
+    prog_varset::in, prog_varset::out,
+    vartypes::in, vartypes::out) is det.
+
+make_ssdb_event_type_construction(Event, Goal, EventVar, !Varset, !Vartypes) :-
+    (
+        Event = ssdb_call,
+        SSDB_Event = "ssdb_call"
+    ;
+        Event = ssdb_exit,
+        SSDB_Event = "ssdb_exit"
+    ;
+        Event = ssdb_redo,
+        SSDB_Event = "ssdb_redo"
+    ;
+        Event = ssdb_fail,
+        SSDB_Event = "ssdb_fail"
+    ),
+	
+    SSDBModule = mercury_ssdb_builtin_module,
+    TypeCtor = type_ctor(qualified(SSDBModule, "ssdb_event_type"), 0),
+
+    svvarset.new_named_var(SSDB_Event, EventVar, !Varset), 
+    ConsId = cons(qualified(SSDBModule, SSDB_Event), 0),
+    construct_type(TypeCtor, [], EventVarType),	
+    svmap.det_insert(EventVar, EventVarType, !Vartypes),
+    construct_functor(EventVar, ConsId, [], Goal).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: compiler/transform_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/transform_hlds.m,v
retrieving revision 1.27
diff -u -r1.27 transform_hlds.m
--- compiler/transform_hlds.m	23 May 2007 00:17:23 -0000	1.27
+++ compiler/transform_hlds.m	3 Oct 2007 23:40:09 -0000
@@ -43,6 +43,8 @@
    :- include_module term_norm.
    :- include_module term_util.
 
+:- include_module ssdebug.
+
 :- include_module transform_hlds.ctgc.
 
 :- include_module transform_hlds.rbmm.
Index: mdbcomp/prim_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/prim_data.m,v
retrieving revision 1.25
diff -u -r1.25 prim_data.m
--- mdbcomp/prim_data.m	3 Oct 2007 12:11:56 -0000	1.25
+++ mdbcomp/prim_data.m	3 Oct 2007 23:40:09 -0000
@@ -340,7 +340,7 @@
 mercury_profiling_builtin_module = unqualified("profiling_builtin").
 mercury_term_size_prof_builtin_module = unqualified("term_size_prof_builtin").
 mercury_par_builtin_module = unqualified("par_builtin").
-mercury_ssdb_builtin_module = unqualified("ssdb_builtin").
+mercury_ssdb_builtin_module = unqualified("ssdb").
 mercury_std_lib_module_name(Name) = Name.
 
 is_std_lib_module_name(SymName, Name) :-

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list