From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/9] Return value_print_options from get_formatted_print_options
Date: Sat, 04 Jul 2026 16:05:15 -0600 [thread overview]
Message-ID: <20260704-print-opts-cleanup-v1-1-fb54a5112a8d@tromey.com> (raw)
In-Reply-To: <20260704-print-opts-cleanup-v1-0-fb54a5112a8d@tromey.com>
This changes get_formatted_print_options to return the
value_print_options object.
---
gdb/dwarf2/read.c | 5 ++---
gdb/infcmd.c | 4 +---
gdb/mi/mi-main.c | 7 +++----
gdb/mips-tdep.c | 11 +++--------
gdb/printcmd.c | 10 +++-------
gdb/riscv-tdep.c | 3 +--
gdb/valprint.c | 14 +++++++-------
gdb/valprint.h | 7 +++----
gdb/varobj.c | 2 +-
9 files changed, 24 insertions(+), 39 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 114c608fde3..6f34f187d47 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5119,8 +5119,6 @@ dwarf2_compute_name (const char *name,
cu->language_defn->printchar (value, type, &buf);
else
{
- struct value_print_options opts;
-
if (baton != NULL)
v = dwarf2_evaluate_loc_desc (type, NULL,
baton->expr (),
@@ -5137,7 +5135,8 @@ dwarf2_compute_name (const char *name,
/* Specify decimal so that we do not depend on
the radix. */
- get_formatted_print_options (&opts, 'd');
+ value_print_options opts
+ = get_formatted_print_options ('d');
opts.raw = true;
value_print (v, &buf, &opts);
release_value (v);
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index bd5dbb02f48..eb7b4efa2a0 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2439,10 +2439,8 @@ default_print_one_register_info (struct ui_file *file,
}
else
{
- struct value_print_options opts;
-
/* Print the register in hex. */
- get_formatted_print_options (&opts, 'x');
+ value_print_options opts = get_formatted_print_options ('x');
opts.deref_ref = true;
common_val_print (val, &format_stream, 0, &opts, current_language);
/* If not a vector register, print it also according to its
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 73c64b82186..200d29309ba 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1059,7 +1059,6 @@ output_register (const frame_info_ptr &frame, int regnum, int format,
struct ui_out *uiout = current_uiout;
value *val
= value_of_register (regnum, get_next_frame_sentinel_okay (frame));
- struct value_print_options opts;
if (skip_unavailable && !val->entirely_available ())
return;
@@ -1075,7 +1074,7 @@ output_register (const frame_info_ptr &frame, int regnum, int format,
string_file stb;
- get_formatted_print_options (&opts, format);
+ value_print_options opts = get_formatted_print_options (format);
opts.deref_ref = true;
common_val_print (val, &stb, 0, &opts, current_language);
uiout->field_stream ("value", stb);
@@ -1315,7 +1314,6 @@ mi_cmd_data_read_memory (const char *command, const char *const *argv,
{
int col;
int col_byte;
- struct value_print_options print_opts;
ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_core_addr ("addr", gdbarch, addr + row_byte);
@@ -1323,7 +1321,8 @@ mi_cmd_data_read_memory (const char *command, const char *const *argv,
row_byte); */
{
ui_out_emit_list list_data_emitter (uiout, "data");
- get_formatted_print_options (&print_opts, word_format);
+ value_print_options print_opts
+ = get_formatted_print_options (word_format);
for (col = 0, col_byte = row_byte;
col < nr_cols;
col++, col_byte += word_size)
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index fe0482fe5bf..6532884f69b 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -6340,15 +6340,13 @@ mips_print_fp_register (struct ui_file *file, const frame_info_ptr &frame,
if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame))
{
- struct value_print_options opts;
-
/* 4-byte registers: Print hex and floating. Also print even
numbered registers as doubles. */
mips_read_fp_register_single (frame, regnum, raw_buffer);
flt_str = target_float_to_string (raw_buffer.data (), flt_type,
"%-17.9g");
- get_formatted_print_options (&opts, 'x');
+ value_print_options opts = get_formatted_print_options ('x');
print_scalar_formatted (raw_buffer.data (),
builtin_type (gdbarch)->builtin_uint32,
&opts, 'w', file);
@@ -6366,8 +6364,6 @@ mips_print_fp_register (struct ui_file *file, const frame_info_ptr &frame,
}
else
{
- struct value_print_options opts;
-
/* Eight byte registers: print each one as hex, float and double. */
mips_read_fp_register_single (frame, regnum, raw_buffer);
flt_str = target_float_to_string (raw_buffer.data (), flt_type,
@@ -6377,7 +6373,7 @@ mips_print_fp_register (struct ui_file *file, const frame_info_ptr &frame,
dbl_str = target_float_to_string (raw_buffer.data (), dbl_type,
"%-24.17g");
- get_formatted_print_options (&opts, 'x');
+ value_print_options opts = get_formatted_print_options ('x');
print_scalar_formatted (raw_buffer.data (),
builtin_type (gdbarch)->builtin_uint64,
&opts, 'g', file);
@@ -6392,7 +6388,6 @@ mips_print_register (struct ui_file *file, const frame_info_ptr &frame,
int regnum)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct value_print_options opts;
struct value *val;
if (mips_float_register_p (gdbarch, regnum))
@@ -6414,7 +6409,7 @@ mips_print_register (struct ui_file *file, const frame_info_ptr &frame,
else
gdb_printf (file, ": ");
- get_formatted_print_options (&opts, 'x');
+ value_print_options opts = get_formatted_print_options ('x');
value_print_scalar_formatted (val, &opts, 0, file);
}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a337a6b7db9..4c964915a8b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1101,8 +1101,7 @@ do_examine_next_address (struct format_data fmt)
if (format == 's' || format == 'i')
maxelts = 1;
- value_print_options opts;
- get_formatted_print_options (&opts, format);
+ value_print_options opts = get_formatted_print_options (format);
bool need_to_update_next_address = false;
CORE_ADDR addr_rewound = 0;
@@ -1458,7 +1457,6 @@ output_command (const char *exp, int from_tty)
char format = 0;
struct value *val;
struct format_data fmt;
- struct value_print_options opts;
fmt.size = 0;
fmt.raw = 0;
@@ -1477,7 +1475,7 @@ output_command (const char *exp, int from_tty)
annotate_value_begin (val->type ());
- get_formatted_print_options (&opts, format);
+ value_print_options opts = get_formatted_print_options (format);
opts.raw = fmt.raw;
/* This setting allows large arrays to be printed by limiting the
@@ -2192,8 +2190,6 @@ do_one_display (struct display *d)
}
else
{
- struct value_print_options opts;
-
annotate_display_format ();
if (d->format.format)
@@ -2208,7 +2204,7 @@ do_one_display (struct display *d)
annotate_display_expression ();
- get_formatted_print_options (&opts, d->format.format);
+ value_print_options opts = get_formatted_print_options (d->format.format);
opts.raw = d->format.raw;
try
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 1751d78a5f3..a21796db1f9 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1199,11 +1199,10 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
}
else
{
- struct value_print_options opts;
riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
/* Print the register in hex. */
- get_formatted_print_options (&opts, 'x');
+ value_print_options opts = get_formatted_print_options ('x');
opts.deref_ref = true;
common_val_print (val, file, 0, &opts, current_language);
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 50a4663ca3b..cf2bc8e135c 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -113,14 +113,14 @@ get_no_prettyformat_print_options (struct value_print_options *opts)
opts->prettyformat = Val_no_prettyformat;
}
-/* Initialize *OPTS to be a copy of the user print options, but using
- FORMAT as the formatting option. */
-void
-get_formatted_print_options (struct value_print_options *opts,
- char format)
+/* See valprint.h. */
+
+value_print_options
+get_formatted_print_options (char format)
{
- *opts = user_print_options;
- opts->format = format;
+ value_print_options opts = user_print_options;
+ opts.format = format;
+ return opts;
}
/* Implement 'show print elements'. */
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 15d0be2ac7a..775ff333646 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -151,10 +151,9 @@ extern void get_user_print_options (struct value_print_options *opts);
pretty-formatting disabled. */
extern void get_no_prettyformat_print_options (struct value_print_options *);
-/* Initialize *OPTS to be a copy of the user print options, but using
- FORMAT as the formatting option. */
-extern void get_formatted_print_options (struct value_print_options *opts,
- char format);
+/* Return a copy of the user print options, but using FORMAT as the
+ formatting option. */
+extern value_print_options get_formatted_print_options (char format);
extern void maybe_print_array_index (struct type *index_type, LONGEST index,
struct ui_file *stream,
diff --git a/gdb/varobj.c b/gdb/varobj.c
index a55c2c6dd2b..a5caee56707 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2106,7 +2106,7 @@ void
varobj_formatted_print_options (struct value_print_options *opts,
enum varobj_display_formats format)
{
- get_formatted_print_options (opts, format_code[(int) format]);
+ *opts = get_formatted_print_options (format_code[(int) format]);
opts->deref_ref = false;
opts->raw = !pretty_printing;
}
--
2.49.0
next prev parent reply other threads:[~2026-07-04 22:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 22:05 [PATCH 0/9] Some cleanups and C++-ification of value_print_options Tom Tromey
2026-07-04 22:05 ` Tom Tromey [this message]
2026-07-04 22:05 ` [PATCH 2/9] Return value_print_options from get_no_prettyformat_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 3/9] Convert get_user_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 4/9] Return a const reference from gdbpy_get_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 5/9] Return value_print_options from varobj_formatted_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 6/9] Use 'const' with some value_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 7/9] Don't use 'struct' keyword with value_print_options Tom Tromey
2026-07-04 22:05 ` [PATCH 8/9] Use std::forward in fortran_array_walker Tom Tromey
2026-07-04 22:05 ` [PATCH 9/9] Use references for value_print_options Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260704-print-opts-cleanup-v1-1-fb54a5112a8d@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox