public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: tom@tromey.com, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] gdb: terminate upon receipt of SIGFPE
Date: Sat, 3 Jul 2021 19:02:50 +0100	[thread overview]
Message-ID: <fa201837-a240-6db1-d301-76d0b19488f2@palves.net> (raw)
In-Reply-To: <83wnq7j54g.fsf@gnu.org>

On 2021-07-03 7:14 a.m., Eli Zaretskii wrote:
>> From: Pedro Alves <pedro@palves.net>
>> Date: Fri, 2 Jul 2021 23:51:47 +0100
>>
>>> Eli> It is indeed a bad idea to return from a fatal signal handler, but
>>> Eli> terminating the GDB process is not the only safe alternative.  Another
>>> Eli> alternative is to longjmp from the signal handler to the top-level
>>> Eli> command loop.  Wouldn't that be better?
>>>
>>> I was also wondering if this would be possible -- treat it the way that
>>> gdb treats assertion failures and try to carry on.
>>
>> Unless restricted to some small defined area of code like what we do
>> with the demangler and SIGSEGV, I don't see that recovering very well, because
>> it will skip running C++ destructors, and we tend to have RAII objects
>> on the stack all the time.
> 
> Does this mean C++ doesn't allow recovering from a fatal signal?

(Note that even in C -- if you siglongjmp and skip a bunch of manual
unwinding / restoring state in mainline code, then the program will be broken too.
If we were still using C and old C-base implementation of exceptions/cleanups, then
we'd siglongjmp up to the closest sigsetjmp, not to the top level.
Longjmping to the top level directly would likely result in a broken
GDB in a similar way.)

> Isn't there some way of converting a signal into a C++ exception, and
> then unwinding "the C++ way"?
> 

Not with standard C++.  Though as an extension, with GCC, if we build GDB
with -fnon-call-exceptions, then we can throw from trapping instructions:

 -fnon-call-exceptions
 Generate code that allows trapping instructions to throw exceptions. Note that this requires platform-specific runtime support
 that does not exist everywhere. Moreover, it only allows trapping instructions to throw exceptions, i.e. memory references
 or floating  point instructions. It does not allow exceptions to be thrown from arbitrary signal handlers such as SIGALRM.

I don't know how portable that is, but I think the Ada and Go frontends rely
on it, so it's probably solid.

I compared '-O2' vs '-O2 -fnon-call-exceptions' builds for code size, and
the binary grew about 3%:

 $ size gdb.O2
    text    data     bss     dec     hex filename
 9332146  918258  151232 10401636         9eb764 gdb.O2
 
 $ size gdb.O2-fnon-call-exceptions
    text    data     bss     dec     hex filename
 9628267  918882  151232 10698381         a33e8d gdb.O2-fnon-call-exceptions

For Windows I think we'd need to use SEH instead and register a translator 
with _set_se_translator, but I don't know the status of SEH support in
mingw nowadays.

  reply	other threads:[~2021-07-03 18:02 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02 11:06 [PATCH 0/5] GDB Synchronous Signal Handling Andrew Burgess
2021-07-02 11:06 ` [PATCH 1/5] gdb: terminate upon receipt of SIGFPE Andrew Burgess
2021-07-02 12:09   ` Eli Zaretskii
2021-07-02 18:11     ` Tom Tromey
2021-07-02 22:51       ` Pedro Alves
2021-07-03  6:14         ` Eli Zaretskii
2021-07-03 18:02           ` Pedro Alves [this message]
2021-07-03 18:23             ` Eli Zaretskii
2021-07-03 22:52               ` Pedro Alves
2021-07-04  4:27                 ` Eli Zaretskii
2021-07-04 14:51                   ` Pedro Alves
2021-07-04 16:31                     ` Eli Zaretskii
2021-07-03 22:58   ` Pedro Alves
2021-07-02 11:06 ` [PATCH 2/5] gdb: register signal handler after setting up event token Andrew Burgess
2021-07-03 23:02   ` Pedro Alves
2021-07-02 11:06 ` [PATCH 3/5] gdb: rewrite header comment on async_init_signals Andrew Burgess
2021-07-03 23:23   ` Pedro Alves
2021-07-02 11:06 ` [PATCH 4/5] gdb: print backtrace on fatal SIGSEGV Andrew Burgess
2021-07-02 11:47   ` Eli Zaretskii
2021-07-04  0:55     ` Pedro Alves
2021-07-04  4:32       ` Eli Zaretskii
2021-07-04 14:32         ` Pedro Alves
2021-07-04 14:38           ` Eli Zaretskii
2021-07-04 15:03             ` Pedro Alves
2021-07-04 16:34               ` Eli Zaretskii
2021-07-04  0:51   ` Pedro Alves
2021-07-04  0:53   ` Pedro Alves
2021-07-02 11:06 ` [PATCH 5/5] gdb: register SIGBUS, SIGFPE, and SIGABRT handlers Andrew Burgess
2021-07-04  0:58   ` Pedro Alves
2021-07-21 18:08 ` [PATCHv2 0/6] GDB Synchronous Signal Handling Andrew Burgess
2021-07-21 18:08   ` [PATCHv2 1/6] gdb: terminate upon receipt of SIGFPE Andrew Burgess
2021-07-21 18:08   ` [PATCHv2 2/6] gdb: register signal handler after setting up event token Andrew Burgess
2021-07-21 18:08   ` [PATCHv2 3/6] gdb: rename async_init_signals to gdb_init_signals Andrew Burgess
2021-07-21 18:08   ` [PATCHv2 4/6] gdb: print backtrace on fatal SIGSEGV Andrew Burgess
2021-08-10 18:53     ` Pedro Alves
2021-07-21 18:08   ` [PATCHv2 5/6] gdb: register SIGBUS, SIGFPE, and SIGABRT handlers Andrew Burgess
2021-07-21 18:08   ` [PATCHv2 6/6] gdb: don't print backtrace when dumping core after an internal error Andrew Burgess
2021-07-27 18:54   ` [PATCHv2 0/6] GDB Synchronous Signal Handling Tom Tromey
2021-08-10  9:33   ` Andrew Burgess
2021-08-10 18:56     ` 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=fa201837-a240-6db1-d301-76d0b19488f2@palves.net \
    --to=pedro@palves.net \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).