[m-rev.] ssdb minor modifications

Olivier Annet oan at missioncriticalit.com
Wed Dec 12 15:45:39 AEDT 2007


Hi,

Could someone review my code before committing.

Thank.

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


Estimated hours taken: 8
Branches: main

Some minor modifications of the code.

compiler/ssdebug.m:
	Some minor corrections in the comments.

ssdb/ssdb.m:
	Modification of some commands : print, up, down to print details on 
	what is going on at the screen more clearly.
	I use pprint instead of pretty_printer to print the argument list of a
	predicate because there was a strange behavior with pretty_printer: 
	Sometimes, when I tried to print the arguments of a procedure, all 
	values of an input argument was not print in front of the corresponding 
	variable but in the next ssdb prompt.
	A bug with the command <retry N> had been corrected.

Index: compiler/ssdebug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ssdebug.m,v
retrieving revision 1.14
diff -u -r1.14 ssdebug.m
--- compiler/ssdebug.m	5 Dec 2007 05:38:54 -0000	1.14
+++ compiler/ssdebug.m	12 Dec 2007 03:55:52 -0000
@@ -12,7 +12,9 @@
 % The ssdebug module does a source to source tranformation on each procedure
 % which allows the procedure to be debugged.
 %
-% Here is the transformation (note currently we don't do all of this)
+% XXX Only user-made procedures are debugged, not yet the library procedures.
+%
+% Here is the transformation:
 %
 % original:
 %
@@ -123,11 +125,9 @@
 %
 %   p(...) :-
 %       promise_<original_purity> (
-%           (
-%               CallVarDescs = [ ... ],
-%               impure call_port(ProcId, CallVarDescs),
-%               <original body>,
-%           )
+%           CallVarDescs = [ ... ],
+%           impure call_port(ProcId, CallVarDescs),
+%           <original body>
 %       ).
 %
 % 
@@ -917,9 +922,8 @@
         [], Features, InstMapSrc, ModuleInfo, Context, FailGoal).
 
 
-    %
     % Detect if all argument's mode are fully input or output.
-    % XXX Other mode than fully input or output are not managed for the 
+    % XXX Other mode than fully input or output are not handled for the 
     % moment. So the code of these procedures will not be generated.
     %
 :- pred check_arguments_modes(module_info::in, list(mer_mode)::in) 
Index: ssdb/ssdb.m
===================================================================
RCS file: /home/mercury1/repository/mercury/ssdb/ssdb.m,v
retrieving revision 1.13
diff -u -r1.13 ssdb.m
--- ssdb/ssdb.m	5 Dec 2007 05:38:55 -0000	1.13
+++ ssdb/ssdb.m	12 Dec 2007 03:55:52 -0000
@@ -128,7 +115,7 @@
 :- import_module map.
 :- import_module maybe.
 :- import_module pair.
-:- import_module pretty_printer.
+:- import_module pprint.
 :- import_module require.
 :- import_module set.
 :- import_module stack.
@@ -415,7 +389,7 @@
         
         Event = ssdb_exit,
         impure get_ssdb_event_number_inc(EventNum),
-        impure get_ssdb_depth_dec(PrintDepth),
+        semipure get_cur_ssdb_depth(PrintDepth),
         impure set_list_var_value_in_shadow_stack(ListVarValue),
 
         % Just get the top stack frame. It will be popped at the end of
@@ -433,14 +407,18 @@
             (
                 impure invent_io(!:IO),
                 
-                print_event_info(Event, EventNum, ProcId, PrintDepth + 1, CSN, 
-                    !IO),
-             
                 (
                     AutoRetry = do_retry,
+                    EventNumF = StackFrame ^ se_event_number,
+                    CSNF = StackFrame ^ se_csn,
+                    impure set_cur_ssdb_event_number(EventNumF-1),
+                    impure set_cur_ssdb_csn(CSNF-1),
                     WhatNext = wn_retry(CSN)
                 ;
                     AutoRetry = do_not_retry,
+                    print_event_info(Event, EventNum, ProcId, PrintDepth, CSN,
+                        !IO),
+             
                     impure prompt(Event, ShadowStack0, 0, WhatNext, !IO)
                 ),
 
@@ -452,7 +430,8 @@
             Stop = no,
             Retry = do_not_retry
         ),
