This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]