diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2020-10-02 14:44:40 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2020-10-02 14:47:42 -0400 |
commit | 6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72 (patch) | |
tree | bb4c228df496538c86485682474aee12791491c4 /gdbsupport | |
parent | ba98841943b085891eb4bf4debc3981ac95bb7fb (diff) | |
download | gdb-6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72.zip gdb-6b01403b25c0eb6ce9e7b2e3cc6f5da674089e72.tar.gz gdb-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 'gdbsupport')
-rw-r--r-- | gdbsupport/ChangeLog | 9 | ||||
-rw-r--r-- | gdbsupport/event-loop.cc | 38 | ||||
-rw-r--r-- | gdbsupport/event-loop.h | 44 |
3 files changed, 83 insertions, 8 deletions
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index d5b20ec..05462e6 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,5 +1,14 @@ 2020-10-02 Simon Marchi <simon.marchi@polymtl.ca> + * 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. + +2020-10-02 Simon Marchi <simon.marchi@polymtl.ca> + * common-debug.cc (debug_prefixed_vprintf): Move here. * common-debug.h (debug_prefixed_vprintf): Move here. diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc index 0d78122..9494158 100644 --- a/gdbsupport/event-loop.cc +++ b/gdbsupport/event-loop.cc @@ -34,6 +34,10 @@ #include "gdbsupport/gdb_sys_time.h" #include "gdbsupport/gdb_select.h" +/* See event-loop.h. */ + +debug_event_loop_kind debug_event_loop; + /* Tell create_file_handler what events we are interested in. This is used by the select version of the event loop. */ @@ -64,6 +68,9 @@ struct file_handler /* User-friendly name of this handler. Heap-allocated, owned by this.*/ std::string *name; + /* If set, this file descriptor is used for a user interface. */ + bool is_ui; + /* Was an error detected on this fd? */ int error; @@ -164,7 +171,7 @@ timer_list; static void create_file_handler (int fd, int mask, handler_func *proc, gdb_client_data client_data, - std::string &&name); + std::string &&name, bool is_ui); static int gdb_wait_for_event (int); static int update_wait_timeout (void); static int poll_timers (void); @@ -239,7 +246,7 @@ gdb_do_one_event (void) void add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, - std::string &&name) + std::string &&name, bool is_ui) { #ifdef HAVE_POLL struct pollfd fds; @@ -265,7 +272,8 @@ 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, std::move (name)); + create_file_handler (fd, POLLIN, proc, client_data, std::move (name), + is_ui); #else internal_error (__FILE__, __LINE__, _("use_poll without HAVE_POLL")); @@ -273,7 +281,7 @@ add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, } else create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION, - proc, client_data, std::move (name)); + proc, client_data, std::move (name), is_ui); } /* Helper for add_file_handler. @@ -289,7 +297,8 @@ add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, static void create_file_handler (int fd, int mask, handler_func * proc, - gdb_client_data client_data, std::string &&name) + gdb_client_data client_data, std::string &&name, + bool is_ui) { file_handler *file_ptr; @@ -358,6 +367,7 @@ create_file_handler (int fd, int mask, handler_func * proc, file_ptr->client_data = client_data; file_ptr->mask = mask; file_ptr->name = new std::string (std::move (name)); + file_ptr->is_ui = is_ui; } /* Return the next file handler to handle, and advance to the next @@ -558,7 +568,12 @@ handle_file_event (file_handler *file_ptr, int ready_mask) /* If there was a match, then call the handler. */ if (mask != 0) - (*file_ptr->proc) (file_ptr->error, file_ptr->client_data); + { + event_loop_ui_debug_printf (file_ptr->is_ui, + "invoking fd file handler `%s`", + file_ptr->name->c_str ()); + file_ptr->proc (file_ptr->error, file_ptr->client_data); + } } } } @@ -897,3 +912,14 @@ poll_timers (void) return 0; } + +/* See event-loop.h. */ + +void +event_loop_debug_printf_1 (const char *func_name, const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + debug_prefixed_vprintf ("event-loop", func_name, fmt, args); + va_end (args); +} diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h index d7478b0..c29d6a8 100644 --- a/gdbsupport/event-loop.h +++ b/gdbsupport/event-loop.h @@ -84,11 +84,13 @@ extern void delete_file_handler (int fd); FD is the file descriptor for the file/stream to be listened to. - NAME is a user-friendly name for the handler. */ + NAME is a user-friendly name for the handler. + + If IS_UI is set, this file descriptor is used for a user interface. */ extern void add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, - std::string &&name); + std::string &&name, bool is_ui = false); extern int create_timer (int milliseconds, timer_handler_func *proc, @@ -109,4 +111,42 @@ extern int invoke_async_signal_handlers (); extern int check_async_event_handlers (); +enum class debug_event_loop_kind +{ + OFF, + + /* Print all event-loop related messages, except events from user-interface + event sources. */ + ALL_EXCEPT_UI, + + /* Print all event-loop related messages. */ + ALL, +}; + +/* True if we are printing event loop debug statements. */ +extern debug_event_loop_kind debug_event_loop; + +/* Print an "event loop" debug statement. Should be used through + event_loop_debug_printf. */ +void ATTRIBUTE_PRINTF (2, 3) event_loop_debug_printf_1 + (const char *func_name, const char *fmt, ...); + +#define event_loop_debug_printf(fmt, ...) \ + do \ + { \ + if (debug_event_loop != debug_event_loop_kind::OFF) \ + event_loop_debug_printf_1 (__func__, fmt, ##__VA_ARGS__); \ + } \ + while (0) + +#define event_loop_ui_debug_printf(is_ui, fmt, ...) \ + do \ + { \ + if (debug_event_loop == debug_event_loop_kind::ALL \ + || (debug_event_loop == debug_event_loop_kind::ALL_EXCEPT_UI \ + && !is_ui)) \ + event_loop_debug_printf_1 (__func__, fmt, ##__VA_ARGS__); \ + } \ + while (0) + #endif /* EVENT_LOOP_H */ |