-        
+
+        impure get_ssdb_depth_dec(_Depth),
         stack.pop_det(ShadowStack0, _StackFrame1, ShadowStack),
         impure set_cur_ssdb_shadow_stack(ShadowStack)
     ;
@@ -463,7 +442,6 @@
     ).
 
 
-    %
     % Call at exit port of nondet procedure only.
     %
 handle_event_exit_nondet(ProcId, ListVarValue) :-
@@ -473,7 +451,7 @@
         
         Event = ssdb_exit_nondet,
         impure get_ssdb_event_number_inc(EventNum),
-        impure get_ssdb_depth_dec(PrintDepth),
+        semipure get_cur_ssdb_depth(PrintDepth),
         impure set_list_var_value_in_shadow_stack(ListVarValue),
 
         % Just get the top stack frame. It will be popped at the end of
@@ -491,14 +469,14 @@
             (
                 impure invent_io(!:IO),
                 
-                print_event_info(Event, EventNum, ProcId, PrintDepth + 1, CSN, 
-                    !IO),
-             
                 (
                     AutoRetry = do_retry,
                     WhatNext = wn_retry(CSN)
                 ;
                     AutoRetry = do_not_retry,
+                    print_event_info(Event, EventNum, ProcId, PrintDepth, CSN,
+                        !IO),
+             
                     impure prompt(Event, ShadowStack0, 0, WhatNext, !IO)
                 ),
 
@@ -510,6 +488,7 @@
             Stop = no
         ),
         
+        impure get_ssdb_depth_dec(_Depth),
         stack.pop_det(ShadowStack0, _StackFrame1, ShadowStack),
         impure set_cur_ssdb_shadow_stack(ShadowStack)
     ;
@@ -529,7 +507,7 @@
 
         Event = ssdb_fail,
         impure get_ssdb_event_number_inc(EventNum),
-        impure get_ssdb_depth_dec(PrintDepth),
+        semipure get_cur_ssdb_depth(PrintDepth),
         semipure get_cur_ssdb_shadow_stack(ShadowStack0),
         stack.top_det(ShadowStack0, StackFrame),
         CSN = StackFrame ^ se_csn,
@@ -542,14 +520,18 @@
             (
                 impure invent_io(!:IO),
                 
-                print_event_info(Event, EventNum, ProcId, PrintDepth + 1, CSN, 
-                    !IO),
-             
                 (
                     AutoRetry = do_retry,
+                    EventNumF = StackFrame ^ se_event_number,
+                    CSNF = StackFrame ^ se_csn,
+                    impure set_cur_ssdb_event_number(EventNumF-1),
+                    impure set_cur_ssdb_csn(CSNF-1),
                     WhatNext = wn_retry(CSN)
                 ;
                     AutoRetry = do_not_retry,
+                    print_event_info(Event, EventNum, ProcId, PrintDepth, CSN,
+                        !IO),
+             
                     impure prompt(Event, ShadowStack0, 0, WhatNext, !IO)
                 ),
 
@@ -562,6 +544,7 @@
             Retry = do_not_retry
         ),
         
+        impure get_ssdb_depth_dec(_Depth),
         stack.pop_det(ShadowStack0, _StackFrame1, ShadowStack),
         impure set_cur_ssdb_shadow_stack(ShadowStack)
     ;
@@ -586,7 +568,7 @@
         semipure get_cur_ssdb_shadow_stack(ShadowStack0),
         stack.top_det(ShadowStack0, StackFrame),
         CSN = StackFrame ^ se_csn,
