From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 87A9B388F010 for ; Mon, 12 Jul 2021 16:07:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87A9B388F010 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 6482B70D6C; Mon, 12 Jul 2021 16:07:12 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GNpYr2Cfkz4fd4; Mon, 12 Jul 2021 16:07:12 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro.local (d-24-233-223-154.va.cpe.atlanticbb.net [24.233.223.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 1CACDF9E1; Mon, 12 Jul 2021 16:07:12 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: [RFC PATCH 1/7] gdbsupport: Add an event-pipe class. To: Pedro Alves , gdb-patches@sourceware.org References: <20210607170932.3954-1-jhb@FreeBSD.org> <20210607170932.3954-2-jhb@FreeBSD.org> From: John Baldwin Message-ID: Date: Mon, 12 Jul 2021 12:07:11 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 12 Jul 2021 16:07:13 -0000 On 6/27/21 9:12 AM, Pedro Alves wrote: > On 2021-06-07 6:09 p.m., John Baldwin wrote: >> This pulls out the implementation of an event pipe used to implement >> target async support in both linux-low.cc (gdbserver) and linux-nat.c >> (gdb). >> > > Seems like a good idea, thanks. > >> + /* Create a new pipe. */ >> + bool open (); >> + >> + /* Close the pipe. */ >> + void close (); >> + >> + /* True if the event pipe has been initialized. */ >> + bool active () const { return fds[0] != -1; } >> + > > Did you consider "is_open" instead of "active"? I think reading "active()" at the call > sites can make one wonder whether "active" is a different state from being > open, like e.g., the pipe is open but not registered in the event loop. Hmmm, I hadn't considered is_open. I think was just going off the names of the existing macros in the Linux targets, but I prefer is_open and will switch to that. >> diff --git a/gdbsupport/event-pipe.h b/gdbsupport/event-pipe.h >> new file mode 100644 >> index 0000000000..1717ea6790 >> --- /dev/null >> +++ b/gdbsupport/event-pipe.h >> @@ -0,0 +1,55 @@ >> +/* Event pipe for GDB, the GNU debugger. >> + >> + Copyright (C) 2021 Free Software Foundation, Inc. >> + >> + This file is part of GDB. >> + >> + This program is free software; you can redistribute it and/or modify >> + it under the terms of the GNU General Public License as published by >> + the Free Software Foundation; either version 3 of the License, or >> + (at your option) any later version. >> + >> + This program is distributed in the hope that it will be useful, >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + GNU General Public License for more details. >> + >> + You should have received a copy of the GNU General Public License >> + along with this program. If not, see . */ >> + >> +#ifndef COMMON_EVENT_PIPE_H >> +#define COMMON_EVENT_PIPE_H >> + >> +/* An event pipe used as a waitable file in the event loop in place of >> + some other event not associated with a file descriptor. */ > > Note this comment can be a little bit unclear given we also have > create_async_event_handler / mark_async_event_handler, for events not associated > with a file descriptor. > > We need to use a pipe iff we need to wake up the select/poll in the event loop > from a signal handler, otherwise we can use the cheaper mark_async_event_handler > from mainline code. > > Maybe mention in the comment that this is used for implementing the well-known > self-pipe trick? Yeah, I wanted to find a way to mention that anyway, and these are good points. Here is what I came up with: /* An event pipe used as a waitable file in the event loop in place of some other event associated with a signal. The handler for the signal marks the event pipe to force a wakeup in the event loop. This uses the well-known self-pipe trick. */ -- John Baldwin