From patchwork Sat Oct 1 13:23:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Monnerat X-Patchwork-Id: 58255 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0489385828A for ; Sat, 1 Oct 2022 13:25:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0489385828A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664630705; bh=iX7q+NP/PiqVUAu7/xGWToTbJZlOdQVlSX6NqRF8RQE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=V58tA3RSL+GAVH6O488Fw58JrL+sZiBr6WSx2ceEomJP9Mzt4goo5DJ13bIuG9RgZ SsnmzwV4EA+q07ziqdaZ2dXBCJK9A21eYw1S0U82PA3A85Rzx/h2XiNm4vz+4K+5Dl xvF5OJVhM8f5wF9RWj7Kq9yT50YoxmE8INwttv9o= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from vimdzmsp-nwas04.bluewin.ch (vimdzmsp-nwas04.bluewin.ch [195.186.228.51]) by sourceware.org (Postfix) with ESMTPS id 5F30F3858D1E for ; Sat, 1 Oct 2022 13:24:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F30F3858D1E Received: from patrick.monnerat ([92.106.168.209]) by vimdzmsp-nwas04.bluewin.ch Swisscom AG with ESMTP id ecTqoZVncywoTecTvoI7Ia; Sat, 01 Oct 2022 15:24:39 +0200 Received: from patrick.monnerat (localhost [127.0.0.1]) by patrick.monnerat (8.17.1/8.16.1) with ESMTPS id 291DOKaj076826 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 1 Oct 2022 15:24:20 +0200 Received: (from patrick@localhost) by patrick.monnerat (8.17.1/8.17.1/Submit) id 291DOKfB076825; Sat, 1 Oct 2022 15:24:20 +0200 X-Authentication-Warning: patrick.monnerat: patrick set sender to patrick@monnerat.net using -f To: gdb-patches@sourceware.org Subject: [PING][PATCH v2] gdb: add a file event mask parameter to add_file_handler Date: Sat, 1 Oct 2022 15:23:50 +0200 Message-Id: <20221001132349.76809-1-patrick@monnerat.net> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-CMAE-Envelope: MS4xfBphHe93Kurr4BV9TmttLICaz92oAtcP1/s6FQOO0WPobHtJKneEW9oZWsH3ebftsE0gbOw5rAL5ZCJM3+oxioC6OSPiFJwP/+1u9O/FXs/be1cfQ6IC SD7edX77eYwmtlnd0zreZRjaqBah/feB3G1xBMbOj16QzJS2cxhywLVevjWrhgXVFOBMWmQbiIgFM2icuNXTZsJ3dt5IfAZRdtE= X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Monnerat via Gdb-patches From: Patrick Monnerat Reply-To: Patrick Monnerat Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Tcl/Tk (used as the Insight GUI) delegates event handling to gdb and requires file events monitoring to be masked with READ/WRITE/EXCEPTION flags. Currently, gdb only uses read events, but an unused and incomplete provision exists for such flags. This patch adds an event mask parameter to add_file_handler, allowing to monitor non-read file events. Its value is always given as ored-in gdb flags, whether effectively using poll or select. This parameter defaults to GDB_READABLE | GDB_EXCEPTION, resulting in no change for existing calls. To unify the semantics between select and poll, POLLRDHUP (HANGUP-sensitiveness) is also included in read events on platforms supporting it. This is the only change in this patch that may affect bare gdb. This patch benefits to Insight: the latter itself does not use non-read file events. However these must be supported for Tcl/Tk internals. It should be noted that gdb does not support write events on the mingw platform but checks this condition with gdb_assert. This patch does not change this. Flags GDB_READABLE, GDB_WRITABLE and GDB_EXCEPTION are now made globally available through the inclusion of event-loop.h. --- gdbsupport/event-loop.cc | 43 +++++++++++++++++++++++----------------- gdbsupport/event-loop.h | 11 ++++++++-- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc index 941885529f1..45990fbdd9b 100644 --- a/gdbsupport/event-loop.cc +++ b/gdbsupport/event-loop.cc @@ -28,6 +28,11 @@ #elif defined (HAVE_SYS_POLL_H) #include #endif +#if defined (POLLRDHUP) +#define POLL_HANGUP POLLRDHUP +#else +#define POLL_HANGUP 0 +#endif #endif #include @@ -40,13 +45,6 @@ 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. */ - -#define GDB_READABLE (1<<1) -#define GDB_WRITABLE (1<<2) -#define GDB_EXCEPTION (1<<3) - /* Information about each file descriptor we register with the event loop. */ @@ -269,8 +267,14 @@ gdb_do_one_event (int mstimeout) void add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, - std::string &&name, bool is_ui) + std::string &&name, bool is_ui, int mask) { + /* If no event is monitored, remove an existing handler. */ + if ((mask & (GDB_READABLE | GDB_WRITABLE | GDB_EXCEPTION)) == 0) { + delete_file_handler (fd); + return; + } + #ifdef HAVE_POLL if (use_poll) { @@ -282,25 +286,28 @@ add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, On m68k-motorola-sysv, tty's are not stream-based and not `poll'able. */ fds.fd = fd; - fds.events = POLLIN; + fds.events = 0; + if (mask & GDB_READABLE) + fds.events |= POLLIN | POLL_HANGUP; + if (mask & GDB_WRITABLE) + fds.events |= POLLOUT; + if (mask & GDB_EXCEPTION) + fds.events |= POLLPRI; if (poll (&fds, 1, 0) == 1 && (fds.revents & POLLNVAL)) use_poll = false; + else + create_file_handler (fd, fds.events, proc, client_data, + std::move (name), is_ui); } - if (use_poll) - { - create_file_handler (fd, POLLIN, proc, client_data, std::move (name), - is_ui); - } - else + if (!use_poll) #endif /* HAVE_POLL */ - create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION, - proc, client_data, std::move (name), is_ui); + create_file_handler (fd, mask, proc, client_data, std::move (name), is_ui); } /* Helper for add_file_handler. For the poll case, MASK is a combination (OR) of POLLIN, - POLLRDNORM, POLLRDBAND, POLLPRI, POLLOUT, POLLWRNORM, POLLWRBAND: + POLLRDNORM, POLLRDBAND, POLLPRI, POLLOUT, POLLWRNORM, POLLWRBAND, POLLRDHUP: these are the events we are interested in. If any of them occurs, proc should be called. diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h index c82493e9bdf..8c1f831af27 100644 --- a/gdbsupport/event-loop.h +++ b/gdbsupport/event-loop.h @@ -70,11 +70,17 @@ Corollary tasks are the creation and deletion of event sources. */ +/* Tell add_file_handler what events we are interested in. */ + +#define GDB_READABLE (1<<1) +#define GDB_WRITABLE (1<<2) +#define GDB_EXCEPTION (1<<3) + typedef void *gdb_client_data; typedef void (handler_func) (int, gdb_client_data); typedef void (timer_handler_func) (gdb_client_data); -/* Exported functions from event-loop.c */ +/* Exported functions from event-loop.cc */ extern int gdb_do_one_event (int mstimeout = -1); extern void delete_file_handler (int fd); @@ -90,7 +96,8 @@ extern void delete_file_handler (int fd); extern void add_file_handler (int fd, handler_func *proc, gdb_client_data client_data, - std::string &&name, bool is_ui = false); + std::string &&name, bool is_ui = false, + int mask = GDB_READABLE | GDB_EXCEPTION); extern int create_timer (int milliseconds, timer_handler_func *proc,