[07/11] gdb: Remove uses of gdb::to_string (const std::string_view &)

Message ID 20231013144418.3180617-8-lancelot.six@amd.com
State New
Headers
Series GDB: Require C++17 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Lancelot SIX Oct. 13, 2023, 2:44 p.m. UTC
  This patch removes all uses of to_string(const std::string_view&) and
use the std::string ctor or implicit conversion from std::string_view to
std::string instead.

A later patch will remove this gdb::to_string while removing
gdbsupport/gdb_string_view.h.

Change-Id: I877cde557a0727be7b0435107e3c7a2aac165895
---
 gdb/ada-lang.c           | 20 +++++++++-----------
 gdb/amdgpu-tdep.c        | 18 +++++++++---------
 gdb/debuginfod-support.c |  3 +--
 gdb/dwarf2/read.c        |  2 +-
 gdb/solib-rocm.c         |  8 ++++----
 5 files changed, 24 insertions(+), 27 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3e394619399..ff7222c7eed 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1040,7 +1040,7 @@  ada_fold_name (std::string_view name, bool throw_on_error = false)
   static std::string fold_storage;
 
   if (!name.empty () && name[0] == '\'')
-    fold_storage = gdb::to_string (name.substr (1, name.size () - 2));
+    fold_storage = name.substr (1, name.size () - 2);
   else
     {
       /* Why convert to UTF-32 and implement our own case-folding,
@@ -1081,12 +1081,12 @@  ada_fold_name (std::string_view name, bool throw_on_error = false)
 	      warned = true;
 	      warning (_("could not convert '%s' from the host encoding (%s) to UTF-32.\n"
 			 "This normally should not happen, please file a bug report."),
-		       gdb::to_string (name).c_str (), host_charset ());
+		       std::string (name).c_str (), host_charset ());
 	    }
 
 	  /* We don't try to recover from errors; just return the
 	     original string.  */
-	  fold_storage = gdb::to_string (name);
+	  fold_storage = name;
 	  return fold_storage.c_str ();
 	}
 
@@ -1135,12 +1135,12 @@  ada_fold_name (std::string_view name, bool throw_on_error = false)
 	      warned = true;
 	      warning (_("could not convert the lower-cased variant of '%s'\n"
 			 "from UTF-32 to the host encoding (%s)."),
-		       gdb::to_string (name).c_str (), host_charset ());
+		       std::string (name).c_str (), host_charset ());
 	    }
 
 	  /* We don't try to recover from errors; just return the
 	     original string.  */
-	  fold_storage = gdb::to_string (name);
+	  fold_storage = name;
 	}
     }
 
@@ -13255,11 +13255,9 @@  ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
   if (!user_name.empty () && user_name[0] == '<')
     {
       if (user_name.back () == '>')
-	m_encoded_name
-	  = gdb::to_string (user_name.substr (1, user_name.size () - 2));
+	m_encoded_name = user_name.substr (1, user_name.size () - 2);
       else
-	m_encoded_name
-	  = gdb::to_string (user_name.substr (1, user_name.size () - 1));
+	m_encoded_name = user_name.substr (1, user_name.size () - 1);
       m_encoded_p = true;
       m_verbatim_p = true;
       m_wild_match_p = false;
@@ -13276,10 +13274,10 @@  ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
 	  const char *folded = ada_fold_name (user_name);
 	  m_encoded_name = ada_encode_1 (folded, false);
 	  if (m_encoded_name.empty ())
-	    m_encoded_name = gdb::to_string (user_name);
+	    m_encoded_name = user_name;
 	}
       else
-	m_encoded_name = gdb::to_string (user_name);
+	m_encoded_name = user_name;
 
       /* Handle the 'package Standard' special case.  See description
 	 of m_standard_p.  */
diff --git a/gdb/amdgpu-tdep.c b/gdb/amdgpu-tdep.c
index 48dc8db6bcc..15f32885b07 100644
--- a/gdb/amdgpu-tdep.c
+++ b/gdb/amdgpu-tdep.c
@@ -401,7 +401,7 @@  parse_amd_dbgapi_register_type_enum_fields
       if (value > std::numeric_limits<uint32_t>::max ())
 	enum_type.set_bit_size (64);
 
-      enum_type.add_enumerator (gdb::to_string (name), value);
+      enum_type.add_enumerator (std::string (name), value);
 
       fields = fields.substr (matches[0].rm_eo);
     }
@@ -445,7 +445,7 @@  parse_amd_dbgapi_register_type_flags_fields
       ULONGEST pos_begin = try_strtoulst (pos_begin_str);
 
       if (field_type_str == "bool")
