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 v3 6/7] QUIT processing w/ explicit throw for gdb_exception_forced_quit
Date: Sat, 26 Feb 2022 17:00:50 -0700	[thread overview]
Message-ID: <20220227000051.3336149-7-kevinb@redhat.com> (raw)
In-Reply-To: <20220227000051.3336149-1-kevinb@redhat.com>

This commit contains changes which have an explicit throw for
gdb_exception_forced_quit, or, in a couple of cases for gdb_exception,
but with a throw following a check to see if 'reason' is
RETURN_FORCED_QUIT.

Most of these are straightforward - it made sense to continue to allow
an existing catch of gdb_exception to also catch gdb_exception_quit;
in these cases, a catch/throw for gdb_exception_forced_quit was added.

There are two cases, however, which deserve a more detailed
explanation.

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():

  remote_fileio_func_open(remote_target*, char*)
    -> target_read_memory(unsigned long, unsigned char*, long)
    -> target_read(target_ops*, target_object, char const*, unsigned char*, unsigned long, long)
    -> maybe_quit()

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 a
catch/throw for gdb_exception_forced_quit.  I also did a bit of
rewriting here, adding a catch for gdb_exception_quit in favor of
checking the 'reason' code in the catch block for gdb_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():

  captured_mi_execute_command(ui_out*, mi_parse*)
    -> mi_cmd_execute(mi_parse*)
    -> get_current_frame()
    -> get_prev_frame_always_1(frame_info*)
    -> frame_register_unwind_location(frame_info*, int, int*, lval_type*, unsigned long*, int*)
    -> frame_register_unwind(frame_info*, int, int*, int*, lval_type*, unsigned long*, int*, unsigned char*)
    -> value_entirely_available(value*)
    -> value_fetch_lazy(value*)
    -> value_fetch_lazy_memory(value*)
    -> read_value_memory(value*, long, int, unsigned long, unsigned char*, unsigned long)
    -> maybe_quit()

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
check the exception's 'reason' field for RETURN_FORCED_QUIT and
do a throw for this case.
---
 gdb/event-top.c     |  2 ++
 gdb/mi/mi-main.c    |  4 ++++
 gdb/remote-fileio.c | 15 ++++++++++-----
 gdb/tui/tui-io.c    |  4 ++++
 gdb/tui/tui.c       |  4 ++++
 gdb/windows-nat.c   |  4 ++++
 6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 8890c4fae2d..bef70ccbcdc 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1224,6 +1224,8 @@ async_disconnect (gdb_client_data arg)
       fputs_filtered ("Could not kill the program being debugged",
 		      gdb_stderr);
       exception_print (gdb_stderr, exception);
+      if (exception.reason == RETURN_FORCED_QUIT)
+        throw;
     }
 
   for (inferior *inf : all_inferiors ())
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 4860da7536a..b74a1e2034f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1959,6 +1959,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 (result.reason == RETURN_FORCED_QUIT)
+	    throw;
 	}
 
       bpstat_do_actions ();
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 9963f1ebc01..1a0d9452d6f 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1191,12 +1191,17 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p)
 	{
 	  do_remote_fileio_request (remote, buf);
 	}
-      catch (const gdb_exception &ex)
+      catch (const gdb_exception_forced_quit &ex)
+        {
+	  throw;
+	}
+      catch (const gdb_exception_quit &ex)
 	{
-	  if (ex.reason == RETURN_QUIT)
-	    remote_fileio_reply (remote, -1, FILEIO_EINTR);
-	  else
-	    remote_fileio_reply (remote, -1, FILEIO_EIO);
+	  remote_fileio_reply (remote, -1, FILEIO_EINTR);
+	}
+      catch (const gdb_exception &ex)
+        {
+	  remote_fileio_reply (remote, -1, FILEIO_EIO);
 	}
     }
 
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 8cac1c40f13..4f6f7513142 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -1259,6 +1259,10 @@ tui_getc (FILE *fp)
     {
       return tui_getc_1 (fp);
     }
+  catch (const gdb_exception_forced_quit &ex)
+    {
+      throw;
+    }
   catch (const gdb_exception &ex)
     {
       /* Just in case, don't ever let an exception escape to readline.
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 776dccf0bb2..bba493fcdb8 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -109,6 +109,10 @@ tui_rl_switch_mode (int notused1, int notused2)
 	  tui_enable ();
 	}
     }
+  catch (const gdb_exception_forced_quit &ex)
+    {
+      throw;
+    }
   catch (const gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 81e26fe4759..0f77bc94705 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -825,6 +825,10 @@ catch_errors (void (*func) ())
     {
       func ();
     }
+  catch (const gdb_exception_forced_quit &ex)
+    {
+      throw;
+    }
   catch (const gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
-- 
2.35.1


  parent reply	other threads:[~2022-02-27  0:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-27  0:00 [PATCH v3 0/7] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner
2022-02-27  0:00 ` [PATCH v3 1/7] Introduce gdb_exception_forced_quit Kevin Buettner
2022-02-27  0:00 ` [PATCH v3 2/7] Handle gdb SIGTERM by throwing / catching gdb_exception_force_quit Kevin Buettner
2022-02-27  0:00 ` [PATCH v3 3/7] Catch gdb_exception_error instead of gdb_exception (in many places) Kevin Buettner
2022-03-03 21:11   ` Pedro Alves
2022-02-27  0:00 ` [PATCH v3 4/7] Python QUIT processing updates Kevin Buettner
2022-02-27  0:00 ` [PATCH v3 5/7] Guile " Kevin Buettner
2022-02-27  0:00 ` Kevin Buettner [this message]
2022-03-03 21:26   ` [PATCH v3 6/7] QUIT processing w/ explicit throw for gdb_exception_forced_quit Pedro Alves
2022-02-27  0:00 ` [PATCH v3 7/7] Handle QUIT processing in the scoped_switch_fork_info destructor Kevin Buettner
2022-07-20  1:53 ` [PATCH v3 0/7] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Simon Marchi
2023-01-05 13:35   ` Tom de Vries
2023-01-10 15:19     ` 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=20220227000051.3336149-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).