Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH v3 10/17] Don't use the single-argument gdb::span constructor
Date: Tue, 17 Nov 2026 15:10:06 -0700	[thread overview]
Message-ID: <20261117-span-part-1-v3-10-40b8b11d2d8c@adacore.com> (raw)
In-Reply-To: <20261117-span-part-1-v3-0-40b8b11d2d8c@adacore.com>

Currently the gdb code relies on gdb::span having a single-object
constructor and then making a span of 1 element from this object.
This isn't part of C++20, and it seemed better to be explicit here, so
this patch changes these spots to use make_span(&x, 1).

A few callers could be cleaned up more nicely; for instance some of
the sal-using code was making a span when it seemed just as good to
push to a vector.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31422
---
 gdb/breakpoint.c         | 18 +++++++-----------
 gdb/displaced-stepping.h |  5 +++++
 gdb/elfread.c            |  7 ++++---
 gdb/gcore.c              |  2 +-
 gdb/gdbtypes.c           |  8 +++++---
 gdb/gnu-v3-abi.c         |  2 +-
 gdb/objc-lang.c          | 22 +++++++++++++++-------
 gdb/python/python.c      | 14 +++++---------
 gdb/source.c             | 13 ++++---------
 gdb/thread.c             |  2 +-
 gdb/valarith.c           |  5 +++--
 gdb/valops.c             |  2 +-
 gdb/value.c              |  4 ++--
 13 files changed, 54 insertions(+), 50 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a5ac06c46c3..0f173fa9fe6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -11338,29 +11338,25 @@ clear_command (const char *arg, int from_tty)
 {
   int default_match;
 
-  std::vector<symtab_and_line> decoded_sals;
-  symtab_and_line last_sal;
-  gdb::span<symtab_and_line> sals;
+  std::vector<symtab_and_line> sals;
   if (arg)
     {
-      decoded_sals
-	= decode_line_with_current_source (arg,
-					   (DECODE_LINE_FUNFIRSTLINE
-					    | DECODE_LINE_LIST_MODE));
+      sals = decode_line_with_current_source (arg,
+					      (DECODE_LINE_FUNFIRSTLINE
+					       | DECODE_LINE_LIST_MODE));
       default_match = 0;
-      sals = decoded_sals;
     }
   else
     {
       /* Set sal's line, symtab, pc, and pspace to the values
 	 corresponding to the last call to print_frame_info.  If the
 	 codepoint is not valid, this will set all the fields to 0.  */
-      last_sal = get_last_displayed_sal ();
+      symtab_and_line last_sal = get_last_displayed_sal ();
       if (last_sal.symtab == 0)
 	error (_("No source file specified."));
 
       default_match = 1;
-      sals = last_sal;
+      sals.emplace_back (std::move (last_sal));
     }
 
   /* We don't call resolve_sal_pc here.  That's not as bad as it
@@ -12833,7 +12829,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
       std::unique_ptr<tracepoint> tp
 	(new tracepoint (gdbarch,
 			 type_wanted,
-			 lsal.sals[i],
+			 gdb::make_span (&lsal.sals[i], 1),
 			 std::move (locspec),
 			 NULL,
 			 std::move (cond_string),
diff --git a/gdb/displaced-stepping.h b/gdb/displaced-stepping.h
index e2bd9d21003..ca768ed1be6 100644
--- a/gdb/displaced-stepping.h
+++ b/gdb/displaced-stepping.h
@@ -203,6 +203,11 @@ struct displaced_step_buffers
       m_buffers.emplace_back (buffer_addr);
   }
 
+  explicit displaced_step_buffers (CORE_ADDR addr)
+  {
+    m_buffers.emplace_back (addr);
+  }
+
   displaced_step_prepare_status prepare (thread_info *thread,
 					 CORE_ADDR &displaced_pc);
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 2f4d326f20a..0e810da65ba 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -935,7 +935,8 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
   target_auxv_search (AT_HWCAP, &hwcap);
   hwcap_val = value_from_longest (builtin_type (gdbarch)
 				  ->builtin_unsigned_long, hwcap);
-  address_val = call_function_by_hand (function, NULL, hwcap_val);
+  address_val = call_function_by_hand (function, nullptr,
+				       gdb::make_span (&hwcap_val, 1));
   address = value_as_address (address_val);
   address = gdbarch_convert_from_func_ptr_addr
     (gdbarch, address, current_inferior ()->top_target ());
@@ -1068,9 +1069,9 @@ elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b)
   elf_gnu_ifunc_record_cache (b->locspec->to_string (), resolved_pc);
 
   b->type = bp_breakpoint;
+  symtab_and_line sal = find_function_start_sal (resolved_pc, nullptr, true);
   update_breakpoint_locations (b, current_program_space,
-			       find_function_start_sal (resolved_pc, nullptr, true),
-			       {});
+			       gdb::make_span (&sal, 1), {});
 }
 
 /* A helper function for elf_symfile_read that reads the minimal
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 77d915505d1..b88085ad78b 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -294,7 +294,7 @@ call_target_sbrk (int sbrk_arg)
   gdb_assert (target_sbrk_arg);
   ret = call_function_by_hand (sbrk_fn,
 			       builtin_type (gdbarch)->builtin_data_ptr,
-			       target_sbrk_arg);
+			       gdb::make_span (&target_sbrk_arg, 1));
   if (ret == NULL)
     return (bfd_vma) 0;
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c414cb12e0f..648bb2c7987 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2008,11 +2008,13 @@ resolve_dynamic_range (struct type *dyn_range_type,
   gdb_assert (dyn_range_type->code () == TYPE_CODE_RANGE);
   gdb_assert (rank >= 0);
 
+  CORE_ADDR core_rank = rank;
+
   const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
   if (resolve_p)
     {
       if (dwarf2_evaluate_property (prop, frame, addr_stack, &value,
-				    { (CORE_ADDR) rank }))
+				    gdb::make_span (&core_rank, 1)))
 	low_bound.set_const_val (value);
       else if (prop->kind () == PROP_UNDEFINED)
 	low_bound.set_undefined ();
@@ -2026,7 +2028,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
   if (resolve_p)
     {
       if (dwarf2_evaluate_property (prop, frame, addr_stack, &value,
-				    { (CORE_ADDR) rank }))
+				    gdb::make_span (&core_rank, 1)))
 	{
 	  high_bound.set_const_val (value);
 
@@ -2045,7 +2047,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
   bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride;
   prop = &dyn_range_type->bounds ()->stride;
   if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value,
-					     { (CORE_ADDR) rank }))
+					     gdb::make_span (&core_rank, 1)))
     {
       stride.set_const_val (value);
 
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 8c5c3c9ede9..6770e0ae786 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -495,7 +495,7 @@ gnuv3_baseclass_offset (struct type *type, int index,
 
       CORE_ADDR result;
       if (dwarf2_evaluate_property (&prop, nullptr, &addr_stack, &result,
-				    {addr_stack.addr}))
+				    gdb::make_span (&addr_stack.addr, 1)))
 	return (int) (result - addr_stack.addr);
     }
 
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index c0755220627..62bac5107c0 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -116,9 +116,11 @@ lookup_objc_class (struct gdbarch *gdbarch, const char *classname)
 
   classval = value_string (classname, strlen (classname) + 1, char_type);
   classval = value_coerce_array (classval);
-  return (CORE_ADDR) value_as_long (call_function_by_hand (function,
-							   NULL,
-							   classval));
+  return ((CORE_ADDR)
+	  value_as_long (call_function_by_hand
+			 (function,
+			  nullptr,
+			  gdb::make_span (&classval, 1))));
 }
 
 CORE_ADDR
@@ -148,7 +150,8 @@ lookup_child_selector (struct gdbarch *gdbarch, const char *selname)
   selstring = value_coerce_array (value_string (selname,
 						strlen (selname) + 1,
 						char_type));
-  return value_as_long (call_function_by_hand (function, NULL, selstring));
+  return value_as_long (call_function_by_hand (function, nullptr,
+					       gdb::make_span (&selstring, 1)));
 }
 
 namespace expr
@@ -179,13 +182,17 @@ objc_nsstring_operation::evaluate (struct type *expect_type,
 			     "_NSNewStringFromCString").minsym != nullptr)
     {
       function = find_function_in_inferior("_NSNewStringFromCString", NULL);
-      nsstringValue = call_function_by_hand(function, NULL, stringValue[2]);
+      nsstringValue
+	= call_function_by_hand(function, nullptr,
+				gdb::make_span (&stringValue[2], 1));
     }
   else if (lookup_minimal_symbol (current_program_space,
 				  "istr").minsym != nullptr)
     {
       function = find_function_in_inferior("istr", NULL);
-      nsstringValue = call_function_by_hand(function, NULL, stringValue[2]);
+      nsstringValue
+	= call_function_by_hand(function, nullptr,
+				gdb::make_span (&stringValue[2], 1));
     }
   else if (lookup_minimal_symbol (current_program_space,
 				  "+[NSString stringWithCString:]").minsym
@@ -1217,7 +1224,8 @@ print_object_command (const char *args, int from_tty)
   if (function == NULL)
     error (_("Unable to locate _NSPrintForDebugger in child process"));
 
-  description = call_function_by_hand (function, NULL, object);
+  description = call_function_by_hand (function, nullptr,
+				       gdb::make_span (&object, 1));
 
   string_addr = value_as_long (description);
   if (string_addr == 0)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d6a14a90424..1d540959879 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -991,21 +991,17 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
     locspec = string_to_location_spec_basic (&arg, current_language,
 					     symbol_name_match_type::WILD);
 
-  std::vector<symtab_and_line> decoded_sals;
-  symtab_and_line def_sal;
-  gdb::span<symtab_and_line> sals;
+  std::vector<symtab_and_line> sals;
   try
     {
       if (locspec != NULL)
-	{
-	  decoded_sals = decode_line_1 (locspec.get (), 0, NULL, NULL, 0);
-	  sals = decoded_sals;
-	}
+	sals = decode_line_1 (locspec.get (), 0, nullptr, nullptr, 0);
       else
 	{
 	  set_default_source_symtab_and_line ();
-	  def_sal = get_current_source_symtab_and_line (current_program_space);
-	  sals = def_sal;
+	  symtab_and_line def_sal
+	    = get_current_source_symtab_and_line (current_program_space);
+	  sals.emplace_back (std::move (def_sal));
 	}
     }
   catch (const gdb_exception &ex)
diff --git a/gdb/source.c b/gdb/source.c
index a0584847451..c590e74e4dc 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1470,14 +1470,12 @@ info_line_command (const char *arg, int from_tty)
 {
   CORE_ADDR start_pc, end_pc;
 
-  std::vector<symtab_and_line> decoded_sals;
-  symtab_and_line curr_sal;
-  gdb::span<symtab_and_line> sals;
-
+  std::vector<symtab_and_line> sals;
   if (arg == 0)
     {
       current_source_location *loc
 	= get_source_location (current_program_space);
+      symtab_and_line curr_sal;
       curr_sal.symtab = loc->symtab ();
       curr_sal.pspace = current_program_space;
       if (last_line_listed != 0)
@@ -1485,14 +1483,11 @@ info_line_command (const char *arg, int from_tty)
       else
 	curr_sal.line = loc->line ();
 
-      sals = curr_sal;
+      sals.emplace_back (std::move (curr_sal));
     }
   else
     {
-      decoded_sals = decode_line_with_last_displayed (arg,
-						      DECODE_LINE_LIST_MODE);
-      sals = decoded_sals;
-
+      sals = decode_line_with_last_displayed (arg, DECODE_LINE_LIST_MODE);
       dont_repeat ();
     }
 
diff --git a/gdb/thread.c b/gdb/thread.c
index e9ef77228b1..559ec111920 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1725,7 +1725,7 @@ make_thread_apply_all_options_def_group (bool *ascending,
 					 qcs_flags *flags)
 {
   return {{
-    { {ascending_option_def.def ()}, ascending},
+      { gdb::make_span (&ascending_option_def.def (), 1), ascending},
     { {thr_qcs_flags_option_defs}, flags },
   }};
 }
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 1918050aa6f..0814a1698d2 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -655,13 +655,14 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	    {
 	      struct type *return_type
-		= argvec[0]->result_type_of_xmethod (argvec[1]);
+		= (argvec[0]->result_type_of_xmethod
+		   (gdb::make_span (&argvec[1], 1)));
 
 	      if (return_type == NULL)
 		error (_("Xmethod is missing return type."));
 	      return value::zero (return_type, arg1->lval ());
 	    }
-	  return argvec[0]->call_xmethod (argvec[1]);
+	  return argvec[0]->call_xmethod (gdb::make_span (&argvec[1], 1));
 	}
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	{
diff --git a/gdb/valops.c b/gdb/valops.c
index 4109c8ff498..c8794f6e87d 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -191,7 +191,7 @@ value_allocate_space_in_inferior (int len)
   blocklen = value_from_longest (builtin_type (gdbarch)->builtin_int, len);
   val = call_function_by_hand (val,
 			       builtin_type (gdbarch)->builtin_data_ptr,
-			       blocklen);
+			       gdb::make_span (&blocklen, 1));
   if (value_logical_not (val))
     {
       if (!target_has_execution ())
diff --git a/gdb/value.c b/gdb/value.c
index 0e0da08cef0..536eef3e00c 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -4410,7 +4410,7 @@ test_insert_into_bit_range_vector ()
   {
     insert_into_bit_range_vector (&ranges, 11, 4);
     static const range expected = {10, 5};
-    SELF_CHECK (check_ranges_vector (ranges, expected));
+    SELF_CHECK (check_ranges_vector (ranges, gdb::make_span (&expected, 1)));
   }
 
   /* [10, 14] [20, 24] */
@@ -4468,7 +4468,7 @@ test_insert_into_bit_range_vector ()
   {
     insert_into_bit_range_vector (&ranges, 4, 30);
     static const range expected = {2, 32};
-    SELF_CHECK (check_ranges_vector (ranges, expected));
+    SELF_CHECK (check_ranges_vector (ranges, gdb::make_span (&expected, 1)));
   }
 }
 

