aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-06-27 11:06:04 -0600
committerTom Tromey <tom@tromey.com>2021-07-30 08:42:39 -0600
commit785e5700ce4bda469e323d1dc7eeae9d86980c79 (patch)
treea16c1cce4eec5f386703f3587a2c26a020c5a494
parentfb6262e8534e0148a4a424e9e5138159af19faf1 (diff)
downloadgdb-785e5700ce4bda469e323d1dc7eeae9d86980c79.zip
gdb-785e5700ce4bda469e323d1dc7eeae9d86980c79.tar.gz
gdb-785e5700ce4bda469e323d1dc7eeae9d86980c79.tar.bz2
Replace exception_print_same with operator!=
I noticed that exception_print_same is only used in a single spot, and it seemed to be better as an operator!= method attached to gdb_exception. Regression tested on x86-64 Fedora 34.
-rw-r--r--gdb/exceptions.c14
-rw-r--r--gdb/exceptions.h3
-rw-r--r--gdb/exec.c2
-rw-r--r--gdbsupport/common-exceptions.h17
4 files changed, 18 insertions, 18 deletions
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 32db6fe..5245b7c 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -133,17 +133,3 @@ exception_fprintf (struct ui_file *file, const struct gdb_exception &e,
print_exception (file, e);
}
}
-
-/* See exceptions.h. */
-
-int
-exception_print_same (const struct gdb_exception &e1,
- const struct gdb_exception &e2)
-{
- const char *msg1 = e1.message == nullptr ? "" : e1.what ();
- const char *msg2 = e2.message == nullptr ? "" : e2.what ();
-
- return (e1.reason == e2.reason
- && e1.error == e2.error
- && strcmp (msg1, msg2) == 0);
-}
diff --git a/gdb/exceptions.h b/gdb/exceptions.h
index b0416d4..8bd2dcc 100644
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -31,7 +31,4 @@ extern void exception_fprintf (struct ui_file *file,
const char *prefix,
...) ATTRIBUTE_PRINTF (3, 4);
-/* Compare two exception objects for print equality. */
-extern int exception_print_same (const struct gdb_exception &e1,
- const struct gdb_exception &e2);
#endif
diff --git a/gdb/exec.c b/gdb/exec.c
index 35bf7bd..a28336b 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -201,7 +201,7 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
}
catch (const gdb_exception_error &err)
{
- if (!exception_print_same (prev_err, err))
+ if (prev_err != err)
warning ("%s", err.what ());
}
}
diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
index 92f43d2..5933c73 100644
--- a/gdbsupport/common-exceptions.h
+++ b/gdbsupport/common-exceptions.h
@@ -165,6 +165,23 @@ struct gdb_exception
return message->c_str ();
}
+ /* Compare two exceptions. */
+ bool operator== (const gdb_exception &other) const
+ {
+ const char *msg1 = message == nullptr ? "" : what ();
+ const char *msg2 = other.message == nullptr ? "" : other.what ();
+
+ return (reason == other.reason
+ && error == other.error
+ && strcmp (msg1, msg2) == 0);
+ }
+
+ /* Compare two exceptions. */
+ bool operator!= (const gdb_exception &other) const
+ {
+ return !(*this == other);
+ }
+
enum return_reason reason;
enum errors error;
std::shared_ptr<std::string> message;