gdb: Remove uses of gdb::to_string (const std::string_view &)

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
This commit is contained in:
Lancelot Six
2023-10-13 10:54:46 +00:00
parent ce752f43cc
commit c59f8e81dc
5 changed files with 24 additions and 27 deletions

View File

@@ -1040,7 +1040,7 @@ ada_fold_name (std::string_view name, bool throw_on_error = false)
static std::string fold_storage; static std::string fold_storage;
if (!name.empty () && name[0] == '\'') 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 else
{ {
/* Why convert to UTF-32 and implement our own case-folding, /* 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; warned = true;
warning (_("could not convert '%s' from the host encoding (%s) to UTF-32.\n" warning (_("could not convert '%s' from the host encoding (%s) to UTF-32.\n"
"This normally should not happen, please file a bug report."), "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 /* We don't try to recover from errors; just return the
original string. */ original string. */
fold_storage = gdb::to_string (name); fold_storage = name;
return fold_storage.c_str (); return fold_storage.c_str ();
} }
@@ -1135,12 +1135,12 @@ ada_fold_name (std::string_view name, bool throw_on_error = false)
warned = true; warned = true;
warning (_("could not convert the lower-cased variant of '%s'\n" warning (_("could not convert the lower-cased variant of '%s'\n"
"from UTF-32 to the host encoding (%s)."), "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 /* We don't try to recover from errors; just return the
original string. */ 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.empty () && user_name[0] == '<')
{ {
if (user_name.back () == '>') if (user_name.back () == '>')
m_encoded_name m_encoded_name = user_name.substr (1, user_name.size () - 2);
= gdb::to_string (user_name.substr (1, user_name.size () - 2));
else else
m_encoded_name m_encoded_name = user_name.substr (1, user_name.size () - 1);
= gdb::to_string (user_name.substr (1, user_name.size () - 1));
m_encoded_p = true; m_encoded_p = true;
m_verbatim_p = true; m_verbatim_p = true;
m_wild_match_p = false; 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); const char *folded = ada_fold_name (user_name);
m_encoded_name = ada_encode_1 (folded, false); m_encoded_name = ada_encode_1 (folded, false);
if (m_encoded_name.empty ()) if (m_encoded_name.empty ())
m_encoded_name = gdb::to_string (user_name); m_encoded_name = user_name;
} }
else else
m_encoded_name = gdb::to_string (user_name); m_encoded_name = user_name;
/* Handle the 'package Standard' special case. See description /* Handle the 'package Standard' special case. See description
of m_standard_p. */ of m_standard_p. */

View File

@@ -401,7 +401,7 @@ parse_amd_dbgapi_register_type_enum_fields
if (value > std::numeric_limits<uint32_t>::max ()) if (value > std::numeric_limits<uint32_t>::max ())
enum_type.set_bit_size (64); 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); 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); ULONGEST pos_begin = try_strtoulst (pos_begin_str);
if (field_type_str == "bool") 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); nullptr);
else else
{ {
@@ -456,7 +456,7 @@ parse_amd_dbgapi_register_type_flags_fields
ULONGEST pos_end = try_strtoulst (pos_end_str.substr (1)); ULONGEST pos_end = try_strtoulst (pos_end_str.substr (1));
const amd_dbgapi_register_type &field_type const amd_dbgapi_register_type &field_type
= parse_amd_dbgapi_register_type (field_type_str, type_map); = 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); &field_type);
} }
@@ -470,7 +470,7 @@ static const amd_dbgapi_register_type &
parse_amd_dbgapi_register_type_scalar (std::string_view name, parse_amd_dbgapi_register_type_scalar (std::string_view name,
amd_dbgapi_register_type_map &type_map) 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); auto it = type_map.find (name_str);
if (it != type_map.end ()) 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 std::string_view count_str_view
= type_str.substr (pos_open_bracket + 1, = type_str.substr (pos_open_bracket + 1,
pos_close_bracket - pos_open_bracket); 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); unsigned int count = std::stoul (count_str);
std::string lookup_name std::string lookup_name
@@ -579,7 +579,7 @@ parse_amd_dbgapi_register_type (std::string_view type_str,
/* No braces, lookup existing type. */ /* No braces, lookup existing type. */
if (existing_type_it == type_map.end ()) if (existing_type_it == type_map.end ())
error (_("reference to unknown type %s."), error (_("reference to unknown type %s."),
gdb::to_string (name).c_str ()); std::string (name).c_str ());
if (existing_type_it->second->kind () if (existing_type_it->second->kind ()
!= amd_dbgapi_register_type::kind::FLAGS) != 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. */ /* With braces, it's a definition. */
if (existing_type_it != type_map.end ()) if (existing_type_it != type_map.end ())
error (_("re-definition of type %s."), 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 amd_dbgapi_register_type_flags_up flags_type
(new amd_dbgapi_register_type_flags (bit_size, name)); (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. */ /* No braces, lookup existing type. */
if (existing_type_it == type_map.end ()) if (existing_type_it == type_map.end ())
error (_("reference to unknown type %s"), error (_("reference to unknown type %s"),
gdb::to_string (name).c_str ()); std::string (name).c_str ());
if (existing_type_it->second->kind () if (existing_type_it->second->kind ()
!= amd_dbgapi_register_type::kind::ENUM) != 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. */ /* With braces, it's a definition. */
if (existing_type_it != type_map.end ()) if (existing_type_it != type_map.end ())
error (_("re-definition of type %s"), 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 amd_dbgapi_register_type_enum_up enum_type
(new amd_dbgapi_register_type_enum (name)); (new amd_dbgapi_register_type_enum (name));

View File

@@ -264,8 +264,7 @@ debuginfod_is_enabled ()
gdb_printf gdb_printf
(_(" <%ps>\n"), (_(" <%ps>\n"),
styled_string (file_name_style.style (), styled_string (file_name_style.style (),
gdb::to_string (url_view.substr (0, std::string (url_view.substr (0, off)).c_str ()));
off)).c_str ()));
if (off == std::string_view::npos) if (off == std::string_view::npos)
break; break;
url_view = url_view.substr (off); url_view = url_view.substr (off);

View File

@@ -16886,7 +16886,7 @@ cooked_index_functions::expand_symtabs_matching
{ {
std::vector<std::string_view> name_vec std::vector<std::string_view> name_vec
= lookup_name_without_params.split_name (lang); = 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, for (const cooked_index_entry *entry : table->find (last_name,
completing)) completing))

View File

@@ -454,7 +454,7 @@ rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
std::string_view uri (bfd_get_filename (abfd)); std::string_view uri (bfd_get_filename (abfd));
std::string_view protocol_delim = "://"; std::string_view protocol_delim = "://";
size_t protocol_end = uri.find (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 (); protocol_end += protocol_delim.length ();
std::transform (protocol.begin (), protocol.end (), protocol.begin (), 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::isxdigit (path[i + 2]))
{ {
std::string_view hex_digits = path.substr (i + 1, 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; i += 2;
} }
else else
@@ -563,7 +563,7 @@ rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
if (pid != inferior->pid) if (pid != inferior->pid)
{ {
warning (_("`%s': code object is from another inferior"), 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); bfd_set_error (bfd_error_bad_value);
return nullptr; return nullptr;
} }
@@ -580,7 +580,7 @@ rocm_bfd_iovec_open (bfd *abfd, inferior *inferior)
} }
warning (_("`%s': protocol not supported: %s"), 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); bfd_set_error (bfd_error_bad_value);
return nullptr; return nullptr;
} }