public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Replace exception_print_same with operator!=
@ 2021-07-29 23:13 Tom Tromey
  2021-07-30  2:13 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-07-29 23:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.
---
 gdb/exceptions.c               | 14 --------------
 gdb/exec.c                     |  2 +-
 gdbsupport/common-exceptions.h | 17 +++++++++++++++++
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 32db6fe8235..5245b7ca28d 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/exec.c b/gdb/exec.c
index 35bf7bd4506..a28336be8ef 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 92f43d267ad..5933c7356fe 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;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Replace exception_print_same with operator!=
  2021-07-29 23:13 [PATCH] Replace exception_print_same with operator!= Tom Tromey
@ 2021-07-30  2:13 ` Simon Marchi
  2021-07-30 14:37   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-07-30  2:13 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2021-07-29 7:13 p.m., Tom Tromey wrote:
> 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.

I think the declaration should be removed as well, otherwise LGTM.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Replace exception_print_same with operator!=
  2021-07-30  2:13 ` Simon Marchi
@ 2021-07-30 14:37   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2021-07-30 14:37 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> On 2021-07-29 7:13 p.m., Tom Tromey wrote:
>> 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.

Simon> I think the declaration should be removed as well, otherwise LGTM.

Oops, I thought I did this.
I'll be sure to do it before pushing.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-30 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 23:13 [PATCH] Replace exception_print_same with operator!= Tom Tromey
2021-07-30  2:13 ` Simon Marchi
2021-07-30 14:37   ` Tom Tromey

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).