From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id vzzQKL8f/mIrESkAWB0awg (envelope-from ) for ; Thu, 18 Aug 2022 07:17:19 -0400 Received: by simark.ca (Postfix, from userid 112) id 9A95B1E5EA; Thu, 18 Aug 2022 07:17:19 -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=mUPuvdvf; 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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 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 ED0C51E13B for ; Thu, 18 Aug 2022 07:17:16 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06EC9385842F for ; Thu, 18 Aug 2022 11:17:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06EC9385842F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660821436; bh=6m6MeDrhHPpKGGzqCjckfosBrT9n3FL0SVcY//bQUI4=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mUPuvdvf+TNJE58chZGDZXeQYY3cz70tlbOHZAvbmE3hCjJ9WH1TPjVlsnHv7HMO7 IRvZ1ZcXFVyI9FM2qRlDQn1K6DuU6x8uOzMG61ZVFHOUXqGuYcY63HvKFBOLawflDf 11Io7yu0NppPZfxxxxA66OMCOaRPQGM87C+mbTpE= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 23CBB3858D28 for ; Thu, 18 Aug 2022 11:16:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23CBB3858D28 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-393-8M-CKzXGOBG844w4wkrvzw-1; Thu, 18 Aug 2022 07:16:54 -0400 X-MC-Unique: 8M-CKzXGOBG844w4wkrvzw-1 Received: by mail-wm1-f71.google.com with SMTP id j36-20020a05600c1c2400b003a540d88677so807337wms.1 for ; Thu, 18 Aug 2022 04:16:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc; bh=6m6MeDrhHPpKGGzqCjckfosBrT9n3FL0SVcY//bQUI4=; b=BvWvzj/vi/ov2g5UwpLmcjIzxgp7/hICxgLgVCI1cN2aTWL2uHIjTZMwZEPl7VLVO9 4GYH03WJAcAjlbxf9lqx2TfdN4tItwii6gCGi8pwsCo1XfQElpFjEqu7qMYx+YxigSos ro4qSGTITCRXkZLY4sUIFt2TVrp+vAszxvzqSiZtuJcxucUo+WOfYavnapUBexPfeWr8 QAqAiqLrxpsU+QwgcfYwcvL8j80/FTvnipCTfcgEoxHYA5jYXUtIhR4QqMqgm6VbO5AG OjYYyVPimMBo+qCaZ/JJZcv7Tab/HJ7WRUSe9a00XYmDV+OGyJ7kzd1NGEhqhpOp+QX6 fiPQ== X-Gm-Message-State: ACgBeo1NB7fkEuQvjAUcpyR+BJcQTcZGSXI+Wh7vXpxWYAZONfrHzQXf 4MiQjZ/lf+ZNgIxZ6RkxXFZiJIQjsoXjixWZNz69YsCCbQ7sFnzZNKYhDFvHVNeY52VsvvRpydI RgjHSltRgq/w5rDpZYlodHw== X-Received: by 2002:a5d:6489:0:b0:220:6399:c7c8 with SMTP id o9-20020a5d6489000000b002206399c7c8mr1393199wri.655.1660821413258; Thu, 18 Aug 2022 04:16:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Z9Xw+jauCPchBXBfz0rVBsdQYricdMJadsaDfHWWO/qRGX4y26egTVs+zo0k9yrD22Cq5jA== X-Received: by 2002:a5d:6489:0:b0:220:6399:c7c8 with SMTP id o9-20020a5d6489000000b002206399c7c8mr1393188wri.655.1660821412959; Thu, 18 Aug 2022 04:16:52 -0700 (PDT) Received: from localhost ([31.111.84.229]) by smtp.gmail.com with ESMTPSA id e26-20020a05600c219a00b003a5de95b105sm5095023wme.41.2022.08.18.04.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 04:16:52 -0700 (PDT) To: Patrick Monnerat , gdb-patches@sourceware.org Subject: Re: [PATCH] Add a timeout parameter to gdb_do_one_event In-Reply-To: <20220317130846.162955-1-patrick@monnerat.net> References: <20220317130846.162955-1-patrick@monnerat.net> Date: Thu, 18 Aug 2022 12:16:51 +0100 Message-ID: <87tu69ajj0.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Patrick Monnerat via Gdb-patches writes: > 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 gdb 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. > --- > gdbsupport/event-loop.cc | 45 +++++++++++++++++++++++++++++++--------- > gdbsupport/event-loop.h | 2 +- > 2 files changed, 36 insertions(+), 11 deletions(-) > > diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc > index 385b45b2de1..14168cae5a6 100644 > --- a/gdbsupport/event-loop.cc > +++ b/gdbsupport/event-loop.cc > @@ -33,6 +33,8 @@ > #include > #include "gdbsupport/gdb_sys_time.h" > #include "gdbsupport/gdb_select.h" > +#include "gdbsupport/gdb_optional.h" > +#include "gdbsupport/scope-exit.h" > > /* See event-loop.h. */ > > @@ -177,12 +179,17 @@ 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 > + 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. > + A timeout of 0 allows to serve an already pending event, but does not > + wait if none found. > + Setting the timeout to a negative value disables it. > + The timeout is never used by gdb itself, it is however needed to > + integrate gdb event handling within Insight's GUI event loop. */ > > int > -gdb_do_one_event (void) > +gdb_do_one_event (int mstimeout) > { > static int event_source_head = 0; > const int number_of_sources = 3; > @@ -229,17 +236,35 @@ gdb_do_one_event (void) > return 1; > } > > + if (!mstimeout) > + return 0; /* Null timeout: do not wait for an event. */ > + This should be: if (mstimeout == 0) As mstimeout is an int, not a bool. > /* Block waiting for a new event. If gdb_wait_for_event returns -1, > we should get out because this means that there are no event > sources left. This will make the event loop stop, and the > - application exit. */ > + application exit. > + If a timeout has been given, a new timer is set accordingly > + to abort event wait. It is deleted upon gdb_wait_for_event > + termination and thus should never be triggered. > + When the timeout is reached, events are not monitored again: > + they already have been checked in the loop above. */ > > - if (gdb_wait_for_event (1) < 0) > - return -1; > + gdb::optional timer_id; > > - /* If gdb_wait_for_event has returned 1, it means that one event has > - been handled. We break out of the loop. */ > - return 1; > + SCOPE_EXIT > + { > + if (timer_id.has_value ()) > + delete_timer (*timer_id); > + }; > + > + if (mstimeout > 0) > + timer_id = create_timer (mstimeout, > + [] (gdb_client_data arg) > + { > + ((gdb::optional *) arg)->reset (); > + }, > + &timer_id); > + return gdb_wait_for_event (1); More just a warning really, but this isn't going to work in all cases. If a target doesn't support async-mode then GDB will block waiting for events in the check_async_event_handlers call above, and never gets down this far. I'm interested in this because I also want to have the event loop run under a timeout for a patch I'm working on, and everything works fine except for the case when I run with async support disabled. I'm currently investigating having non-async targets ask the event loop for a maximum wait time before they block, then return to the event loop in order to check timers. If I can get this working, I'll want to move your create_timer call to the start of gdb_do_one_event, so that the timer is in place before the call to check_async_event_handlers - though I'm not quite sure how this would be expected to interact with the case where 'mstimeout == 0'. Thanks, Andrew > } > > /* See event-loop.h */ > diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h > index 9ed592877ab..c82493e9bdf 100644 > --- a/gdbsupport/event-loop.h > +++ b/gdbsupport/event-loop.h > @@ -76,7 +76,7 @@ typedef void (timer_handler_func) (gdb_client_data); > > /* Exported functions from event-loop.c */ > > -extern int gdb_do_one_event (void); > +extern int gdb_do_one_event (int mstimeout = -1); > extern void delete_file_handler (int fd); > > /* Add a file handler/descriptor to the list of descriptors we are > -- > 2.35.1