-	flags_type.add_field (gdb::to_string (field_name), pos_begin, pos_begin,
+	flags_type.add_field (std::string (field_name), pos_begin, pos_begin,
 			      nullptr);
       else
 	{
@@ -456,7 +456,7 @@  parse_amd_dbgapi_register_type_flags_fields
 	  ULONGEST pos_end = try_strtoulst (pos_end_str.substr (1));
 	  const amd_dbgapi_register_type &field_type
 	    = parse_amd_dbgapi_register_type (field_type_str, type_map);
-	  flags_type.add_field (gdb::to_string (field_name), pos_begin, pos_end,
+	  flags_type.add_field (std::string (field_name), pos_begin, pos_end,
 				&field_type);
 	}
 
@@ -470,7 +470,7 @@  static const amd_dbgapi_register_type &
 parse_amd_dbgapi_register_type_scalar (std::string_view name,
 				       amd_dbgapi_register_type_map &type_map)
 {
-  std::string name_str = gdb::to_string (name);
+  std::string name_str (name);
   auto it = type_map.find (name_str);
   if (it != type_map.end ())
     {
@@ -533,7 +533,7 @@  parse_amd_dbgapi_register_type (std::string_view type_str,
       std::string_view count_str_view
 	= type_str.substr (pos_open_bracket + 1,
 			    pos_close_bracket - pos_open_bracket);
-      std::string count_str = gdb::to_string (count_str_view);
+      std::string count_str (count_str_view);
       unsigned int count = std::stoul (count_str);
 
       std::string lookup_name
@@ -579,7 +579,7 @@  parse_amd_dbgapi_register_type (std::string_view type_str,
 	  /* No braces, lookup existing type.  */
 	  if (existing_type_it == type_map.end ())
 	    error (_("reference to unknown type %s."),
-		   gdb::to_string (name).c_str ());
+		   std::string (name).c_str ());
 
 	  if (existing_type_it->second->kind ()
 	      != amd_dbgapi_register_type::kind::FLAGS)
@@ -592,7 +592,7 @@  parse_amd_dbgapi_register_type (std::string_view type_str,
 	  /* With braces, it's a definition.  */
 	  if (existing_type_it != type_map.end ())
 	    error (_("re-definition of type %s."),
-		   gdb::to_string (name).c_str ());
+		   std::string (name).c_str ());
 
 	  amd_dbgapi_register_type_flags_up flags_type
 	    (new amd_dbgapi_register_type_flags (bit_size, name));
@@ -631,7 +631,7 @@  parse_amd_dbgapi_register_type (std::string_view type_str,
 	  /* No braces, lookup existing type.  */
 	  if (existing_type_it == type_map.end ())
 	    error (_("reference to unknown type %s"),
-		   gdb::to_string (name).c_str ());
+		   std::string (name).c_str ());
 
 	  if (existing_type_it->second->kind ()
 	      != amd_dbgapi_register_type::kind::ENUM)
@@ -644,7 +644,7 @@  parse_amd_dbgapi_register_type (std::string_view type_str,
 	  /* With braces, it's a definition.  */
 	  if (existing_type_it != type_map.end ())
 	    error (_("re-definition of type %s"),
-		   gdb::to_string (name).c_str ());
+		   std::string (name).c_str ());
 
 	  amd_dbgapi_register_type_enum_up enum_type
 	    (new amd_dbgapi_register_type_enum (name));
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 0e202ff5d96..eb88c406ad6 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -264,8 +264,7 @@  debuginfod_is_enabled ()
 	  gdb_printf
 	    (_("  <%ps>\n"),
 	     styled_string (file_name_style.style (),
-			    gdb::to_string (url_view.substr (0,
-							     off)).c_str ()));
+			    std::string (url_view.substr (0, off)).c_str ()));
 	  if (off == std::string_view::npos)
 	    break;
 	  url_view = url_view.substr (off);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1846f7160cc..0973fb6fe13 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16886,7 +16886,7 @@  cooked_index_functions::expand_symtabs_matching
     {
       std::vector<std::string_view> name_vec
 	= lookup_name_without_params.split_name (lang);
-      std::string last_name = gdb::to_string (name_vec.back ());
+      std::string last_name (name_vec.back ());
 
       for (const cooked_index_entry *entry : table->find (last_name,
 							  completing))
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index 27cefb9604b..c39b5b8bdeb 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -454,7 +454,7 @@  rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
   std::string_view uri (bfd_get_filename (abfd));
   std::string_view protocol_delim = "://";
   size_t protocol_end = uri.find (protocol_delim);
-  std::string protocol = gdb::to_string (uri.substr (0, protocol_end));
+  std::string protocol (uri.substr (0, protocol_end));
   protocol_end += protocol_delim.length ();
 
   std::transform (protocol.begin (), protocol.end (), protocol.begin (),
@@ -477,7 +477,7 @@  rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
 	&& std::isxdigit (path[i + 2]))
       {
 	std::string_view hex_digits = path.substr (i + 1, 2);
-	decoded_path += std::stoi (gdb::to_string (hex_digits), 0, 16);
+	decoded_path += std::stoi (std::string (hex_digits), 0, 16);
 	i += 2;
       }
     else
@@ -563,7 +563,7 @@  rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
 	  if (pid != inferior->pid)
 	    {
 	      warning (_("`%s': code object is from another inferior"),
-		       gdb::to_string (uri).c_str ());
+		       std::string (uri).c_str ());
 	      bfd_set_error (bfd_error_bad_value);
 	      return nullptr;
 	    }
@@ -580,7 +580,7 @@  rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
 	}
 
       warning (_("`%s': protocol not supported: %s"),
-	       gdb::to_string (uri).c_str (), protocol.c_str ());
+	       std::string (uri).c_str (), protocol.c_str ());
       bfd_set_error (bfd_error_bad_value);
       return nullptr;
     }