aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-01-28 10:56:58 -0700
committerTom Tromey <tom@tromey.com>2019-04-08 09:05:41 -0600
commit26003a205e207db7985c32ec1964a04652b68413 (patch)
tree9800bd8e170266abe2ecc4f07972ba47f88429ff /gdb
parentd272eb370a4c086a1d0f86a7a94e89328ec8d97e (diff)
downloadfsf-binutils-gdb-26003a205e207db7985c32ec1964a04652b68413.zip
fsf-binutils-gdb-26003a205e207db7985c32ec1964a04652b68413.tar.gz
fsf-binutils-gdb-26003a205e207db7985c32ec1964a04652b68413.tar.bz2
Make exception throwing a bit more efficient
This makes exception throwing a bit more efficient, by removing some copies. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.c (throw_exception): Rename from throw_exception_cxx. Remove old copy. Make argument const. (throw_it): Create and throw exception objects directly. * common/common-exceptions.h (throw_exception): Make argument const. (struct gdb_exception_error): Add constructor. (struct gdb_exception_quit): Add constructor.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/common/common-exceptions.c33
-rw-r--r--gdb/common/common-exceptions.h12
3 files changed, 37 insertions, 18 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 36b6b61..a0d8d09 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
2019-04-08 Tom Tromey <tom@tromey.com>
+ * common/common-exceptions.c (throw_exception): Rename from
+ throw_exception_cxx. Remove old copy. Make argument const.
+ (throw_it): Create and throw exception objects directly.
+ * common/common-exceptions.h (throw_exception): Make argument
+ const.
+ (struct gdb_exception_error): Add constructor.
+ (struct gdb_exception_quit): Add constructor.
+
+2019-04-08 Tom Tromey <tom@tromey.com>
+
* common/common-exceptions.h (exception_rethrow): Don't declare.
(TRY_SJLJ): Update comment.
(TRY, CATCH, END_CATCH): Remove.
diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index d3c01e5..83f2c74 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -180,8 +180,8 @@ throw_exception_sjlj (struct gdb_exception exception)
/* Implementation of throw_exception that uses C++ try/catch. */
-static ATTRIBUTE_NORETURN void
-throw_exception_cxx (struct gdb_exception exception)
+void
+throw_exception (const gdb_exception &exception)
{
if (exception.reason == RETURN_QUIT)
{
@@ -197,25 +197,24 @@ throw_exception_cxx (struct gdb_exception exception)
gdb_assert_not_reached ("invalid return reason");
}
-void
-throw_exception (struct gdb_exception exception)
-{
- throw_exception_cxx (exception);
-}
-
static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0)
throw_it (enum return_reason reason, enum errors error, const char *fmt,
va_list ap)
{
- struct gdb_exception e;
-
- /* Create the exception. */
- e.reason = reason;
- e.error = error;
- e.message.reset (new std::string (string_vprintf (fmt, ap)));
-
- /* Throw the exception. */
- throw_exception (e);
+ if (reason == RETURN_QUIT)
+ {
+ gdb_exception_quit ex (reason, error);
+ ex.message.reset (new std::string (string_vprintf (fmt, ap)));
+ throw ex;
+ }
+ else if (reason == RETURN_ERROR)
+ {
+ gdb_exception_error ex (reason, error);
+ ex.message.reset (new std::string (string_vprintf (fmt, ap)));
+ throw ex;
+ }
+ else
+ gdb_assert_not_reached ("invalid return reason");
}
void
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index b09a34b..1aedb83 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -214,6 +214,11 @@ extern int exceptions_state_mc_catch (struct gdb_exception *, int);
struct gdb_exception_error : public gdb_exception
{
+ gdb_exception_error (enum return_reason r, enum errors e)
+ : gdb_exception (r, e)
+ {
+ }
+
explicit gdb_exception_error (const gdb_exception &ex) noexcept
: gdb_exception (ex)
{
@@ -222,6 +227,11 @@ struct gdb_exception_error : public gdb_exception
struct gdb_exception_quit : public gdb_exception
{
+ gdb_exception_quit (enum return_reason r, enum errors e)
+ : gdb_exception (r, e)
+ {
+ }
+
explicit gdb_exception_quit (const gdb_exception &ex) noexcept
: gdb_exception (ex)
{
@@ -250,7 +260,7 @@ struct gdb_quit_bad_alloc
/* Throw an exception (as described by "struct gdb_exception"),
landing in the inner most containing exception handler established
using TRY/CATCH. */
-extern void throw_exception (struct gdb_exception exception)
+extern void throw_exception (const gdb_exception &exception)
ATTRIBUTE_NORETURN;
/* Throw an exception by executing a LONG JUMP to the inner most