From db20ebdfae432f23def32f0b9bbf6e023c926235 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 2 Oct 2020 14:44:38 -0400 Subject: [PATCH] gdb: give names to async event/signal handlers Assign names to async event/signal handlers. They will be used in debug messages when file handlers are invoked. Unlike in the previous patch, the names are not copied in the structure, since we don't need to (all names are string literals for the moment). gdb/ChangeLog: * async-event.h (create_async_signal_handler): Add name parameter. (create_async_event_handler): Likewise. * async-event.c (struct async_signal_handler) : New field. (struct async_event_handler) : New field. (create_async_signal_handler): Assign name. (create_async_event_handler): Assign name. * event-top.c (async_init_signals): Pass name when creating handler. * infrun.c (_initialize_infrun): Likewise. * record-btrace.c (record_btrace_push_target): Likewise. * record-full.c (record_full_open): Likewise. * remote-notif.c (remote_notif_state_allocate): Likewise. * remote.c (remote_target::open_1): Likewise. * tui/tui-win.c (tui_initialize_win): Likewise. Change-Id: Icd9d9f775542ae5fc2cd148c12f481e7885936d5 --- gdb/ChangeLog | 18 ++++++++++++++++++ gdb/async-event.c | 20 ++++++++++++++------ gdb/async-event.h | 15 +++++++++++---- gdb/event-top.c | 14 +++++++------- gdb/infrun.c | 3 ++- gdb/record-btrace.c | 2 +- gdb/record-full.c | 2 +- gdb/remote-notif.c | 2 +- gdb/remote.c | 3 ++- gdb/tui/tui-win.c | 3 ++- 10 files changed, 59 insertions(+), 23 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 48caf1e9057..3b60116d273 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,21 @@ +2020-10-02 Simon Marchi + + * async-event.h (create_async_signal_handler): Add name + parameter. + (create_async_event_handler): Likewise. + * async-event.c (struct async_signal_handler) : New field. + (struct async_event_handler) : New field. + (create_async_signal_handler): Assign name. + (create_async_event_handler): Assign name. + * event-top.c (async_init_signals): Pass name when creating + handler. + * infrun.c (_initialize_infrun): Likewise. + * record-btrace.c (record_btrace_push_target): Likewise. + * record-full.c (record_full_open): Likewise. + * remote-notif.c (remote_notif_state_allocate): Likewise. + * remote.c (remote_target::open_1): Likewise. + * tui/tui-win.c (tui_initialize_win): Likewise. + 2020-10-02 Simon Marchi * async-event.c (initialize_async_signal_handlers): Pass name to diff --git a/gdb/async-event.c b/gdb/async-event.c index e5cd63e309e..55be014484e 100644 --- a/gdb/async-event.c +++ b/gdb/async-event.c @@ -46,6 +46,9 @@ struct async_signal_handler /* Argument to PROC. */ gdb_client_data client_data; + + /* User-friendly name of this handler. */ + const char *name; }; /* PROC is a function to be invoked when the READY flag is set. This @@ -68,6 +71,9 @@ struct async_event_handler /* Argument to PROC. */ gdb_client_data client_data; + + /* User-friendly name of this handler. */ + const char *name; }; /* All the async_signal_handlers gdb is interested in are kept onto @@ -127,7 +133,8 @@ initialize_async_signal_handlers (void) whenever the handler is invoked. */ async_signal_handler * create_async_signal_handler (sig_handler_func * proc, - gdb_client_data client_data) + gdb_client_data client_data, + const char *name) { async_signal_handler *async_handler_ptr; @@ -136,6 +143,7 @@ create_async_signal_handler (sig_handler_func * proc, async_handler_ptr->next_handler = NULL; async_handler_ptr->proc = proc; async_handler_ptr->client_data = client_data; + async_handler_ptr->name = name; if (sighandler_list.first_handler == NULL) sighandler_list.first_handler = async_handler_ptr; else @@ -236,13 +244,12 @@ delete_async_signal_handler (async_signal_handler ** async_handler_ptr) (*async_handler_ptr) = NULL; } -/* Create an asynchronous event handler, allocating memory for it. - Return a pointer to the newly created handler. PROC is the - function to call with CLIENT_DATA argument whenever the handler is - invoked. */ +/* See async-event.h. */ + async_event_handler * create_async_event_handler (async_event_handler_func *proc, - gdb_client_data client_data) + gdb_client_data client_data, + const char *name) { async_event_handler *h; @@ -251,6 +258,7 @@ create_async_event_handler (async_event_handler_func *proc, h->next_handler = NULL; h->proc = proc; h->client_data = client_data; + h->name = name; if (async_event_handler_list.first_handler == NULL) async_event_handler_list.first_handler = h; else diff --git a/gdb/async-event.h b/gdb/async-event.h index adf6dc8f8c4..8f279d63d63 100644 --- a/gdb/async-event.h +++ b/gdb/async-event.h @@ -27,8 +27,9 @@ typedef void (sig_handler_func) (gdb_client_data); typedef void (async_event_handler_func) (gdb_client_data); extern struct async_signal_handler * - create_async_signal_handler (sig_handler_func *proc, - gdb_client_data client_data); + create_async_signal_handler (sig_handler_func *proc, + gdb_client_data client_data, + const char *name); extern void delete_async_signal_handler (struct async_signal_handler **); /* Call the handler from HANDLER the next time through the event @@ -48,10 +49,16 @@ extern void clear_async_signal_handler (struct async_signal_handler *handler); and set PROC as its callback. CLIENT_DATA is passed as argument to PROC upon its invocation. Returns a pointer to an opaque structure used to mark as ready and to later delete this event source from - the event loop. */ + the event loop. + + NAME is a user-friendly name for the handler, used in debug statements. The + name is not copied: its lifetime should be at least as long as that of the + handler. */ + extern struct async_event_handler * create_async_event_handler (async_event_handler_func *proc, - gdb_client_data client_data); + gdb_client_data client_data, + const char *name); /* Remove the event source pointed by HANDLER_PTR created by CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it. */ diff --git a/gdb/event-top.c b/gdb/event-top.c index c96f10450dd..fdce5de6f42 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -916,10 +916,10 @@ async_init_signals (void) signal (SIGINT, handle_sigint); sigint_token = - create_async_signal_handler (async_request_quit, NULL); + create_async_signal_handler (async_request_quit, NULL, "sigint"); signal (SIGTERM, handle_sigterm); async_sigterm_token - = create_async_signal_handler (async_sigterm_handler, NULL); + = create_async_signal_handler (async_sigterm_handler, NULL, "sigterm"); /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed to the inferior and breakpoints will be ignored. */ @@ -938,23 +938,23 @@ async_init_signals (void) to SIG_DFL for us. */ signal (SIGQUIT, handle_sigquit); sigquit_token = - create_async_signal_handler (async_do_nothing, NULL); + create_async_signal_handler (async_do_nothing, NULL, "sigquit"); #endif #ifdef SIGHUP if (signal (SIGHUP, handle_sighup) != SIG_IGN) sighup_token = - create_async_signal_handler (async_disconnect, NULL); + create_async_signal_handler (async_disconnect, NULL, "sighup"); else sighup_token = - create_async_signal_handler (async_do_nothing, NULL); + create_async_signal_handler (async_do_nothing, NULL, "sighup"); #endif signal (SIGFPE, handle_sigfpe); sigfpe_token = - create_async_signal_handler (async_float_handler, NULL); + create_async_signal_handler (async_float_handler, NULL, "sigfpe"); #ifdef SIGTSTP sigtstp_token = - create_async_signal_handler (async_sigtstp_handler, NULL); + create_async_signal_handler (async_sigtstp_handler, NULL, "sigtstp"); #endif install_handle_sigsegv (); diff --git a/gdb/infrun.c b/gdb/infrun.c index a150585bd5a..0458c3acb9d 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -9278,7 +9278,8 @@ _initialize_infrun () /* Register extra event sources in the event loop. */ infrun_async_inferior_event_token - = create_async_event_handler (infrun_async_inferior_event_handler, NULL); + = create_async_event_handler (infrun_async_inferior_event_handler, NULL, + "infrun"); add_info ("signals", info_signals_command, _("\ What debugger does when program gets various signals.\n\ diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 678984baeb6..dd05b932c1e 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -342,7 +342,7 @@ record_btrace_push_target (void) record_btrace_async_inferior_event_handler = create_async_event_handler (record_btrace_handle_async_inferior_event, - NULL); + NULL, "record-btrace"); record_btrace_generating_corefile = 0; format = btrace_format_short_string (record_btrace_conf.format); diff --git a/gdb/record-full.c b/gdb/record-full.c index c0fedfc32e1..9a6187e8104 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -986,7 +986,7 @@ record_full_open (const char *name, int from_tty) /* Register extra event sources in the event loop. */ record_full_async_inferior_event_token = create_async_event_handler (record_full_async_inferior_event_handler, - NULL); + NULL, "record-full"); record_full_init_record_breakpoints (); diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c index 2e5f124284b..f18bc8678e3 100644 --- a/gdb/remote-notif.c +++ b/gdb/remote-notif.c @@ -219,7 +219,7 @@ remote_notif_state_allocate (remote_target *remote) notif_state->get_pending_events_token = create_async_event_handler (remote_async_get_pending_events_handler, - notif_state); + notif_state, "remote-notif"); return notif_state; } diff --git a/gdb/remote.c b/gdb/remote.c index 1ef9b44f731..f95148643f8 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5605,7 +5605,8 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p) /* Register extra event sources in the event loop. */ rs->remote_async_inferior_event_token - = create_async_event_handler (remote_async_inferior_event_handler, remote); + = create_async_event_handler (remote_async_inferior_event_handler, remote, + "remote"); rs->notif_state = remote_notif_state_allocate (remote); /* Reset the target state; these things will be queried either by diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index f906b0dc4fe..86c0fdba2bc 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -576,7 +576,8 @@ tui_initialize_win (void) { #ifdef SIGWINCH tui_sigwinch_token - = create_async_signal_handler (tui_async_resize_screen, NULL); + = create_async_signal_handler (tui_async_resize_screen, NULL, + "tui-sigwinch"); { #ifdef HAVE_SIGACTION -- 2.30.2