From 85098eeb4c47debd67c793477bd04d33ab1a5645 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 6 Sep 2021 15:22:44 -0600 Subject: [PATCH] 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. --- 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 /* 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 -- 2.30.2