public inbox for gcc-regression@sourceware.org
help / color / mirror / Atom feed
* [TCWG CI] Regression caused by gdb: gdb: make string-like set show commands use std::string variable
@ 2021-10-04 14:32 ci_notify
0 siblings, 0 replies; 2+ messages in thread
From: ci_notify @ 2021-10-04 14:32 UTC (permalink / raw)
To: Simon Marchi; +Cc: gcc-regression
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 46178 bytes --]
[TCWG CI] Regression caused by gdb: gdb: make string-like set show commands use std::string variable:
commit e0700ba44c5695d07f4cc9841315adc91ca18bf5
Author: Simon Marchi <simon.marchi@efficios.com>
gdb: make string-like set show commands use std::string variable
Results regressed to
# reset_artifacts:
-10
# true:
0
# build_abe binutils:
1
# build_abe gcc:
2
# build_abe linux:
4
# build_abe glibc:
5
# First few build errors in logs:
# 00:01:30 ../../../../../../gdb/gdb/remote-sim.c:686:27: error: cannot convert âconst stringâ {aka âconst std::__cxx11::basic_string<char>â} to âconst char*â
# 00:01:30 ../../../../../../gdb/gdb/remote-sim.c:687:13: error: no match for âoperator+=â (operand types are âconst stringâ {aka âconst std::__cxx11::basic_string<char>â} and âsize_tâ {aka âlong unsigned intâ})
# 00:01:30 ../../../../../../gdb/gdb/remote-sim.c:687:23: error: invalid conversion from âsize_tâ {aka âlong unsigned intâ} to âconst char*â [-fpermissive]
# 00:01:30 ../../../../../../gdb/gdbsupport/offset-type.h:99:41: error: âis_offset_typeâ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
# 00:01:30 ../../../../../../gdb/gdbsupport/offset-type.h:99:41: error: no matching function for call to âis_offset_type(const std::__cxx11::basic_string<char>)â
# 00:01:30 make[1]: *** [Makefile:1654: remote-sim.o] Error 1
# 00:01:46 make: *** [Makefile:10770: all-gdb] Error 2
from
# reset_artifacts:
-10
# true:
0
# build_abe binutils:
1
# build_abe gcc:
2
# build_abe linux:
4
# build_abe glibc:
5
# build_abe gdb:
6
THIS IS THE END OF INTERESTING STUFF. BELOW ARE LINKS TO BUILDS, REPRODUCTION INSTRUCTIONS, AND THE RAW COMMIT.
This commit has regressed these CI configurations:
- tcwg_gnu_native_build/master-aarch64
First_bad build: https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/build-e0700ba44c5695d07f4cc9841315adc91ca18bf5/
Last_good build: https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/build-1d7fe7f01b93ecaeb3e481ed09d3deac7890a97f/
Baseline build: https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/build-baseline/
Even more details: https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/
Reproduce builds:
<cut>
mkdir investigate-gdb-e0700ba44c5695d07f4cc9841315adc91ca18bf5
cd investigate-gdb-e0700ba44c5695d07f4cc9841315adc91ca18bf5
# Fetch scripts
git clone https://git.linaro.org/toolchain/jenkins-scripts
# Fetch manifests and test.sh script
mkdir -p artifacts/manifests
curl -o artifacts/manifests/build-baseline.sh https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/manifests/build-baseline.sh --fail
curl -o artifacts/manifests/build-parameters.sh https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/manifests/build-parameters.sh --fail
curl -o artifacts/test.sh https://ci.linaro.org/job/tcwg_gnu_native_build-bisect-master-aarch64/4/artifact/artifacts/test.sh --fail
chmod +x artifacts/test.sh
# Reproduce the baseline build (build all pre-requisites)
./jenkins-scripts/tcwg_gnu-build.sh @@ artifacts/manifests/build-baseline.sh
# Save baseline build state (which is then restored in artifacts/test.sh)
mkdir -p ./bisect
rsync -a --del --delete-excluded --exclude /bisect/ --exclude /artifacts/ --exclude /gdb/ ./ ./bisect/baseline/
cd gdb
# Reproduce first_bad build
git checkout --detach e0700ba44c5695d07f4cc9841315adc91ca18bf5
../artifacts/test.sh
# Reproduce last_good build
git checkout --detach 1d7fe7f01b93ecaeb3e481ed09d3deac7890a97f
../artifacts/test.sh
cd ..
</cut>
Full commit (up to 1000 lines):
<cut>
commit e0700ba44c5695d07f4cc9841315adc91ca18bf5
Author: Simon Marchi <simon.marchi@efficios.com>
Date: Fri Sep 10 17:10:13 2021 -0400
gdb: make string-like set show commands use std::string variable
String-like settings (var_string, var_filename, var_optional_filename,
var_string_noescape) currently take a pointer to a `char *` storage
variable (typically global) that holds the setting's value. I'd like to
"mordernize" this by changing them to use an std::string for storage.
An obvious reason is that string operations on std::string are often
easier to write than with C strings. And they avoid having to do any
manual memory management.
Another interesting reason is that, with `char *`, nullptr and an empty
string often both have the same meaning of "no value". String settings
are initially nullptr (unless initialized otherwise). But when doing
"set foo" (where `foo` is a string setting), the setting now points to
an empty string. For example, solib_search_path is nullptr at startup,
but points to an empty string after doing "set solib-search-path". This
leads to some code that needs to check for both to check for "no value".
Or some code that converts back and forth between NULL and "" when
getting or setting the value. I find this very error-prone, because it
is very easy to forget one or the other. With std::string, we at least
know that the variable is not "NULL". There is only one way of
representing an empty string setting, that is with an empty string.
I was wondering whether the distinction between NULL and "" would be
important for some setting, but it doesn't seem so. If that ever
happens, it would be more C++-y and self-descriptive to use
optional<string> anyway.
Actually, there's one spot where this distinction mattered, it's in
init_history, for the test gdb.base/gdbinit-history.exp. init_history
sets the history filename to the default ".gdb_history" if it sees that
the setting was never set - if history_filename is nullptr. If
history_filename is an empty string, it means the setting was explicitly
cleared, so it leaves it as-is. With the change to std::string, this
distinction doesn't exist anymore. This can be fixed by moving the code
that chooses a good default value for history_filename to
_initialize_top. This is ran before -ex commands are processed, so an
-ex command can then clear that value if needed (what
gdb.base/gdbinit-history.exp tests).
Another small improvement, in my opinion is that we can now easily
give string parameters initial values, by simply initializing the global
variables, instead of xstrdup-ing it in the _initialize function.
In Python and Guile, when registering a string-like parameter, we
allocate (with new) an std::string that is owned by the param_smob (in
Guile) and the parmpy_object (in Python) objects.
This patch started by changing all relevant add_setshow_* commands to
take an `std::string *` instead of a `char **` and fixing everything
that failed to build. That includes of course all string setting
variable and their uses.
string_option_def now uses an std::string also, because there's a
connection between options and settings (see
add_setshow_cmds_for_options).
The add_path function in source.c is really complex and twisted, I'd
rather not try to change it to work on an std::string right now.
Instead, I added an overload that copies the std:string to a `char *`
and back. This means more copying, but this is not used in a hot path
at all, so I think it is acceptable.
Change-Id: I92c50a1bdd8307141cdbacb388248e4e4fc08c93
Co-authored-by: Lancelot SIX <lsix@lancelotsix.com>
---
gdb/auto-load.c | 48 +++++++-------------
gdb/breakpoint.c | 22 +++++----
gdb/build-id.c | 4 +-
gdb/cli/cli-cmds.c | 49 ++++++++++++--------
gdb/cli/cli-decode.c | 38 ++++++++--------
gdb/cli/cli-logging.c | 23 +++++-----
gdb/cli/cli-option.c | 9 ++--
gdb/cli/cli-option.h | 4 +-
gdb/cli/cli-setshow.c | 59 +++++++++---------------
gdb/command.h | 23 +++++-----
gdb/compile/compile.c | 46 +++++++++----------
gdb/corefile.c | 17 ++++---
gdb/defs.h | 4 +-
gdb/disasm.c | 11 +++--
gdb/disasm.h | 2 +-
gdb/dwarf2/dwz.c | 2 +-
gdb/dwarf2/index-cache.c | 10 ++---
gdb/dwarf2/read.c | 10 ++---
gdb/event-top.c | 12 +++--
gdb/fork-child.c | 7 ++-
gdb/guile/scm-param.c | 62 ++++++++++++++-----------
gdb/infcmd.c | 14 +++---
gdb/linux-thread-db.c | 17 +++----
gdb/main.c | 17 +++----
gdb/maint-test-options.c | 11 +----
gdb/maint-test-settings.c | 8 ++--
gdb/mi/mi-cmd-env.c | 18 ++++----
gdb/proc-api.c | 5 +--
gdb/python/py-param.c | 45 ++++++++++---------
gdb/python/python.c | 10 ++---
gdb/remote-sim.c | 7 ++-
gdb/remote.c | 10 ++---
gdb/serial.c | 8 ++--
gdb/solib.c | 20 ++++-----
gdb/source.c | 66 +++++++++++++++------------
gdb/source.h | 5 ++-
gdb/stack.c | 22 ++++-----
gdb/symfile.c | 49 ++++++++++----------
gdb/symtab.c | 46 +++++++++----------
gdb/target-descriptions.c | 2 +-
gdb/top.c | 112 ++++++++++++++++++++++------------------------
gdb/top.h | 2 +-
gdb/tracepoint.c | 29 ++++++------
gdb/tracepoint.h | 2 +-
44 files changed, 477 insertions(+), 510 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 7f0bb74c32a..36d87252b3f 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -137,7 +137,7 @@ show_auto_load_local_gdbinit (struct ui_file *file, int from_tty,
/* Directory list from which to load auto-loaded scripts. It is not checked
for absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_dir;
+static std::string auto_load_dir = AUTO_LOAD_DIR;
/* "set" command for the auto_load_dir configuration variable. */
@@ -145,11 +145,8 @@ static void
set_auto_load_dir (const char *args, int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_dir[0] == '\0')
- {
- xfree (auto_load_dir);
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
- }
+ if (auto_load_dir.empty ())
+ auto_load_dir = AUTO_LOAD_DIR;
}
/* "show" command for the auto_load_dir configuration variable. */
@@ -166,7 +163,7 @@ show_auto_load_dir (struct ui_file *file, int from_tty,
/* Directory list safe to hold auto-loaded files. It is not checked for
absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_safe_path;
+static std::string auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
/* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
by tilde_expand and possibly each entries has added its gdb_realpath
@@ -181,7 +178,7 @@ auto_load_expand_dir_vars (const char *string)
{
char *s = xstrdup (string);
substitute_path_component (&s, "$datadir", gdb_datadir.c_str ());
- substitute_path_component (&s, "$debugdir", debug_file_directory);
+ substitute_path_component (&s, "$debugdir", debug_file_directory.c_str ());
if (debug_auto_load && strcmp (s, string) != 0)
auto_load_debug_printf ("Expanded $-variables to \"%s\".", s);
@@ -199,9 +196,10 @@ static void
auto_load_safe_path_vec_update (void)
{
auto_load_debug_printf ("Updating directories of \"%s\".",
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
- auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
+ auto_load_safe_path_vec
+ = auto_load_expand_dir_vars (auto_load_safe_path.c_str ());
size_t len = auto_load_safe_path_vec.size ();
/* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
@@ -253,11 +251,8 @@ set_auto_load_safe_path (const char *args,
int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_safe_path[0] == '\0')
- {
- xfree (auto_load_safe_path);
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
- }
+ if (auto_load_safe_path.empty ())
+ auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
auto_load_safe_path_vec_update ();
}
@@ -291,17 +286,14 @@ show_auto_load_safe_path (struct ui_file *file, int from_tty,
static void
add_auto_load_safe_path (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("\
Directory argument required.\n\
Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
"));
- s = xstrprintf ("%s%c%s", auto_load_safe_path, DIRNAME_SEPARATOR, args);
- xfree (auto_load_safe_path);
- auto_load_safe_path = s;
+ auto_load_safe_path = string_printf ("%s%c%s", auto_load_safe_path.c_str (),
+ DIRNAME_SEPARATOR, args);
auto_load_safe_path_vec_update ();
}
@@ -312,14 +304,11 @@ Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
static void
add_auto_load_dir (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("Directory argument required."));
- s = xstrprintf ("%s%c%s", auto_load_dir, DIRNAME_SEPARATOR, args);
- xfree (auto_load_dir);
- auto_load_dir = s;
+ auto_load_dir = string_printf ("%s%c%s", auto_load_dir.c_str (),
+ DIRNAME_SEPARATOR, args);
}
/* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
@@ -459,7 +448,7 @@ file_is_auto_load_safe (const char *filename)
warning (_("File \"%ps\" auto-loading has been declined by your "
"`auto-load safe-path' set to \"%s\"."),
styled_string (file_name_style.style (), filename_real.get ()),
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
if (!advice_printed)
{
@@ -749,11 +738,11 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
directory. */
std::vector<gdb::unique_xmalloc_ptr<char>> vec
- = auto_load_expand_dir_vars (auto_load_dir);
+ = auto_load_expand_dir_vars (auto_load_dir.c_str ());
auto_load_debug_printf
("Searching 'set auto-load scripts-directory' path \"%s\".",
- auto_load_dir);
+ auto_load_dir.c_str ());
/* Convert Windows file name from c:/dir/file to /c/dir/file. */
if (HAS_DRIVE_SPEC (debugfile))
@@ -1542,8 +1531,6 @@ This option has security implications for untrusted inferiors."),
Usage: info auto-load local-gdbinit"),
auto_load_info_cmdlist_get ());
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
-
suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB));
gdb_name_help
= xstrprintf (_("\
@@ -1595,7 +1582,6 @@ Show the list of directories from which to load auto-loaded scripts."),
xfree (gdb_name_help);
xfree (guile_name_help);
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
auto_load_safe_path_vec_update ();
add_setshow_optional_filename_cmd ("safe-path", class_support,
&auto_load_safe_path, _("\
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 3b626b8f4aa..e742a1eccfe 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -276,7 +276,7 @@ static const char *dprintf_style = dprintf_style_gdb;
copied into the command, so it can be anything that GDB can
evaluate to a callable address, not necessarily a function name. */
-static char *dprintf_function;
+static std::string dprintf_function = "printf";
/* The channel to use for dynamic printf if the preferred style is to
call into the inferior; if a nonempty string, it will be passed to
@@ -286,7 +286,7 @@ static char *dprintf_function;
"stderr", this could be an app-specific expression like
"mystreams[curlogger]". */
-static char *dprintf_channel;
+static std::string dprintf_channel;
/* True if dprintf commands should continue to operate even if GDB
has disconnected. */
@@ -6658,7 +6658,7 @@ default_collect_info (void)
/* If it has no value (which is frequently the case), say nothing; a
message like "No default-collect." gets in user's face when it's
not wanted. */
- if (!*default_collect)
+ if (default_collect.empty ())
return;
/* The following phrase lines up nicely with per-tracepoint collect
@@ -8759,17 +8759,17 @@ update_dprintf_command_list (struct breakpoint *b)
printf_line = xstrprintf ("printf %s", dprintf_args);
else if (strcmp (dprintf_style, dprintf_style_call) == 0)
{
- if (!dprintf_function)
+ if (dprintf_function.empty ())
error (_("No function supplied for dprintf call"));
- if (dprintf_channel && strlen (dprintf_channel) > 0)
+ if (!dprintf_channel.empty ())
printf_line = xstrprintf ("call (void) %s (%s,%s)",
- dprintf_function,
- dprintf_channel,
+ dprintf_function.c_str (),
+ dprintf_channel.c_str (),
dprintf_args);
else
printf_line = xstrprintf ("call (void) %s (%s)",
- dprintf_function,
+ dprintf_function.c_str (),
dprintf_args);
}
else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
@@ -15102,8 +15102,8 @@ save_breakpoints (const char *filename, int from_tty,
}
}
- if (extra_trace_bits && *default_collect)
- fp.printf ("set default-collect %s\n", default_collect);
+ if (extra_trace_bits && !default_collect.empty ())
+ fp.printf ("set default-collect %s\n", default_collect.c_str ());
if (from_tty)
printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ());
@@ -16014,7 +16014,6 @@ output stream by setting dprintf-function and dprintf-channel."),
update_dprintf_commands, NULL,
&setlist, &showlist);
- dprintf_function = xstrdup ("printf");
add_setshow_string_cmd ("dprintf-function", class_support,
&dprintf_function, _("\
Set the function to use for dynamic printf."), _("\
@@ -16022,7 +16021,6 @@ Show the function to use for dynamic printf."), NULL,
update_dprintf_commands, NULL,
&setlist, &showlist);
- dprintf_channel = xstrdup ("");
add_setshow_string_cmd ("dprintf-channel", class_support,
&dprintf_channel, _("\
Set the channel to use for dynamic printf."), _("\
diff --git a/gdb/build-id.c b/gdb/build-id.c
index d2f2576d96d..553d6cec3d2 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -130,7 +130,7 @@ build_id_to_bfd_suffix (size_t build_id_len, const bfd_byte *build_id,
cause "/.build-id/..." lookups. */
std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
- = dirnames_to_char_ptr_vec (debug_file_directory);
+ = dirnames_to_char_ptr_vec (debug_file_directory.c_str ());
for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
{
@@ -167,7 +167,7 @@ build_id_to_bfd_suffix (size_t build_id_len, const bfd_byte *build_id,
Don't do it if the sysroot is the target system ("target:"). It
could work in theory, but the lrealpath in build_id_to_debug_bfd_1
only works with local paths. */
- if (strcmp (gdb_sysroot, TARGET_SYSROOT_PREFIX) != 0)
+ if (gdb_sysroot != TARGET_SYSROOT_PREFIX)
{
link = gdb_sysroot + link;
debug_bfd = build_id_to_debug_bfd_1 (link, build_id_len, build_id);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index ecbe5a4b43c..f8f013348db 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -650,7 +650,7 @@ find_and_open_script (const char *script_file, int search_path)
/* Search for and open 'file' on the search path used for source
files. Put the full location in *FULL_PATHP. */
gdb::unique_xmalloc_ptr<char> full_path;
- fd = openp (source_path, search_flags,
+ fd = openp (source_path.c_str (), search_flags,
file.get (), O_RDONLY, &full_path);
if (fd == -1)
@@ -1042,12 +1042,7 @@ edit_command (const char *arg, int from_tty)
struct pipe_cmd_opts
{
/* For "-d". */
- char *delimiter = nullptr;
-
- ~pipe_cmd_opts ()
- {
- xfree (delimiter);
- }
+ std::string delimiter;
};
static const gdb::option::option_def pipe_cmd_option_defs[] = {
@@ -1084,8 +1079,8 @@ pipe_command (const char *arg, int from_tty)
(&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
const char *delim = "|";
- if (opts.delimiter != nullptr)
- delim = opts.delimiter;
+ if (!opts.delimiter.empty ())
+ delim = opts.delimiter.c_str ();
const char *command = arg;
if (command == nullptr)
@@ -1148,8 +1143,8 @@ pipe_command_completer (struct cmd_list_element *ignore,
return;
const char *delimiter = "|";
- if (opts.delimiter != nullptr)
- delimiter = opts.delimiter;
+ if (!opts.delimiter.empty ())
+ delimiter = opts.delimiter.c_str ();
/* Check if we're past option values already. */
if (text > org_text && !isspace (text[-1]))
@@ -2152,13 +2147,21 @@ value_from_setting (const setting &var, struct gdbarch *gdbarch)
case var_enum:
{
const char *value;
+ size_t len;
if (var.type () == var_enum)
- value = var.get<const char *> ();
+ {
+ value = var.get<const char *> ();
+ len = strlen (value);
+ }
else
- value = var.get<char *> ();
+ {
+ const std::string &st = var.get<std::string> ();
+ value = st.c_str ();
+ len = st.length ();
+ }
- if (value != nullptr)
- return value_cstring (value, strlen (value),
+ if (len > 0)
+ return value_cstring (value, len,
builtin_type (gdbarch)->builtin_char);
else
return value_cstring ("", 1,
@@ -2231,13 +2234,21 @@ str_value_from_setting (const setting &var, struct gdbarch *gdbarch)
similarly to the value_from_setting code for these casevar. */
{
const char *value;
+ size_t len;
if (var.type () == var_enum)
- value = var.get<const char *> ();
+ {
+ value = var.get<const char *> ();
+ len = strlen (value);
+ }
else
- value = var.get<char *> ();
+ {
+ const std::string &st = var.get<std::string> ();
+ value = st.c_str ();
+ len = st.length ();
+ }
- if (value != nullptr)
- return value_cstring (value, strlen (value),
+ if (len > 0)
+ return value_cstring (value, len,
builtin_type (gdbarch)->builtin_char);
else
return value_cstring ("", 1,
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 56befc979dc..b3bf6276157 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -655,7 +655,7 @@ add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *va
set_show_commands
add_setshow_filename_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -664,10 +664,10 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_filename, var,
- set_doc, show_doc, help_doc,
- set_func, show_func,
- set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_filename, var,
+ set_doc, show_doc, help_doc,
+ set_func, show_func,
+ set_list, show_list);
set_cmd_completer (commands.set, filename_completer);
@@ -679,7 +679,7 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_string_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -688,10 +688,10 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_string, var,
- set_doc, show_doc, help_doc,
- set_func, show_func,
- set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_string, var,
+ set_doc, show_doc, help_doc,
+ set_func, show_func,
+ set_list, show_list);
/* Disable the default symbol completer. */
set_cmd_completer (commands.set, nullptr);
@@ -704,7 +704,7 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -713,9 +713,10 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_string_noescape, var,
- set_doc, show_doc, help_doc, set_func,
- show_func, set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_string_noescape,
+ var, set_doc, show_doc, help_doc,
+ set_func, show_func, set_list,
+ show_list);
/* Disable the default symbol completer. */
set_cmd_completer (commands.set, nullptr);
@@ -728,7 +729,7 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_optional_filename_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -737,9 +738,10 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_optional_filename,
- var, set_doc, show_doc, help_doc,
- set_func, show_func, set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_optional_filename,
+ var, set_doc, show_doc, help_doc,
+ set_func, show_func, set_list,
+ show_list);
set_cmd_completer (commands.set, filename_completer);
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index dfedd7599a2..c9093520a71 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -25,7 +25,7 @@
static char *saved_filename;
-static char *logging_filename;
+static std::string logging_filename = "gdb.txt";
static void
show_logging_filename (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
@@ -102,7 +102,7 @@ handle_redirections (int from_tty)
}
stdio_file_up log (new no_terminal_escape_file ());
- if (!log->open (logging_filename, logging_overwrite ? "w" : "a"))
+ if (!log->open (logging_filename.c_str (), logging_overwrite ? "w" : "a"))
perror_with_name (_("set logging"));
/* Redirects everything to gdb_stdout while this is running. */
@@ -110,20 +110,20 @@ handle_redirections (int from_tty)
{
if (!logging_redirect)
fprintf_unfiltered (gdb_stdout, "Copying output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
else
fprintf_unfiltered (gdb_stdout, "Redirecting output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
if (!debug_redirect)
fprintf_unfiltered (gdb_stdout, "Copying debug output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
else
fprintf_unfiltered (gdb_stdout, "Redirecting debug output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
}
- saved_filename = xstrdup (logging_filename);
+ saved_filename = xstrdup (logging_filename.c_str ());
/* Let the interpreter do anything it needs. */
current_interp_set_logging (std::move (log), logging_redirect,
@@ -145,10 +145,8 @@ set_logging_on (const char *args, int from_tty)
const char *rest = args;
if (rest && *rest)
- {
- xfree (logging_filename);
- logging_filename = xstrdup (rest);
- }
+ logging_filename = rest;
+
handle_redirections (from_tty);
}
@@ -201,6 +199,7 @@ If debug redirect is on, debug will go only to the log file."),
set_logging_redirect,
show_logging_redirect,
&set_logging_cmdlist, &show_logging_cmdlist);
+
add_setshow_filename_cmd ("file", class_support, &logging_filename, _("\
Set the current logfile."), _("\
Show the current logfile."), _("\
@@ -212,6 +211,4 @@ The logfile is used when directing GDB's output."),
_("Enable logging."), &set_logging_cmdlist);
add_cmd ("off", class_support, set_logging_off,
_("Disable logging."), &set_logging_cmdlist);
-
- logging_filename = xstrdup ("gdb.txt");
}
diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c
index ab76f194c3d..846b8198985 100644
--- a/gdb/cli/cli-option.c
+++ b/gdb/cli/cli-option.c
@@ -45,7 +45,7 @@ union option_value
const char *enumeration;
/* For var_string options. This is malloc-allocated. */
- char *string;
+ std::string *string;
};
/* Holds an options definition and its value. */
@@ -87,7 +87,7 @@ struct option_def_and_value
if (value.has_value ())
{
if (option.type == var_string)
- xfree (value->string);
+ delete value->string;
}
}
@@ -439,7 +439,7 @@ parse_option (gdb::array_view<const option_def_group> options_group,
error (_("-%s requires an argument"), match->name);
option_value val;
- val.string = xstrdup (str.c_str ());
+ val.string = new std::string (std::move (str));
return option_def_and_value {*match, match_ctx, val};
}
@@ -603,8 +603,7 @@ save_option_value_in_ctx (gdb::optional<option_def_and_value> &ov)
break;
case var_string:
*ov->option.var_address.string (ov->option, ov->ctx)
- = ov->value->string;
- ov->value->string = nullptr;
+ = std::move (*ov->value->string);
break;
default:
gdb_assert_not_reached ("unhandled option type");
diff --git a/gdb/cli/cli-option.h b/gdb/cli/cli-option.h
index aa2ccbed5d0..b7ede458748 100644
--- a/gdb/cli/cli-option.h
+++ b/gdb/cli/cli-option.h
@@ -86,7 +86,7 @@ struct option_def
unsigned int *(*uinteger) (const option_def &, void *ctx);
int *(*integer) (const option_def &, void *ctx);
const char **(*enumeration) (const option_def &, void *ctx);
- char **(*string) (const option_def &, void *ctx);
+ std::string *(*string) (const option_def &, void *ctx);
}
var_address;
@@ -268,7 +268,7 @@ template<typename Context>
struct string_option_def : option_def
{
string_option_def (const char *long_option_,
- char **(*get_var_address_cb_) (Context *),
+ std::string *(*get_var_address_cb_) (Context *),
show_value_ftype *show_cmd_cb_,
const char *set_doc_,
const char *show_doc_ = nullptr,
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 86ab553f48c..8d29c0c3fc2 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -360,27 +360,22 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
*q++ = '\0';
newobj = (char *) xrealloc (newobj, q - newobj);
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, newobj) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str(), newobj) != 0)
{
- xfree (var);
- c->var->set<char *> (newobj);
+ c->var->set<std::string> (std::string (newobj));
option_changed = true;
}
- else
- xfree (newobj);
+ xfree (newobj);
}
break;
case var_string_noescape:
{
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, arg) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str (), arg) != 0)
{
- xfree (var);
- c->var->set<char *> (xstrdup (arg));
+ c->var->set<std::string> (std::string (arg));
option_changed = true;
}
@@ -410,17 +405,14 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
else
val = xstrdup ("");
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, val) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str (), val) != 0)
{
- xfree (var);
- c->var->set<char *> (val);
+ c->var->set<std::string> (std::string (val));
option_changed = true;
}
- else
- xfree (val);
+ xfree (val);
}
break;
case var_boolean:
@@ -598,15 +590,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
case var_string_noescape:
case var_filename:
case var_optional_filename:
+ gdb::observers::command_param_changed.notify
+ (name, c->var->get<std::string> ().c_str ());
+ break;
case var_enum:
- {
- const char *var;
- if (c->var->type () == var_enum)
- var = c->var->get<const char *> ();
- else
- var = c->var->get<char *> ();
- gdb::observers::command_param_changed.notify (name, var);
- }
+ gdb::observers::command_param_changed.notify
+ (name, c->var->get<const char *> ());
break;
case var_boolean:
{
@@ -658,23 +647,19 @@ get_setshow_command_value_string (const setting &var)
{
case var_string:
{
- char *value = var.get<char *> ();
-
- if (value != nullptr)
- stb.putstr (value, '"');
+ std::string value = var.get<std::string> ();
+ if (!value.empty ())
+ stb.putstr (value.c_str (), '"');
}
break;
case var_string_noescape:
case var_optional_filename:
case var_filename:
+ stb.puts (var.get<std::string> ().c_str ());
+ break;
case var_enum:
{
- const char *value;
- if (var.type () == var_enum)
- value = var.get<const char *> ();
- else
- value = var.get<char *> ();
-
+ const char *value = var.get<const char *> ();
if (value != nullptr)
stb.puts (value);
}
diff --git a/gdb/command.h b/gdb/command.h
index e7b81100f26..e6e6ec8a5d8 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -97,16 +97,15 @@ typedef enum var_types
/* String which the user enters with escapes (e.g. the user types
\n and it is a real newline in the stored string).
- *VAR is a malloc'd string, or NULL if the string is empty. */
+ *VAR is a std::string, "" if the string is empty. */
var_string,
/* String which stores what the user types verbatim.
- *VAR is a malloc'd string, or NULL if the string is empty. */
+ *VAR is std::string, "" if the string is empty. */
var_string_noescape,
- /* String which stores a filename. (*VAR) is a malloc'd string,
- or "" if the string was empty. */
+ /* String which stores a filename. (*VAR) is a std::string,
+ "" if the string was empty. */
var_optional_filename,
- /* String which stores a filename. (*VAR) is a malloc'd
- string. */
+ /* String which stores a filename. (*VAR) is a std::string. */
var_filename,
/* ZeroableInteger. *VAR is an int. Like var_integer except
that zero really means zero. */
@@ -166,9 +165,9 @@ inline bool var_type_uses<int> (var_types t)
|| t == var_zuinteger_unlimited);
}
-/* Return true if a setting of type T is backed by a char * variable. */
+/* Return true if a setting of type T is backed by a std::string variable. */
template<>
-inline bool var_type_uses<char *> (var_types t)
+inline bool var_type_uses<std::string> (var_types t)
{
return (t == var_string || t == var_string_noescape
|| t == var_optional_filename || t == var_filename);
@@ -562,25 +561,25 @@ extern set_show_commands add_setshow_boolean_cmd
cmd_list_element **show_list);
extern set_show_commands add_setshow_filename_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_string_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_string_noescape_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_optional_filename_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index e815348ff07..25cfd283b33 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -495,7 +495,22 @@ get_expr_block_and_pc (CORE_ADDR *pc)
}
/* String for 'set compile-args' and 'show compile-args'. */
-static char *compile_args;
+static std::string compile_args =
+ /* Override flags possibly coming from DW_AT_producer. */
+ "-O0 -gdwarf-4"
+ /* We use -fPIE Otherwise GDB would need to reserve space large enough for
+ any object file in the inferior in advance to get the final address when
+ to link the object file to and additionally the default system linker
+ script would need to be modified so that one can specify there the
+ absolute target address.
+ -fPIC is not used at is would require from GDB to generate .got. */
+ " -fPIE"
+ /* We want warnings, except for some commonly happening for GDB commands. */
+ " -Wall "
+ " -Wno-unused-but-set-variable"
+ " -Wno-unused-variable"
+ /* Override CU's possible -fstack-protector-strong. */
+ " -fno-stack-protector";
/* Parsed form of COMPILE_ARGS. */
static gdb_argv compile_args_argv;
@@ -505,7 +520,7 @@ static gdb_argv compile_args_argv;
static void
set_compile_args (const char *args, int from_tty, struct cmd_list_element *c)
{
- compile_args_argv = gdb_argv (compile_args);
+ compile_args_argv = gdb_argv (compile_args.c_str ());
}
/* Implement 'show compile-args'. */
@@ -520,7 +535,7 @@ show_compile_args (struct ui_file *file, int from_tty,
}
/* String for 'set compile-gcc' and 'show compile-gcc'. */
-static char *compile_gcc;
+static std::string compile_gcc;
/* Implement 'show compile-gcc'. */
@@ -696,13 +711,13 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
compiler->set_verbose (compile_debug);
- if (compile_gcc[0] != 0)
+ if (!compile_gcc.empty ())
{
if (compiler->version () < GCC_FE_VERSION_1)
error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
"(libcc1 interface version 1 or higher)"));
- compiler->set_driver_filename (compile_gcc);
+ compiler->set_driver_filename (compile_gcc.c_str ());
}
else
{
@@ -1029,23 +1044,9 @@ String quoting is parsed like in shell, for example:\n\
-mno-align-double \"-I/dir with a space/include\""),
set_compile_args, show_compile_args, &setlist, &showlist);
- /* Override flags possibly coming from DW_AT_producer. */
- compile_args = xstrdup ("-O0 -gdwarf-4"
- /* We use -fPIE Otherwise GDB would need to reserve space large enough for
- any object file in the inferior in advance to get the final address when
- to link the object file to and additionally the default system linker
- script would need to be modified so that one can specify there the
- absolute target address.
- -fPIC is not used at is would require from GDB to generate .got. */
- " -fPIE"
- /* We want warnings, except for some commonly happening for GDB commands. */
- " -Wall "
- " -Wno-unused-but-set-variable"
- " -Wno-unused-variable"
- /* Override CU's possible -fstack-protector-strong. */
- " -fno-stack-protector"
- );
- set_compile_args (compile_args, 0, NULL);
+
+ /* Initialize compile_args_argv. */
+ set_compile_args (compile_args.c_str (), 0, NULL);
add_setshow_optional_filename_cmd ("compile-gcc", class_support,
&compile_gcc,
@@ -1058,5 +1059,4 @@ It should be absolute filename of the gcc executable.\n\
If empty the default target triplet will be searched in $PATH."),
NULL, show_compile_gcc, &setlist,
&showlist);
- compile_gcc = xstrdup ("");
}
diff --git a/gdb/corefile.c b/gdb/corefile.c
index ff2494738b0..4b1451487e2 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -395,7 +395,7 @@ write_memory_signed_integer (CORE_ADDR addr, int len,
const char *gnutarget;
/* Same thing, except it is "auto" not NULL for the default case. */
-static char *gnutarget_string;
+static std::string gnutarget_string;
static void
show_gnutarget_string (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
@@ -409,15 +409,15 @@ static void
set_gnutarget_command (const char *ignore, int from_tty,
struct cmd_list_element *c)
{
- char *gend = gnutarget_string + strlen (gnutarget_string);
</cut>
>From hjl@sc.intel.com Mon Oct 4 17:39:07 2021
Return-Path: <hjl@sc.intel.com>
X-Original-To: gcc-regression@gcc.gnu.org
Delivered-To: gcc-regression@gcc.gnu.org
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
by sourceware.org (Postfix) with ESMTPS id 9E04F3858D28
for <gcc-regression@gcc.gnu.org>; Mon, 4 Oct 2021 17:39:06 +0000 (GMT)
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E04F3858D28
X-IronPort-AV: E=McAfee;i="6200,9189,10127"; a="212660566"
X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="212660566"
Received: from fmsmga005.fm.intel.com ([10.253.24.32])
by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
04 Oct 2021 10:39:05 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="713552764"
Received: from scymds01.sc.intel.com ([10.148.94.138])
by fmsmga005.fm.intel.com with ESMTP; 04 Oct 2021 10:39:04 -0700
Received: from gnu-clx-1.sc.intel.com (gnu-clx-1.sc.intel.com [172.25.70.216])
by scymds01.sc.intel.com with ESMTP id 194Hd4fq004523;
Mon, 4 Oct 2021 10:39:04 -0700
Received: by gnu-clx-1.sc.intel.com (Postfix, from userid 1000)
id AFF183E001F; Mon, 4 Oct 2021 10:39:04 -0700 (PDT)
Date: Mon, 04 Oct 2021 10:39:04 -0700
To: skpgkp2@gmail.com, hjl.tools@gmail.com, gcc-regression@gcc.gnu.org
Subject: Regressions on native/master at commit r12-4144 vs commit
r12-4139 on Linux/x86_64
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20211004173904.AFF183E001F@gnu-clx-1.sc.intel.com>
From: "H. J. Lu" <hjl@sc.intel.com>
X-Spam-Status: No, score=-3471.6 required=5.0 testsºYES_00, KAM_DMARC_STATUS,
KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,
SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
server2.sourceware.org
X-BeenThere: gcc-regression@gcc.gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Gcc-regression mailing list <gcc-regression.gcc.gnu.org>
List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-regression>,
<mailto:gcc-regression-request@gcc.gnu.org?subject=unsubscribe>
List-Archive: <https://gcc.gnu.org/pipermail/gcc-regression/>
List-Post: <mailto:gcc-regression@gcc.gnu.org>
List-Help: <mailto:gcc-regression-request@gcc.gnu.org?subject=help>
List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-regression>,
<mailto:gcc-regression-request@gcc.gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Oct 2021 17:39:07 -0000
New failures:
FAIL: gfortran.dg/predict-2.f90 -O scan-tree-dump-times profile_estimate "Fortran loop preheader heuristics of edge" 2
FAIL: gfortran.dg/predict-2.f90 -O scan-tree-dump-times profile_estimate "Fortran loop preheader heuristics of edge" 2
FAIL: gfortran.dg/predict-2.f90 -O scan-tree-dump-times profile_estimate "Fortran loop preheader heuristics of edge" 2
New passes:
^ permalink raw reply [flat|nested] 2+ messages in thread
* [TCWG CI] Regression caused by gdb: gdb: make string-like set show commands use std::string variable
@ 2021-10-03 22:42 ci_notify
0 siblings, 0 replies; 2+ messages in thread
From: ci_notify @ 2021-10-03 22:42 UTC (permalink / raw)
To: Simon Marchi; +Cc: gcc-regression
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 45882 bytes --]
[TCWG CI] Regression caused by gdb: gdb: make string-like set show commands use std::string variable:
commit e0700ba44c5695d07f4cc9841315adc91ca18bf5
Author: Simon Marchi <simon.marchi@efficios.com>
gdb: make string-like set show commands use std::string variable
Results regressed to
# reset_artifacts:
-10
# true:
0
# build_abe binutils:
1
# build_abe stage1:
2
# build_abe linux:
3
# build_abe glibc:
4
# build_abe stage2:
5
# First few build errors in logs:
# 00:03:43 ../../../../../../gdb/gdb/remote-sim.c:686:27: error: cannot convert âconst stringâ {aka âconst std::__cxx11::basic_string<char>â} to âconst char*â
# 00:03:43 ../../../../../../gdb/gdb/remote-sim.c:687:13: error: no match for âoperator+=â (operand types are âconst stringâ {aka âconst std::__cxx11::basic_string<char>â} and âsize_tâ {aka âlong unsigned intâ})
# 00:03:43 ../../../../../../gdb/gdb/remote-sim.c:687:23: error: invalid conversion from âsize_tâ {aka âlong unsigned intâ} to âconst char*â [-fpermissive]
# 00:03:43 ../../../../../../gdb/gdbsupport/offset-type.h:99:41: error: âis_offset_typeâ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
# 00:03:43 ../../../../../../gdb/gdbsupport/offset-type.h:99:41: error: no matching function for call to âis_offset_type(const std::__cxx11::basic_string<char>)â
# 00:03:43 make[1]: *** [Makefile:1649: remote-sim.o] Error 1
# 00:03:56 make: *** [Makefile:10436: all-gdb] Error 2
from
# reset_artifacts:
-10
# true:
0
# build_abe binutils:
1
# build_abe stage1:
2
# build_abe linux:
3
# build_abe glibc:
4
# build_abe stage2:
5
# build_abe gdb:
6
# build_abe qemu:
7
THIS IS THE END OF INTERESTING STUFF. BELOW ARE LINKS TO BUILDS, REPRODUCTION INSTRUCTIONS, AND THE RAW COMMIT.
This commit has regressed these CI configurations:
- tcwg_gnu_cross_build/master-arm
First_bad build: https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/build-e0700ba44c5695d07f4cc9841315adc91ca18bf5/
Last_good build: https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/build-1d7fe7f01b93ecaeb3e481ed09d3deac7890a97f/
Baseline build: https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/build-baseline/
Even more details: https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/
Reproduce builds:
<cut>
mkdir investigate-gdb-e0700ba44c5695d07f4cc9841315adc91ca18bf5
cd investigate-gdb-e0700ba44c5695d07f4cc9841315adc91ca18bf5
# Fetch scripts
git clone https://git.linaro.org/toolchain/jenkins-scripts
# Fetch manifests and test.sh script
mkdir -p artifacts/manifests
curl -o artifacts/manifests/build-baseline.sh https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/manifests/build-baseline.sh --fail
curl -o artifacts/manifests/build-parameters.sh https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/manifests/build-parameters.sh --fail
curl -o artifacts/test.sh https://ci.linaro.org/job/tcwg_gnu_cross_build-bisect-master-arm/2/artifact/artifacts/test.sh --fail
chmod +x artifacts/test.sh
# Reproduce the baseline build (build all pre-requisites)
./jenkins-scripts/tcwg_gnu-build.sh @@ artifacts/manifests/build-baseline.sh
# Save baseline build state (which is then restored in artifacts/test.sh)
mkdir -p ./bisect
rsync -a --del --delete-excluded --exclude /bisect/ --exclude /artifacts/ --exclude /gdb/ ./ ./bisect/baseline/
cd gdb
# Reproduce first_bad build
git checkout --detach e0700ba44c5695d07f4cc9841315adc91ca18bf5
../artifacts/test.sh
# Reproduce last_good build
git checkout --detach 1d7fe7f01b93ecaeb3e481ed09d3deac7890a97f
../artifacts/test.sh
cd ..
</cut>
Full commit (up to 1000 lines):
<cut>
commit e0700ba44c5695d07f4cc9841315adc91ca18bf5
Author: Simon Marchi <simon.marchi@efficios.com>
Date: Fri Sep 10 17:10:13 2021 -0400
gdb: make string-like set show commands use std::string variable
String-like settings (var_string, var_filename, var_optional_filename,
var_string_noescape) currently take a pointer to a `char *` storage
variable (typically global) that holds the setting's value. I'd like to
"mordernize" this by changing them to use an std::string for storage.
An obvious reason is that string operations on std::string are often
easier to write than with C strings. And they avoid having to do any
manual memory management.
Another interesting reason is that, with `char *`, nullptr and an empty
string often both have the same meaning of "no value". String settings
are initially nullptr (unless initialized otherwise). But when doing
"set foo" (where `foo` is a string setting), the setting now points to
an empty string. For example, solib_search_path is nullptr at startup,
but points to an empty string after doing "set solib-search-path". This
leads to some code that needs to check for both to check for "no value".
Or some code that converts back and forth between NULL and "" when
getting or setting the value. I find this very error-prone, because it
is very easy to forget one or the other. With std::string, we at least
know that the variable is not "NULL". There is only one way of
representing an empty string setting, that is with an empty string.
I was wondering whether the distinction between NULL and "" would be
important for some setting, but it doesn't seem so. If that ever
happens, it would be more C++-y and self-descriptive to use
optional<string> anyway.
Actually, there's one spot where this distinction mattered, it's in
init_history, for the test gdb.base/gdbinit-history.exp. init_history
sets the history filename to the default ".gdb_history" if it sees that
the setting was never set - if history_filename is nullptr. If
history_filename is an empty string, it means the setting was explicitly
cleared, so it leaves it as-is. With the change to std::string, this
distinction doesn't exist anymore. This can be fixed by moving the code
that chooses a good default value for history_filename to
_initialize_top. This is ran before -ex commands are processed, so an
-ex command can then clear that value if needed (what
gdb.base/gdbinit-history.exp tests).
Another small improvement, in my opinion is that we can now easily
give string parameters initial values, by simply initializing the global
variables, instead of xstrdup-ing it in the _initialize function.
In Python and Guile, when registering a string-like parameter, we
allocate (with new) an std::string that is owned by the param_smob (in
Guile) and the parmpy_object (in Python) objects.
This patch started by changing all relevant add_setshow_* commands to
take an `std::string *` instead of a `char **` and fixing everything
that failed to build. That includes of course all string setting
variable and their uses.
string_option_def now uses an std::string also, because there's a
connection between options and settings (see
add_setshow_cmds_for_options).
The add_path function in source.c is really complex and twisted, I'd
rather not try to change it to work on an std::string right now.
Instead, I added an overload that copies the std:string to a `char *`
and back. This means more copying, but this is not used in a hot path
at all, so I think it is acceptable.
Change-Id: I92c50a1bdd8307141cdbacb388248e4e4fc08c93
Co-authored-by: Lancelot SIX <lsix@lancelotsix.com>
---
gdb/auto-load.c | 48 +++++++-------------
gdb/breakpoint.c | 22 +++++----
gdb/build-id.c | 4 +-
gdb/cli/cli-cmds.c | 49 ++++++++++++--------
gdb/cli/cli-decode.c | 38 ++++++++--------
gdb/cli/cli-logging.c | 23 +++++-----
gdb/cli/cli-option.c | 9 ++--
gdb/cli/cli-option.h | 4 +-
gdb/cli/cli-setshow.c | 59 +++++++++---------------
gdb/command.h | 23 +++++-----
gdb/compile/compile.c | 46 +++++++++----------
gdb/corefile.c | 17 ++++---
gdb/defs.h | 4 +-
gdb/disasm.c | 11 +++--
gdb/disasm.h | 2 +-
gdb/dwarf2/dwz.c | 2 +-
gdb/dwarf2/index-cache.c | 10 ++---
gdb/dwarf2/read.c | 10 ++---
gdb/event-top.c | 12 +++--
gdb/fork-child.c | 7 ++-
gdb/guile/scm-param.c | 62 ++++++++++++++-----------
gdb/infcmd.c | 14 +++---
gdb/linux-thread-db.c | 17 +++----
gdb/main.c | 17 +++----
gdb/maint-test-options.c | 11 +----
gdb/maint-test-settings.c | 8 ++--
gdb/mi/mi-cmd-env.c | 18 ++++----
gdb/proc-api.c | 5 +--
gdb/python/py-param.c | 45 ++++++++++---------
gdb/python/python.c | 10 ++---
gdb/remote-sim.c | 7 ++-
gdb/remote.c | 10 ++---
gdb/serial.c | 8 ++--
gdb/solib.c | 20 ++++-----
gdb/source.c | 66 +++++++++++++++------------
gdb/source.h | 5 ++-
gdb/stack.c | 22 ++++-----
gdb/symfile.c | 49 ++++++++++----------
gdb/symtab.c | 46 +++++++++----------
gdb/target-descriptions.c | 2 +-
gdb/top.c | 112 ++++++++++++++++++++++------------------------
gdb/top.h | 2 +-
gdb/tracepoint.c | 29 ++++++------
gdb/tracepoint.h | 2 +-
44 files changed, 477 insertions(+), 510 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 7f0bb74c32a..36d87252b3f 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -137,7 +137,7 @@ show_auto_load_local_gdbinit (struct ui_file *file, int from_tty,
/* Directory list from which to load auto-loaded scripts. It is not checked
for absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_dir;
+static std::string auto_load_dir = AUTO_LOAD_DIR;
/* "set" command for the auto_load_dir configuration variable. */
@@ -145,11 +145,8 @@ static void
set_auto_load_dir (const char *args, int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_dir[0] == '\0')
- {
- xfree (auto_load_dir);
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
- }
+ if (auto_load_dir.empty ())
+ auto_load_dir = AUTO_LOAD_DIR;
}
/* "show" command for the auto_load_dir configuration variable. */
@@ -166,7 +163,7 @@ show_auto_load_dir (struct ui_file *file, int from_tty,
/* Directory list safe to hold auto-loaded files. It is not checked for
absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
-static char *auto_load_safe_path;
+static std::string auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
/* Vector of directory elements of AUTO_LOAD_SAFE_PATH with each one normalized
by tilde_expand and possibly each entries has added its gdb_realpath
@@ -181,7 +178,7 @@ auto_load_expand_dir_vars (const char *string)
{
char *s = xstrdup (string);
substitute_path_component (&s, "$datadir", gdb_datadir.c_str ());
- substitute_path_component (&s, "$debugdir", debug_file_directory);
+ substitute_path_component (&s, "$debugdir", debug_file_directory.c_str ());
if (debug_auto_load && strcmp (s, string) != 0)
auto_load_debug_printf ("Expanded $-variables to \"%s\".", s);
@@ -199,9 +196,10 @@ static void
auto_load_safe_path_vec_update (void)
{
auto_load_debug_printf ("Updating directories of \"%s\".",
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
- auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
+ auto_load_safe_path_vec
+ = auto_load_expand_dir_vars (auto_load_safe_path.c_str ());
size_t len = auto_load_safe_path_vec.size ();
/* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
@@ -253,11 +251,8 @@ set_auto_load_safe_path (const char *args,
int from_tty, struct cmd_list_element *c)
{
/* Setting the variable to "" resets it to the compile time defaults. */
- if (auto_load_safe_path[0] == '\0')
- {
- xfree (auto_load_safe_path);
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
- }
+ if (auto_load_safe_path.empty ())
+ auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
auto_load_safe_path_vec_update ();
}
@@ -291,17 +286,14 @@ show_auto_load_safe_path (struct ui_file *file, int from_tty,
static void
add_auto_load_safe_path (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("\
Directory argument required.\n\
Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
"));
- s = xstrprintf ("%s%c%s", auto_load_safe_path, DIRNAME_SEPARATOR, args);
- xfree (auto_load_safe_path);
- auto_load_safe_path = s;
+ auto_load_safe_path = string_printf ("%s%c%s", auto_load_safe_path.c_str (),
+ DIRNAME_SEPARATOR, args);
auto_load_safe_path_vec_update ();
}
@@ -312,14 +304,11 @@ Use 'set auto-load safe-path /' for disabling the auto-load safe-path security.\
static void
add_auto_load_dir (const char *args, int from_tty)
{
- char *s;
-
if (args == NULL || *args == 0)
error (_("Directory argument required."));
- s = xstrprintf ("%s%c%s", auto_load_dir, DIRNAME_SEPARATOR, args);
- xfree (auto_load_dir);
- auto_load_dir = s;
+ auto_load_dir = string_printf ("%s%c%s", auto_load_dir.c_str (),
+ DIRNAME_SEPARATOR, args);
}
/* Implementation for filename_is_in_pattern overwriting the caller's FILENAME
@@ -459,7 +448,7 @@ file_is_auto_load_safe (const char *filename)
warning (_("File \"%ps\" auto-loading has been declined by your "
"`auto-load safe-path' set to \"%s\"."),
styled_string (file_name_style.style (), filename_real.get ()),
- auto_load_safe_path);
+ auto_load_safe_path.c_str ());
if (!advice_printed)
{
@@ -749,11 +738,11 @@ auto_load_objfile_script_1 (struct objfile *objfile, const char *realname,
directory. */
std::vector<gdb::unique_xmalloc_ptr<char>> vec
- = auto_load_expand_dir_vars (auto_load_dir);
+ = auto_load_expand_dir_vars (auto_load_dir.c_str ());
auto_load_debug_printf
("Searching 'set auto-load scripts-directory' path \"%s\".",
- auto_load_dir);
+ auto_load_dir.c_str ());
/* Convert Windows file name from c:/dir/file to /c/dir/file. */
if (HAS_DRIVE_SPEC (debugfile))
@@ -1542,8 +1531,6 @@ This option has security implications for untrusted inferiors."),
Usage: info auto-load local-gdbinit"),
auto_load_info_cmdlist_get ());
- auto_load_dir = xstrdup (AUTO_LOAD_DIR);
-
suffix = ext_lang_auto_load_suffix (get_ext_lang_defn (EXT_LANG_GDB));
gdb_name_help
= xstrprintf (_("\
@@ -1595,7 +1582,6 @@ Show the list of directories from which to load auto-loaded scripts."),
xfree (gdb_name_help);
xfree (guile_name_help);
- auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH);
auto_load_safe_path_vec_update ();
add_setshow_optional_filename_cmd ("safe-path", class_support,
&auto_load_safe_path, _("\
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 3b626b8f4aa..e742a1eccfe 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -276,7 +276,7 @@ static const char *dprintf_style = dprintf_style_gdb;
copied into the command, so it can be anything that GDB can
evaluate to a callable address, not necessarily a function name. */
-static char *dprintf_function;
+static std::string dprintf_function = "printf";
/* The channel to use for dynamic printf if the preferred style is to
call into the inferior; if a nonempty string, it will be passed to
@@ -286,7 +286,7 @@ static char *dprintf_function;
"stderr", this could be an app-specific expression like
"mystreams[curlogger]". */
-static char *dprintf_channel;
+static std::string dprintf_channel;
/* True if dprintf commands should continue to operate even if GDB
has disconnected. */
@@ -6658,7 +6658,7 @@ default_collect_info (void)
/* If it has no value (which is frequently the case), say nothing; a
message like "No default-collect." gets in user's face when it's
not wanted. */
- if (!*default_collect)
+ if (default_collect.empty ())
return;
/* The following phrase lines up nicely with per-tracepoint collect
@@ -8759,17 +8759,17 @@ update_dprintf_command_list (struct breakpoint *b)
printf_line = xstrprintf ("printf %s", dprintf_args);
else if (strcmp (dprintf_style, dprintf_style_call) == 0)
{
- if (!dprintf_function)
+ if (dprintf_function.empty ())
error (_("No function supplied for dprintf call"));
- if (dprintf_channel && strlen (dprintf_channel) > 0)
+ if (!dprintf_channel.empty ())
printf_line = xstrprintf ("call (void) %s (%s,%s)",
- dprintf_function,
- dprintf_channel,
+ dprintf_function.c_str (),
+ dprintf_channel.c_str (),
dprintf_args);
else
printf_line = xstrprintf ("call (void) %s (%s)",
- dprintf_function,
+ dprintf_function.c_str (),
dprintf_args);
}
else if (strcmp (dprintf_style, dprintf_style_agent) == 0)
@@ -15102,8 +15102,8 @@ save_breakpoints (const char *filename, int from_tty,
}
}
- if (extra_trace_bits && *default_collect)
- fp.printf ("set default-collect %s\n", default_collect);
+ if (extra_trace_bits && !default_collect.empty ())
+ fp.printf ("set default-collect %s\n", default_collect.c_str ());
if (from_tty)
printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ());
@@ -16014,7 +16014,6 @@ output stream by setting dprintf-function and dprintf-channel."),
update_dprintf_commands, NULL,
&setlist, &showlist);
- dprintf_function = xstrdup ("printf");
add_setshow_string_cmd ("dprintf-function", class_support,
&dprintf_function, _("\
Set the function to use for dynamic printf."), _("\
@@ -16022,7 +16021,6 @@ Show the function to use for dynamic printf."), NULL,
update_dprintf_commands, NULL,
&setlist, &showlist);
- dprintf_channel = xstrdup ("");
add_setshow_string_cmd ("dprintf-channel", class_support,
&dprintf_channel, _("\
Set the channel to use for dynamic printf."), _("\
diff --git a/gdb/build-id.c b/gdb/build-id.c
index d2f2576d96d..553d6cec3d2 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -130,7 +130,7 @@ build_id_to_bfd_suffix (size_t build_id_len, const bfd_byte *build_id,
cause "/.build-id/..." lookups. */
std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
- = dirnames_to_char_ptr_vec (debug_file_directory);
+ = dirnames_to_char_ptr_vec (debug_file_directory.c_str ());
for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
{
@@ -167,7 +167,7 @@ build_id_to_bfd_suffix (size_t build_id_len, const bfd_byte *build_id,
Don't do it if the sysroot is the target system ("target:"). It
could work in theory, but the lrealpath in build_id_to_debug_bfd_1
only works with local paths. */
- if (strcmp (gdb_sysroot, TARGET_SYSROOT_PREFIX) != 0)
+ if (gdb_sysroot != TARGET_SYSROOT_PREFIX)
{
link = gdb_sysroot + link;
debug_bfd = build_id_to_debug_bfd_1 (link, build_id_len, build_id);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index ecbe5a4b43c..f8f013348db 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -650,7 +650,7 @@ find_and_open_script (const char *script_file, int search_path)
/* Search for and open 'file' on the search path used for source
files. Put the full location in *FULL_PATHP. */
gdb::unique_xmalloc_ptr<char> full_path;
- fd = openp (source_path, search_flags,
+ fd = openp (source_path.c_str (), search_flags,
file.get (), O_RDONLY, &full_path);
if (fd == -1)
@@ -1042,12 +1042,7 @@ edit_command (const char *arg, int from_tty)
struct pipe_cmd_opts
{
/* For "-d". */
- char *delimiter = nullptr;
-
- ~pipe_cmd_opts ()
- {
- xfree (delimiter);
- }
+ std::string delimiter;
};
static const gdb::option::option_def pipe_cmd_option_defs[] = {
@@ -1084,8 +1079,8 @@ pipe_command (const char *arg, int from_tty)
(&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
const char *delim = "|";
- if (opts.delimiter != nullptr)
- delim = opts.delimiter;
+ if (!opts.delimiter.empty ())
+ delim = opts.delimiter.c_str ();
const char *command = arg;
if (command == nullptr)
@@ -1148,8 +1143,8 @@ pipe_command_completer (struct cmd_list_element *ignore,
return;
const char *delimiter = "|";
- if (opts.delimiter != nullptr)
- delimiter = opts.delimiter;
+ if (!opts.delimiter.empty ())
+ delimiter = opts.delimiter.c_str ();
/* Check if we're past option values already. */
if (text > org_text && !isspace (text[-1]))
@@ -2152,13 +2147,21 @@ value_from_setting (const setting &var, struct gdbarch *gdbarch)
case var_enum:
{
const char *value;
+ size_t len;
if (var.type () == var_enum)
- value = var.get<const char *> ();
+ {
+ value = var.get<const char *> ();
+ len = strlen (value);
+ }
else
- value = var.get<char *> ();
+ {
+ const std::string &st = var.get<std::string> ();
+ value = st.c_str ();
+ len = st.length ();
+ }
- if (value != nullptr)
- return value_cstring (value, strlen (value),
+ if (len > 0)
+ return value_cstring (value, len,
builtin_type (gdbarch)->builtin_char);
else
return value_cstring ("", 1,
@@ -2231,13 +2234,21 @@ str_value_from_setting (const setting &var, struct gdbarch *gdbarch)
similarly to the value_from_setting code for these casevar. */
{
const char *value;
+ size_t len;
if (var.type () == var_enum)
- value = var.get<const char *> ();
+ {
+ value = var.get<const char *> ();
+ len = strlen (value);
+ }
else
- value = var.get<char *> ();
+ {
+ const std::string &st = var.get<std::string> ();
+ value = st.c_str ();
+ len = st.length ();
+ }
- if (value != nullptr)
- return value_cstring (value, strlen (value),
+ if (len > 0)
+ return value_cstring (value, len,
builtin_type (gdbarch)->builtin_char);
else
return value_cstring ("", 1,
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 56befc979dc..b3bf6276157 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -655,7 +655,7 @@ add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *va
set_show_commands
add_setshow_filename_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -664,10 +664,10 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_filename, var,
- set_doc, show_doc, help_doc,
- set_func, show_func,
- set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_filename, var,
+ set_doc, show_doc, help_doc,
+ set_func, show_func,
+ set_list, show_list);
set_cmd_completer (commands.set, filename_completer);
@@ -679,7 +679,7 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_string_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -688,10 +688,10 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_string, var,
- set_doc, show_doc, help_doc,
- set_func, show_func,
- set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_string, var,
+ set_doc, show_doc, help_doc,
+ set_func, show_func,
+ set_list, show_list);
/* Disable the default symbol completer. */
set_cmd_completer (commands.set, nullptr);
@@ -704,7 +704,7 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -713,9 +713,10 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_string_noescape, var,
- set_doc, show_doc, help_doc, set_func,
- show_func, set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_string_noescape,
+ var, set_doc, show_doc, help_doc,
+ set_func, show_func, set_list,
+ show_list);
/* Disable the default symbol completer. */
set_cmd_completer (commands.set, nullptr);
@@ -728,7 +729,7 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
set_show_commands
add_setshow_optional_filename_cmd (const char *name, enum command_class theclass,
- char **var,
+ std::string *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_func_ftype *set_func,
@@ -737,9 +738,10 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
struct cmd_list_element **show_list)
{
set_show_commands commands
- = add_setshow_cmd_full<char *> (name, theclass, var_optional_filename,
- var, set_doc, show_doc, help_doc,
- set_func, show_func, set_list, show_list);
+ = add_setshow_cmd_full<std::string> (name, theclass, var_optional_filename,
+ var, set_doc, show_doc, help_doc,
+ set_func, show_func, set_list,
+ show_list);
set_cmd_completer (commands.set, filename_completer);
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index dfedd7599a2..c9093520a71 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -25,7 +25,7 @@
static char *saved_filename;
-static char *logging_filename;
+static std::string logging_filename = "gdb.txt";
static void
show_logging_filename (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
@@ -102,7 +102,7 @@ handle_redirections (int from_tty)
}
stdio_file_up log (new no_terminal_escape_file ());
- if (!log->open (logging_filename, logging_overwrite ? "w" : "a"))
+ if (!log->open (logging_filename.c_str (), logging_overwrite ? "w" : "a"))
perror_with_name (_("set logging"));
/* Redirects everything to gdb_stdout while this is running. */
@@ -110,20 +110,20 @@ handle_redirections (int from_tty)
{
if (!logging_redirect)
fprintf_unfiltered (gdb_stdout, "Copying output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
else
fprintf_unfiltered (gdb_stdout, "Redirecting output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
if (!debug_redirect)
fprintf_unfiltered (gdb_stdout, "Copying debug output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
else
fprintf_unfiltered (gdb_stdout, "Redirecting debug output to %s.\n",
- logging_filename);
+ logging_filename.c_str ());
}
- saved_filename = xstrdup (logging_filename);
+ saved_filename = xstrdup (logging_filename.c_str ());
/* Let the interpreter do anything it needs. */
current_interp_set_logging (std::move (log), logging_redirect,
@@ -145,10 +145,8 @@ set_logging_on (const char *args, int from_tty)
const char *rest = args;
if (rest && *rest)
- {
- xfree (logging_filename);
- logging_filename = xstrdup (rest);
- }
+ logging_filename = rest;
+
handle_redirections (from_tty);
}
@@ -201,6 +199,7 @@ If debug redirect is on, debug will go only to the log file."),
set_logging_redirect,
show_logging_redirect,
&set_logging_cmdlist, &show_logging_cmdlist);
+
add_setshow_filename_cmd ("file", class_support, &logging_filename, _("\
Set the current logfile."), _("\
Show the current logfile."), _("\
@@ -212,6 +211,4 @@ The logfile is used when directing GDB's output."),
_("Enable logging."), &set_logging_cmdlist);
add_cmd ("off", class_support, set_logging_off,
_("Disable logging."), &set_logging_cmdlist);
-
- logging_filename = xstrdup ("gdb.txt");
}
diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c
index ab76f194c3d..846b8198985 100644
--- a/gdb/cli/cli-option.c
+++ b/gdb/cli/cli-option.c
@@ -45,7 +45,7 @@ union option_value
const char *enumeration;
/* For var_string options. This is malloc-allocated. */
- char *string;
+ std::string *string;
};
/* Holds an options definition and its value. */
@@ -87,7 +87,7 @@ struct option_def_and_value
if (value.has_value ())
{
if (option.type == var_string)
- xfree (value->string);
+ delete value->string;
}
}
@@ -439,7 +439,7 @@ parse_option (gdb::array_view<const option_def_group> options_group,
error (_("-%s requires an argument"), match->name);
option_value val;
- val.string = xstrdup (str.c_str ());
+ val.string = new std::string (std::move (str));
return option_def_and_value {*match, match_ctx, val};
}
@@ -603,8 +603,7 @@ save_option_value_in_ctx (gdb::optional<option_def_and_value> &ov)
break;
case var_string:
*ov->option.var_address.string (ov->option, ov->ctx)
- = ov->value->string;
- ov->value->string = nullptr;
+ = std::move (*ov->value->string);
break;
default:
gdb_assert_not_reached ("unhandled option type");
diff --git a/gdb/cli/cli-option.h b/gdb/cli/cli-option.h
index aa2ccbed5d0..b7ede458748 100644
--- a/gdb/cli/cli-option.h
+++ b/gdb/cli/cli-option.h
@@ -86,7 +86,7 @@ struct option_def
unsigned int *(*uinteger) (const option_def &, void *ctx);
int *(*integer) (const option_def &, void *ctx);
const char **(*enumeration) (const option_def &, void *ctx);
- char **(*string) (const option_def &, void *ctx);
+ std::string *(*string) (const option_def &, void *ctx);
}
var_address;
@@ -268,7 +268,7 @@ template<typename Context>
struct string_option_def : option_def
{
string_option_def (const char *long_option_,
- char **(*get_var_address_cb_) (Context *),
+ std::string *(*get_var_address_cb_) (Context *),
show_value_ftype *show_cmd_cb_,
const char *set_doc_,
const char *show_doc_ = nullptr,
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 86ab553f48c..8d29c0c3fc2 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -360,27 +360,22 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
*q++ = '\0';
newobj = (char *) xrealloc (newobj, q - newobj);
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, newobj) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str(), newobj) != 0)
{
- xfree (var);
- c->var->set<char *> (newobj);
+ c->var->set<std::string> (std::string (newobj));
option_changed = true;
}
- else
- xfree (newobj);
+ xfree (newobj);
}
break;
case var_string_noescape:
{
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, arg) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str (), arg) != 0)
{
- xfree (var);
- c->var->set<char *> (xstrdup (arg));
+ c->var->set<std::string> (std::string (arg));
option_changed = true;
}
@@ -410,17 +405,14 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
else
val = xstrdup ("");
- char * const var = c->var->get<char *> ();
- if (var == nullptr
- || strcmp (var, val) != 0)
+ const std::string &cur_val = c->var->get<std::string> ();
+ if (strcmp (cur_val.c_str (), val) != 0)
{
- xfree (var);
- c->var->set<char *> (val);
+ c->var->set<std::string> (std::string (val));
option_changed = true;
}
- else
- xfree (val);
+ xfree (val);
}
break;
case var_boolean:
@@ -598,15 +590,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
case var_string_noescape:
case var_filename:
case var_optional_filename:
+ gdb::observers::command_param_changed.notify
+ (name, c->var->get<std::string> ().c_str ());
+ break;
case var_enum:
- {
- const char *var;
- if (c->var->type () == var_enum)
- var = c->var->get<const char *> ();
- else
- var = c->var->get<char *> ();
- gdb::observers::command_param_changed.notify (name, var);
- }
+ gdb::observers::command_param_changed.notify
+ (name, c->var->get<const char *> ());
break;
case var_boolean:
{
@@ -658,23 +647,19 @@ get_setshow_command_value_string (const setting &var)
{
case var_string:
{
- char *value = var.get<char *> ();
-
- if (value != nullptr)
- stb.putstr (value, '"');
+ std::string value = var.get<std::string> ();
+ if (!value.empty ())
+ stb.putstr (value.c_str (), '"');
}
break;
case var_string_noescape:
case var_optional_filename:
case var_filename:
+ stb.puts (var.get<std::string> ().c_str ());
+ break;
case var_enum:
{
- const char *value;
- if (var.type () == var_enum)
- value = var.get<const char *> ();
- else
- value = var.get<char *> ();
-
+ const char *value = var.get<const char *> ();
if (value != nullptr)
stb.puts (value);
}
diff --git a/gdb/command.h b/gdb/command.h
index e7b81100f26..e6e6ec8a5d8 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -97,16 +97,15 @@ typedef enum var_types
/* String which the user enters with escapes (e.g. the user types
\n and it is a real newline in the stored string).
- *VAR is a malloc'd string, or NULL if the string is empty. */
+ *VAR is a std::string, "" if the string is empty. */
var_string,
/* String which stores what the user types verbatim.
- *VAR is a malloc'd string, or NULL if the string is empty. */
+ *VAR is std::string, "" if the string is empty. */
var_string_noescape,
- /* String which stores a filename. (*VAR) is a malloc'd string,
- or "" if the string was empty. */
+ /* String which stores a filename. (*VAR) is a std::string,
+ "" if the string was empty. */
var_optional_filename,
- /* String which stores a filename. (*VAR) is a malloc'd
- string. */
+ /* String which stores a filename. (*VAR) is a std::string. */
var_filename,
/* ZeroableInteger. *VAR is an int. Like var_integer except
that zero really means zero. */
@@ -166,9 +165,9 @@ inline bool var_type_uses<int> (var_types t)
|| t == var_zuinteger_unlimited);
}
-/* Return true if a setting of type T is backed by a char * variable. */
+/* Return true if a setting of type T is backed by a std::string variable. */
template<>
-inline bool var_type_uses<char *> (var_types t)
+inline bool var_type_uses<std::string> (var_types t)
{
return (t == var_string || t == var_string_noescape
|| t == var_optional_filename || t == var_filename);
@@ -562,25 +561,25 @@ extern set_show_commands add_setshow_boolean_cmd
cmd_list_element **show_list);
extern set_show_commands add_setshow_filename_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_string_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_string_noescape_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
extern set_show_commands add_setshow_optional_filename_cmd
- (const char *name, command_class theclass, char **var, const char *set_doc,
+ (const char *name, command_class theclass, std::string *var, const char *set_doc,
const char *show_doc, const char *help_doc, cmd_func_ftype *set_func,
show_value_ftype *show_func, cmd_list_element **set_list,
cmd_list_element **show_list);
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index e815348ff07..25cfd283b33 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -495,7 +495,22 @@ get_expr_block_and_pc (CORE_ADDR *pc)
}
/* String for 'set compile-args' and 'show compile-args'. */
-static char *compile_args;
+static std::string compile_args =
+ /* Override flags possibly coming from DW_AT_producer. */
+ "-O0 -gdwarf-4"
+ /* We use -fPIE Otherwise GDB would need to reserve space large enough for
+ any object file in the inferior in advance to get the final address when
+ to link the object file to and additionally the default system linker
+ script would need to be modified so that one can specify there the
+ absolute target address.
+ -fPIC is not used at is would require from GDB to generate .got. */
+ " -fPIE"
+ /* We want warnings, except for some commonly happening for GDB commands. */
+ " -Wall "
+ " -Wno-unused-but-set-variable"
+ " -Wno-unused-variable"
+ /* Override CU's possible -fstack-protector-strong. */
+ " -fno-stack-protector";
/* Parsed form of COMPILE_ARGS. */
static gdb_argv compile_args_argv;
@@ -505,7 +520,7 @@ static gdb_argv compile_args_argv;
static void
set_compile_args (const char *args, int from_tty, struct cmd_list_element *c)
{
- compile_args_argv = gdb_argv (compile_args);
+ compile_args_argv = gdb_argv (compile_args.c_str ());
}
/* Implement 'show compile-args'. */
@@ -520,7 +535,7 @@ show_compile_args (struct ui_file *file, int from_tty,
}
/* String for 'set compile-gcc' and 'show compile-gcc'. */
-static char *compile_gcc;
+static std::string compile_gcc;
/* Implement 'show compile-gcc'. */
@@ -696,13 +711,13 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
compiler->set_verbose (compile_debug);
- if (compile_gcc[0] != 0)
+ if (!compile_gcc.empty ())
{
if (compiler->version () < GCC_FE_VERSION_1)
error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
"(libcc1 interface version 1 or higher)"));
- compiler->set_driver_filename (compile_gcc);
+ compiler->set_driver_filename (compile_gcc.c_str ());
}
else
{
@@ -1029,23 +1044,9 @@ String quoting is parsed like in shell, for example:\n\
-mno-align-double \"-I/dir with a space/include\""),
set_compile_args, show_compile_args, &setlist, &showlist);
- /* Override flags possibly coming from DW_AT_producer. */
- compile_args = xstrdup ("-O0 -gdwarf-4"
- /* We use -fPIE Otherwise GDB would need to reserve space large enough for
- any object file in the inferior in advance to get the final address when
- to link the object file to and additionally the default system linker
- script would need to be modified so that one can specify there the
- absolute target address.
- -fPIC is not used at is would require from GDB to generate .got. */
- " -fPIE"
- /* We want warnings, except for some commonly happening for GDB commands. */
- " -Wall "
- " -Wno-unused-but-set-variable"
- " -Wno-unused-variable"
- /* Override CU's possible -fstack-protector-strong. */
- " -fno-stack-protector"
- );
- set_compile_args (compile_args, 0, NULL);
+
+ /* Initialize compile_args_argv. */
+ set_compile_args (compile_args.c_str (), 0, NULL);
add_setshow_optional_filename_cmd ("compile-gcc", class_support,
&compile_gcc,
@@ -1058,5 +1059,4 @@ It should be absolute filename of the gcc executable.\n\
If empty the default target triplet will be searched in $PATH."),
NULL, show_compile_gcc, &setlist,
&showlist);
- compile_gcc = xstrdup ("");
}
diff --git a/gdb/corefile.c b/gdb/corefile.c
index ff2494738b0..4b1451487e2 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -395,7 +395,7 @@ write_memory_signed_integer (CORE_ADDR addr, int len,
const char *gnutarget;
/* Same thing, except it is "auto" not NULL for the default case. */
-static char *gnutarget_string;
+static std::string gnutarget_string;
static void
show_gnutarget_string (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
@@ -409,15 +409,15 @@ static void
set_gnutarget_command (const char *ignore, int from_tty,
struct cmd_list_element *c)
{
- char *gend = gnutarget_string + strlen (gnutarget_string);
</cut>
>From hjl@sc.intel.com Mon Oct 4 06:11:16 2021
Return-Path: <hjl@sc.intel.com>
X-Original-To: gcc-regression@gcc.gnu.org
Delivered-To: gcc-regression@gcc.gnu.org
Received: from mga05.intel.com (mga05.intel.com [192.55.52.43])
by sourceware.org (Postfix) with ESMTPS id 3DAB83858C3A
for <gcc-regression@gcc.gnu.org>; Mon, 4 Oct 2021 06:11:15 +0000 (GMT)
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3DAB83858C3A
X-IronPort-AV: E=McAfee;i="6200,9189,10126"; a="311497056"
X-IronPort-AV: E=Sophos;i="5.85,345,1624345200"; d="scan'208";a="311497056"
Received: from fmsmga007.fm.intel.com ([10.253.24.52])
by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
03 Oct 2021 23:11:13 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.85,345,1624345200"; d="scan'208";a="482756058"
Received: from scymds02.sc.intel.com ([10.82.73.244])
by fmsmga007.fm.intel.com with ESMTP; 03 Oct 2021 23:11:13 -0700
Received: from gnu-clx-1.sc.intel.com (gnu-clx-1.sc.intel.com [172.25.70.216])
by scymds02.sc.intel.com with ESMTP id 1946BDXg020412;
Sun, 3 Oct 2021 23:11:13 -0700
Received: by gnu-clx-1.sc.intel.com (Postfix, from userid 1000)
id EF3093E001F; Sun, 3 Oct 2021 23:11:12 -0700 (PDT)
Date: Sun, 03 Oct 2021 23:11:12 -0700
To: skpgkp2@gmail.com, hjl.tools@gmail.com, gcc-regression@gcc.gnu.org
Subject: Regressions on native/releases/gcc-10 at commit r10-10166 vs
commit r10-10151 on Linux/x86_64
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20211004061112.EF3093E001F@gnu-clx-1.sc.intel.com>
From: "H. J. Lu" <hjl@sc.intel.com>
X-Spam-Status: No, score=-3469.2 required=5.0 testsºYES_00, KAM_DMARC_STATUS,
KAM_LAZY_DOMAIN_SECURITY, KAM_LINKBAIT, KAM_NUMSUBJECT, SPF_HELO_NONE,
SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
server2.sourceware.org
X-BeenThere: gcc-regression@gcc.gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Gcc-regression mailing list <gcc-regression.gcc.gnu.org>
List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-regression>,
<mailto:gcc-regression-request@gcc.gnu.org?subject=unsubscribe>
List-Archive: <https://gcc.gnu.org/pipermail/gcc-regression/>
List-Post: <mailto:gcc-regression@gcc.gnu.org>
List-Help: <mailto:gcc-regression-request@gcc.gnu.org?subject=help>
List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-regression>,
<mailto:gcc-regression-request@gcc.gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Oct 2021 06:11:16 -0000
New failures:
FAIL: 30_threads/future/members/poll.cc execution test
New passes:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-04 14:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 14:32 [TCWG CI] Regression caused by gdb: gdb: make string-like set show commands use std::string variable ci_notify
-- strict thread matches above, loose matches on Subject: below --
2021-10-03 22:42 ci_notify
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).