public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Specialize std::hash for gdb_exception
Date: Tue, 12 Apr 2022 15:40:11 +0000 (GMT)	[thread overview]
Message-ID: <20220412154011.24605385840C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=85098eeb4c47debd67c793477bd04d33ab1a5645

commit 85098eeb4c47debd67c793477bd04d33ab1a5645
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Sep 6 15:22:44 2021 -0600

    Specialize std::hash for gdb_exception
    
    This adds a std::hash specialization for gdb_exception.  This lets us
    store these objects in a hash table, which is used later in this
    series to de-duplicate the exception output from multiple threads.

Diff:
---
 gdbsupport/common-exceptions.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
index b7e6f2dd7ca..543afda508a 100644
--- a/gdbsupport/common-exceptions.h
+++ b/gdbsupport/common-exceptions.h
@@ -24,6 +24,7 @@
 #include <new>
 #include <memory>
 #include <string>
+#include <functional>
 
 /* Reasons for calling throw_exceptions().  NOTE: all reason values
    must be different from zero.  enum value 0 is reserved for internal
@@ -187,6 +188,24 @@ struct gdb_exception
   std::shared_ptr<std::string> message;
 };
 
+namespace std
+{
+
+/* Specialization of std::hash for gdb_exception.  */
+template<>
+struct hash<gdb_exception>
+{
+  size_t operator() (const gdb_exception &exc) const
+  {
+    size_t result = exc.reason + exc.error;
+    if (exc.message != nullptr)
+      result += std::hash<std::string> {} (*exc.message);
+    return result;
+  }
+};
+
+}
+
 /* Functions to drive the sjlj-based exceptions state machine.  Though
    declared here by necessity, these functions should be considered
    internal to the exceptions subsystem and not used other than via


                 reply	other threads:[~2022-04-12 15:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220412154011.24605385840C@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).