Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/9] Convert get_user_print_options
Date: Sat, 04 Jul 2026 16:05:17 -0600	[thread overview]
Message-ID: <20260704-print-opts-cleanup-v1-3-fb54a5112a8d@tromey.com> (raw)
In-Reply-To: <20260704-print-opts-cleanup-v1-0-fb54a5112a8d@tromey.com>

This changes get_user_print_options to return a const reference to the
global user print options.  This is maybe slightly more efficient in
some cases, though probably not anywhere that matters.
---
 gdb/ada-lang.c              |  3 +--
 gdb/auxv.c                  |  4 +---
 gdb/break-catch-exec.c      |  4 +---
 gdb/break-catch-fork.c      |  3 +--
 gdb/break-catch-load.c      |  3 +--
 gdb/break-catch-sig.c       |  4 +---
 gdb/break-catch-syscall.c   |  3 +--
 gdb/break-catch-throw.c     |  3 +--
 gdb/breakpoint.c            | 18 +++++-------------
 gdb/c-varobj.c              |  6 ++----
 gdb/compile/compile.c       |  3 +--
 gdb/eval.c                  |  3 +--
 gdb/f-valprint.c            |  4 +---
 gdb/gnu-v3-abi.c            |  9 +++------
 gdb/guile/scm-value.c       |  6 ++----
 gdb/infcmd.c                |  9 +++------
 gdb/linux-thread-db.c       |  4 +---
 gdb/mi/mi-main.c            |  3 +--
 gdb/printcmd.c              |  8 +++-----
 gdb/python/py-framefilter.c | 14 ++++----------
 gdb/python/py-lazy-string.c |  3 +--
 gdb/python/py-prettyprint.c |  2 +-
 gdb/python/py-unwind.c      |  3 +--
 gdb/record-full.c           |  3 +--
 gdb/riscv-tdep.c            |  5 ++---
 gdb/skip.c                  |  3 ---
 gdb/stack.c                 |  7 ++-----
 gdb/tracepoint.c            |  4 +---
 gdb/typeprint.c             |  3 +--
 gdb/valprint.c              |  7 -------
 gdb/valprint.h              | 10 ++++++++--
 gdb/value.c                 | 11 +++--------
 gdb/varobj.c                |  4 +---
 33 files changed, 57 insertions(+), 122 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 35ebd924021..74a35332bee 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12410,9 +12410,8 @@ bool
 ada_catchpoint::print_one (const bp_location **last_loc) const
 {
   struct ui_out *uiout = current_uiout;
-  struct value_print_options opts;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   if (opts.addressprint)
     uiout->field_skip ("addr");
diff --git a/gdb/auxv.c b/gdb/auxv.c
index 1a58fd8c844..206406f8175 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -442,9 +442,7 @@ fprint_auxv_entry (struct ui_file *file, const char *name,
       break;
     case AUXV_FORMAT_STR:
       {
-	struct value_print_options opts;
-
-	get_user_print_options (&opts);
+	const value_print_options &opts = get_user_print_options ();
 	if (opts.addressprint)
 	  gdb_printf (file, ("%s "), paddress (arch, val));
 	val_print_string (builtin_type (arch)->builtin_char,
diff --git a/gdb/break-catch-exec.c b/gdb/break-catch-exec.c
index 4fbe5e4f067..4e37bca585b 100644
--- a/gdb/break-catch-exec.c
+++ b/gdb/break-catch-exec.c
@@ -111,10 +111,8 @@ exec_catchpoint::print_it (const bpstat *bs) const
 bool
 exec_catchpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* Field 4, the address, is omitted (which makes the columns
      not line up too nicely with the headers, but the effect
diff --git a/gdb/break-catch-fork.c b/gdb/break-catch-fork.c
index be00c15adeb..7af329ff7e3 100644
--- a/gdb/break-catch-fork.c
+++ b/gdb/break-catch-fork.c
@@ -137,10 +137,9 @@ fork_catchpoint::print_it (const bpstat *bs) const
 bool
 fork_catchpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* Field 4, the address, is omitted (which makes the columns not
      line up too nicely with the headers, but the effect is relatively
diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 30bdd0604a7..5492a56b423 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -158,10 +158,9 @@ solib_catchpoint::print_it (const bpstat *bs) const
 bool
 solib_catchpoint::print_one (const bp_location **locs) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
   /* Field 4, the address, is omitted (which makes the columns not
      line up too nicely with the headers, but the effect is relatively
      readable).  */
diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index ea85083b6f8..15ff2c5c8ac 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -214,10 +214,8 @@ signal_catchpoint::print_it (const bpstat *bs) const
 bool
 signal_catchpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* Field 4, the address, is omitted (which makes the columns
      not line up too nicely with the headers, but the effect
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 1a0bb931080..a2a68b22d0c 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -229,10 +229,9 @@ syscall_catchpoint::print_it (const bpstat *bs) const
 bool
 syscall_catchpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
   /* Field 4, the address, is omitted (which makes the columns not
      line up too nicely with the headers, but the effect is relatively
      readable).  */
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 03d8c5f772d..be4ff2a43a0 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -255,10 +255,9 @@ exception_catchpoint::print_it (const bpstat *bs) const
 bool
 exception_catchpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   if (opts.addressprint)
     uiout->field_skip ("addr");
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e4df4df04a7..68811ed57da 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5038,8 +5038,7 @@ watchpoint_value_print (struct value *val, struct ui_file *stream)
     fprintf_styled (stream, metadata_style.style (), _("<unreadable>"));
   else
     {
-      struct value_print_options opts;
-      get_user_print_options (&opts);
+      const value_print_options &opts = get_user_print_options ();
       value_print (val, stream, &opts);
     }
 }
@@ -6591,9 +6590,7 @@ print_one_breakpoint_location (struct breakpoint *b,
   struct ui_out *uiout = current_uiout;
   bool header_of_multiple = false;
   bool part_of_multiple = (loc != NULL);
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   gdb_assert (!loc || loc_number != 0);
   /* See comment in print_one_breakpoint concerning treatment of
@@ -7081,13 +7078,11 @@ breakpoint_1 (const char *bp_num_list, bool show_internal,
 {
   const bp_location *last_loc = nullptr;
   int nr_printable_breakpoints;
-  struct value_print_options opts;
   int print_address_bits = 0;
   int print_type_col_width = 14;
   struct ui_out *uiout = current_uiout;
   bool has_disabled_by_cond_location = false;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* Compute the number of rows in the table, as well as the size
      required for address fields.  */
@@ -9653,13 +9648,12 @@ ranged_breakpoint::print_it (const bpstat *bs) const
 bool
 ranged_breakpoint::print_one (const bp_location **last_loc) const
 {
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
   /* Ranged breakpoints have only one location.  */
   gdb_assert (this->has_single_location ());
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   if (opts.addressprint)
     /* We don't print the address range here, it will be printed later
@@ -11840,9 +11834,7 @@ bpstat_remove_bp_location (bpstat *bps, struct breakpoint *bpt)
 void
 code_breakpoint::say_where () const
 {
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* i18n: cagney/2005-02-11: Below needs to be merged into a
      single string.  */
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 9428ce08ae2..5312eccdaca 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -558,12 +558,11 @@ cplus_number_of_children (const struct varobj *var)
   struct type *type;
   int children, dont_know;
   int lookup_actual_type = 0;
-  struct value_print_options opts;
 
   dont_know = 1;
   children = 0;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   if (!CPLUS_FAKE_CHILD (var))
     {
@@ -681,7 +680,6 @@ cplus_describe_child (const struct varobj *parent, int index,
   int lookup_actual_type = 0;
   const char *parent_expression = NULL;
   const struct varobj *var;
-  struct value_print_options opts;
 
   if (cname)
     *cname = std::string ();
@@ -692,7 +690,7 @@ cplus_describe_child (const struct varobj *parent, int index,
   if (cfull_expression)
     *cfull_expression = std::string ();
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
   if (opts.objectprint)
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 4a027de2625..7a60bd33a64 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -271,11 +271,10 @@ static void
 compile_print_command (const char *arg, int from_tty)
 {
   enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
-  value_print_options print_opts;
 
   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
-  get_user_print_options (&print_opts);
+  value_print_options print_opts = get_user_print_options ();
   /* Override global settings with explicit options, if any.  */
   auto group = make_value_print_options_def_group (&print_opts);
   gdb::option::process_options
diff --git a/gdb/eval.c b/gdb/eval.c
index 7e07765c9e6..d5d4963e374 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1250,9 +1250,8 @@ eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
     struct type *real_type;
     int full, using_enc;
     LONGEST top;
-    struct value_print_options opts;
 
-    get_user_print_options (&opts);
+    const value_print_options &opts = get_user_print_options ();
     if (opts.objectprint && arg_type->target_type ()
 	&& (arg_type->target_type ()->code () == TYPE_CODE_STRUCT))
       {
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 8a383281a6c..f91c585fc0b 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -622,9 +622,7 @@ static void
 info_common_command_for_block (const struct block *block, const char *comname,
 			       int *any_printed)
 {
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   for (struct symbol *sym : block_iterator_range (block))
     if (sym->domain () == COMMON_BLOCK_DOMAIN)
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 35910be0f06..2ca29ef77d3 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -683,9 +683,7 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
     }
   else
     {
-      struct value_print_options opts;
-
-      get_user_print_options (&opts);
+      const value_print_options &opts = get_user_print_options ();
       print_address_demangle (&opts, gdbarch, ptr_value, stream, demangle);
     }
 
@@ -872,7 +870,7 @@ compute_vtable_size (vtable_hash_t &offset_hash, struct value *value)
 static void
 print_one_vtable (struct gdbarch *gdbarch, struct value *value,
 		  int max_voffset,
-		  struct value_print_options *opts)
+		  const value_print_options *opts)
 {
   int i;
   struct type *type = check_typedef (value->type ());
@@ -930,7 +928,6 @@ gnuv3_print_vtable (struct value *value)
   struct gdbarch *gdbarch;
   struct type *type;
   struct value *vtable;
-  struct value_print_options opts;
   int count;
 
   value = coerce_ref (value);
@@ -941,7 +938,7 @@ gnuv3_print_vtable (struct value *value)
       type = check_typedef (value->type ());
     }
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   /* Respect 'set print object'.  */
   if (opts.objectprint)
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 6eaf486af07..fb739c370ef 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -143,12 +143,11 @@ static int
 vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
 {
   value_smob *v_smob = (value_smob *) SCM_SMOB_DATA (self);
-  struct value_print_options opts;
 
   if (pstate->writingp)
     gdbscm_printf (port, "#<%s ", value_smob_name);
 
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.deref_ref = false;
 
   /* pstate->writingp = zero if invoked by display/~A, and nonzero if
@@ -1266,9 +1265,8 @@ gdbscm_value_print (SCM self)
   value_smob *v_smob
     = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct value *value = v_smob->value;
-  struct value_print_options opts;
 
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.deref_ref = false;
 
   string_file stb;
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index eb7b4efa2a0..90a49eff8be 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1650,9 +1650,7 @@ print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
 
       if (finish_print)
 	{
-	  struct value_print_options opts;
-	  get_user_print_options (&opts);
-
+	  const value_print_options opts = get_user_print_options ();
 	  string_file stb;
 	  value_print (rv->value, &stb, &opts);
 	  uiout->field_stream ("return-value", stb);
@@ -2419,11 +2417,10 @@ default_print_one_register_info (struct ui_file *file,
   if (regtype->code () == TYPE_CODE_FLT
       || regtype->code () == TYPE_CODE_DECFLOAT)
     {
-      struct value_print_options opts;
       const gdb_byte *valaddr = val->contents_for_printing ().data ();
       enum bfd_endian byte_order = type_byte_order (regtype);
 
-      get_user_print_options (&opts);
+      value_print_options opts = get_user_print_options ();
       opts.deref_ref = true;
 
       common_val_print (val, &format_stream, 0, &opts, current_language);
@@ -2448,7 +2445,7 @@ default_print_one_register_info (struct ui_file *file,
       if (print_raw_format && regtype->is_vector () == 0)
 	{
 	  pad_to_column (format_stream, value_column_2);
-	  get_user_print_options (&opts);
+	  opts = get_user_print_options ();
 	  opts.deref_ref = true;
 	  common_val_print (val, &format_stream, 0, &opts, current_language);
 	}
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 5e506c4f497..bbeed776f70 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -698,9 +698,7 @@ check_thread_db_callback (const td_thrhandle_t *th, void *arg)
 
       if (tdb_testinfo->log_progress)
 	{
-	  struct value_print_options opts;
-
-	  get_user_print_options (&opts);
+	  const value_print_options &opts = get_user_print_options ();
 	  LOG (" = ");
 	  value_print (val, gdb_stdlog, &opts);
 	}
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b1c42ddfd24..5e5244619af 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1145,7 +1145,6 @@ mi_cmd_data_evaluate_expression (const char *command, const char *const *argv,
 				 int argc)
 {
   struct value *val;
-  struct value_print_options opts;
   struct ui_out *uiout = current_uiout;
 
   if (argc != 1)
@@ -1159,7 +1158,7 @@ mi_cmd_data_evaluate_expression (const char *command, const char *const *argv,
   string_file stb;
 
   /* Print the result of the expression evaluation.  */
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.deref_ref = false;
   common_val_print (val, &stb, 0, &opts, current_language);
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 4c964915a8b..9ebe563fed3 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1334,7 +1334,7 @@ static struct value *
 process_print_command_args (const char *args, value_print_options *print_opts,
 			    bool voidprint)
 {
-  get_user_print_options (print_opts);
+  *print_opts = get_user_print_options ();
   /* Override global settings with explicit options, if any.  */
   auto group = make_value_print_options_def_group (print_opts);
   gdb::option::process_options
@@ -2378,14 +2378,13 @@ print_variable_value (symbol *var, const frame_info_ptr &frame,
   try
     {
       struct value *val;
-      struct value_print_options opts;
 
       /* READ_VAR_VALUE needs a block in order to deal with non-local
 	 references (i.e. to handle nested functions).  In this context, we
 	 print variables that are local to this frame, so we can avoid passing
 	 a block to it.  */
       val = read_var_value (var, NULL, frame);
-      get_user_print_options (&opts);
+      value_print_options opts = get_user_print_options ();
       opts.deref_ref = true;
       common_val_print_checked (val, stream, indent, &opts, language);
     }
@@ -2888,8 +2887,7 @@ ui_printf (const char *arg, struct ui_file *stream)
 	    break;
 	  case value_arg:
 	    {
-	      value_print_options print_opts;
-	      get_user_print_options (&print_opts);
+	      value_print_options print_opts = get_user_print_options ();
 
 	      if (current_substring[2] == '[')
 		{
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index f256a26807c..6e3012a3331 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -417,9 +417,7 @@ enumerate_args (PyObject *iter,
 		int print_args_field,
 		const frame_info_ptr &frame)
 {
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.raw = raw_frame_args;
 
   if (args_type == CLI_SCALAR_VALUES)
@@ -549,9 +547,7 @@ enumerate_locals (PyObject *iter,
 		  int print_args_field,
 		  const frame_info_ptr &frame)
 {
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.deref_ref = true;
 
   while (true)
@@ -633,7 +629,6 @@ enumerate_locals (PyObject *iter,
 
 static enum ext_lang_bt_status
 py_mi_print_variables (PyObject *filter, struct ui_out *out,
-		       struct value_print_options *opts,
 		       enum ext_lang_frame_args args_type,
 		       const frame_info_ptr &frame,
 		       bool raw_frame_args_p)
@@ -767,7 +762,6 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
   CORE_ADDR address = 0;
   struct gdbarch *gdbarch = NULL;
   frame_info_ptr frame = NULL;
-  struct value_print_options opts;
 
   int print_level, print_frame_info, print_args, print_locals;
   /* Note that the below default in non-mi mode is the same as the
@@ -786,7 +780,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
   print_args = (flags & PRINT_ARGS) ? 1 : 0;
   print_locals = (flags & PRINT_LOCALS) ? 1 : 0;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
   if (print_frame_info)
     {
       std::optional<enum print_what> user_frame_info_print_what;
@@ -818,7 +812,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
   if (print_locals && print_args && ! print_frame_info)
     {
       bool raw_frame_args = (flags & PRINT_RAW_FRAME_ARGUMENTS) != 0;
-      if (py_mi_print_variables (filter, out, &opts, args_type, frame,
+      if (py_mi_print_variables (filter, out, args_type, frame,
 				 raw_frame_args) == EXT_LANG_BT_ERROR)
 	return EXT_LANG_BT_ERROR;
       return EXT_LANG_BT_OK;
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index c9d06338b0a..e095bc3fb69 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -305,8 +305,7 @@ stpy_str (PyObject *self)
 {
   lazy_string_object *str = (lazy_string_object *) self;
 
-  struct value_print_options opts;
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.addressprint = false;
 
   string_file stream;
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index d3faf861fcf..1326aaae476 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -776,7 +776,7 @@ gdbpy_get_print_options (value_print_options *opts)
   if (gdbpy_current_print_options != nullptr)
     *opts = *gdbpy_current_print_options;
   else
-    get_user_print_options (opts);
+    *opts = get_user_print_options ();
 }
 
 /* A ValuePrinter is just a "tag", so it has no state other than that
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 13eced4cecb..ec682c34ebc 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -210,9 +210,8 @@ unwind_infopy_str (PyObject *self)
   stb.printf ("Frame ID: %s", unwind_info->frame_id.to_string ().c_str ());
   {
     const char *sep = "";
-    struct value_print_options opts;
 
-    get_user_print_options (&opts);
+    const value_print_options &opts = get_user_print_options ();
     stb.printf ("\nSaved registers: (");
     for (const saved_reg &reg : *unwind_info->saved_regs)
       {
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 695d9d1622c..c843236e5fe 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2806,8 +2806,7 @@ maintenance_print_record_instruction (const char *args, int from_tty)
   auto to_print = record_full_log.begin () + offset;
 
   gdbarch *arch = current_inferior ()->arch ();
-  struct value_print_options opts;
-  get_user_print_options (&opts);
+  value_print_options opts = get_user_print_options ();
   opts.raw = true;
 
   for (auto &entry : to_print->effects)
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index a21796db1f9..d98d3f33fed 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1180,11 +1180,10 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
 
   if (riscv_is_fp_regno_p (regnum))
     {
-      struct value_print_options opts;
       const gdb_byte *valaddr = val->contents_for_printing ().data ();
       enum bfd_endian byte_order = type_byte_order (regtype);
 
-      get_user_print_options (&opts);
+      value_print_options opts = get_user_print_options ();
       opts.deref_ref = true;
 
       common_val_print (val, file, 0, &opts, current_language);
@@ -1337,7 +1336,7 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
 		 natural format.  */
 	      if (regtype->is_vector () == 0)
 		{
-		  get_user_print_options (&opts);
+		  opts = get_user_print_options ();
 		  opts.deref_ref = true;
 		  gdb_printf (file, "\t");
 		  common_val_print (val, file, 0, &opts, current_language);
diff --git a/gdb/skip.c b/gdb/skip.c
index 917b084860d..795a573412b 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -1035,9 +1035,6 @@ static void
 info_skip_command (const char *arg, int from_tty)
 {
   int num_printable_entries = 0;
-  struct value_print_options opts;
-
-  get_user_print_options (&opts);
 
   /* Count the number of rows in the table and see if we need space for a
      64-bit address anywhere.  */
diff --git a/gdb/stack.c b/gdb/stack.c
index 5d725803c1e..4ebecfc36c3 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1081,9 +1081,7 @@ do_print_frame_info (struct ui_out *uiout, const frame_print_options &fp_opts,
 						  sal.line + 1, 0);
       else
 	{
-	  struct value_print_options opts;
-
-	  get_user_print_options (&opts);
+	  const value_print_options &opts = get_user_print_options ();
 	  /* We used to do this earlier, but that is clearly
 	     wrong.  This function is used by many different
 	     parts of gdb, including normal_stop in infrun.c,
@@ -1267,7 +1265,6 @@ print_frame (struct ui_out *uiout,
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum language funlang = language_unknown;
-  struct value_print_options opts;
   struct symbol *func;
   std::optional <CORE_ADDR> pc;
 
@@ -1288,7 +1285,7 @@ print_frame (struct ui_out *uiout,
 	uiout->field_fmt_signed (2, ui_left, "level",
 				 frame_relative_level (frame));
       }
-    get_user_print_options (&opts);
+    const value_print_options &opts = get_user_print_options ();
     if (opts.addressprint)
       if (!sal.symtab
 	  || frame_show_address (frame, sal)
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 798bb9a552d..18b678afd52 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -523,8 +523,6 @@ teval_pseudocommand (const char *args, int from_tty)
 const char *
 decode_agent_options (const char *exp, int *trace_string)
 {
-  struct value_print_options opts;
-
   *trace_string = 0;
 
   if (*exp != '/')
@@ -532,7 +530,7 @@ decode_agent_options (const char *exp, int *trace_string)
 
   /* Call this to borrow the print elements default for collection
      size.  */
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   exp++;
   if (*exp == 's')
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 31a9c1814a3..46dd01199e5 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -357,7 +357,6 @@ whatis_exp (const char *exp, int show)
   int full = 0;
   LONGEST top = -1;
   int using_enc = 0;
-  struct value_print_options opts;
   struct type_print_options flags = default_ptype_flags;
 
   if (exp)
@@ -457,7 +456,7 @@ whatis_exp (const char *exp, int show)
       flags.print_offsets = 0;
     }
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
   if (val != NULL && opts.objectprint)
     {
       if (type->is_pointer_or_reference ()
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0c385f6ad52..4ef50707bef 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -97,13 +97,6 @@ struct value_print_options user_print_options =
   PRINT_MAX_DEPTH_DEFAULT,	/* max_depth */
 };
 
-/* Initialize *OPTS to be a copy of the user print options.  */
-void
-get_user_print_options (struct value_print_options *opts)
-{
-  *opts = user_print_options;
-}
-
 /* See valprint.h.  */
 
 value_print_options
diff --git a/gdb/valprint.h b/gdb/valprint.h
index b38af46f344..e743c39dca5 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -144,8 +144,14 @@ extern gdb::option::option_def_group make_value_print_options_def_group
    code should call get_user_print_options instead.  */
 extern struct value_print_options user_print_options;
 
-/* Initialize *OPTS to be a copy of the user print options.  */
-extern void get_user_print_options (struct value_print_options *opts);
+/* Accessor for the user print options.  */
+
+static inline
+const value_print_options &
+get_user_print_options ()
+{
+  return user_print_options;
+}
 
 /* Return a copy of the user print options, but with pretty-formatting
    disabled.  */
diff --git a/gdb/value.c b/gdb/value.c
index 1f6d7949d4d..e9c22cbc9da 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1083,10 +1083,8 @@ struct type *
 value_actual_type (struct value *value, int resolve_simple_types,
 		   int *real_type_found)
 {
-  struct value_print_options opts;
   struct type *result;
-
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
 
   if (real_type_found)
     *real_type_found = 0;
@@ -1786,11 +1784,9 @@ show_values (const char *num_exp, int from_tty)
 
   for (i = num; i < num + 10 && i <= value_history.size (); i++)
     {
-      struct value_print_options opts;
-
       val = access_value_history (i);
       gdb_printf (("$%d = "), i);
-      get_user_print_options (&opts);
+      const value_print_options &opts = get_user_print_options ();
       value_print (val, gdb_stdout, &opts);
       gdb_printf (("\n"));
     }
@@ -2564,9 +2560,8 @@ show_convenience (const char *ignore, int from_tty)
 {
   struct gdbarch *gdbarch = get_current_arch ();
   int varseen = 0;
-  struct value_print_options opts;
 
-  get_user_print_options (&opts);
+  const value_print_options &opts = get_user_print_options ();
   for (auto &pair : internalvars)
     {
       internalvar &var = pair.second;
diff --git a/gdb/varobj.c b/gdb/varobj.c
index a5caee56707..92a1f5ae578 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1129,9 +1129,7 @@ update_type_if_necessary (struct varobj *var, struct value *new_value)
 {
   if (new_value)
     {
-      struct value_print_options opts;
-
-      get_user_print_options (&opts);
+      const value_print_options &opts = get_user_print_options ();
       if (opts.objectprint)
 	{
 	  struct type *new_type = value_actual_type (new_value, 0, 0);

-- 
2.49.0


  parent reply	other threads:[~2026-07-04 22:06 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 ` [PATCH 1/9] Return value_print_options from get_formatted_print_options Tom Tromey
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 ` Tom Tromey [this message]
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-3-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