aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-10-02 14:44:40 -0400
committerSimon Marchi <simon.marchi@efficios.com>2020-10-02 14:47:42 -0400
commit6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72 (patch)
treebb4c228df496538c86485682474aee12791491c4 /gdb
parentba98841943b085891eb4bf4debc3981ac95bb7fb (diff)
downloadbinutils-6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72.zip
binutils-6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72.tar.gz
binutils-6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72.tar.bz2
gdb: add debug prints in event loop
Add debug printouts about event loop-related events: - When a file descriptor handler gets invoked - When an async event/signal handler gets invoked gdb/ChangeLog: * async-event.c (invoke_async_signal_handlers): Add debug print. (check_async_event_handlers): Likewise. * event-top.c (show_debug_event_loop): New function. (_initialize_event_top): Register "set debug event-loop" setting. gdbserver/ChangeLog: * server.cc (handle_monitor_command): Handle "set debug-event-loop". (captured_main): Handle "--debug-event-loop". (monitor_show_help): Mention new setting. (gdbserver_usage): Mention new flag. gdbsupport/ChangeLog: * event-loop.h (debug_event_loop): New variable declaration. (event_loop_debug_printf_1): New function declaration. (event_loop_debug_printf): New macro. * event-loop.cc (debug_event_loop): New variable. (handle_file_event): Add debug print. (event_loop_debug_printf_1): New function. Change-Id: If78ed3a69179881368e7895b42940ce13b6a1a05
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/async-event.c27
-rw-r--r--gdb/event-top.c52
3 files changed, 86 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9f74494..737091e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
+ * async-event.c (invoke_async_signal_handlers): Add debug
+ print.
+ (check_async_event_handlers): Likewise.
+ * event-top.c (show_debug_event_loop): New function.
+ (_initialize_event_top): Register "set debug event-loop"
+ setting.
+
+2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
+
* debug.c (debug_prefixed_vprintf): Move to gdbsupport.
* debug.h: Remove.
* infrun.c: Include gdbsupport/common-debug.h.
diff --git a/gdb/async-event.c b/gdb/async-event.c
index 55be014..4228dfb 100644
--- a/gdb/async-event.c
+++ b/gdb/async-event.c
@@ -157,8 +157,23 @@ create_async_signal_handler (sig_handler_func * proc,
for some event. The caller of this function is the interrupt
handler associated with a signal. */
void
-mark_async_signal_handler (async_signal_handler * async_handler_ptr)
+mark_async_signal_handler (async_signal_handler *async_handler_ptr)
{
+ if (debug_event_loop != debug_event_loop_kind::OFF)
+ {
+ /* This is called by signal handlers, so we print it "by hand" using
+ the async-signal-safe methods. */
+ const char head[] = ("[event-loop] mark_async_signal_handler: marking"
+ "async signal handler `");
+ gdb_stdlog->write_async_safe (head, strlen (head));
+
+ gdb_stdlog->write_async_safe (async_handler_ptr->name,
+ strlen (async_handler_ptr->name));
+
+ const char tail[] = "`\n";
+ gdb_stdlog->write_async_safe (tail, strlen (tail));
+ }
+
async_handler_ptr->ready = 1;
serial_event_set (async_signal_handlers_serial_event);
}
@@ -168,6 +183,8 @@ mark_async_signal_handler (async_signal_handler * async_handler_ptr)
void
clear_async_signal_handler (async_signal_handler *async_handler_ptr)
{
+ event_loop_debug_printf ("clearing async signal handler `%s`",
+ async_handler_ptr->name);
async_handler_ptr->ready = 0;
}
@@ -211,6 +228,8 @@ invoke_async_signal_handlers (void)
/* Async signal handlers have no connection to whichever was the
current UI, and thus always run on the main one. */
current_ui = main_ui;
+ event_loop_debug_printf ("invoking async signal handler `%s`",
+ async_handler_ptr->name);
(*async_handler_ptr->proc) (async_handler_ptr->client_data);
}
@@ -274,6 +293,8 @@ create_async_event_handler (async_event_handler_func *proc,
void
mark_async_event_handler (async_event_handler *async_handler_ptr)
{
+ event_loop_debug_printf ("marking async event handler `%s`",
+ async_handler_ptr->name);
async_handler_ptr->ready = 1;
}
@@ -282,6 +303,8 @@ mark_async_event_handler (async_event_handler *async_handler_ptr)
void
clear_async_event_handler (async_event_handler *async_handler_ptr)
{
+ event_loop_debug_printf ("clearing async event handler `%s`",
+ async_handler_ptr->name);
async_handler_ptr->ready = 0;
}
@@ -300,6 +323,8 @@ check_async_event_handlers ()
if (async_handler_ptr->ready)
{
async_handler_ptr->ready = 0;
+ event_loop_debug_printf ("invoking async event handler `%s`",
+ async_handler_ptr->name);
(*async_handler_ptr->proc) (async_handler_ptr->client_data);
return 1;
}
diff --git a/gdb/event-top.c b/gdb/event-top.c
index fdce5de..63d2295 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -525,7 +525,7 @@ void
ui_register_input_event_handler (struct ui *ui)
{
add_file_handler (ui->input_fd, stdin_event_handler, ui,
- string_printf ("ui-%d", ui->num));
+ string_printf ("ui-%d", ui->num), true);
}
/* See top.h. */
@@ -1287,3 +1287,53 @@ gdb_disable_readline (void)
gdb_rl_callback_handler_remove ();
delete_file_handler (ui->input_fd);
}
+
+static const char debug_event_loop_off[] = "off";
+static const char debug_event_loop_all_except_ui[] = "all-except-ui";
+static const char debug_event_loop_all[] = "all";
+
+static const char *debug_event_loop_enum[] = {
+ debug_event_loop_off,
+ debug_event_loop_all_except_ui,
+ debug_event_loop_all,
+ nullptr
+};
+
+static const char *debug_event_loop_value = debug_event_loop_off;
+
+static void
+set_debug_event_loop_command (const char *args, int from_tty,
+ cmd_list_element *c)
+{
+ if (debug_event_loop_value == debug_event_loop_off)
+ debug_event_loop = debug_event_loop_kind::OFF;
+ else if (debug_event_loop_value == debug_event_loop_all_except_ui)
+ debug_event_loop = debug_event_loop_kind::ALL_EXCEPT_UI;
+ else if (debug_event_loop_value == debug_event_loop_all)
+ debug_event_loop = debug_event_loop_kind::ALL;
+ else
+ gdb_assert_not_reached ("Invalid debug event look kind value.");
+}
+
+static void
+show_debug_event_loop_command (struct ui_file *file, int from_tty,
+ struct cmd_list_element *cmd, const char *value)
+{
+ fprintf_filtered (file, _("Event loop debugging is %s.\n"), value);
+}
+
+void _initialize_event_top ();
+void
+_initialize_event_top ()
+{
+ add_setshow_enum_cmd ("event-loop", class_maintenance,
+ debug_event_loop_enum,
+ &debug_event_loop_value,
+ _("Set event-loop debugging."),
+ _("Show event-loop debugging."),
+ _("\
+Control whether to show event loop-related debug messages."),
+ set_debug_event_loop_command,
+ show_debug_event_loop_command,
+ &setdebuglist, &showdebuglist);
+}