mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
91395d97d9
This commit replaces an earlier commit that worked around the issues reported in bug PR gdb/28833. The previous commit just implemented a work around in order to avoid the worst results of the bug, but was not a complete solution. The full solution was considered too risky to merge close to branching GDB 12. This improved fix has been applied after GDB 12 branched. See this thread for more details: https://sourceware.org/pipermail/gdb-patches/2022-March/186391.html This commit replaces this earlier commit: commit 74a159a420d4b466cc81061c16d444568e36740c Date: Fri Mar 11 14:44:03 2022 +0000 gdb: work around prompt corruption caused by bracketed-paste-mode Please read that commit for a full description of the bug, and why is occurs. In this commit I extend GDB to use readline's rl_deprep_term_function hook to call a new function gdb_rl_deprep_term_function. From this new function we can now print the 'quit' message, this replaces the old printing of 'quit' in command_line_handler. Of course, we only print 'quit' in gdb_rl_deprep_term_function when we are handling EOF, but thanks to the previous commit (to readline) we now know when this is. There are two aspects of this commit that are worth further discussion, the first is in the new gdb_rl_deprep_term_function function. In here I have used a scoped_restore_tmpl to disable the readline global variable rl_eof_found. The reason for this is that, in rl_deprep_terminal, readline will print an extra '\n' character before printing the escape sequence to leave bracketed paste mode. You might then think that in the gdb_rl_deprep_term_function function, we could simply print "quit" and rely on rl_deprep_terminal to print the trailing '\n'. However, rl_deprep_terminal only prints the '\n' when bracketed paste mode is on. If the user has turned this feature off, no '\n' is printed. This means that in gdb_rl_deprep_term_function we need to print "quit" when bracketed paste mode is on, and "quit\n" when bracketed paste mode is off. We could absolutely do that, no problem, but given we know how rl_deprep_terminal is implemented, it's easier (I think) to just temporarily clear rl_eof_found, this prevents the '\n' being printed from rl_deprep_terminal, and so in gdb_rl_deprep_term_function, we can now always print "quit\n" and this works for all cases. The second issue that should be discussed is backwards compatibility with older versions of readline. GDB can be built against the system readline, which might be older than the version contained within GDB's tree. If this is the case then the system readline might not contain the fixes needed to support correctly printing the 'quit' string. To handle this situation I have retained the existing code in command_line_handler for printing 'quit', however, this code is only used now if the version of readline we are using doesn't not include the required fixes. And so, if a user is using an older version of readline, and they have bracketed paste mode on, then they will see the 'quit' sting printed on the line below the prompt, like this: (gdb) quit I think this is the best we can do when someone builds GDB against an older version of readline. Using a newer version of readline, or the patched version of readline that is in-tree, will now give a result like this in all cases: (gdb) quit Which is what we want. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833
95 lines
3.2 KiB
C++
95 lines
3.2 KiB
C++
/* Definitions used by event-top.c, for GDB, the GNU debugger.
|
|
|
|
Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
|
|
|
Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef EVENT_TOP_H
|
|
#define EVENT_TOP_H
|
|
|
|
#include <signal.h>
|
|
|
|
struct cmd_list_element;
|
|
|
|
/* Exported functions from event-top.c.
|
|
FIXME: these should really go into top.h. */
|
|
|
|
extern void display_gdb_prompt (const char *new_prompt);
|
|
extern void gdb_setup_readline (int);
|
|
extern void gdb_disable_readline (void);
|
|
extern void gdb_init_signals (void);
|
|
extern void change_line_handler (int);
|
|
|
|
extern void command_line_handler (gdb::unique_xmalloc_ptr<char> &&rl);
|
|
extern void command_handler (const char *command);
|
|
|
|
#ifdef SIGTSTP
|
|
extern void handle_sigtstp (int sig);
|
|
#endif
|
|
|
|
extern void handle_sigint (int sig);
|
|
extern void handle_sigterm (int sig);
|
|
extern void async_request_quit (void *arg);
|
|
extern void stdin_event_handler (int error, void *client_data);
|
|
extern void async_disable_stdin (void);
|
|
extern void async_enable_stdin (void);
|
|
|
|
/* Exported variables from event-top.c.
|
|
FIXME: these should really go into top.h. */
|
|
|
|
extern bool set_editing_cmd_var;
|
|
extern bool exec_done_display_p;
|
|
extern struct prompts the_prompts;
|
|
extern void (*after_char_processing_hook) (void);
|
|
extern int call_stdin_event_handler_again_p;
|
|
extern void gdb_readline_no_editing_callback (void *client_data);
|
|
|
|
/* Wrappers for rl_callback_handler_remove and
|
|
rl_callback_handler_install that keep track of whether the callback
|
|
handler is installed in readline. Do not call the readline
|
|
versions directly. */
|
|
extern void gdb_rl_callback_handler_remove (void);
|
|
extern void gdb_rl_callback_handler_install (const char *prompt);
|
|
|
|
/* Reinstall the readline callback handler (with no prompt), if not
|
|
currently installed. */
|
|
extern void gdb_rl_callback_handler_reinstall (void);
|
|
|
|
/* Called by readline after a complete line has been gathered from the
|
|
user, but before the line is dispatched to back to GDB. This function
|
|
is a wrapper around readline's builtin rl_deprep_terminal function, and
|
|
handles the case where readline received EOF. */
|
|
extern void gdb_rl_deprep_term_function (void);
|
|
|
|
typedef void (*segv_handler_t) (int);
|
|
|
|
/* On construction, replaces the current thread's SIGSEGV handler with
|
|
the provided one. On destruction, restores the handler to the
|
|
original one. */
|
|
class scoped_segv_handler_restore
|
|
{
|
|
public:
|
|
scoped_segv_handler_restore (segv_handler_t new_handler);
|
|
~scoped_segv_handler_restore ();
|
|
|
|
private:
|
|
segv_handler_t m_old_handler;
|
|
};
|
|
|
|
#endif
|