[m-rev.] Breakpoint added in source-to-source debugger

Olivier Annet oan at missioncriticalit.com
Mon Oct 8 17:32:57 AEST 2007


Hi,

Could someone review my code before commit please.

Olivier.

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


Estimated hours taken: 4
Branches: main

The breakpoint command has been added in the debugger

compiler/ssdebug.m:
    Adding feature to send the module name in the ssdb_proc_id structure
 
ssdb/ssdb.m:
    Print out the event number, name of the module, name of the predicate, 
    call sequence number and call depth at each event.  
    Some minor changement to make the code more understandable
    Add code to manage breakpoint.

Index: compiler/ssdebug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ssdebug.m,v
retrieving revision 1.3
diff -u -r1.3 ssdebug.m
--- compiler/ssdebug.m	4 Oct 2007 01:04:47 -0000	1.3
+++ compiler/ssdebug.m	8 Oct 2007 07:28:01 -0000
@@ -198,7 +198,7 @@
         goal_util.generate_simple_call(SSDBModule, "handle_event",		
             pf_predicate, only_mode, detism_det, purity_impure,
             [ProcIdVar, CallVar],
-            Features, InstMapSrc, !.ModuleInfo, Context, HandleCallEventGoal),		
+            Features, InstMapSrc, !.ModuleInfo, Context, HandleCallEventGoal),
             %
             % Build the following two goals
             %   ExitVar = ssdb_exit,
@@ -210,7 +210,7 @@
         goal_util.generate_simple_call(SSDBModule, "handle_event",		
             pf_predicate, only_mode, detism_det, purity_impure,
             [ProcIdVar, ExitVar],
-            Features, InstMapSrc, !.ModuleInfo, Context, HandleExitEventGoal),		
+            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
@@ -247,21 +247,26 @@
 
 make_proc_id_construction(PredInfo,
         _ProcInfo, Goals, ProcIdVar, !Varset, !Vartypes) :-
-    Name = pred_info_name(PredInfo),
+    SymModName = pred_info_module(PredInfo),
+    ModName = sym_name_to_string(SymModName),
+    PredName = pred_info_name(PredInfo),
 
-	make_string_const_construction_alloc(Name, yes("Name"),
-	    ConstructPredName, PredNameVar, !Varset, !Vartypes),
+    make_string_const_construction_alloc(ModName, yes("ModName"),
+	ConstructModName, ModNameVar, !Varset, !Vartypes),
+
+    make_string_const_construction_alloc(PredName, yes("PredName"),
+	ConstructPredName, PredNameVar, !Varset, !Vartypes),
 
     SSDBModule = mercury_ssdb_builtin_module,
     TypeCtor = type_ctor(qualified(SSDBModule, "ssdb_proc_id"), 0),
 
     svvarset.new_named_var("ProcId", ProcIdVar, !Varset), 
-    ConsId = cons(qualified(SSDBModule, "ssdb_proc_id"), 1),
+    ConsId = cons(qualified(SSDBModule, "ssdb_proc_id"), 2),
     construct_type(TypeCtor, [], ProcIdType),	
     svmap.det_insert(ProcIdVar, ProcIdType, !Vartypes),
-    construct_functor(ProcIdVar, ConsId, [PredNameVar], ConstructProcIdGoal),
+    construct_functor(ProcIdVar, ConsId, [ModNameVar, PredNameVar], ConstructProcIdGoal),
 
-    Goals = [ConstructPredName, ConstructProcIdGoal].
+    Goals = [ConstructModName, ConstructPredName, ConstructProcIdGoal].
     
     
 %-----------------------------------------------------------------------------%
Index: ssdb/ssdb.m
===================================================================
RCS file: /home/mercury1/repository/mercury/ssdb/ssdb.m,v
retrieving revision 1.4
diff -u -r1.4 ssdb.m
--- ssdb/ssdb.m	8 Oct 2007 02:44:27 -0000	1.4
+++ ssdb/ssdb.m	8 Oct 2007 07:28:01 -0000
@@ -24,6 +24,7 @@
 
 :- type ssdb_proc_id
     --->    ssdb_proc_id(
+                module_name :: string,
                 proc_name   :: string
             ).
 
@@ -35,7 +36,7 @@
     .
 
     %
