29#include "gdbsupport/event-loop.h"
41#include "gdbsupport/gdb_select.h"
42#include "gdbsupport/gdb-sigmask.h"
48#include "readline/readline.h"
49#include "readline/history.h"
62static void handle_sigquit (
int sig);
65static void handle_sighup (
int sig);
70#if defined (SIGQUIT) || defined (SIGHUP)
71static void async_do_nothing (gdb_client_data);
74static void async_disconnect (gdb_client_data);
77static void async_sigtstp_handler (gdb_client_data);
140#if RL_VERSION_MAJOR == 7
141EXTERN_C
void _rl_signal_handler (
int);
184static struct gdb_exception
187 struct gdb_exception gdb_expt;
195 rl_callback_read_char ();
196#if RL_VERSION_MAJOR >= 8
204 while (rl_pending_signal () != 0)
209#elif RL_VERSION_MAJOR == 7
213 while (rl_pending_signal () != 0)
214 _rl_signal_handler (rl_pending_signal ());
216#error "Readline major version >= 7 expected"
219 (*after_char_processing_hook) ();
221 CATCH_SJLJ (ex, RETURN_MASK_ALL)
223 gdb_expt = std::move (ex);
233 struct gdb_exception gdb_expt
237 if (gdb_expt.reason < 0)
238 throw_exception (std::move (gdb_expt));
252 static struct gdb_exception gdb_rl_expt;
261 catch (gdb_exception &ex)
263 gdb_rl_expt = std::move (ex);
273 if (gdb_rl_expt.reason < 0)
274 throw_exception_sjlj (gdb_rl_expt);
343 rl_callback_handler_remove ();
400 std::string actual_gdb_prompt;
415 internal_error (_(
"double prompt"));
446 actual_gdb_prompt = new_prompt;
481 const char prefix[] =
"\n\032\032pre-prompt\n";
485 const char suffix[] =
"\n\032\032prompt\n";
487 return std::string (
prefix) + prompt.c_str () + suffix;
548 for (c = command; *c ==
' ' || *c ==
'\t'; c++)
567 size_t len = strlen (rl);
569 if (len > 0 && rl[len - 1] ==
'\\')
572 cmd_line_buffer.append (rl, len - 1);
579 cmd_line_buffer.append (rl, len + 1);
606 const char *rl,
int repeat,
607 const char *annotation_suffix)
622#define SERVER_COMMAND_PREFIX "server "
642 expanded = history_expand (&cmd_line_buffer[0], &cmd_expansion);
643 gdb::unique_xmalloc_ptr<char> history_value (cmd_expansion);
651 return cmd_line_buffer.c_str ();
653 cmd_line_buffer = history_value.get ();
660 for (p1 = cmd_line_buffer.c_str (); *p1 ==
' ' || *p1 ==
'\t'; p1++)
662 if (repeat && *p1 ==
'\0')
686 return cmd_line_buffer.c_str ();
695 gdb::optional<scoped_restore_tmpl<int>> restore_eof_found;
697 if (RL_ISSTATE (RL_STATE_EOF))
700 restore_eof_found.emplace (&rl_eof_found, 0);
705 rl_deprep_terminal ();
723 if (cmd == (
char *) EOF)
767 const char *
value = rl_variable_value (
"enable-bracketed-paste");
768 if (
value !=
nullptr && strcmp (
value,
"on") == 0
769 && ((rl_readline_version >> 8) & 0xff) > 0x07)
776 else if (cmd == NULL)
807 gdb_assert (stream !=
nullptr);
858 sigemptyset (&sigset);
859 sigaddset (&sigset, sig);
860 gdb_sigmask (SIG_UNBLOCK, &sigset, 0);
869static void ATTRIBUTE_NORETURN
876#ifdef GDB_PRINT_INTERNAL_BACKTRACE
877 const auto sig_write = [] (
const char *msg) ->
void
879 gdb_stderr->write_async_safe (msg, strlen (msg));
885 sig_write (_(
"Fatal signal: "));
886 sig_write (strsignal (sig));
891 sig_write (_(
"A fatal error internal to GDB has been detected, "
892 "further\ndebugging is not possible. GDB will now "
894 sig_write (_(
"This is a bug, please report it."));
897 sig_write (_(
" For instructions, see:\n"));
910 if (signal (sig, SIG_DFL) != SIG_ERR
916 signal (SIGABRT, SIG_DFL);
939#if defined (HAVE_SIGACTION)
942 sigemptyset (&sa.sa_mask);
943#ifdef HAVE_SIGALTSTACK
944 sa.sa_flags = SA_ONSTACK;
948 sigaction (SIGSEGV, &sa,
nullptr);
1008 signal (SIGQUIT, handle_sigquit);
1012 if (signal (SIGHUP, handle_sighup) != SIG_IGN)
1104 fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
1105 struct timeval *timeout)
1111 if (readfds == NULL)
1113 readfds = &my_readfds;
1114 FD_ZERO (&my_readfds);
1118 FD_SET (fd, readfds);
1124 res =
gdb_select (n, readfds, writefds, exceptfds, timeout);
1126 while (res == -1 && errno == EINTR);
1128 if (res == 1 && FD_ISSET (fd, readfds))
1182handle_sigquit (
int sig)
1185 signal (sig, handle_sigquit);
1189#if defined (SIGQUIT) || defined (SIGHUP)
1193async_do_nothing (gdb_client_data arg)
1203handle_sighup (
int sig)
1206 signal (sig, handle_sighup);
1211async_disconnect (gdb_client_data arg)
1219 catch (
const gdb_exception &exception)
1221 gdb_puts (
"Could not kill the program being debugged",
1224 if (exception.reason == RETURN_FORCED_QUIT)
1232 inf->pop_all_targets ();
1234 catch (
const gdb_exception &exception)
1239 signal (SIGHUP, SIG_DFL);
1246handle_sigtstp (
int sig)
1249 signal (sig, handle_sigtstp);
1253async_sigtstp_handler (gdb_client_data arg)
1257 signal (SIGTSTP, SIG_DFL);
1260 signal (SIGTSTP, handle_sigtstp);
1357 debug_event_loop = debug_event_loop_kind::OFF;
1359 debug_event_loop = debug_event_loop_kind::ALL_EXCEPT_UI;
1361 debug_event_loop = debug_event_loop_kind::ALL;
1363 gdb_assert_not_reached (
"Invalid debug event look kind value.");
1380 _(
"Set event-loop debugging."),
1381 _(
"Show event-loop debugging."),
1383Control whether to show event loop-related debug messages."),
1390Set whether to produce a backtrace if GDB receives a fatal signal."), _(
"\
1391Show whether GDB will produce a backtrace if it receives a fatal signal."), _(
"\
1392Use \"on\" to enable, \"off\" to disable.\n\
1393If enabled, GDB will produce a minimal backtrace if it encounters a fatal\n\
1394signal from within GDB itself. This is a mechanism to help diagnose\n\
1395crashes within GDB, not a mechanism for debugging inferiors."),
void annotate_display_prompt(void)
async_signal_handler * create_async_signal_handler(sig_handler_func *proc, gdb_client_data client_data, const char *name)
void initialize_async_signal_handlers(void)
void mark_async_signal_handler(async_signal_handler *async_handler_ptr)
void bpstat_do_actions(void)
void gdb_internal_backtrace_set_cmd(const char *args, int from_tty, cmd_list_element *c)
void gdb_internal_backtrace()
#define GDB_PRINT_INTERNAL_BACKTRACE_INIT_ON
segv_handler_t m_old_handler
~scoped_segv_handler_restore()
scoped_segv_handler_restore(segv_handler_t new_handler)
struct cmd_list_element * showdebuglist
struct cmd_list_element * setdebuglist
struct cmd_list_element * maintenance_show_cmdlist
struct cmd_list_element * maintenance_set_cmdlist
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void reset_command_nest_depth(void)
void save_command_line(const char *cmd)
char * get_saved_command_line()
completion_result complete(const char *line, char const **word, int *quote_char)
int check_quit_flag(void)
void quit_handler_ftype(void)
static const char * debug_event_loop_enum[]
void gdb_rl_deprep_term_function(void)
static bool unblock_signal(int sig)
static void show_bt_on_fatal_signal(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
void display_gdb_prompt(const char *new_prompt)
void set_force_quit_flag()
static void install_handle_sigsegv()
void gdb_setup_readline(int editing)
void async_enable_stdin(void)
void _initialize_event_top()
void(* after_char_processing_hook)(void)
void command_handler(const char *command)
const char * handle_line_of_input(std::string &cmd_line_buffer, const char *rl, int repeat, const char *annotation_suffix)
static void set_debug_event_loop_command(const char *args, int from_tty, cmd_list_element *c)
static bool bt_on_fatal_signal
int call_stdin_event_handler_again_p
quit_handler_ftype * quit_handler
static bool command_line_append_input_line(std::string &cmd_line_buffer, const char *rl)
static struct async_signal_handler * sigint_token
void gdb_rl_callback_handler_install(const char *prompt)
static std::string & get_command_line_buffer(void)
static struct async_signal_handler * async_sigterm_token
void gdb_rl_callback_handler_remove(void)
int interruptible_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
void gdb_init_signals(void)
void async_request_quit(gdb_client_data arg)
void gdb_disable_readline(void)
static void ATTRIBUTE_NORETURN handle_fatal_signal(int sig)
static struct gdb_exception gdb_rl_callback_read_char_wrapper_noexcept() noexcept
void handle_sigint(int sig)
static const char debug_event_loop_all_except_ui[]
static thread_local void(* thread_local_segv_handler)(int)
static const char * debug_event_loop_value
void handle_sigterm(int sig)
static int quit_serial_event_fd(void)
void command_line_handler(gdb::unique_xmalloc_ptr< char > &&rl)
void gdb_rl_callback_handler_reinstall(void)
void default_quit_handler(void)
static bool callback_handler_installed
volatile bool sync_quit_force_run
static const char debug_event_loop_all[]
void quit_serial_event_clear(void)
static const char debug_event_loop_off[]
void async_disable_stdin(void)
static void async_sigterm_handler(gdb_client_data arg)
static void gdb_rl_callback_handler(char *rl) noexcept
static void show_debug_event_loop_command(struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value)
void quit_serial_event_set(void)
static struct serial_event * quit_serial_event
#define SERVER_COMMAND_PREFIX
static void gdb_rl_callback_read_char_wrapper(gdb_client_data client_data)
static void handle_sigsegv(int sig)
void gdb_readline_no_editing_callback(gdb_client_data client_data)
void change_line_handler(int editing)
static std::string top_level_prompt()
void(* segv_handler_t)(int)
void exception_print(struct ui_file *file, const struct gdb_exception &e)
void execute_command(const char *, int)
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
c_c_handler_ftype * install_sigint_handler(c_c_handler_ftype *fn)
struct interp * top_level_interpreter(void)
struct interp * command_interp(void)
int gdb_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
observable< const char * > before_prompt
#define prefix(a, b, R, do)
void serial_event_set(struct serial_event *event)
void serial_event_clear(struct serial_event *event)
struct serial_event * make_serial_event(void)
int serial_event_fd(struct serial_event *event)
void(* input_handler)(gdb::unique_xmalloc_ptr< char > &&)
enum prompt_state prompt_state
bool input_interactive_p() const
void unregister_file_handler()
void(* call_readline)(gdb_client_data)
void register_file_handler()
void target_pass_ctrlc(void)
void quit_force(int *exit_arg, int from_tty)
const std::string & get_prompt()
void gdb_add_history(const char *command)
void reinitialize_more_filter(void)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_flush(struct ui_file *stream)
void printf_unfiltered(const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)