From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6hsgEmPoI2EPNwAAWB0awg (envelope-from ) for ; Mon, 23 Aug 2021 14:26:43 -0400 Received: by simark.ca (Postfix, from userid 112) id 3A1521EE18; Mon, 23 Aug 2021 14:26:43 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham 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 6AA321ECEB for ; Mon, 23 Aug 2021 14:26:42 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0BA7385782D for ; Mon, 23 Aug 2021 18:26:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0BA7385782D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629743201; bh=xDA++7qSbgzZqmDoEdcix6dj+LA7eGCD+ZIG5RocS84=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ZXIIqIGlqLntJ1pL4kTCe4g6HdzpNOjaDz4Rv4n3nPzPFy3Wpo2yPnCAP5KhXJgDe cZIFxnaTu89cnwsK8uIoh6Ryts1P4QZOJ+vgDnSB93UZdb/V55iHjl2HS1aDtzm/zO ixXtP5b1QdNU2j0HblkcnUqbQ8FNJbCZ3xsiN5p4= Received: from vimdzmsp-nwas02.bluewin.ch (vimdzmsp-nwas02.bluewin.ch [195.186.228.50]) by sourceware.org (Postfix) with ESMTPS id 4B9343858038 for ; Mon, 23 Aug 2021 18:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B9343858038 Received: from patrick.monnerat ([178.193.82.56]) by vimdzmsp-nwas02.bluewin.ch Swisscom AG with ESMTP id IEd0mZUN9slQjIEd5mC5t7; Mon, 23 Aug 2021 20:25:04 +0200 Received: from patrick.monnerat (localhost [127.0.0.1]) by patrick.monnerat (8.16.1/8.16.1) with ESMTPS id 17NIOrIx104574 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 23 Aug 2021 20:24:53 +0200 Received: (from patrick@localhost) by patrick.monnerat (8.16.1/8.16.1/Submit) id 17NIO7Gs104503; Mon, 23 Aug 2021 20:24:07 +0200 X-Authentication-Warning: patrick.monnerat: patrick set sender to patrick@monnerat.net using -f To: gdb-patches@sourceware.org Subject: [PATCH] Add a timeout parameter to gdb_do_one_event Date: Mon, 23 Aug 2021 20:23:59 +0200 Message-Id: <20210823182359.104456-1-patrick@monnerat.net> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfFJcYDHhCsYCPLDoSDOK1S7xxkhS/dSyofc248r1LJnn753EXur8HsKOCU0JIcYDlIKjctfmazjLSse4CfxUUHI1fS7TqHIzX3opYHZax0H+SG2Hwuw1 2kUAy/SQilpZrxepNG4xnCS5euXvkmRdDRYaZlga4pU+exx1YLvuiaJNNJJWG9afjqFq2LobqHDW6+WmzEdupQEPzklRK45yEDE= 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" 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. --- 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 + 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. + The timeout is never used by gdb itself, it is however needed to + integrate gdb event handling within some external (i.e.: 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; int current = 0; + int res = 0; /* First let's see if there are any asynchronous signal handlers that are ready. These would be the result of invoking any of the @@ -198,8 +203,6 @@ gdb_do_one_event (void) round-robin fashion. */ for (current = 0; current < number_of_sources; current++) { - int res; - switch (event_source_head) { case 0: @@ -232,14 +235,30 @@ gdb_do_one_event (void) /* 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. */ - - if (gdb_wait_for_event (1) < 0) - return -1; + 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 (mstimeout != 0) + { + int timerid = 0; + + if (mstimeout > 0) + timerid = create_timer (mstimeout, + [] (gdb_client_data timeridp) + { + *((int *) timeridp) = 0; + }, + &timerid); + res = gdb_wait_for_event (1); + if (timerid) + delete_timer (timerid); + } - /* If gdb_wait_for_event has returned 1, it means that one event has - been handled. We break out of the loop. */ - return 1; + return res; } /* See event-loop.h */ diff --git a/gdbsupport/event-loop.h b/gdbsupport/event-loop.h index dc4e4d59f03..cf62f654c1c 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.31.1