-- 
2.56.0


  parent reply	other threads:[~2026-11-17 22:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 22:09 [PATCH v3 00/17] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-17 22:09 ` [PATCH v3 01/17] Rename array_view files Tom Tromey
2026-11-17 22:09 ` [PATCH v3 02/17] Rename gdb::array_view to gdb::span Tom Tromey
2026-11-17 22:09 ` [PATCH v3 03/17] Rename gdb::make_array_view to gdb::make_span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 04/17] Rename gdb_argv::as_array_view Tom Tromey
2026-11-17 22:10 ` [PATCH v3 05/17] Remove operator== and operator!= from gdb::span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 06/17] Rename span::slice to span::subspan Tom Tromey
2026-11-17 22:10 ` [PATCH v3 07/17] Qualify calls to gdb::copy Tom Tromey
2026-11-17 22:10 ` [PATCH v3 08/17] Add single-argument overloads of process_options et al Tom Tromey
2026-11-17 22:10 ` [PATCH v3 09/17] Remove span from cli-option.c:build_help_option Tom Tromey
2026-11-17 22:10 ` Tom Tromey [this message]
2026-11-17 22:10 ` [PATCH v3 11/17] Don't turn rvalue reference into a span Tom Tromey
2026-11-17 22:10 ` [PATCH v3 12/17] gdb/unittests: use one static_assert per check in span-selftests.c Tom Tromey
2026-11-17 22:10 ` [PATCH v3 13/17] Change span-selftests.c for C++20 Tom Tromey
2026-11-17 22:10 ` [PATCH v3 14/17] Make gdb::span conform more closely to C++20 Tom Tromey
2026-11-17 22:10 ` [PATCH v3 15/17] Allow the use of C++20 std::ranges in gdbsupport/ranges.h Tom Tromey
2026-11-17 22:10 ` [PATCH v3 16/17] Allow the use of C++20 std::span in gdbsupport/span.h Tom Tromey
2026-11-17 22:10 ` [PATCH v3 17/17] Move gdb::ranges::equal to gdbsupport/ranges.h Tom Tromey
2026-11-18 15:04 ` [PATCH v3 00/17] Rename gdb::array_view to gdb::span 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=20261117-span-part-1-v3-10-40b8b11d2d8c@adacore.com \
    --to=tromey@adacore.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