[m-rev.] diff/for review: limiting mdb stack dumps by number of lines

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jan 14 17:28:50 AEDT 2005


I intend to commit this on monday, after final bootchecks in a couple of grades,
which may result in further changes .exp files. Comments welcome.

Zoltan.

runtime/mercury_stack_trace.[ch]:
	Add a mechanism to limit the number of lines printed by stack traces.

trace/mercury_trace_internal.c:
	Change the existing "stack" and "nondet_stack" mdb commands to make the
	integer argument specify the number of lines printed by default, not
	the number of stack frames reported on, since this is usually what is
	wanted. The number of stack frames N to be reported on can still be
	specified, via the new option -fN.

	Add a new mdb command, "stack_default_limit", that specifies the
	default number of lines to print in stack traces.

trace/mercury_trace_external.c:
	Conform to the changed interfaces in mercury_stack_trace.h.

doc/user_guide.texi:
	Document the changes to mdb commands.

tests/debugger/mdb_command_text.inp:
	Test the documentation of the new command.

tests/debugger/completion.exp*:
	Expect to see the new stack_default_limit command listed.

tests/debugger/queens.exp*:
	Expect the new meaning of the stack command.

tests/debugger/nondet_stack.{inp,exp*}
	Use the new -f option of the nondet_stack command to specify the
	printing of the same number of frames as before. Update the expected
	accordingly.

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
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.408
diff -u -b -r1.408 user_guide.texi
--- doc/user_guide.texi	9 Jan 2005 01:14:04 -0000	1.408
+++ doc/user_guide.texi	14 Jan 2005 06:22:13 -0000
@@ -2602,7 +2602,7 @@
 @c for @samp{set} for more details.
 @sp 1
 
- at item stack [-d] [@var{num}] 
+ at item stack [-d] [-f at var{numframes}] [@var{numlines}] 
 @kindex stack (mdb command)
 Prints the names of the ancestors of the call
 specified by the current event.
@@ -2615,8 +2615,11 @@
 the call's event number, sequence number and depth should also be printed
 if the call is to a procedure that is being execution traced.
 @sp 1
-The optional number, if present,
-specifies that only the topmost @var{num} stack frames should be printed.
+If the @samp{-f} option, if present, specifies that
+only the topmost @var{numframes} stack frames should be printed.
+ at sp 1
+The optional number @var{numlines}, if present,
+specifies that only the topmost @var{numlines} lines should be printed.
 @sp 1
 This command will report an error if there is no stack trace
 information available about any ancestor.
@@ -3127,6 +3130,12 @@
 @item scroll
 Reports whether user scroll control is enabled and what the window size is.
 @sp 1
+ at item stack_default_limit @var{size}
+ at kindex stack_default_limit (mdb command)
+Set the default number of lines printed by
+the @samp{stack} and @samp{nondet_stack} commands to @var{size}.
+If @var{size} is zero, the limit is disabled.
+ at sp 1
 @item context none
 @kindex context (mdb command)
 @cindex line numbers
@@ -3438,15 +3447,18 @@
 the cut stack and the possible negated context stack.
 In other grades, it reports an error.
 @sp 1
- at item nondet_stack [-d] [@var{num}]
+ at item nondet_stack [-d] [-f at var{numframes}] [@var{numlines}]
 @kindex nondet_stack (mdb command)
 Prints the contents of the frames on the nondet stack.
 By default, it prints only of the fixed slots in each nondet stack frame,
 but if the option @samp{-d} or @samp{--detailed} option is given,
 it will also print the names and values of the live variables in them.
 @sp 1
-The optional number, if present,
-specifies that only the topmost @var{num} stack frames should be printed.
+If the @samp{-f} option, if present, specifies that
+only the topmost @var{numframes} stack frames should be printed.
+ at sp 1
+The optional number @var{numlines}, if present,
+specifies that only the topmost @var{numlines} lines should be printed.
 @sp 1
 @item stack_regs
 @kindex stack_regs (mdb command)
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 profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_stack_trace.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_stack_trace.c,v
retrieving revision 1.69
diff -u -b -r1.69 mercury_stack_trace.c
--- runtime/mercury_stack_trace.c	9 Dec 2004 01:03:12 -0000	1.69
+++ runtime/mercury_stack_trace.c	14 Jan 2005 06:18:51 -0000
@@ -68,10 +68,11 @@
 
 static  void        MR_dump_stack_record_init(MR_bool include_trace_data,
                         MR_bool include_contexts);
