public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Specialize std::hash for gdb_exception
@ 2022-04-12 15:40 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-12 15:40 UTC (permalink / raw)
To: gdb-cvs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-12 15:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 15:40 [binutils-gdb] Specialize std::hash for gdb_exception Tom Tromey
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).