-    % This routine is called at each event that occurs
+    % This routine is called at each event that occurs.
     %
 :- impure pred handle_event(ssdb_proc_id::in, ssdb_event_type::in) is det.
 
@@ -49,6 +50,7 @@
 :- import_module int.
 :- import_module list.
 :- import_module require.
+:- import_module set.
 :- import_module stack.
 :- import_module string.
 
@@ -56,55 +58,68 @@
 
 :- type debugger_state
     --->    state(
-                % Current event number
+                % Current event number.
                 ssdb_event_number   :: int,                 
 
-                % Call Sequence Number
+                % Call Sequence Number.
                 ssdb_csn            :: int,                 
 
-                % Depth of the function
+                % Depth of the function.
                 ssdb_call_depth     :: int,                 
 
-                % Where the program should stop next time
+                % Where the program should stop next time.
                 ssdb_next_stop      :: next_stop,           
 
-                % The shadow stack
-                ssdb_stack          :: stack(stack_elem)    
+                % The shadow stack.
+                ssdb_stack          :: stack(stack_elem),
+
+                % The set of breakpoint added.
+                ssdb_breakpoints    :: set(breakpoint)
             ).
 
 
 :- type stack_elem
     --->    elem(
                 proc_id         :: ssdb_proc_id,
+                
+                % The debugger state at the call port.
                 initial_state   :: debugger_state
-                    % The debugger state at the call port.
             ).
 
     %
-    % Type filled by the prompt function to configure the next step in the
-    % handle_event function 
+    % Type used by the prompt predicate to configure the next step in the
+    % handle_event predicate.
     %
 :- type what_next
     --->    what_next_step
     ;       what_next_next
+    ;       what_next_continue
     ;       what_next_finish(int).
 
 
     %
-    % Type filled by the handle_event function to determine the next stop of
-    % the prompt function
+    % Type used by the handle_event predicate to determine the next stop of
+    % the prompt predicate.
     %
 :- type next_stop
     --->    step
     ;       next(int)
+    ;       continue
     ;       final_port(int).
 
 
+:- type breakpoint
+    --->    breakpoint(
+                bp_module_name  :: string,
+                bp_pred_name    :: string
+    ).
+
+
 %----------------------------------------------------------------------------%
 
     %
-    % Initialize the debugger state
-    % XXX Will be extended
+    % Initialize the debugger state.
+    % XXX Will be extended.
     %
 :- func init_debugger_state = debugger_state.
 
@@ -114,7 +129,8 @@
     Depth = 0,
     NextStop = step,
     Stack = stack.init,
-    DbgState = state(EventNum, CSN, Depth, NextStop, Stack).
+    Breakpoints = set.init,
+    DbgState = state(EventNum, CSN, Depth, NextStop, Stack, Breakpoints).
 
 :- mutable(debugger_state, debugger_state, init_debugger_state, ground, 
     [untrailed, attach_to_io_state]).
@@ -123,26 +139,25 @@
 
 
     %
-    % Write the event out and call the prompt
-    % XXX Not yet implemented : redo, fail
+    % Write the event out and call the prompt.
+    % XXX Not yet implemented : redo, fail.
     %
 handle_event(ProcId, Event) :-
     impure get_event_num_inc(EventNum),
     impure update_depth(Event, PrintDepth),
 