-        impure get_ssdb_depth_dec(PrintDepth),
+        semipure get_cur_ssdb_depth(PrintDepth),
         semipure get_cur_ssdb_shadow_stack_nondet(ShadowStackNonDet0),
         
         semipure should_stop_at_this_event(Event, EventNum, CSN, ProcId, Stop, 
@@ -598,17 +580,14 @@
             (
                 impure invent_io(!:IO),
                 
-                print_event_info(Event, EventNum, ProcId, PrintDepth + 1, CSN, 
-                    !IO),
-             
                 (
                     AutoRetry = do_retry,
                     (
-                        semipure get_correct_frame_nondet(ProcId, PrintDepth+1, 
-                            StackFrame)
+                        semipure get_correct_frame_nondet(ProcId, PrintDepth, 
+                            StackFrameFound)
                     ->
-                        EventNumF = StackFrame ^ se_event_number,
-                        CSNF = StackFrame ^ se_csn,
+                        EventNumF = StackFrameFound ^ se_event_number,
+                        CSNF = StackFrameFound ^ se_csn,
                         impure set_cur_ssdb_event_number(EventNumF-1),
                         impure set_cur_ssdb_csn(CSNF-1)
                     ;
@@ -618,6 +597,8 @@
                     WhatNext = wn_retry(CSN)
                 ;
                     AutoRetry = do_not_retry,
+                    print_event_info(Event, EventNum, ProcId, PrintDepth, CSN, 
+                        !IO),
                     impure prompt(Event, ShadowStack0, 0, WhatNext, !IO)
                 ),
 
@@ -630,6 +611,7 @@
             Retry = do_not_retry
         ),
 
+        impure get_ssdb_depth_dec(_Depth),
         stack.pop_det(ShadowStack0, _StackFrame, ShadowStack),
         stack.pop_det(ShadowStackNonDet0, _StackFrameNonDet, ShadowStackNonDet),
         impure set_cur_ssdb_shadow_stack(ShadowStack),
@@ -944,46 +915,6 @@
     ).
 
 
-    %
-    % Print the current informations at this event point.
-    %
-:- pred print_event_info(ssdb_event_type::in, int::in, ssdb_proc_id::in, 
-    int::in, int::in, io::di, io::uo) is det.
-    
-print_event_info(Event, EventNum, ProcId, PrintDepth, CSN, !IO) :-
-    io.write_string("       ", !IO),
-    io.write_int(EventNum, !IO),
-    io.write_string("\t", !IO),
-    io.write_int(CSN, !IO),
-    io.write_string("\t", !IO),
-    io.write_int(PrintDepth, !IO),
-    io.write_string("\t", !IO),
-    ( 
-        ( Event = ssdb_call
-        ; Event = ssdb_call_nondet
-        ),
-        io.write_string("CALL", !IO)
-    ;
-        ( Event = ssdb_exit
-        ; Event = ssdb_exit_nondet
-        ),
-        io.write_string("EXIT", !IO)
-    ;
-        ( Event = ssdb_fail
-        ; Event = ssdb_fail_nondet
-        ),
-        io.write_string("FAIL", !IO)
-    ;
-        Event = ssdb_redo_nondet,
-        io.write_string("REDO", !IO)
-    ),
-    io.write_string("\t\t", !IO),
-    io.write_string(ProcId ^ module_name, !IO),
-    io.write_string(".", !IO),
-    io.write_string(ProcId ^ proc_name, !IO),
-    io.nl(!IO).
-
-
 %----------------------------------------------------------------------------%
 
     %
@@ -1024,30 +955,7 @@
             ; Words = ["help"]
             )
         ->
-                io.nl(!IO),
-                io.write_string("\nPrincipal Commands", !IO),
-                io.write_string("\n------------------", !IO),
-                io.nl(!IO),
-                io.write_string("\n<step> or <s> or < >", !IO),
-                io.write_string("\n<next> or <n>n", !IO),
-                io.write_string("\n<continue> or <c>", !IO),
-                io.write_string("\n<finish> or <f>", !IO),
-                io.write_string("\n<retry> or <r>", !IO),
-                io.write_string("\n<break X Y> or <b X Y>", !IO),
-                io.write_string("\n<break info> or <b info>", !IO),
-                io.write_string("\n<enable / disable / delete *>", !IO),
-                io.write_string("\n<enable / disable / delete N>", !IO),
-                io.write_string("\n<print> or <p>", !IO),
-                io.write_string("\n<stack> or <st>", !IO),
-                io.write_string("\n<up> or <u>", !IO),
-                io.write_string("\n<down> or <d>", !IO),
-                io.write_string("\n<goto N> or <g N>", !IO),
-                io.write_string("\n<help> or <h>", !IO),
-                io.nl(!IO),
-                io.nl(!IO),
-                io.write_string("\nConsult the file : " ++
-                    "/ssdb/SSDB_COMMAND_HELP.txt for details", !IO),
-                io.nl(!IO),
+                print_help(!IO),
                 impure prompt(Event, ShadowStack, Depth, WhatNext, !IO)
 
         ; 