-static  void        MR_dump_stack_record_frame(FILE *fp,
+static  int         MR_dump_stack_record_frame(FILE *fp,
                         const MR_Label_Layout *label_layout,
                         MR_Word *base_sp, MR_Word *base_curfr,
-                        MR_Print_Stack_Record print_stack_record);
+                        MR_Print_Stack_Record print_stack_record,
+                        MR_bool at_line_limit);
 static  void        MR_dump_stack_record_flush(FILE *fp,
                         MR_Print_Stack_Record print_stack_record);
 
@@ -121,7 +122,7 @@
             layout = label->i_layout;
             result = MR_dump_stack_from_layout(stderr, layout,
                 det_stack_pointer, current_frame, include_trace_data,
-                MR_TRUE, 0, &MR_dump_stack_record_print);
+                MR_TRUE, 0, 0, &MR_dump_stack_record_print);
 
             if (result != NULL) {
                 fprintf(stderr, "%s\n", result);
@@ -135,7 +136,8 @@
 const char *
 MR_dump_stack_from_layout(FILE *fp, const MR_Label_Layout *label_layout,
     MR_Word *det_stack_pointer, MR_Word *current_frame,
-    MR_bool include_trace_data, MR_bool include_contexts, int limit,
+    MR_bool include_trace_data, MR_bool include_contexts,
+    int frame_limit, int line_limit,
     MR_Print_Stack_Record print_stack_record)
 {
     MR_Stack_Walk_Step_Result       result;
@@ -148,6 +150,7 @@
     MR_Word                         *old_trace_sp;
     MR_Word                         *old_trace_curfr;
     int                             frames_dumped_so_far;
+    int                             lines_dumped_so_far;
 
     MR_do_init_modules();
     MR_dump_stack_record_init(include_trace_data, include_contexts);
@@ -158,8 +161,15 @@
     cur_label_layout = label_layout;
 
     frames_dumped_so_far = 0;
+    lines_dumped_so_far = 0;
     do {
-        if (limit > 0 && frames_dumped_so_far >= limit) {
+        if (frame_limit > 0 && frames_dumped_so_far >= frame_limit) {
+            MR_dump_stack_record_flush(fp, print_stack_record);
+            fprintf(fp, "<more stack frames snipped>\n");
+            return NULL;
+        }
+
+        if (line_limit > 0 && lines_dumped_so_far >= line_limit) {
             MR_dump_stack_record_flush(fp, print_stack_record);
             fprintf(fp, "<more stack frames snipped>\n");
             return NULL;
@@ -177,14 +187,15 @@
             MR_dump_stack_record_flush(fp, print_stack_record);
             return problem;
         } else if (result == MR_STEP_ERROR_AFTER) {
-            MR_dump_stack_record_frame(fp, prev_label_layout,
-                old_trace_sp, old_trace_curfr, print_stack_record);
+            (void) MR_dump_stack_record_frame(fp, prev_label_layout,
+                old_trace_sp, old_trace_curfr, print_stack_record, MR_FALSE);
 
             MR_dump_stack_record_flush(fp, print_stack_record);
             return problem;
         } else {
-            MR_dump_stack_record_frame(fp, prev_label_layout,
-                old_trace_sp, old_trace_curfr, print_stack_record);
+            lines_dumped_so_far += MR_dump_stack_record_frame(fp,
+                prev_label_layout, old_trace_sp, old_trace_curfr,
+                print_stack_record, lines_dumped_so_far == line_limit);
         }
 
         frames_dumped_so_far++;
@@ -316,13 +327,13 @@
 /**************************************************************************/
 
 void
-MR_dump_nondet_stack(FILE *fp, MR_Word *limit_addr, int limit,
-        MR_Word *base_maxfr)
+MR_dump_nondet_stack(FILE *fp, MR_Word *limit_addr, int frame_limit,
+    int line_limit, MR_Word *base_maxfr)
 {
 #ifndef MR_HIGHLEVEL_CODE
 
-    MR_dump_nondet_stack_from_layout(fp, limit_addr, limit, base_maxfr,
-            NULL, NULL, NULL);
+    MR_dump_nondet_stack_from_layout(fp, limit_addr, frame_limit, line_limit,
+        base_maxfr, NULL, NULL, NULL);
 
 #else   /* !MR_HIGHLEVEL_CODE */
 
@@ -334,7 +345,8 @@
 #ifdef MR_HIGHLEVEL_CODE
 
 void
-MR_dump_nondet_stack_from_layout(FILE *fp, MR_Word *limit_addr, int limit,
+MR_dump_nondet_stack_from_layout(FILE *fp, MR_Word *limit_addr,
+    int frame_limit, int line_limit,
     MR_Word *base_maxfr, const MR_Label_Layout *top_layout,
     MR_Word *base_sp, MR_Word *base_curfr)
 {
@@ -409,18 +421,19 @@
 #define MR_INIT_NONDET_BRANCH_ARRAY_SIZE        10
 
 void
-MR_dump_nondet_stack_from_layout(FILE *fp, MR_Word *limit_addr, int limit,
-    MR_Word *base_maxfr, const MR_Label_Layout *top_layout,
-    MR_Word *base_sp, MR_Word *base_curfr)
+MR_dump_nondet_stack_from_layout(FILE *fp, MR_Word *limit_addr,
+    int frame_limit, int line_limit, MR_Word *base_maxfr,
+    const MR_Label_Layout *top_layout, MR_Word *base_sp, MR_Word *base_curfr)
 {
     int                     frame_size;
     int                     level_number;
     MR_bool                 print_vars;
     const char              *problem;
-    int                     frames_traversed_so_far;
     int                     branch;
     const MR_Label_Layout   *label_layout;
     const MR_Proc_Layout    *proc_layout;
+    int                     frames_traversed_so_far;
+    int                     lines_dumped_so_far;
 
     MR_do_init_modules();
 
@@ -444,9 +457,15 @@
     */
 
     frames_traversed_so_far = 0;
+    lines_dumped_so_far = 0;
     level_number = 0;
     while (base_maxfr >= MR_nondet_stack_trace_bottom) {
-        if (limit > 0 && frames_traversed_so_far >= limit) {
+        if (frame_limit > 0 && frames_traversed_so_far >= frame_limit) {
+            fprintf(fp, "<more stack frames snipped>\n");
+            return;
+        }
+
+        if (line_limit > 0 && lines_dumped_so_far >= line_limit) {
             fprintf(fp, "<more stack frames snipped>\n");
             return;
         }
@@ -469,6 +488,8 @@
             if (print_vars) {
                 MR_record_temp_redoip(base_maxfr);
             }
+
+            lines_dumped_so_far += 3;
         } else if (frame_size == MR_DET_TEMP_SIZE) {
             MR_print_nondstackptr(fp, base_maxfr);
             fprintf(fp, ": temp\n");
@@ -480,6 +501,8 @@
             fprintf(fp, " detfr:  ");
             MR_print_detstackptr(fp, MR_tmp_detfr_slot(base_maxfr));
             fprintf(fp, "\n");
+
+            lines_dumped_so_far += 4;
         } else {
             MR_print_nondstackptr(fp, base_maxfr);
             fprintf(fp, ": ordinary, %d words", frame_size);
@@ -500,10 +523,12 @@
             fprintf(fp, " succfr: ");
             MR_print_nondstackptr(fp, MR_succfr_slot(base_maxfr));
             fprintf(fp, "\n");
+            lines_dumped_so_far += 5;
 #ifdef  MR_USE_MINIMAL_MODEL_STACK_COPY
             fprintf(fp, " detfr:  ");
             MR_print_detstackptr(fp, MR_table_detfr_slot(base_maxfr));
             fprintf(fp, "\n");
+            lines_dumped_so_far += 1;
 #endif
             if (print_vars && MR_find_matching_branch(base_maxfr, &branch)) {
                 label_layout = MR_nondet_branch_infos[branch].branch_layout;
@@ -527,6 +552,8 @@
                         &MR_call_depth_framevar(base_maxfr));
                     fprintf(fp, " => %d\n",
                         MR_call_depth_framevar(base_maxfr));
+
+                    lines_dumped_so_far += 1;
                 }
             }
 
@@ -1015,15 +1042,16 @@
     trace_data_enabled = include_trace_data;
 }
 
-static void
+static int
 MR_dump_stack_record_frame(FILE *fp, const MR_Label_Layout *label_layout,
     MR_Word *base_sp, MR_Word *base_curfr,
-    MR_Print_Stack_Record print_stack_record)
+    MR_Print_Stack_Record print_stack_record, MR_bool at_line_limit)
 {
     const MR_Proc_Layout    *entry_layout;
     const char              *filename;
     int                     linenumber;
     MR_bool                 must_flush;
+    int                     lines_printed;
 
     entry_layout = label_layout->MR_sll_entry;
     if (! MR_find_context(label_layout, &filename, &linenumber)
@@ -1048,7 +1076,9 @@
     must_flush = (entry_layout != prev_entry_layout) || trace_data_enabled;
 
     if (must_flush) {
+        if (! at_line_limit) {
         MR_dump_stack_record_flush(fp, print_stack_record);
+        }
 
         prev_entry_layout = entry_layout;
         prev_entry_layout_count = 1;
@@ -1059,6 +1089,7 @@
         prev_entry_linenumber = linenumber;
         prev_entry_goal_path = MR_label_goal_path(label_layout);
         prev_entry_context_mismatch = MR_FALSE;
+        lines_printed = 1;
     } else {
         prev_entry_layout_count++;
         if (prev_entry_filename != filename
@@ -1066,9 +1097,11 @@
         {
             prev_entry_context_mismatch = MR_TRUE;
         }
+        lines_printed = 0;
     }
 
     current_level++;
+    return lines_printed;
 }
 
 static void
Index: runtime/mercury_stack_trace.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_stack_trace.h,v
retrieving revision 1.35
diff -u -b -r1.35 mercury_stack_trace.h
--- runtime/mercury_stack_trace.h	9 Dec 2004 01:03:13 -0000	1.35
+++ runtime/mercury_stack_trace.h	13 Jan 2005 12:26:31 -0000
@@ -72,7 +72,8 @@
 				MR_Word *det_stack_pointer,
 				MR_Word *current_frame,
 				MR_bool include_trace_data,
-				MR_bool include_contexts, int limit,
+				MR_bool include_contexts,
+				int frame_limit, int line_limit,
 				MR_Print_Stack_Record print_stack_record);
 
 /*
@@ -83,8 +84,8 @@
 **	The output format is not meant to be intelligible to non-implementors.
 */
 
-extern	void	MR_dump_nondet_stack(FILE *fp, MR_Word *limit_addr, int limit,
-			MR_Word *maxfr);
+extern	void	MR_dump_nondet_stack(FILE *fp, MR_Word *limit_addr,
+			int frame_limit, int line_limit, MR_Word *maxfr);
 
 /*
 ** MR_dump_nondet_stack_from_layout:
@@ -95,8 +96,8 @@
 */
 
 extern	void	MR_dump_nondet_stack_from_layout(FILE *fp,
-			MR_Word *limit_addr, int limit, MR_Word *maxfr,
-			const MR_Label_Layout *label_layout,
+			MR_Word *limit_addr, int frame_limit, int line_limit,
+			MR_Word *maxfr, const MR_Label_Layout *label_layout,
 			MR_Word *base_sp, MR_Word *base_curfr);
 
 /*
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 tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
Index: tests/debugger/mdb_command_test.inp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/mdb_command_test.inp,v
retrieving revision 1.34
diff -u -b -r1.34 mdb_command_test.inp
--- tests/debugger/mdb_command_test.inp	9 Dec 2004 01:03:19 -0000	1.34
+++ tests/debugger/mdb_command_test.inp	14 Jan 2005 05:21:51 -0000
@@ -36,6 +36,7 @@
 printlevel           xyzzy xyzzy xyzzy xyzzy xyzzy
 echo                 xyzzy xyzzy xyzzy xyzzy xyzzy
 scroll               xyzzy xyzzy xyzzy xyzzy xyzzy
+stack_default_limit  xyzzy xyzzy xyzzy xyzzy xyzzy
 context              xyzzy xyzzy xyzzy xyzzy xyzzy
 goal_paths           xyzzy xyzzy xyzzy xyzzy xyzzy
 scope                xyzzy xyzzy xyzzy xyzzy xyzzy
Index: tests/debugger/nondet_stack.inp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/nondet_stack.inp,v
retrieving revision 1.3
diff -u -b -r1.3 nondet_stack.inp
--- tests/debugger/nondet_stack.inp	16 Apr 2003 12:37:47 -0000	1.3
+++ tests/debugger/nondet_stack.inp	14 Jan 2005 06:19:13 -0000
@@ -2,7 +2,7 @@
 context none
 register --quiet
 goto 22
-nondet_stack 3
+nondet_stack -f 3
 nondet_stack
 stack_regs
 nondet_stack -d
Index: tests/debugger/queens.exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/queens.exp,v
retrieving revision 1.29
diff -u -b -r1.29 queens.exp
--- tests/debugger/queens.exp	19 Nov 2004 05:46:17 -0000	1.29
+++ tests/debugger/queens.exp	14 Jan 2005 06:08:54 -0000
@@ -144,8 +144,9 @@
    4      E4      C3    2 pred queens.queen/2-0 (nondet) (queens.m:30) c2;
    5      E1      C1    1 pred queens.main/2-0 (cc_multi) (queens.m:15) ?;c2;q!;
 mdb> stack 3
-   0    3* pred queens.qperm/2-0 (nondet) (queens.m:36 and others)
-<more stack frames snipped>
+   0    4* pred queens.qperm/2-0 (nondet) (queens.m:36 and others)
+   4       pred queens.queen/2-0 (nondet) (queens.m:30)
+   5       pred queens.main/2-0 (cc_multi) (queens.m:15)
 mdb> stack -d 3
    0     E20     C10    6 pred queens.qperm/2-0 (nondet) (queens.m:36) (empty)
    1     E15      C8    5 pred queens.qperm/2-0 (nondet) (queens.m:40) s2;c3;
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_external.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.76
diff -u -b -r1.76 mercury_trace_external.c
--- trace/mercury_trace_external.c	16 Aug 2004 03:51:16 -0000	1.76
+++ trace/mercury_trace_external.c	14 Jan 2005 01:27:02 -0000
@@ -644,7 +644,7 @@
 					stdout, layout,
 					MR_saved_sp(saved_regs),
 					MR_saved_curfr(saved_regs),
-					include_trace_data, MR_FALSE, 0,
+					include_trace_data, MR_FALSE, 0, 0,
 					&MR_dump_stack_record_print_to_socket);
 				MR_send_message_to_socket("end_stack");
 				if (message != NULL) {
@@ -671,7 +671,7 @@
 				** MR_dump_nondet_stack() (as we do
 				** with MR_dump_stack_record_print()).
 				*/						
-				MR_dump_nondet_stack(stdout, NULL, 0,
+				MR_dump_nondet_stack(stdout, NULL, 0, 0,
 					MR_saved_maxfr(saved_regs));
 				MR_send_message_to_socket("ok");
 				break;
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.186
diff -u -b -r1.186 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	9 Jan 2005 01:14:09 -0000	1.186
+++ trace/mercury_trace_internal.c	14 Jan 2005 06:18:58 -0000
@@ -131,6 +131,13 @@
 static	int			MR_scroll_next = 0;
 
 /*
+** This variable controls the number of stack frame lines printed by the stack
+** and nondet_stack commands if the user doesn't override it.
+*/
+
+static	int			MR_stack_default_line_limit = 0;
+
+/*
 ** We echo each command just as it is executed iff this variable is MR_TRUE.
 */
 
@@ -436,6 +443,7 @@
 static	MR_TraceCmdFunc	MR_trace_cmd_printlevel;
 static	MR_TraceCmdFunc	MR_trace_cmd_mmc_options;
 static	MR_TraceCmdFunc	MR_trace_cmd_scroll;
+static	MR_TraceCmdFunc	MR_trace_cmd_stack_default_limit;
 static	MR_TraceCmdFunc	MR_trace_cmd_context;
 static	MR_TraceCmdFunc	MR_trace_cmd_goal_paths;
 static	MR_TraceCmdFunc	MR_trace_cmd_scope;
@@ -494,10 +502,10 @@
 			MR_bool verbose);
 static	void	MR_trace_maybe_close_source_window(MR_bool verbose);
 
-static	void	MR_trace_cmd_stack_2(MR_Event_Info *event_info, int limit,
-			MR_bool detailed);
+static	void	MR_trace_cmd_stack_2(MR_Event_Info *event_info,	
+			MR_bool detailed, int frame_limit, int line_limit);
 static	void	MR_trace_cmd_nondet_stack_2(MR_Event_Info *event_info,
-			int limit, MR_bool detailed);
+			MR_bool detailed, int frame_limit, int line_limit);
 
 static	MR_bool	MR_trace_options_movement_cmd(MR_Trace_Cmd_Info *cmd,
 			char ***words, int *word_count,
@@ -521,7 +529,7 @@
 static	MR_bool	MR_trace_options_detailed(MR_bool *detailed, char ***words,
 			int *word_count, const char *cat, const char *item);
 static	MR_bool	MR_trace_options_stack_trace(MR_bool *detailed,
-			char ***words, int *word_count,
+			int *frame_limit, char ***words, int *word_count,
 			const char *cat, const char *item);
 static	MR_bool	MR_trace_options_confirmed(MR_bool *confirmed, char ***words,
 			int *word_count, const char *cat, const char *item);
@@ -2190,19 +2198,23 @@
 	MR_Code **jumpaddr)
 {
 	MR_bool			detailed;
-	int			limit;
+	int			frame_limit = 0;
+	int			line_limit = MR_stack_default_line_limit;
+	int			spec_line_limit;
 
 	detailed = MR_FALSE;
-	if (! MR_trace_options_stack_trace(&detailed, &words, &word_count,
-		"browsing", "stack"))
+	if (! MR_trace_options_stack_trace(&detailed, &frame_limit,
+		&words, &word_count, "browsing", "stack"))
 	{
 		; /* the usage message has already been printed */
 	} else if (word_count == 1) {
-		MR_trace_cmd_stack_2(event_info, 0, detailed);
+		MR_trace_cmd_stack_2(event_info, detailed,
+			frame_limit, line_limit);
 	} else if (word_count == 2 &&
-		MR_trace_is_natural_number(words[1], &limit))
+		MR_trace_is_natural_number(words[1], &spec_line_limit))
 	{
-		MR_trace_cmd_stack_2(event_info, limit, detailed);
+		MR_trace_cmd_stack_2(event_info, detailed,
+			frame_limit, spec_line_limit);
 	} else {
 		MR_trace_usage("browsing", "stack");
 	}
@@ -2211,7 +2223,8 @@
 }
 
 static void
-MR_trace_cmd_stack_2(MR_Event_Info *event_info, int limit, MR_bool detailed)
+MR_trace_cmd_stack_2(MR_Event_Info *event_info, MR_bool detailed,
+	int frame_limit, int line_limit)
 {
 	const MR_Label_Layout	*layout;
 	MR_Word 		*saved_regs;
@@ -2224,7 +2237,7 @@
 	msg = MR_dump_stack_from_layout(MR_mdb_out, layout,
 		MR_saved_sp(saved_regs), MR_saved_curfr(saved_regs),
 		detailed, MR_context_position != MR_CONTEXT_NOWHERE,
-		limit, &MR_dump_stack_record_print);
+		frame_limit, line_limit, &MR_dump_stack_record_print);
 
 	if (msg != NULL) {
 		fflush(MR_mdb_out);
@@ -3078,6 +3091,48 @@
 }
 
 static MR_Next
+MR_trace_cmd_stack_default_limit(char **words, int word_count,
+	MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+	MR_Event_Details *event_details, MR_Code **jumpaddr)
+{
+	int	n;
+
+	if (word_count == 2) {
+		if (MR_trace_is_natural_number(words[1], &n)) {
+			MR_stack_default_line_limit = n;
+			if (! MR_trace_internal_interacting) {
+				return KEEP_INTERACTING;
+			}
+			
+			if (MR_stack_default_line_limit > 0) {
+				fprintf(MR_mdb_out,
+					"Default stack dump size limit set to "
+					"%d.\n", MR_stack_default_line_limit);
+			} else {
+				fprintf(MR_mdb_out,
+					"Default stack dump size limit set to "
+					"none.\n");
+			}
+		} else {
+			MR_trace_usage("parameter", "stack_default_limit");
+		}
+	} else if (word_count == 1) {
+		if (MR_stack_default_line_limit > 0) {
+			fprintf(MR_mdb_out,
+				"Default stack dump size limit is %d.\n",
+				MR_stack_default_line_limit);
+		} else {
+			fprintf(MR_mdb_out,
+				"There is no default stack dump size limit.\n");
+		}
+	} else {
+		MR_trace_usage("parameter", "stack_default_limit");
+	}
+
+	return KEEP_INTERACTING;
+}
+
+static MR_Next
 MR_trace_cmd_context(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
 	MR_Event_Info *event_info, MR_Event_Details *event_details,
 	MR_Code **jumpaddr)
@@ -3807,19 +3862,23 @@
 	MR_Code **jumpaddr)
 {
 	MR_bool			detailed;
-	int			limit;
+	int			frame_limit = 0;
+	int			line_limit = MR_stack_default_line_limit;
+	int			spec_line_limit;
 
 	detailed = MR_FALSE;
-	if (! MR_trace_options_stack_trace(&detailed, &words, &word_count,
-		"browsing", "nondet_stack"))
+	if (! MR_trace_options_stack_trace(&detailed, &frame_limit,
+		&words, &word_count, "browsing", "nondet_stack"))
 	{
 		; /* the usage message has already been printed */
 	} else if (word_count == 1) {
-		MR_trace_cmd_nondet_stack_2(event_info, 0, detailed);
+		MR_trace_cmd_nondet_stack_2(event_info, detailed,
+			frame_limit, line_limit);
 	} else if (word_count == 2 &&
-		MR_trace_is_natural_number(words[1], &limit))
+		MR_trace_is_natural_number(words[1], &spec_line_limit))
 	{
-		MR_trace_cmd_nondet_stack_2(event_info, limit, detailed);
+		MR_trace_cmd_nondet_stack_2(event_info, detailed,
+			frame_limit, spec_line_limit);
 	} else {
 		MR_trace_usage("developer", "nondet_stack");
 	}
@@ -3828,8 +3887,8 @@
 }
 
 static void
-MR_trace_cmd_nondet_stack_2(MR_Event_Info *event_info, int limit,
-	MR_bool detailed)
+MR_trace_cmd_nondet_stack_2(MR_Event_Info *event_info, MR_bool detailed,
+	int frame_limit, int line_limit)
 {
 	const MR_Label_Layout	*layout;
 	MR_Word 		*saved_regs;
@@ -3842,12 +3901,13 @@
 		int	saved_level;
 
 		saved_level = MR_trace_current_level();
-		MR_dump_nondet_stack_from_layout(MR_mdb_out, NULL, limit,
+		MR_dump_nondet_stack_from_layout(MR_mdb_out, NULL,
+			frame_limit, line_limit,
 			MR_saved_maxfr(saved_regs), layout,
 			MR_saved_sp(saved_regs), MR_saved_curfr(saved_regs));
 		MR_trace_set_level(saved_level, MR_print_optionals);
 	} else {
-		MR_dump_nondet_stack(MR_mdb_out, NULL, limit,
+		MR_dump_nondet_stack(MR_mdb_out, NULL, frame_limit, line_limit,
 			MR_saved_maxfr(saved_regs));
 	}
 }
@@ -6189,13 +6249,13 @@
 }
 
 static MR_bool
-MR_trace_options_stack_trace(MR_bool *detailed,
+MR_trace_options_stack_trace(MR_bool *detailed, int *frame_limit,
 	char ***words, int *word_count, const char *cat, const char *item)
 {
 	int	c;
 
 	MR_optind = 0;
-	while ((c = MR_getopt_long(*word_count, *words, "d",
+	while ((c = MR_getopt_long(*word_count, *words, "df:",
 		MR_trace_detailed_opts, NULL)) != EOF)
 	{
 		switch (c) {
@@ -6204,6 +6264,15 @@
 				*detailed = MR_TRUE;
 				break;
 
+			case 'f':
+				if (! MR_trace_is_natural_number(MR_optarg, 
+					frame_limit))
+				{
+					MR_trace_usage(cat, item);
+					return MR_FALSE;
+				}
+				break;
+
 			default:
 				MR_trace_usage(cat, item);
 				return MR_FALSE;
@@ -7581,6 +7650,8 @@
 		NULL, MR_trace_null_completer },
 	{ "parameter", "scroll", MR_trace_cmd_scroll,
 		MR_trace_on_off_args, MR_trace_null_completer },
+	{ "parameter", "stack_default_limit", MR_trace_cmd_stack_default_limit,
+		NULL, MR_trace_null_completer },
 	{ "parameter", "context", MR_trace_cmd_context,
 		MR_trace_context_cmd_args, MR_trace_null_completer },
 	{ "parameter", "goal_paths", MR_trace_cmd_goal_paths,
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