This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [Bug-readline] [readline patch, gdb-7.3?] Avoid free from a signal handler [Re: [PATCH] Make interrupting tab-completion safe.]
- From: Chet Ramey <chet dot ramey at case dot edu>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: chet dot ramey at case dot edu, bug-readline at gnu dot org, gdb-patches at sourceware dot org, Sterling Augustine <saugustine at google dot com>
- Date: Fri, 08 Jul 2011 10:26:21 -0400
- Subject: Re: [Bug-readline] [readline patch, gdb-7.3?] Avoid free from a signal handler [Re: [PATCH] Make interrupting tab-completion safe.]
- References: <BANLkTikW2qaihdZ2zGxx6K+4q8eGzFZOr3mcbPdZsJ+2Ra=YXQ@mail.gmail.com> <20110612121158.GA10611@host1.jankratochvil.net> <BANLkTik1Z5GoCjNP9enPJeLThVk=g9Aj5ZF6zeDULburd2w=bw@mail.gmail.com> <20110626222146.GA4410@host1.jankratochvil.net> <4E0B2E83.9030202@case.edu> <20110629203457.GA28353@host1.jankratochvil.net> <4E0C8A5D.7000807@case.edu> <20110706154621.GA17142@host1.jankratochvil.net> <110706155826.AA07325.SM@caleb.INS.CWRU.Edu> <20110706164400.GA31447@host1.jankratochvil.net> <4E15A220.4030404@case.edu>
- Reply-to: chet dot ramey at case dot edu
On 7/7/11 8:10 AM, I wrote:
>> I do not know if it is possible to code _rl_handle_signal in a way which uses
>> only the safe syscalls and only atomic operations on volatile data structures.
>> Anyway even if it would be possible I find such code very fragile and
>> I believe the signals should be always delayed through _rl_caught_signal.
>
> Ironically, I changed it to respond immediately to signals when in callback
> mode because of a bug you filed from gdb. When readline was reading input
> using rl_callback_read_char it did not respond quickly enough to SIGINT,
> and gdb didn't catch it. You will have to check and make sure the
> conditions have changed enough to make it acceptable to delay signal
> handling.
It occurs to me that this will not work unless I make changes to readline's
callback implementation. Currently readline installs its signal handlers
as part of the callback setup (rl_callback_handler_install ->
_rl_callback_newline). This results in a situation where readline's signal
handlers are active when the application has flow control. I imagine the
most likely scenario is that the application (gdb) is in a select() call
waiting for input when the signal arrives, readline sets a flag, and the
select call either restarts or returns -1/EINTR. Either way, gdb can't do
anything about it except guess.
The most straightforward solution would be to move the signal setup into
rl_callback_read_char, so readline's signal handlers are in place only
when readline has control. It's still important that the application
call rl_callback_handler_remove to restore the original signal handlers.
Once that's done, readline will not have to call signal handlers
synchronously when running in callback mode. Thoughts?
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/