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
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
This commit is contained in:
Lancelot Six 2023-10-13 10:54:46 +00:00
parent 8082468ffe
commit 882b050516
6 changed files with 24 additions and 33 deletions

View file

@ -58,7 +58,6 @@
#include "gdbsupport/function-view.h"
#include "gdbsupport/byte-vector.h"
#include "gdbsupport/selftest.h"
#include "gdbsupport/gdb_string_view.h"
#include <algorithm>
#include "ada-exp.h"
#include "charset.h"
@ -1041,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,
@ -1082,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 ();
}
@ -1136,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;
}
}
@ -13256,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;
@ -13277,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. */

View file

@ -27,7 +27,6 @@
#include "frame-unwind.h"
#include "gdbarch.h"
#include "gdbsupport/selftest.h"
#include "gdbsupport/gdb_string_view.h"
#include "gdbtypes.h"
#include "inferior.h"
#include "objfiles.h"
@ -402,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);
}
@ -446,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
{
@ -457,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);
}
@ -471,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 ())
{
@ -534,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
@ -580,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)
@ -593,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));
@ -632,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)
@ -645,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));

View file

@ -20,7 +20,6 @@
#include "diagnostics.h"
#include <errno.h>
#include "gdbsupport/scoped_fd.h"
#include "gdbsupport/gdb_string_view.h"
#include "debuginfod-support.h"
#include <optional>
#include "cli/cli-cmds.h"
@ -265,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);

View file

@ -96,7 +96,6 @@
#include "split-name.h"
#include "gdbsupport/parallel-for.h"
#include "gdbsupport/thread-pool.h"
#include "gdbsupport/gdb_string_view.h"
/* When == 1, print basic high level tracing messages.
When > 1, be more verbose.
@ -16770,7 +16769,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))

View file

@ -37,7 +37,6 @@
#include "user-regs.h"
#include "valprint.h"
#include "gdbsupport/gdb_obstack.h"
#include "gdbsupport/gdb_string_view.h"
#include "objfiles.h"
#include "typeprint.h"
#include <ctype.h>

View file

@ -31,7 +31,6 @@
#include "solib-svr4.h"
#include "solist.h"
#include "symfile.h"
#include "gdbsupport/gdb_string_view.h"
#include <unordered_map>
@ -440,7 +439,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 (),
@ -463,7 +462,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
@ -549,7 +548,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;
}
@ -566,7 +565,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;
}