[03/55] Introduce common_val_print_checked
Commit Message
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
2019-12-08 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.
Change-Id: I6802b6bf9b4aa30b399bb133e5c848b24ad16d7a
---
gdb/ChangeLog | 6 ++++++
gdb/stack.c | 2 +-
gdb/valprint.c | 13 +++++++++++++
gdb/valprint.h | 8 ++++++++
4 files changed, 28 insertions(+), 1 deletion(-)
Comments
On Sun, Dec 8, 2019 at 1:33 PM Tom Tromey <tom@tromey.com> wrote:
> However, doing this will also break dw2-op-out-param.exp. Making the
> change causes "bt" to print:
Did you forget to paste something here...?
> 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
> 2019-12-08 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.
>
> Change-Id: I6802b6bf9b4aa30b399bb133e5c848b24ad16d7a
> ---
> gdb/ChangeLog | 6 ++++++
> gdb/stack.c | 2 +-
> gdb/valprint.c | 13 +++++++++++++
> gdb/valprint.h | 8 ++++++++
> 4 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/stack.c b/gdb/stack.c
> index cc7b7e5bbe0..26229983f8b 100644
> --- a/gdb/stack.c
> +++ b/gdb/stack.c
> @@ -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)
> {
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 62c78b95ad2..20763338aff 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1210,6 +1210,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. */
>
> diff --git a/gdb/valprint.h b/gdb/valprint.h
> index 24b731ab357..c63ac8de19b 100644
> --- a/gdb/valprint.h
> +++ b/gdb/valprint.h
> @@ -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
> --
> 2.17.2
>
Christian> Did you forget to paste something here...?
I'll dig it up again later but I think it started with a "#" and I
forgot that this makes it a comment to "git commit".
Tom
@@ -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)
{
@@ -1210,6 +1210,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. */
@@ -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