Re: PATCH: PR tui/2173: Arrow keys no longer works in breakpoint command list

Jan Kratochvil
2006-12-17T23:46:08Z

On Sun, 03 Dec 2006 06:25:29 +0100, Chet Ramey wrote:
...
> More appropriate in the sense that the application controls the state
> and switches between the callback and synchronous readline modes.
> Since it's the app that's supposed to be calling into readline when in
> callback mode anyway, I think this patch will work better.

Chet, is it right it is more a design than implementation problem of readline?
readline cannot determine how many nested readline calls have been abandoned by
signal handler's longjmp (). Therefore it cannot determine if the current mode
(the last unabandoned call) is a callback or synchronous one.

The sample code should be readline documentation compliant, still the called
function `_rl_next_macro_key' has undeterministic value of
`RL_ISSTATE (RL_STATE_CALLBACK)'.

Also any longjmp () from inside a signal handler is too dangerous as the data
structures are not locked against signals. The signal handler should only set
some flag. And the synchronous readline () function should be never used if
one needs to quit the input mode by SIGINT (as one cannot abort readline () if
not using the dangerous longjmp ()).

IMO the right way is to stop using longjmp from GDB's signal handlers.
Therefore to always use callbacked readline and stop the loop if detected
a flag set by the installed signal handler.

Thanks for info,
Jan

------------------------------------------------------------------------------

main ()
{
if (setjmp (buf_A))
{
rl_read_key (); /* -> _rl_next_macro_key () */
}
signal (SIGINT, handle_SIGINT_at_A);
readline("mode-A");
...
}
handle_SIGINT_at_A ()
{
if (setjmp (buf_B))
{
rl_read_key (); /* -> _rl_next_macro_key () */
}
signal (SIGINT, handle_SIGINT_at_B);
rl_callback_handler_install ("mode-B", mode_B_command);
for (;;)
rl_callback_read_char ();
}
handle_SIGINT_at_B ()
{
if (rand () & 1)
longjmp (buf_A);
else
longjmp (buf_B);
}