From: Pedro Alves <pedro@palves.net>
To: Kevin Buettner <kevinb@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2 2/6] Handle gdb SIGTERM via normal QUIT processing
Date: Mon, 27 Sep 2021 18:39:11 +0100 [thread overview]
Message-ID: <a6e6d828-c8fd-c2ad-5af7-cbf955386fb1@palves.net> (raw)
In-Reply-To: <20210822231959.184061-3-kevinb@redhat.com>
Hi Kevin,
On 2021-08-23 12:19 a.m., Kevin Buettner wrote:
> When a GDB process receives the SIGTERM signal, handle_sigterm() in
> event-top.c is called. The global variable "sync_quit_force_run" is
> set by this signal handler. (It does some other things too, but the
> setting of this global is the important bit for the SIGTERM part of
> this discussion.)
>
> GDB will periodically check to see whether a Ctrl-C or SIGTERM has
> been received. This is indicated via use of the QUIT macro in
> GDB's code. QUIT is defined to invoke maybe_quit(), which will be
> periodically called during any lengthy operation. This ensures that
> the user won't have to wait too long for a Ctrl-C or SIGTERM to be
> acted upon.
>
> When a Ctrl-C / SIGINT is received, quit_handler() will decide
> whether to pass the SIGINT onto the inferior or to call quit()
> which (eventually) causes gdb_exception_quit to be thrown. This
> exception (usually) propagates to the top level. At that point,
> exception_print() is called to print the exception. Control
> is then returned to the top level event loop.
>
> At the moment, SIGTERM is handled very differently. Instead of
> throwing an exception, quit_force() is called. This does eventually
> cause GDB to exit(), but prior to that happening, the inferiors
> are killed or detached and other target related cleanup occurs.
> As shown in this discussion between Pedro Alves and myself...
>
> https://sourceware.org/pipermail/gdb-patches/2021-July/180802.html
> https://sourceware.org/pipermail/gdb-patches/2021-July/180902.html
> https://sourceware.org/pipermail/gdb-patches/2021-July/180903.html
>
> ...we found that it is possible for inferior_ptid and current_thread_
> to get out of sync. When that happens, the "current_thread_ != nullptr"
> assertion in inferior_thread() can fail resulting in a GDB internal
> error.
>
> Pedro recommended that we "let the normal quit exception propagate all
> the way to the top level, and then have the top level call quit_force
> if sync_quit_force_run is set."
>
> This commit implements the obvious part of Pedro's suggestion:
> Instead of calling quit_force from quit(), throw_quit() is now called
> instead. We leave sync_quit_force set for interrogation at a higher
> level.
With you up to here.
>
> At the top level, I found that the first thing done in each catch
> block is to call exception_print(). Thus I placed a check to
> see whether sync_quit_force is set within exception_print(). When
> it's set, quit_force() will be called.
But here, not so much. I don't think it's a good idea to do this
within expection_print. For example, nothing prevents some low level
code say within linux-nat.c to try/catch and print the exception, at a
point again where we're very deep in the target stack and shouldn't assume
much of global state.
>
> Making these changes fixed the failure / regression that I was seeing
> for gdb.base/gdb-sigterm.exp when run on a machine with glibc-2.34.
> However, there are many other paths back to the top level which this
> test case does not test. It seemed likely to me that some catch
> blocks might swallow a QUIT, not allowing it to get to the top level.
> The rest of the patches in this series deal with this concern.
next prev parent reply other threads:[~2021-09-27 17:43 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 via Gdb-patches
2021-08-22 23:19 ` [PATCH v2 1/6] Handle recursive internal problem in gdb_internal_error_resync Kevin Buettner via Gdb-patches
2021-09-27 17:38 ` Pedro Alves
2022-02-26 20:40 ` Kevin Buettner via Gdb-patches
2021-08-22 23:19 ` [PATCH v2 2/6] Handle gdb SIGTERM via normal QUIT processing Kevin Buettner via Gdb-patches
2021-09-27 17:39 ` Pedro Alves [this message]
2021-08-22 23:20 ` [PATCH v2 3/6] Catch and (re)throw gdb_exception_quit Kevin Buettner via Gdb-patches
2021-09-27 18:05 ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 4/6] Python QUIT processing updates Kevin Buettner via Gdb-patches
2021-09-27 18:24 ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 5/6] Guile " Kevin Buettner via Gdb-patches
2021-09-27 18:26 ` Pedro Alves
2021-08-22 23:20 ` [PATCH v2 6/6] QUIT processing w/ explicit sync_quit_force_run check Kevin Buettner via Gdb-patches
2021-09-27 18:34 ` Pedro Alves
2021-09-27 17:20 ` [PATCH v2 0/6] glibc-2.34: Fix gdb.base/gdb-sigterm.exp failure/error Kevin Buettner via Gdb-patches
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=a6e6d828-c8fd-c2ad-5af7-cbf955386fb1@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
/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