public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/6] QUIT processing w/ explicit sync_quit_force_run check
Date: Sun, 22 Aug 2021 16:20:04 -0700	[thread overview]
Message-ID: <20210822231959.184061-7-kevinb@redhat.com> (raw)
In-Reply-To: <20210822231959.184061-1-kevinb@redhat.com>

Aside from the extension language updates, I found two other
cases which required explicit checks of sync_quit_force_run...

1) remote_fileio_request in gdb/remote-fileio.c:

The try block calls do_remote_fileio_request which can (in turn)
call one of the functions in remote_fio_func_map[].  Taking the
first one, remote_fileio_func_open(), we have the following call
path to maybe_quit():

  "_ZL23remote_fileio_func_openP13remote_targetPc"
    -> "_Z18target_read_memorymPhl"
    -> "_Z11target_readP10target_ops13target_objectPKcPhml"
    -> "_Z10maybe_quitv";

Since there is a path to maybe_quit(), we must ensure that the
catch block is not permitted to swallow a QUIT representing a
SIGTERM.

However, for this case, we must take care not to change the way
that Ctrl-C / SIGINT is handled; we want to send a suitable
EINTR reply to the remote target should that happen.  That
being the case, I added an explicit check for sync_quit_force_run;
if set, it rethrows the exception.

2) mi_execute_command in gdb/mi/mi-main.c:

The try block calls captured_mi_execute_command(); there exists
a call path to maybe_quit():

  "_ZL27captured_mi_execute_commandP6ui_outP8mi_parse"
    -> "_ZL14mi_cmd_executeP8mi_parse"
    -> "_Z17get_current_framev"
    -> "_ZL23get_prev_frame_always_1P10frame_info"
    -> "_ZL30frame_register_unwind_locationP10frame_infoiPiP9lval_typePmS1_"
    -> "_Z21frame_register_unwindP10frame_infoiPiS1_P9lval_typePmS1_Ph"
    -> "_Z24value_entirely_availableP5value"
    -> "_Z16value_fetch_lazyP5value"
    -> "_ZL23value_fetch_lazy_memoryP5value"
    -> "_Z17read_value_memoryP5valuelimPhm"
    -> "_Z10maybe_quitv";

That being the case, we can't allow the exception handler (catch block)
to swallow a gdb_exception_quit for SIGTERM.  However, it does seem
reasonable to output the exception via the mi interface so that some
suitable message regarding SIGTERM might be printed; therefore, I
do the check of sync_quit_force_run and the potential throw at the
end of the catch block.

(While doing all of this, it's occurred to me that these checks of the
global could be avoided by introducing a new exception for SIGTERM.
I haven't explored the implications of doing this though.)
---
 gdb/mi/mi-main.c    | 4 ++++
 gdb/remote-fileio.c | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index e293dddc08d..74a02f2b58d 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1962,6 +1962,10 @@ mi_execute_command (const char *cmd, int from_tty)
 	     somewhere.  */
 	  mi_print_exception (command->token, result);
 	  mi_out_rewind (current_uiout);
+
+	  /* Throw to a higher level catch for SIGTERM sent to GDB.  */
+	  if (sync_quit_force_run)
+	    throw;
 	}
 
       bpstat_do_actions ();
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 9765093a723..e4965acaad6 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1194,7 +1194,13 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p)
       catch (const gdb_exception &ex)
 	{
 	  if (ex.reason == RETURN_QUIT)
-	    remote_fileio_reply (remote, -1, FILEIO_EINTR);
+	    {
+	      /* Throw to a higher level catch for SIGTERM sent to GDB.  */
+	      if (sync_quit_force_run)
+		throw;
+
+	      remote_fileio_reply (remote, -1, FILEIO_EINTR);
+	    }
 	  else
 	    remote_fileio_reply (remote, -1, FILEIO_EIO);
 	}
-- 
2.31.1


  parent reply	other threads:[~2021-08-22 23:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-22 23:19 [PATCH v2 0/6] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner
2021-08-22 23:19 ` [PATCH v2 1/6] Handle recursive internal problem in gdb_internal_error_resync Kevin Buettner
2021-09-27 17:38   ` Pedro Alves
2022-02-26 20:40     ` Kevin Buettner
2021-08-22 23:19 ` [PATCH v2 2/6] Handle gdb SIGTERM via normal QUIT processing Kevin Buettner
2021-09-27 17:39   ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 3/6] Catch and (re)throw gdb_exception_quit Kevin Buettner
2021-09-27 18:05   ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 4/6] Python QUIT processing updates Kevin Buettner
2021-09-27 18:24   ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 5/6] Guile " Kevin Buettner
2021-09-27 18:26   ` Pedro Alves
2021-08-22 23:20 ` Kevin Buettner [this message]
2021-09-27 18:34   ` [PATCH v2 6/6] QUIT processing w/ explicit sync_quit_force_run check Pedro Alves
2021-09-27 17:20 ` [PATCH v2 0/6] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner

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=20210822231959.184061-7-kevinb@redhat.com \
    --to=kevinb@redhat.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).