Make "bt N" print correct number of frames when using a frame filter
authorTom Tromey <tom@tromey.com>
Mon, 20 Jun 2016 16:36:29 +0000 (10:36 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 26 Feb 2018 16:37:03 +0000 (09:37 -0700)
PR python/16497 notes that using "bt" with a positive argument prints
the wrong number of frames when a frame filter is in use.  Also, in this
case, the non-frame-filter path will print a message about "More stack
frames" when there are more; but this is not done in the frame-filter
case.

The first problem is that backtrace_command_1 passes the wrong value
to apply_ext_lang_frame_filter -- that function takes the final
frame's number as an argument, but backtrace_command_1 passes the
count, which is off by one.

The solution to the second problem is to have the C stack-printing
code stop at the correct number of frames and then print the message.

Tested using the buildbot.

ChangeLog
2018-02-26  Tom Tromey  <tom@tromey.com>

PR python/16497:
* stack.c (backtrace_command_1): Set PRINT_MORE_FRAMES flag.  Fix
off-by-one in py_end computation.
* python/py-framefilter.c (gdbpy_apply_frame_filter): Handle
PRINT_MORE_FRAMES.
* extension.h (enum frame_filter_flags) <PRINT_MORE_FRAMES>: New
constant.

2018-02-26  Tom Tromey  <tom@tromey.com>

PR python/16497:
* gdb.python/py-framefilter.exp: Update test.

gdb/ChangeLog
gdb/extension.h
gdb/python/py-framefilter.c
gdb/stack.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-framefilter.exp

index 0897d59d89ca3a4e84988268351f5226c5239c04..906d14c1919fb0a55a9b0f31c78e4159c79f1e49 100644 (file)
@@ -1,3 +1,13 @@
+2018-02-26  Tom Tromey  <tom@tromey.com>
+
+       PR python/16497:
+       * stack.c (backtrace_command_1): Set PRINT_MORE_FRAMES flag.  Fix
+       off-by-one in py_end computation.
+       * python/py-framefilter.c (gdbpy_apply_frame_filter): Handle
+       PRINT_MORE_FRAMES.
+       * extension.h (enum frame_filter_flags) <PRINT_MORE_FRAMES>: New
+       constant.
+
 2018-02-26  Tom Tromey  <tom@tromey.com>
 
        * dwarf2read.c (struct variant_field): New.
index effa5bbffe509913c60522552f66110b74520451..7375d72a643fb259a5e426f3ca36ada93abf0467 100644 (file)
@@ -100,6 +100,9 @@ enum frame_filter_flags
 
     /* Set this flag if frame locals are to be printed.  */
     PRINT_LOCALS = 8,
+
+    /* Set this flag if a "More frames" message is to be printed.  */
+    PRINT_MORE_FRAMES = 16,
   };
 
 /* A choice of the different frame argument printing strategies that
index e887849c3625869ba18950c325bc2dd9b95d9390..3a3fb97c6c26da963f269f8b6bc1f5c4cb28105b 100644 (file)
@@ -1355,6 +1355,18 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
 
   gdbpy_enter enter_py (gdbarch, current_language);
 
+  /* When we're limiting the number of frames, be careful to request
+     one extra frame, so that we can print a message if there are more
+     frames.  */
+  int frame_countdown = -1;
+  if ((flags & PRINT_MORE_FRAMES) != 0 && frame_low >= 0 && frame_high >= 0)
+    {
+      ++frame_high;
+      /* This has an extra +1 because it is checked before a frame is
+        printed.  */
+      frame_countdown = frame_high - frame_low + 1;
+    }
+
   gdbpy_ref<> iterable (bootstrap_python_frame_filters (frame, frame_low,
                                                        frame_high));
 
@@ -1402,6 +1414,19 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
          break;
        }
 
+      if (frame_countdown != -1)
+       {
+         gdb_assert ((flags & PRINT_MORE_FRAMES) != 0);
+         --frame_countdown;
+         if (frame_countdown == 0)
+           {
+             /* We've printed all the frames we were asked to
+                print, but more frames existed.  */
+             printf_filtered (_("(More stack frames follow...)\n"));
+             break;
+           }
+       }
+
       success = py_print_frame (item.get (), flags, args_type, out, 0,
                                levels_printed.get ());
 
index 9993ae654ad592197b96af82a859734b7f4ec868..4481cc4c6a254f340a0e74042e550748279f4282 100644 (file)
@@ -1744,7 +1744,9 @@ backtrace_command_1 (const char *count_exp, int show_locals, int no_filters,
       else
        {
          py_start = 0;
-         py_end = count;
+         /* The argument to apply_ext_lang_frame_filter is the number
+            of the final frame to print, and frames start at 0.  */
+         py_end = count - 1;
        }
     }
   else
@@ -1778,6 +1780,8 @@ backtrace_command_1 (const char *count_exp, int show_locals, int no_filters,
 
       if (show_locals)
        flags |= PRINT_LOCALS;
+      if (from_tty)
+       flags |= PRINT_MORE_FRAMES;
 
       if (!strcmp (print_frame_arguments, "scalars"))
        arg_type = CLI_SCALAR_VALUES;
index 755fe94c8b053592bcd59bf2904d837acf4125be..be173ec34b84892326129431db464645e718517e 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-26  Tom Tromey  <tom@tromey.com>
+
+       PR python/16497:
+       * gdb.python/py-framefilter.exp: Update test.
+
 2018-02-26  Tom Tromey  <tom@tromey.com>
 
        * gdb.dwarf2/variant.c: New file.
index 7c72c983d2beb9148d19e393b389b80c2038df80..7e02e9d701bcac9bc4fd1c9e939d1d4e8e46539f 100644 (file)
@@ -149,7 +149,7 @@ gdb_test "bt -2" \
     ".*#26.*func5.*#27.*in main \\(\\).*" \
     "bt -2 with frame-filter Reverse disabled"
 gdb_test "bt 3" \
-    ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*" \
+    ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\)\[^#\]*More stack frames follow.*" \
     "bt 3 with frame-filter Reverse disabled"
 gdb_test "bt no-filter full" \
     ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*" \
This page took 0.03333 seconds and 4 git commands to generate.