From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 24605385840C; Tue, 12 Apr 2022 15:40:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24605385840C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Specialize std::hash for gdb_exception X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: f4565e4c99e768d3bcf2998979528569a65d8417 X-Git-Newrev: 85098eeb4c47debd67c793477bd04d33ab1a5645 Message-Id: <20220412154011.24605385840C@sourceware.org> Date: Tue, 12 Apr 2022 15:40:11 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 15:40:11 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D85098eeb4c47= debd67c793477bd04d33ab1a5645 commit 85098eeb4c47debd67c793477bd04d33ab1a5645 Author: Tom Tromey Date: Mon Sep 6 15:22:44 2021 -0600 Specialize std::hash for gdb_exception =20 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 #include #include +#include =20 /* 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 message; }; =20 +namespace std +{ + +/* Specialization of std::hash for gdb_exception. */ +template<> +struct hash +{ + size_t operator() (const gdb_exception &exc) const + { + size_t result =3D exc.reason + exc.error; + if (exc.message !=3D nullptr) + result +=3D std::hash {} (*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