@@ -1055,7 +963,7 @@
             ; Words = ["print"]
             )
         ->
-                CurrentFrame = stack.top_det(ShadowStack),
+                get_correct_frame_with_num(Depth, ShadowStack, CurrentFrame),
                 ListVarValue = CurrentFrame ^ se_list_var_value,
                 print_vars(ListVarValue, !IO),
                 impure prompt(Event, ShadowStack, Depth, WhatNext, !IO)
@@ -1065,7 +973,7 @@
             ; Words = ["stack"] 
             )
         ->
-                print_frames_list(ShadowStack, Depth, !IO),
+                print_frames_list(0, ShadowStack, Depth, !IO),
                 impure prompt(Event, ShadowStack, Depth, WhatNext, !IO)
 
         ; 
@@ -1086,7 +994,6 @@
                 )
 
         ;
-%             ( list.is_empty(Words)
             ( Words = []
             ; Words = ["s"]
             ; Words = ["step"]
@@ -1154,8 +1061,8 @@
                     semipure get_cur_ssdb_depth(CurDepth)
                 ->
                     (
-                        Num >= 1,
-                        Num =< CurDepth 
+                        Num >= 0,
+                        Num =< CurDepth - 1
                     ->
                         get_correct_frame_with_num(Num, ShadowStack, 
                             StackFrame),
@@ -1180,6 +1087,9 @@
                     DownDepth = Depth - 1,
                     DownDepth >= 0
                 ->
+                    get_correct_frame_with_num(DownDepth, ShadowStack, 
+                        FrameToPrint),
+                    print_frame_info(FrameToPrint, !IO),
                     impure prompt(Event, ShadowStack, DownDepth, WhatNext, !IO)
                 ;
                     io.write_string("Impossible to go down\n", !IO),
@@ -1195,6 +1105,9 @@
                     UpDepth = Depth + 1,
                     UpDepth < stack.depth(ShadowStack) 
                 ->
+                    get_correct_frame_with_num(UpDepth, ShadowStack, 
+                        FrameToPrint),
+                    print_frame_info(FrameToPrint, !IO),
                     impure prompt(Event, ShadowStack, UpDepth, WhatNext, !IO)
                 ;
                     io.write_string("Impossible to go up\n", !IO),
@@ -1204,6 +1117,8 @@
         ; 
             ( Words = ["r"] 
             ; Words = ["retry"] 
+            ; Words = ["r", "0"] 
+            ; Words = ["retry", "0"] 
             )
         ->
                 (
@@ -1228,7 +1143,7 @@
                     % value at the event just before the retried procedure.
                     impure set_cur_ssdb_event_number(EventNum-1),
                     impure set_cur_ssdb_csn(CSN-1),
-                    WhatNext = wn_retry_nondet(CSN)
+                    WhatNext = wn_retry(CSN)
                 ;
                     ( Event = ssdb_call
                     ; Event = ssdb_call_nondet
@@ -1248,8 +1163,8 @@
                     semipure get_cur_ssdb_depth(CurDepth)
                 ->
                     (
-                        Num >= 1,
-                        Num =< CurDepth 
+                        Num >= 0,
+                        Num =< CurDepth - 1
                     ->
                         (
                             ( Event = ssdb_exit
@@ -1267,15 +1182,20 @@
                             Event = ssdb_exit_nondet,
                             get_correct_frame_with_num(Num, ShadowStack, 
                                 FrameStack),
-                            EventNum = FrameStack ^ se_event_number,
                             CSN = FrameStack ^ se_csn,
-                            impure set_debugger_state(debugger_off),
                             % Set the event number and the CSN minus 1 because 
                             % it will be increment at the next event. So, we 
                             % need to be at the event just before the call.
-                            impure set_cur_ssdb_event_number(EventNum-1),
-                            impure set_cur_ssdb_csn(CSN-1),     
-                            WhatNext = wn_retry_nondet(CSN)
+                            semipure get_cur_ssdb_shadow_stack_nondet(
+                                ShadowStackNonDet),
+                            ( 
+                                csn_is_in_stack(CSN, ShadowStackNonDet)
+                            ->
+                                impure set_debugger_state(debugger_off),
+                                WhatNext = wn_retry_nondet(CSN)
+                            ;
+                                WhatNext = wn_retry(CSN)
+                            )
                         ;
                             ( Event = ssdb_call
                             ; Event = ssdb_call_nondet
@@ -1371,7 +1291,7 @@
 
         ; Words = ["browse", VarName] ->
             (
-                get_correct_frame_with_num(1, ShadowStack, CurFrame),
+                get_correct_frame_with_num(0, ShadowStack, CurFrame),
                 ListVarValue = CurFrame ^ se_list_var_value,
                 list_var_value_to_assoc_list(ListVarValue, AssListVarValue),
                 assoc_list.search(AssListVarValue, VarName, Univ)
@@ -1388,6 +1308,11 @@
                 io.write_string("\nError in browse command\n", !IO),
                 impure prompt(Event, ShadowStack, Depth, WhatNext, !IO)
             )
+        
+        ; Words = ["exit"] ->
+                exit_debugger(!IO),
+                WhatNext = wn_step
+
         ;
             io.write_string("huh?\n", !IO),
             impure prompt(Event, ShadowStack, Depth, WhatNext, !IO)
@@ -1401,7 +1326,28 @@
     ).
 
 
+    % csn_is_in_stack(CSN, Stack).
+    %
+    % Determine if a CSN from a given frame match a frame in the Stack
     %
+:- pred csn_is_in_stack(int::in, stack(stack_elem)::in) is semidet.
+
+csn_is_in_stack(CSN, ShadowStack0) :-
+    (
+        stack.pop(ShadowStack0, Frame, ShadowStack)
+    ->
+        (
+            CSN = Frame ^ se_csn
+        ->
+            true
+        ;
+            csn_is_in_stack(CSN, ShadowStack)
+        )
+    ;
+        fail
+    ).
+
+
     % Transform the list(var_value) into a assoc_list. As it is for the browser 
     % use, only the bound variable are put into the assoc_list structure.
     %
@@ -1425,22 +1371,21 @@
         AssocListVarValue = [pair(Name, ValueUniv) | AssocListVarValue0]
     ).
 
-    %
+
     % get_correct_frame_with_num(Num, ShadowStack, Frame).
     %
     % Get the Nth frame from the shadow stack, beginning from the top.
-    % Num should be in the interval of 1 =< Num =< Depth.
-    % If Num = 1, get the top frame. 
-    % If Num = Depth, get the deepest frame.
+    % Num should be in the interval of 0 =< Num =< Depth - 1.
+    % If Num = 0, get the top frame. 
     %
 :- pred get_correct_frame_with_num(int::in, stack(stack_elem)::in, 
     stack_elem::out) is det.
 
 get_correct_frame_with_num(Num, ShadowStack0, StackFrame) :-
-    ( Num = 1 ->
+    ( Num = 0 ->
         stack.top_det(ShadowStack0, StackFrame)
 
-    ; Num > 1 ->
+    ; Num > 0 ->
         stack.pop_det(ShadowStack0, _Frame, ShadowStack),
         get_correct_frame_with_num(Num-1, ShadowStack, StackFrame)
 
@@ -1546,34 +1486,145 @@
     ).
 
 
+    % Exit the debugger.
+    %
+:- pred exit_debugger(io::di, io::uo) is det.
+
+:- pragma foreign_proc("C",
+    exit_debugger(IO0::di, IO::uo),
+    [will_not_call_mercury, promise_pure, tabled_for_io],
+"
+    exit(0);
+    IO = IO0;
+").
+
+
 %----------------------------------------------------------------------------%
 
+    % Print the current informations at this event point.
+    %
+:- pred print_event_info(ssdb_event_type::in, int::in, ssdb_proc_id::in, 
+    int::in, int::in, io::di, io::uo) is det.
+    
+print_event_info(Event, EventNum, ProcId, PrintDepth, CSN, !IO) :-
+    io.write_string("       ", !IO),
+    io.write_int(EventNum, !IO),
+    io.write_string("\t", !IO),
+    io.write_int(CSN, !IO),
+    io.write_string("\t", !IO),
+    io.write_int(PrintDepth, !IO),
+    io.write_string("\t", !IO),
+    ( 
+        ( Event = ssdb_call
+        ; Event = ssdb_call_nondet
+        ),
+        io.write_string("CALL", !IO)
+    ;
+        ( Event = ssdb_exit
+        ; Event = ssdb_exit_nondet
+        ),
+        io.write_string("EXIT", !IO)
+    ;
+        ( Event = ssdb_fail
+        ; Event = ssdb_fail_nondet
+        ),
+        io.write_string("FAIL", !IO)
+    ;
+        Event = ssdb_redo_nondet,
+        io.write_string("REDO", !IO)
+    ),
+    io.write_string("\t\t", !IO),
+    io.write_string(ProcId ^ module_name, !IO),
+    io.write_string(".", !IO),
+    io.write_string(ProcId ^ proc_name, !IO),
+    io.nl(!IO).
+
+
+    % print_frame_info(Frame, !IO).
+    %
+    % Print the information of the frame gave in argument.
+    %
+:- pred print_frame_info(stack_elem::in, io::di, io::uo) is det.
+
+print_frame_info(TopFrame, !IO) :-
+    EventNum = TopFrame ^ se_event_number,
+    CSN = TopFrame ^ se_csn,
+    Depth = TopFrame ^ se_depth,
+    ProcId = TopFrame ^ se_proc_id, 
+    io.write_string("       ", !IO),
+    io.write_int(EventNum, !IO),
+    io.write_string("\t", !IO),
+    io.write_int(CSN, !IO),
+    io.write_string("\t", !IO),
+    io.write_int(Depth, !IO),
+    io.write_string("\t\t", !IO),
+    io.write_string(ProcId ^ module_name, !IO),
+    io.write_string(".", !IO),
+    io.write_string(ProcId ^ proc_name, !IO),
+    io.nl(!IO).
+
+
+
+    % Print a summary of the commands.
     %
+:- pred print_help(io::di, io::uo) is det.
+
+print_help(!IO) :-
+    io.nl(!IO),
+    io.write_string("\nPrincipal Commands", !IO),
+    io.write_string("\n------------------", !IO),
+    io.nl(!IO),
+    io.write_string("\n<step> or <s> or < >", !IO),
+    io.write_string("\n<next> or <n>", !IO),
+    io.write_string("\n<continue> or <c>", !IO),
+    io.write_string("\n<finish> or <f>", !IO),
+    io.write_string("\n<retry> or <r>", !IO),
+    io.write_string("\n<break X Y> or <b X Y>", !IO),
+    io.write_string("\n<break info> or <b info>", !IO),
+    io.write_string("\n<enable / disable / delete *>", !IO),
+    io.write_string("\n<enable / disable / delete N>", !IO),
+    io.write_string("\n<print> or <p>", !IO),
+    io.write_string("\n<stack> or <st>", !IO),
+    io.write_string("\n<up> or <u>", !IO),
+    io.write_string("\n<down> or <d>", !IO),
+    io.write_string("\n<goto N> or <g N>", !IO),
+    io.write_string("\n<help> or <h>", !IO),
+    io.write_string("\n<exit>", !IO),
+    io.nl(!IO),
+    io.nl(!IO),
+    io.write_string("\nConsult the file : " ++
+        "/ssdb/SSDB_COMMAND_HELP.txt for details", !IO),
+    io.nl(!IO).
+
+
     % Print the Stack Trace. Predicate call at the 'stack' command.
     %
-:- pred print_frames_list(stack(stack_elem)::in, int::in, 
+:- pred print_frames_list(int::in, stack(stack_elem)::in, int::in, 
     io::di, io::uo) is det.
 
-print_frames_list(ShadowStack0, Depth, !IO) :-
+print_frames_list(Level, ShadowStack0, Depth, !IO) :-
     ( if not stack.is_empty(ShadowStack0) then
         stack.pop_det(ShadowStack0, PopFrame, ShadowStack),
         (if Depth = 0 then
-            print_stack_frame(yes, PopFrame, !IO)
+            print_stack_frame(yes, Level, PopFrame, !IO)
         else
-            print_stack_frame(no, PopFrame, !IO)
+            print_stack_frame(no, Level, PopFrame, !IO)
         ),
-        print_frames_list(ShadowStack, Depth - 1, !IO)
+        print_frames_list(Level + 1, ShadowStack, Depth - 1, !IO)
     else
         true
     ).
 
 
+    % print_stack_frame(Starred, Level, Frame, !IO).
     %
-    % Print one frame.
+    % Print the given Frame. The Level is the place of this frame in the 
+    % stack.
     %
-:- pred print_stack_frame(bool::in, stack_elem::in, io::di, io::uo) is det.
+:- pred print_stack_frame(bool::in, int::in, stack_elem::in, 
+    io::di, io::uo) is det.
 
-print_stack_frame(Starred, Frame, !IO) :-
+print_stack_frame(Starred, Level, Frame, !IO) :-
     Module = Frame ^ se_proc_id ^ module_name ,
     Procedure = Frame ^ se_proc_id ^ proc_name ,
 
@@ -1584,15 +1635,18 @@
         Starred = no,
         io.write_char(' ', !IO)
     ),
-    io.format("  %s.%s(\n", [s(Module), s(Procedure)], !IO),
+    io.format(" %i \t%s.%s(\n", [i(Level), s(Module), s(Procedure)], !IO),
     ListVarValue = Frame ^ se_list_var_value,
     print_vars(ListVarValue, !IO),
     io.write_string("   )\n", !IO).
 
 
-    %
     % Print the given list of variables and their values, if bound.
     % XXX We should treat the io.state better.
+    % XXX The pprint.write predicate is used for the moment instead of 
+    % pretty_printer because this last one had a strange behavior with ssdb
+    % when I tried to print the value T of a variable. Be carefull when you
+    % want to print the argument list which have a big size.
 :- pred print_vars(list(var_value)::in, io::di, io::uo) is det.
 
 print_vars(Vars, !IO) :-
@@ -1602,7 +1656,6 @@
 
 print_var(unbound_head_var(Name, Pos), !IO) :-
     io.write_char('\t', !IO),
-    io.write_string("unbound_head\t", !IO),
     io.write_string(Name, !IO),
     io.write_string(":\t", !IO),
     io.write_int(Pos, !IO),
@@ -1612,27 +1665,26 @@
 
 print_var(bound_head_var(Name, Pos, T), !IO) :-
     io.write_char('\t', !IO),
-    io.write_string("bound_head\t", !IO),
     io.write_string(Name, !IO),
     io.write_string(":\t", !IO),
     io.write_int(Pos, !IO),
     io.write_string("\t=\t", !IO),
-    Doc = pretty_printer.format(T),
-    write_doc(Doc, !IO),
-    io.nl(!IO).
-    
+    io.flush_output(!IO),
+    pprint.write(80, to_doc(T), !IO),
+    io.nl(!IO),
+    io.flush_output(!IO).
+
 print_var(bound_other_var(Name, T), !IO) :-
     io.write_char('\t', !IO),
-    io.write_string("bound_other\t", !IO),
     io.write_string(Name, !IO),
     io.write_string(":\t_\t", !IO),
     io.write_string("=\t", !IO),
-    Doc = pretty_printer.format(T),
-    write_doc(Doc, !IO),
-    io.nl(!IO).
+    io.flush_output(!IO),
+    pprint.write(80, to_doc(T), !IO),
+    io.nl(!IO),
+    io.flush_output(!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