From 2554f6f564097e4e3a4132d3af8ef78d588d13d1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 2 Oct 2020 14:45:52 -0400 Subject: [PATCH] gdb: give names to event loop file handlers Assign names to event loop file handlers. They will be used in debug messages when file handlers are invoked. In GDB, each UI used to get its own unique number, until commit cbe256847e19 ("Remove ui::num"). Re-introduce this field, and use it to make a unique name for the handler. I'm not too sure what goes on in ser-base.c, all I know is that it's what is used when debugging remotely. I've just named the main handler "serial". It would be good to have unique names there too. For instance when debugging with two different remote connections, we'd ideally want the handlers to have unique names. I didn't do it in this patch though. gdb/ChangeLog: * async-event.c (initialize_async_signal_handlers): Pass name to add_file_handler * event-top.c (ui_register_input_event_handler): Likewise. * linux-nat.c (linux_nat_target::async): Likewise. * run-on-main-thread.c (_initialize_run_on_main_thread): Likewise * ser-base.c (reschedule): Likewise. (ser_base_async): Likewise. * tui/tui-io.c: Likewise. * top.h (struct ui) : New field. * top.c (highest_ui_num): New variable. (ui::ui): Initialize num. gdbserver/ChangeLog: * linux-low.cc (linux_process_target::async): Pass name to add_file_handler. * remote-utils.cc (handle_accept_event): Likewise. (remote_open): Likewise. gdbsupport/ChangeLog: * event-loop.h (add_file_handler): Add "name" parameter. * event-loop.cc (struct file_handler) : New field. (create_file_handler): Add "name" parameter, assign it to file handler. (add_file_handler): Add "name" parameter. Change-Id: I9f1545f73888ebb6778eb653a618ca44d105f92c --- gdb/ChangeLog | 15 +++++++++++++++ gdb/async-event.c | 2 +- gdb/event-top.c | 3 ++- gdb/linux-nat.c | 3 ++- gdb/run-on-main-thread.c | 3 ++- gdb/ser-base.c | 6 +++--- gdb/top.c | 4 ++++ gdb/top.h | 3 +++ gdb/tui/tui-io.c | 2 +- gdbserver/ChangeLog | 7 +++++++ gdbserver/linux-low.cc | 3 ++- gdbserver/remote-utils.cc | 10 ++++++---- gdbsupport/ChangeLog | 8 ++++++++ gdbsupport/event-loop.cc | 32 +++++++++++++++++--------------- gdbsupport/event-loop.h | 14 ++++++++++++-- 15 files changed, 85 insertions(+), 30 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8788c60899f..48caf1e9057 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2020-10-02 Simon Marchi + + * async-event.c (initialize_async_signal_handlers): Pass name to + add_file_handler + * event-top.c (ui_register_input_event_handler): Likewise. + * linux-nat.c (linux_nat_target::async): Likewise. + * run-on-main-thread.c (_initialize_run_on_main_thread): + Likewise + * ser-base.c (reschedule): Likewise. + (ser_base_async): Likewise. + * tui/tui-io.c: Likewise. + * top.h (struct ui) : New field. + * top.c (highest_ui_num): New variable. + (ui::ui): Initialize num. + 2020-10-02 Simon Marchi * observable.h : Remove parameters. Update all diff --git a/gdb/async-event.c b/gdb/async-event.c index ffc0edcde88..e5cd63e309e 100644 --- a/gdb/async-event.c +++ b/gdb/async-event.c @@ -114,7 +114,7 @@ initialize_async_signal_handlers (void) async_signal_handlers_serial_event = make_serial_event (); add_file_handler (serial_event_fd (async_signal_handlers_serial_event), - async_signals_handler, NULL); + async_signals_handler, NULL, "async-signals"); } diff --git a/gdb/event-top.c b/gdb/event-top.c index ac0f3701016..c96f10450dd 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -524,7 +524,8 @@ stdin_event_handler (int error, gdb_client_data client_data) void ui_register_input_event_handler (struct ui *ui) { - add_file_handler (ui->input_fd, stdin_event_handler, ui); + add_file_handler (ui->input_fd, stdin_event_handler, ui, + string_printf ("ui-%d", ui->num)); } /* See top.h. */ diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index fbb53885942..7b9b267fc73 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4123,7 +4123,8 @@ linux_nat_target::async (int enable) if (!linux_async_pipe (1)) { add_file_handler (linux_nat_event_pipe[0], - handle_target_event, NULL); + handle_target_event, NULL, + "linux-nat"); /* There may be pending events to handle. Tell the event loop to poll them. */ async_file_mark (); diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c index 2cc93e430d8..1e7bb5f5f8e 100644 --- a/gdb/run-on-main-thread.c +++ b/gdb/run-on-main-thread.c @@ -94,5 +94,6 @@ void _initialize_run_on_main_thread () { runnable_event = make_serial_event (); - add_file_handler (serial_event_fd (runnable_event), run_events, nullptr); + add_file_handler (serial_event_fd (runnable_event), run_events, nullptr, + "run-on-main-thread"); } diff --git a/gdb/ser-base.c b/gdb/ser-base.c index 84ca8c6167c..cb503f6141b 100644 --- a/gdb/ser-base.c +++ b/gdb/ser-base.c @@ -83,7 +83,7 @@ reschedule (struct serial *scb) case NOTHING_SCHEDULED: if (scb->bufcnt == 0) { - add_file_handler (scb->fd, fd_event, scb); + add_file_handler (scb->fd, fd_event, scb, "serial"); next_state = FD_SCHEDULED; } else @@ -95,7 +95,7 @@ reschedule (struct serial *scb) if (scb->bufcnt == 0) { delete_timer (scb->async_state); - add_file_handler (scb->fd, fd_event, scb); + add_file_handler (scb->fd, fd_event, scb, "serial"); next_state = FD_SCHEDULED; } else @@ -597,7 +597,7 @@ ser_base_async (struct serial *scb, reschedule (scb); if (scb->error_fd != -1) - add_file_handler (scb->error_fd, handle_error_fd, scb); + add_file_handler (scb->error_fd, handle_error_fd, scb, "serial-error"); } else { diff --git a/gdb/top.c b/gdb/top.c index c50fb4dc7d4..6233575eed6 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -270,10 +270,14 @@ void (*deprecated_call_command_hook) (struct cmd_list_element * c, void (*deprecated_context_hook) (int id); +/* The highest UI number ever assigned. */ +static int highest_ui_num; + /* See top.h. */ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_) : next (nullptr), + num (++highest_ui_num), call_readline (nullptr), input_handler (nullptr), command_editing (0), diff --git a/gdb/top.h b/gdb/top.h index 92b096492f0..fd992977155 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -65,6 +65,9 @@ struct ui /* Pointer to next in singly-linked list. */ struct ui *next; + /* Convenient handle (UI number). Unique across all UIs. */ + int num; + /* The UI's command line buffer. This is to used to accumulate input until we have a whole command line. */ struct buffer line_buffer; diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 1a2764e2196..a4f93178416 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -921,7 +921,7 @@ tui_initialize_io (void) (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NDELAY); #endif #endif - add_file_handler (tui_readline_pipe[0], tui_readline_output, 0); + add_file_handler (tui_readline_pipe[0], tui_readline_output, 0, "tui"); #else tui_rl_outstream = stdout; #endif diff --git a/gdbserver/ChangeLog b/gdbserver/ChangeLog index d667a203e67..9ed90bacd00 100644 --- a/gdbserver/ChangeLog +++ b/gdbserver/ChangeLog @@ -1,3 +1,10 @@ +2020-10-02 Simon Marchi + + * linux-low.cc (linux_process_target::async): Pass name to + add_file_handler. + * remote-utils.cc (handle_accept_event): Likewise. + (remote_open): Likewise. + 2020-10-01 Kamil Rytarowski * netbsd-i386-low.cc: Add. diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 70d5521d442..1ae72a21d6c 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6092,7 +6092,8 @@ linux_process_target::async (bool enable) /* Register the event loop handler. */ add_file_handler (linux_event_pipe[0], - handle_target_event, NULL); + handle_target_event, NULL, + "linux-low"); /* Always trigger a linux_wait. */ async_file_mark (); diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index c26668dc0f8..5a6ceb1d9a1 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -194,7 +194,7 @@ handle_accept_event (int err, gdb_client_data client_data) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_serial_event, NULL, "remote-net"); /* We have a new GDB connection now. If we were disconnected tracing, there's a window where the target could report a stop @@ -331,7 +331,7 @@ remote_open (const char *name) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_serial_event, NULL, "remote-stdio"); } #ifndef USE_WIN32API else if (port_str == NULL) @@ -372,7 +372,8 @@ remote_open (const char *name) enable_async_notification (remote_desc); /* Register the event loop handler. */ - add_file_handler (remote_desc, handle_serial_event, NULL); + add_file_handler (remote_desc, handle_serial_event, NULL, + "remote-device"); } #endif /* USE_WIN32API */ else @@ -398,7 +399,8 @@ remote_open (const char *name) fflush (stderr); /* Register the event loop handler. */ - add_file_handler (listen_desc, handle_accept_event, NULL); + add_file_handler (listen_desc, handle_accept_event, NULL, + "remote-listen"); } } diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 216fad129c4..b54bfb945ad 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,11 @@ +2020-10-02 Simon Marchi + + * event-loop.h (add_file_handler): Add "name" parameter. + * event-loop.cc (struct file_handler) : New field. + (create_file_handler): Add "name" parameter, assign it to file + handler. + (add_file_handler): Add "name" parameter. + 2020-10-01 Kamil Rytarowski * agent.cc (gdb_connect_sync_socket): Preinitialize addr with zeros. diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc index 59436d467ed..0d78122e0cc 100644 --- a/gdbsupport/event-loop.cc +++ b/gdbsupport/event-loop.cc @@ -61,6 +61,9 @@ struct file_handler /* Argument to pass to proc. */ gdb_client_data client_data; + /* User-friendly name of this handler. Heap-allocated, owned by this.*/ + std::string *name; + /* Was an error detected on this fd? */ int error; @@ -160,7 +163,8 @@ static struct timer_list; static void create_file_handler (int fd, int mask, handler_func *proc, - gdb_client_data client_data); + gdb_client_data client_data, + std::string &&name); static int gdb_wait_for_event (int); static int update_wait_timeout (void); static int poll_timers (void); @@ -231,13 +235,11 @@ gdb_do_one_event (void) return 1; } - +/* See event-loop.h */ -/* Wrapper function for create_file_handler, so that the caller - doesn't have to know implementation details about the use of poll - vs. select. */ void -add_file_handler (int fd, handler_func * proc, gdb_client_data client_data) +add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, + std::string &&name) { #ifdef HAVE_POLL struct pollfd fds; @@ -263,21 +265,18 @@ add_file_handler (int fd, handler_func * proc, gdb_client_data client_data) if (use_poll) { #ifdef HAVE_POLL - create_file_handler (fd, POLLIN, proc, client_data); + create_file_handler (fd, POLLIN, proc, client_data, std::move (name)); #else internal_error (__FILE__, __LINE__, _("use_poll without HAVE_POLL")); #endif } else - create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION, - proc, client_data); + create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION, + proc, client_data, std::move (name)); } -/* Add a file handler/descriptor to the list of descriptors we are - interested in. - - FD is the file descriptor for the file/stream to be listened to. +/* Helper for add_file_handler. For the poll case, MASK is a combination (OR) of POLLIN, POLLRDNORM, POLLRDBAND, POLLPRI, POLLOUT, POLLWRNORM, POLLWRBAND: @@ -289,8 +288,8 @@ add_file_handler (int fd, handler_func * proc, gdb_client_data client_data) occurs for FD. CLIENT_DATA is the argument to pass to PROC. */ static void -create_file_handler (int fd, int mask, handler_func * proc, - gdb_client_data client_data) +create_file_handler (int fd, int mask, handler_func * proc, + gdb_client_data client_data, std::string &&name) { file_handler *file_ptr; @@ -358,6 +357,7 @@ create_file_handler (int fd, int mask, handler_func * proc, file_ptr->proc = proc; file_ptr->client_data = client_data; file_ptr->mask = mask; + file_ptr->name = new std::string (std::move (name)); } /* Return the next file handler to handle, and advance to the next @@ -489,6 +489,8 @@ delete_file_handler (int fd) ; prev_ptr->next_file = file_ptr->next_file; } + + delete file_ptr->name; xfree (file_ptr); } diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h index 2eaaa0c8b60..d7478b037a9 100644 --- a/gdbsupport/event-loop.h +++ b/gdbsupport/event-loop.h @@ -78,8 +78,18 @@ typedef void (timer_handler_func) (gdb_client_data); extern int gdb_do_one_event (void); extern void delete_file_handler (int fd); -extern void add_file_handler (int fd, handler_func *proc, - gdb_client_data client_data); + +/* Add a file handler/descriptor to the list of descriptors we are + interested in. + + FD is the file descriptor for the file/stream to be listened to. + + NAME is a user-friendly name for the handler. */ + +extern void add_file_handler (int fd, handler_func *proc, + gdb_client_data client_data, + std::string &&name); + extern int create_timer (int milliseconds, timer_handler_func *proc, gdb_client_data client_data); -- 2.30.2