From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fyBfB6PM/2La3ikAWB0awg (envelope-from ) for ; Fri, 19 Aug 2022 13:47:15 -0400 Received: by simark.ca (Postfix, from userid 112) id 0C7661E4A7; Fri, 19 Aug 2022 13:47:15 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=N9/z071C; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5B0A51E222 for ; Fri, 19 Aug 2022 13:47:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 054F5385829F for ; Fri, 19 Aug 2022 17:47:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 054F5385829F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660931233; bh=BcX8tPtdqOYuulXLCUgUQpGb8K48VeFsq6MiPGGkkL0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=N9/z071CPVS7LLUE+IataRtkiUygViirQQX4asHhErZ0h5+FIvu8bVapksV6c37U0 QJIPDx46Q/Bdz1C3NtclYWz3x9At/lzsPF6t83FC36RNiNw5qPnv/fcOjLH2JV+rQj H5Te+IvMWY3ozYOhyOpKgrgHdR4GhF89ZSwIGd5c= Received: from vimdzmsp-nwas02.bluewin.ch (vimdzmsp-nwas02.bluewin.ch [195.186.228.50]) by sourceware.org (Postfix) with ESMTPS id 4F60D3858D28 for ; Fri, 19 Aug 2022 17:46:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F60D3858D28 Received: from patrick.monnerat ([92.106.168.209]) by vimdzmsp-nwas02.bluewin.ch Swisscom AG with ESMTP id P650oDwnjJLjaP655ow17t; Fri, 19 Aug 2022 19:46:51 +0200 Received: from patrick.monnerat (localhost [127.0.0.1]) by patrick.monnerat (8.17.1/8.16.1) with ESMTPS id 27JHkdim144889 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 19 Aug 2022 19:46:39 +0200 Received: (from patrick@localhost) by patrick.monnerat (8.17.1/8.17.1/Submit) id 27JHkdfB144888; Fri, 19 Aug 2022 19:46:39 +0200 X-Authentication-Warning: patrick.monnerat: patrick set sender to patrick@monnerat.net using -f To: gdb-patches@sourceware.org Subject: [PATCH] gdb: add a file event mask parameter to add_file_handler Date: Fri, 19 Aug 2022 19:46:01 +0200 Message-Id: <20220819174601.144876-1-patrick@monnerat.net> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfNdAWpZgvmZIEU1H2v/fedf7s8t+g8UYdIb+io/q+ZQZ/OxaczTRQt7PQ0p+ANBqXNAEXb88JR5VZ1DaCZKL0uS4jWTew3oTHyaTy8tCZsPghac3lluf l7zVSgZU3MoNw9TiXckh53lDjADUwgXnhgAPf9+LFInw/GpQNrtqgbNq89N2nXPUK/y3kNkV4wUHb51AdXAgLa42kPl2m7SzAiI= 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: , From: Patrick Monnerat via Gdb-patches Reply-To: Patrick Monnerat Errors-To: gdb-patches-bounces+public-inbox=simark.ca@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 | 40 ++++++++++++++++++++++------------------ gdbsupport/event-loop.h | 11 +++++++++-- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc index 941885529f1..b4797ae04b8 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,11 @@ 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 (fd < 0 || (mask & (GDB_READABLE | GDB_WRITABLE | GDB_EXCEPTION)) == 0) + return; + #ifdef HAVE_POLL if (use_poll) { @@ -282,25 +283,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, -- 2.37.1