aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/cli/cli-setshow.c83
-rw-r--r--gdb/command.h10
2 files changed, 21 insertions, 72 deletions
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 8d29c0c..42c2b15 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -360,26 +360,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
*q++ = '\0';
newobj = (char *) xrealloc (newobj, q - newobj);
- const std::string &cur_val = c->var->get<std::string> ();
- if (strcmp (cur_val.c_str(), newobj) != 0)
- {
- c->var->set<std::string> (std::string (newobj));
-
- option_changed = true;
- }
+ option_changed = c->var->set<std::string> (std::string (newobj));
xfree (newobj);
}
break;
case var_string_noescape:
- {
- const std::string &cur_val = c->var->get<std::string> ();
- if (strcmp (cur_val.c_str (), arg) != 0)
- {
- c->var->set<std::string> (std::string (arg));
-
- option_changed = true;
- }
- }
+ option_changed = c->var->set<std::string> (std::string (arg));
break;
case var_filename:
if (*arg == '\0')
@@ -405,13 +391,8 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
else
val = xstrdup ("");
- const std::string &cur_val = c->var->get<std::string> ();
- if (strcmp (cur_val.c_str (), val) != 0)
- {
- c->var->set<std::string> (std::string (val));
-
- option_changed = true;
- }
+ option_changed
+ = c->var->set<std::string> (std::string (val));
xfree (val);
}
break;
@@ -421,39 +402,18 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
if (val < 0)
error (_("\"on\" or \"off\" expected."));
- if (val != c->var->get<bool> ())
- {
- c->var->set<bool> (val);
- option_changed = true;
- }
+ option_changed = c->var->set<bool> (val);
}
break;
case var_auto_boolean:
- {
- enum auto_boolean val = parse_auto_binary_operation (arg);
-
- if (c->var->get<enum auto_boolean> () != val)
- {
- c->var->set<enum auto_boolean> (val);
-
- option_changed = true;
- }
- }
+ option_changed = c->var->set<enum auto_boolean> (parse_auto_binary_operation (arg));
break;
case var_uinteger:
case var_zuinteger:
- {
- unsigned int val
- = parse_cli_var_uinteger (c->var->type (), &arg, true);
-
- if (c->var->get<unsigned int> () != val)
- {
- c->var->set<unsigned int> (val);
-
- option_changed = true;
- }
- }
+ option_changed
+ = c->var->set<unsigned int> (parse_cli_var_uinteger (c->var->type (),
+ &arg, true));
break;
case var_integer:
case var_zinteger:
@@ -483,12 +443,7 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
|| (c->var->type () == var_zinteger && val > INT_MAX))
error (_("integer %s out of range"), plongest (val));
- if (c->var->get<int> () != val)
- {
- c->var->set<int> (val);
-
- option_changed = true;
- }
+ option_changed = c->var->set<int> (val);
}
break;
case var_enum:
@@ -501,24 +456,12 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c)
if (*after != '\0')
error (_("Junk after item \"%.*s\": %s"), len, arg, after);
- if (c->var->get<const char *> () != match)
- {
- c->var->set<const char *> (match);
-
- option_changed = true;
- }
+ option_changed = c->var->set<const char *> (match);
}
break;
case var_zuinteger_unlimited:
- {
- int val = parse_cli_var_zuinteger_unlimited (&arg, true);
-
- if (c->var->get<int> () != val)
- {
- c->var->set<int> (val);
- option_changed = true;
- }
- }
+ option_changed = c->var->set<int>
+ (parse_cli_var_zuinteger_unlimited (&arg, true));
break;
default:
error (_("gdb internal error: bad var_type in do_setshow_command"));
diff --git a/gdb/command.h b/gdb/command.h
index 2abfbc4..7c226f1 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -300,7 +300,9 @@ struct setting
return *static_cast<const T *> (m_var);
}
- /* Sets the value of the setting to V.
+ /* Sets the value of the setting to V. Returns true if the setting was
+ effectively changed, false if the update failed and the setting is left
+ unchanged.
If we have a user-provided setter, use it to set the setting. Otherwise
copy the value V to the internally referenced buffer.
@@ -310,12 +312,14 @@ struct setting
The var_type of the setting must match T. */
template<typename T>
- void set (const T &v)
+ bool set (const T &v)
{
/* Check that the current instance is of one of the supported types for
this instantiation. */
gdb_assert (var_type_uses<T> (m_var_type));
+ const T old_value = this->get<T> ();
+
if (m_var == nullptr)
{
gdb_assert (m_setter != nullptr);
@@ -324,6 +328,8 @@ struct setting
}
else
*static_cast<T *> (m_var) = v;
+
+ return old_value != this->get<T> ();
}
private: