From: Tom Tromey Date: Mon, 6 Sep 2021 21:22:44 +0000 (-0600) Subject: Specialize std::hash for gdb_exception X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=85098eeb4c47debd67c793477bd04d33ab1a5645;p=binutils-gdb.git 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 --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 /* 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; }; +namespace std +{ + +/* Specialization of std::hash for gdb_exception. */ +template<> +struct hash +{ + size_t operator() (const gdb_exception &exc) const + { + size_t result = exc.reason + exc.error; + if (exc.message != nullptr) + result += 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