From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/5] Make SJLJ exceptions more efficient
Date: Thu, 25 Apr 2019 16:53:00 -0000 [thread overview]
Message-ID: <20190425165256.31226-3-tromey@adacore.com> (raw)
In-Reply-To: <20190425165256.31226-1-tromey@adacore.com>
This changes the SJLJ exception handling code to be a bit more
efficient, by using rvalue references and move assignment when
possible.
Tested by the buildbot.
gdb/ChangeLog
2019-04-25 Tom Tromey <tromey@adacore.com>
* event-top.c (gdb_rl_callback_read_char_wrapper_noexcept)
(gdb_rl_callback_handler): Use std::move.
* common/common-exceptions.h (struct gdb_exception): Add move
assignment operator.
(throw_exception_sjlj): Change "exception" to const reference.
* common/common-exceptions.c (exceptions_state_mc_catch): Update.
(throw_exception_sjlj): Change "exception" to const reference.
---
gdb/ChangeLog | 10 ++++++++++
gdb/common/common-exceptions.c | 5 +++--
gdb/common/common-exceptions.h | 4 +++-
gdb/event-top.c | 6 +++---
4 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 59c27ab52d4..0b96cc679da 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -166,14 +166,15 @@ exceptions_state_mc_action_iter_1 (void)
/* Return EXCEPTION to the nearest containing CATCH_SJLJ block. */
void
-throw_exception_sjlj (struct gdb_exception exception)
+throw_exception_sjlj (const struct gdb_exception &exception)
{
/* Jump to the nearest CATCH_SJLJ block, communicating REASON to
that call via setjmp's return value. Note that REASON can't be
zero, by definition in common-exceptions.h. */
exceptions_state_mc (CATCH_THROWING);
+ enum return_reason reason = exception.reason;
catchers.front ().exception = exception;
- longjmp (catchers.front ().buf, exception.reason);
+ longjmp (catchers.front ().buf, reason);
}
/* Implementation of throw_exception that uses C++ try/catch. */
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index 33fa8a92ec2..d7b25502262 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -152,6 +152,8 @@ struct gdb_exception
return *this;
}
+ gdb_exception &operator= (gdb_exception &&other) noexcept = default;
+
/* Return the contents of the exception message, as a C string. The
string remains owned by the exception object. */
const char *what () const noexcept
@@ -281,7 +283,7 @@ extern void throw_exception (const gdb_exception &exception)
containing exception handler established using TRY_SJLJ. Necessary
in some cases where we need to throw GDB exceptions across
third-party library code (e.g., readline). */
-extern void throw_exception_sjlj (struct gdb_exception exception)
+extern void throw_exception_sjlj (const struct gdb_exception &exception)
ATTRIBUTE_NORETURN;
/* Convenience wrappers around throw_exception that throw GDB
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 959792d9e7a..bb8ba5cfe57 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -178,7 +178,7 @@ gdb_rl_callback_read_char_wrapper_noexcept () noexcept
}
CATCH_SJLJ (ex, RETURN_MASK_ALL)
{
- gdb_expt = ex;
+ gdb_expt = std::move (ex);
}
END_CATCH_SJLJ
@@ -212,9 +212,9 @@ gdb_rl_callback_handler (char *rl) noexcept
{
ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
}
- catch (const gdb_exception &ex)
+ catch (gdb_exception &ex)
{
- gdb_rl_expt = ex;
+ gdb_rl_expt = std::move (ex);
}
/* If we caught a GDB exception, longjmp out of the readline
--
2.20.1
next prev parent reply other threads:[~2019-04-25 16:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-25 16:53 [PATCH 0/5] More exception-handling improvements Tom Tromey
2019-04-25 16:53 ` [PATCH 1/5] Remove exception_none Tom Tromey
2019-04-25 16:53 ` Tom Tromey [this message]
2019-04-25 16:53 ` [PATCH 3/5] Avoid undefined behavior in Guile exception handling Tom Tromey
2019-04-25 16:58 ` [PATCH 5/5] Fix memory leak in exception code Tom Tromey
2019-04-25 18:06 ` Pedro Alves
2019-04-25 18:18 ` Tom Tromey
2019-04-25 18:30 ` Tom Tromey
2019-04-25 18:38 ` Pedro Alves
2019-04-25 18:50 ` Tom Tromey
2019-04-25 16:58 ` [PATCH 4/5] Make exception handling more efficient Tom Tromey
2019-04-25 18:08 ` [PATCH 0/5] More exception-handling improvements Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190425165256.31226-3-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).