From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ebhpDqabJ2FWLQAAWB0awg (envelope-from ) for ; Thu, 26 Aug 2021 09:48:22 -0400 Received: by simark.ca (Postfix, from userid 112) id 29F431EE1B; Thu, 26 Aug 2021 09:48:22 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: * X-Spam-Status: No, score=1.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED, URIBL_DBL_SPAM autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 B27AC1ECEB for ; Thu, 26 Aug 2021 09:48:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2653857C67 for ; Thu, 26 Aug 2021 13:48:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2653857C67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629985701; bh=LmGzUGcCW14NbudlcYemfhcQU1ekBKTiFTFJtegdYk8=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fi79dyIIpNcv3fXRM12PkHjEyBBxgLZeA1JpMjx3WTLM4Dy1GfMtYUc0JK7Lz1moW uE0OuYMWp4+eUdfxq6R4QcBnde6Op49flTKNkuZ7sNNTKIC15oHxRvoAGM+Acy6tID AWirTCyQ/rlgFzO41uyM9+r0qhFfaQbPZxw6lbfI= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id BE6D43858402 for ; Thu, 26 Aug 2021 13:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE6D43858402 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 17QDlauD016825 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Aug 2021 09:47:41 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 17QDlauD016825 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E7C3A1ECEB; Thu, 26 Aug 2021 09:47:35 -0400 (EDT) Subject: Re: [PATCH] Add a timeout parameter to gdb_do_one_event To: Patrick Monnerat , gdb-patches@sourceware.org References: <20210823182359.104456-1-patrick@monnerat.net> <4e3085bb-af40-e0dc-73aa-991f97243e06@polymtl.ca> <60a52fef-89f0-62f1-1a45-5e5a40f47df6@monnerat.net> Message-ID: <12e53aee-05ae-8060-df57-0fc722d4a82c@polymtl.ca> Date: Thu, 26 Aug 2021 09:47:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <60a52fef-89f0-62f1-1a45-5e5a40f47df6@monnerat.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 26 Aug 2021 13:47:36 +0000 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: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-08-26 7:36 a.m., Patrick Monnerat wrote: > > On 8/26/21 5:24 AM, Simon Marchi wrote: >> On 2021-08-23 2:23 p.m., Patrick Monnerat via Gdb-patches wrote: >>> Since commit b2d8657, having a per-interpreter event/command loop is not >>> possible anymore. >>> >>> As Insight uses a GUI that has its own event loop, gdb and GUI event >>> loops have then to be "merged" (i.e.: work together). But this is >>> problematic as gdb_do_one_event is not aware of this alternate event >>> loop and thus may wait forever. >>> >>> The solution is to implement a wait timeout to gdb_do_one_event. This >>> cannot be done externally as timers are event sources themselves. >>> >>> The new parameter defaults to "no timeout": as it is used by Insight >>> only, there is no need to update calls from the gdb source tree. >> So, Insight's main loop looks like: >> >> while True: >> call gdb_do_one_event with a timeout >> call gui_do_one_event with a timeout >> >> ? > > Not exactly, although this is the first idea that emerges. But this approach is not reactive enough and consumes CPU uselessly. Indeed, happy to know it's not that. > The real implementation makes the GUI event loop call gdb_do_one_event and recursively. The actual event waiting is performed by gdb_do_one_event, but the GUI may define a timeout for it. The hard task here is to avoid infinite recursion. > > As Insight GUI is Tcl/Tk, a Tcl C API feature called a notifier (https://www.tcl.tk/man/tcl8.4/TclLib/Notifier.html) allowed me to design such a strategy. See https://sourceware.org/git/?p=insight.git;a=blob;f=gdbtk/generic/gdbtk.c line 247 and under to satisfy your curiosity! But it is a quite large part of the interface between the 2 subsystems that was not needed before gdb commit b2d8657. Note that an additional patch (unsubmitted yet) is needed to map Tcl file events into gdb file handlers. Ok, so you use GDB's event loop, registering some additional events in it. For example, the user clicking a button will generate an event, wake up gdb_wait_for_event and call your handler to go do the GUI work. Is that it? And the timeout is needed to call into the GUI subsystem to do some periodic work? >>> --- >>> gdbsupport/event-loop.cc | 45 ++++++++++++++++++++++++++++------------ >>> gdbsupport/event-loop.h | 2 +- >>> 2 files changed, 33 insertions(+), 14 deletions(-) >>> >>> diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc >>> index 98d1ada52cd..72c64dcdb72 100644 >>> --- a/gdbsupport/event-loop.cc >>> +++ b/gdbsupport/event-loop.cc >>> @@ -177,16 +177,21 @@ static int update_wait_timeout (void); >>> static int poll_timers (void); >>> >>> /* Process one high level event. If nothing is ready at this time, >>> - wait for something to happen (via gdb_wait_for_event), then process >>> - it. Returns >0 if something was done otherwise returns <0 (this >>> - can happen if there are no event sources to wait for). */ >>> + wait at most mstimeout milliseconds for something to happen (via >> mstimeout -> MSTIMEOUT > Even if not a constant but the name of a parameter? Yes, if you look around, this is how we refer to parameter names in comment. Like it or hate it, that's how it is. >>> + gdb_wait_for_event), then process it. Returns >0 if something was >>> + done, <0 if there are no event sources to wait for, =0 if timeout occurred. >>> + Setting the timeout to a negative value disables it. >> Does setting the timeout to 0 mean return immediately if nothing is >> available? > Yes, Ok, can you mention it in the comment? I don't think it is mentioned. >> Probably not a practical concern, but by creating timers over and over, >> for a reaaaaaaally long GDB session, the timer id will eventually wrap >> and create_timer might return 0. I don't know what will happen then. > > Yes, you're right. I'll change it. Maybe an RAII class here too? Not sure, event with an RAII class you need a way to flag whether a timer was created or not. Maybe optional? gdb::optional timer_id; if (mstimeout > 0) timer_id = create_timer (...); res = gdb_wait_for_event (1); if (timer_id.has_value ()) delete_timer (*timer_id); Simon