diff options
author | Tom Tromey <tom@tromey.com> | 2021-09-06 15:22:44 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-04-12 09:31:16 -0600 |
commit | 85098eeb4c47debd67c793477bd04d33ab1a5645 (patch) | |
tree | a852aec0112f72156d80e392eb583e8e02fee457 /gdbsupport | |
parent | f4565e4c99e768d3bcf2998979528569a65d8417 (diff) | |
download | binutils-85098eeb4c47debd67c793477bd04d33ab1a5645.zip binutils-85098eeb4c47debd67c793477bd04d33ab1a5645.tar.gz binutils-85098eeb4c47debd67c793477bd04d33ab1a5645.tar.bz2 |
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.
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/common-exceptions.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h index b7e6f2d..543afda 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 |