-    (
-        Event = ssdb_call,
+    ( Event = ssdb_call,
         impure get_csn_inc(_),
 
         semipure get_debugger_state(InitialState),
-        E = elem(ProcId, InitialState),
-        stack.push(InitialState ^ ssdb_stack, E, FinalStack),
+        Element = elem(ProcId, InitialState),
+        stack.push(InitialState ^ ssdb_stack, Element, FinalStack),
         StateEv = InitialState ^ ssdb_stack := FinalStack,
         impure set_debugger_state(StateEv)
     ;
         Event = ssdb_exit,
         semipure get_debugger_state(InitialState),
-        stack.pop_det(InitialState ^ ssdb_stack, E, FinalStack),
+        stack.pop_det(InitialState ^ ssdb_stack, Element, FinalStack),
         StateEv = InitialState ^ ssdb_stack := FinalStack,
         impure set_debugger_state(StateEv)
     ;
@@ -155,7 +170,7 @@
  
     semipure get_debugger_state(State0),
 
-    PrintCSN = E ^ initial_state ^ ssdb_csn,
+    CSN = Element ^ initial_state ^ ssdb_csn,
 
     NextStop0 = State0 ^ ssdb_next_stop,
     (
@@ -163,12 +178,20 @@
         Stop = yes
     ;
         NextStop0 = next(StopCSN),
-        is_same_event(StopCSN, PrintCSN, Stop)
+        is_same_event(StopCSN, CSN, Stop)
+    ;
+        NextStop0 = continue,
+        ( set.contains(State0 ^ ssdb_breakpoints, 
+            breakpoint(ProcId ^ module_name, ProcId ^ proc_name)) ->
+            Stop = yes
+        ;
+            Stop = no
+        )
     ;
         NextStop0 = final_port(StopCSN),
         (
             Event = ssdb_exit,
-            is_same_event(StopCSN, PrintCSN, Stop)
+            is_same_event(StopCSN, CSN, Stop)
         ;
             Event = ssdb_call,
             Stop = no
@@ -183,13 +206,15 @@
             io.write_string("       ", !IO),
             io.write_int(EventNum, !IO),
             io.write_string("\t", !IO),
+            io.write_string(ProcId ^ module_name, !IO),
+            io.write_string(".", !IO),
             io.write_string(ProcId ^ proc_name, !IO),
             io.write_string(".", !IO),
             io.write(Event, !IO),
             io.write_string("\t\t| DEPTH = ", !IO),
             io.write_int(PrintDepth, !IO),
             io.write_string("\t| CSN = ", !IO),
-            io.write_int(PrintCSN, !IO),
+            io.write_int(CSN, !IO),
             io.nl(!IO),
         
             semipure get_shadow_stack(ShadowStack),
@@ -202,13 +227,16 @@
                 NextStop = step
             ;
                 WhatNext = what_next_next,
-                NextStop = next(PrintCSN)
+                NextStop = next(CSN)
+            ;
+                WhatNext = what_next_continue,
+                NextStop = continue
             ;
                 WhatNext = what_next_finish(EndCSN),
                 NextStop = final_port(EndCSN)
             ),
 
-% XXX do not forget get the latest modification (like new breakpoint)
+            % Set the last update :  breakpoints.
             semipure get_debugger_state(State1),
             State = State1 ^ ssdb_next_stop := NextStop,
             impure set_debugger_state(State)
@@ -217,18 +245,27 @@
         Stop = no
     ).
 
-
     %
-    % Determine if two CSN are equals and if yes, do a stop
+    % IsSame is 'yes' iff the two call sequence numbers are equal, 
+    % 'no' otherwise.
     %
 :- pred is_same_event(int::in, int::in, bool::out) is det.
 
 is_same_event(CSNA, CSNB, IsSame) :-
     IsSame = (CSNA = CSNB -> yes ; no).
+    
+    %
+    % Return the current event number.
+    %
+:- semipure pred get_event_num(int::out) is det.
+
+get_event_num(EventNum) :-
+    semipure get_debugger_state(State0),
+    EventNum = State0 ^ ssdb_event_number.
 
     %
-    % Increment and return the event number
-    % Update the state with the new event number
+    % Increment the current event number in the debugger state, 
+    % returning the new event number.
     %
 :- impure pred get_event_num_inc(int::out) is det.
 
@@ -240,12 +277,12 @@
     impure set_debugger_state(State).
 
     %
-    % For the given event type, update the depth in the debugger state
-    % and return the depth for the given event.
+    % For a given event type, update the depth in the debugger state,
+    % returning the updated depth.
     %
 :- impure pred update_depth(ssdb_event_type::in, int::out) is det.
 
-update_depth(Event, PrintDepth) :-
+update_depth(Event, ReturnDepth) :-
     semipure get_debugger_state(State0),
     Depth0 = State0 ^ ssdb_call_depth,
     (
@@ -253,20 +290,20 @@
         ; Event = ssdb_redo
         ),
         Depth = Depth0 + 1,
-        PrintDepth = Depth0
+        ReturnDepth = Depth0
     ;
         ( Event = ssdb_exit
         ; Event = ssdb_fail
         ),
         Depth = Depth0 - 1,
-        PrintDepth = Depth
+        ReturnDepth = Depth
     ),
     State = State0 ^ ssdb_call_depth := Depth,
     impure set_debugger_state(State).
 
     %
-    % Increment and return the call sequence number
-    % Update the state with this new call sequence number
+    % Increment the current call sequence number in the debugger state,
+    % returning the new call seuqence number.
     %
 :- impure pred get_csn_inc(int::out) is det.
 
@@ -278,16 +315,7 @@
     impure set_debugger_state(State).
 
     %
-    % Return the current event number
-    %
-:- semipure pred get_event_num(int::out) is det.
-
-get_event_num(EventNum) :-
-    semipure get_debugger_state(State0),
-    EventNum = State0 ^ ssdb_event_number.
-
-    %
-    % Return the current call sequence number
+    % Return the current call sequence number.
     %
 :- semipure pred get_csn(int::out) is det.
 
@@ -296,7 +324,7 @@
     CSN = State0 ^ ssdb_csn.
     
     %
-    % Return the current shadow stack
+    % Return the current shadow stack.
     %
 :- semipure pred get_shadow_stack(stack(stack_elem)::out) is det.
 
@@ -313,6 +341,8 @@
     % f     :: finish (go to the next exit or fail of the current call)
     % n     :: next
     % s | _ :: next step
+    % c     :: continue
+    % b X Y :: breakpoint X = module_name Y = predicate_name
     %
 
 :- impure pred prompt(stack(stack_elem)::in, int::in, what_next::out, 
@@ -320,41 +350,61 @@
 
 prompt(ShadowStack, Depth, WhatNext, !IO) :-
     io.write_string("ssdb> ", !IO),
-        %read a string in input and return a string
+    % Read a string in input and return a string.
     io.read_line_as_string(Result, !IO), 
     (
         Result = ok(String0),
-            %string minus any single trailing newline character
+        % String minus any single trailing newline character.
         String = string.chomp(String0), 
 
-        ( 
-            String = "h" ->
+        ( String = "h" ->
+            io.nl(!IO),
+            io.write_string("s      :: step", !IO),
             io.nl(!IO),
-            io.write_string("s   :: step", !IO),
+            io.write_string("n      :: next", !IO),
             io.nl(!IO),
-            io.write_string("n   :: next", !IO),
+            io.write_string("b X Y  :: insert breakpoint where :", !IO),
+            io.write_string(" X = module name", !IO),
+            io.write_string(" and Y = predicate name", !IO),
             io.nl(!IO),
-            io.write_string("f   :: finish", !IO),
+            io.write_string("c      :: next", !IO),
+            io.nl(!IO),
+            io.write_string("f      :: finish", !IO),
             io.nl(!IO),
             io.nl(!IO),
             impure prompt(ShadowStack, Depth, WhatNext, !IO)
         
-        ; 
-            String = "n" ->
+        ; String = "n" ->
             WhatNext = what_next_next
+
         ;
-            (
-                String = "s"
-            ;
-                String = ""
+            ( String = "s"
+            ; String = ""
             )
-            ->
+        ->
                 WhatNext = what_next_step
-        ;
-            String = "f" ->
+
+        ; String = "c" ->
+            WhatNext = what_next_continue
+
+        ; 
+            Words = string.words(String),
+            Words = ["b", ModuleName, ProcedureName] 
+        ->
+            semipure get_debugger_state(State0),
+            Breakpoints0 = State0 ^ ssdb_breakpoints,
+            Breakpoints = set.insert(Breakpoints0, breakpoint(ModuleName, 
+                ProcedureName)),
+            State = State0 ^ ssdb_breakpoints := Breakpoints,
+            io.print(Breakpoints, !IO),nl(!IO),
+            impure set_debugger_state(State),
+            impure prompt(ShadowStack, Depth, WhatNext, !IO)
+
+        ; String = "f" ->
             stack.top_det(ShadowStack, FrameStack),
             CSN = FrameStack ^  initial_state ^ ssdb_csn,
             WhatNext = what_next_finish(CSN)
+
         ;
             io.write_string("huh?\n", !IO),
             impure prompt(ShadowStack, Depth, WhatNext, !IO)

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