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) <num>: 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) <name>: New field.
(create_file_handler): Add "name" parameter, assign it to file
handler.
(add_file_handler): Add "name" parameter.
Change-Id: I9f1545f73888ebb6778eb653a618ca44d105f92c
+2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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) <num>: New field.
+ * top.c (highest_ui_num): New variable.
+ (ui::ui): Initialize num.
+
2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
* observable.h <inferior_created>: Remove parameters. Update all
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");
}
\f
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. */
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 ();
_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");
}
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
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
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
{
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),
/* 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;
(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
+2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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 <n54@gmx.com>
* netbsd-i386-low.cc: Add.
/* 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 ();
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
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)
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
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");
}
}
+2020-10-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * event-loop.h (add_file_handler): Add "name" parameter.
+ * event-loop.cc (struct file_handler) <name>: New field.
+ (create_file_handler): Add "name" parameter, assign it to file
+ handler.
+ (add_file_handler): Add "name" parameter.
+
2020-10-01 Kamil Rytarowski <n54@gmx.com>
* agent.cc (gdb_connect_sync_socket): Preinitialize addr with zeros.
/* 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;
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);
return 1;
}
-\f
+/* 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;
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:
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;
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
;
prev_ptr->next_file = file_ptr->next_file;
}
+
+ delete file_ptr->name;
xfree (file_ptr);
}
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);