Introduce common_val_print_checked
authorTom Tromey <tom@tromey.com>
Fri, 13 Mar 2020 23:39:52 +0000 (17:39 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 14 Mar 2020 00:03:39 +0000 (18:03 -0600)
A (much) later patch will remove the call to value_check_printable
from common_val_print.  This will needed to preserve some details of
how optimized-out structures are printed.

However, doing this will also break dw2-op-out-param.exp.  Making the
change causes "bt" to print:

However, the test wants to see:

... operand2=<optimized out>

That is, a wholly-optimized out structure should not print its fields.

So, this patch introduces a new common_val_print_checked, which calls
value_check_printable first, and then arranges to use it in the one
spot that affects the test suite.

I was not completely sure if it would be preferable to change the
test.  However, I reasoned that, assuming this output was intentional
in the first place, in a backtrace space is at a premium and so this
is a reasonable approach.  In other spots calling common_val_print,
this behavior is probably unintended, or at least a "don't care".

gdb/ChangeLog
2020-03-13  Tom Tromey  <tom@tromey.com>

* valprint.h (common_val_print_checked): Declare.
* valprint.c (common_val_print_checked): New function.
* stack.c (print_frame_arg): Use common_val_print_checked.

gdb/ChangeLog
gdb/stack.c
gdb/valprint.c
gdb/valprint.h

index 2a2b29887f994bc9d6384f7926dddf48c3cfc49f..c761221dd9f0dbee110b616da153d7bb6b5edbc9 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-13  Tom Tromey  <tom@tromey.com>
+
+       * valprint.h (common_val_print_checked): Declare.
+       * valprint.c (common_val_print_checked): New function.
+       * stack.c (print_frame_arg): Use common_val_print_checked.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
        * valprint.c (do_val_print): New function, from val_print.
index 024ead0b611bcec684410a27a7df9b60cd9c3d0e..af35d796d7074ecc9272ba88aca7a6d9c7494f21 100644 (file)
@@ -486,7 +486,7 @@ print_frame_arg (const frame_print_options &fp_opts,
              vp_opts.summary
                = fp_opts.print_frame_arguments == print_frame_arguments_scalars;
 
-             common_val_print (arg->val, &stb, 2, &vp_opts, language);
+             common_val_print_checked (arg->val, &stb, 2, &vp_opts, language);
            }
          catch (const gdb_exception_error &except)
            {
index 66da0e607bac1a49373936b97b63d66ffa422321..aab43d4b8110d0e73fe6769622faaac8ff54fc2f 100644 (file)
@@ -1236,6 +1236,19 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse,
                val, options, language);
 }
 
+/* See valprint.h.  */
+
+void
+common_val_print_checked (struct value *val, struct ui_file *stream,
+                         int recurse,
+                         const struct value_print_options *options,
+                         const struct language_defn *language)
+{
+  if (!value_check_printable (val, stream, options))
+    return;
+  common_val_print (val, stream, recurse, options, language);
+}
+
 /* Print on stream STREAM the value VAL according to OPTIONS.  The value
    is printed using the current_language syntax.  */
 
index e242134d85643747e4bad20897931812e7ab5f93..13b2b2d8c8d1175bad7f4456e19d32a86d96ad07 100644 (file)
@@ -282,4 +282,12 @@ extern bool val_print_check_max_depth (struct ui_file *stream, int recurse,
                                       const struct value_print_options *opts,
                                       const struct language_defn *language);
 
+/* Like common_val_print, but call value_check_printable first.  */
+
+extern void common_val_print_checked
+  (struct value *val,
+   struct ui_file *stream, int recurse,
+   const struct value_print_options *options,
+   const struct language_defn *language);
+
 #endif