From patchwork Mon Jan 30 20:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63923 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 293453858CDA for ; Mon, 30 Jan 2023 20:02:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 293453858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675108976; bh=hFWF/RTJ040koS2qdBg6emgS73kaVGV3/g3ds+gNPSc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nKbBnCKW4EIUgPJZM9cypvVfEnjtSP6lgdcIFbW53ao+WQ5q3PjCJ938whvYoOlJM CGxFBL9sOzcojPAgTCQylS0QvgTV7qBuNunGDi+3T9MAB4GtyZ/7aoZ/aen063EA06 I7ph1EOxERH+qyxa+ABDNtPmK+fSkNqY0VDJBUGs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id 8E8843858D32 for ; Mon, 30 Jan 2023 20:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E8843858D32 Received: by mail-io1-xd32.google.com with SMTP id l128so930798iof.2 for ; Mon, 30 Jan 2023 12:02:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hFWF/RTJ040koS2qdBg6emgS73kaVGV3/g3ds+gNPSc=; b=7AyYxsNdU+U72EJU9AMNVdeA9edDL7lHRJwpkw6r67X9ztB3Rd3HYmOt+pc9UDKNj5 33V7PILj1d60LwFsyU32wuu/uQRGQubfJcJJ1USE53QM/dJO5QGCw4PUyF8bcM7DS4Lb oe2Mo/71rqTHg8jppnnw/PE2F1qL6nrp7JW6yWcjUbBLonNpfpo0djP5ZRAIWdngjowB UvHr+h85LWUFf7tg4R3YMDLlDPObTyOWox8mOcv8v695Hp0FF4I93oNnmfDuKqC/rKLT auKMHGolYBpigRDE3rdDzJtjI+8AxWPSg925ZJ587pSwnczcrLo3qwO1z9rmMKso39X5 X7yg== X-Gm-Message-State: AFqh2krpZ0jzUMyFXrMY1+fUnjRjdvDS1qQaY8iIGsPzk+UUn4jMY0nW I1n4IPT6EI+2gfkD93c0tjbJH1c6mNzvijAQ X-Google-Smtp-Source: AMrXdXucf5JqngN8qgFEGmOFbwsHzAvoAMwqGPcByYFoQpga3X1W/Gep9mpAP3TJo6tYNvWKMq6ygg== X-Received: by 2002:a5d:9f0c:0:b0:6e2:d23a:6296 with SMTP id q12-20020a5d9f0c000000b006e2d23a6296mr33298699iot.20.1675108951435; Mon, 30 Jan 2023 12:02:31 -0800 (PST) Received: from localhost.localdomain (71-211-157-143.hlrn.qwest.net. [71.211.157.143]) by smtp.gmail.com with ESMTPSA id y193-20020a6bc8ca000000b006e02c489089sm3282588iof.32.2023.01.30.12.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 12:02:30 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2] Let user C-c when waiting for DWARF index finalization Date: Mon, 30 Jan 2023 13:02:20 -0700 Message-Id: <20230130200220.2879520-1-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In PR gdb/29854, Simon pointed out that it would be good to be able to use C-c when the DWARF cooked index is waiting for finalization. The idea here is to be able to interrupt a command like "break" -- not to stop the finalization process itself, which runs in a worker thread. This patch implements this idea, by changing the index wait functions to, by default, allow a quit. Polling is done, because there doesn't seem to be a better way to interrupt a wait on a std::future. For v2, I realized that the thread compatibility code in thread-pool.h also needed an update. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29854 --- gdb/dwarf2/cooked-index.c | 16 ++++++++++++++++ gdb/dwarf2/cooked-index.h | 11 +++++------ gdbsupport/thread-pool.h | 27 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 09d76523419..08a85104758 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -27,6 +27,7 @@ #include #include "safe-ctype.h" #include "gdbsupport/selftest.h" +#include /* See cooked-index.h. */ @@ -387,6 +388,21 @@ cooked_index::find (const std::string &name, bool completing) const return range (lower, upper); } +/* See cooked-index.h. */ + +void +cooked_index::wait (bool allow_quit) const +{ + if (allow_quit) + { + std::chrono::milliseconds duration { 15 }; + while (m_future.wait_for (duration) == gdb::future_status::timeout) + QUIT; + } + else + m_future.wait (); +} + cooked_index_vector::cooked_index_vector (vec_type &&vec) : m_vector (std::move (vec)) { diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 891659f56e0..2461622ae17 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -255,10 +255,7 @@ class cooked_index void finalize (); /* Wait for this index's finalization to be complete. */ - void wait () const - { - m_future.wait (); - } + void wait (bool allow_quit = true) const; friend class cooked_index_vector; @@ -369,8 +366,10 @@ class cooked_index_vector : public dwarf_scanner_base end up writing to freed memory. Waiting for finalization to complete avoids this problem; and the cost seems ignorable because creating and immediately destroying the debug info is a - relatively rare thing to do. */ - wait (); + relatively rare thing to do. Do not allow quitting from this + wait. */ + for (auto &item : m_vector) + item->wait (false); } /* A range over a vector of subranges. */ diff --git a/gdbsupport/thread-pool.h b/gdbsupport/thread-pool.h index 013c6abf8ea..cb8696e1fa4 100644 --- a/gdbsupport/thread-pool.h +++ b/gdbsupport/thread-pool.h @@ -23,6 +23,7 @@ #include #include #include +#include #if CXX_STD_THREAD #include #include @@ -40,8 +41,19 @@ namespace gdb template using future = std::future; +/* ... and the standard future_status. */ +using future_status = std::future_status; + #else /* CXX_STD_THREAD */ +/* A compatibility enum for std::future_status. This is just the + subset needed by gdb. */ +enum class future_status +{ + ready, + timeout, +}; + /* A compatibility wrapper for std::future. Once and are available in all GCC builds -- should that ever happen -- this can be removed. GCC does not implement threading for @@ -71,6 +83,13 @@ class future void wait () const { } + template + future_status wait_for (const std::chrono::duration &duration) + const + { + return future_status::ready; + } + T get () { return std::move (m_value); } private: @@ -85,6 +104,14 @@ class future { public: void wait () const { } + + template + future_status wait_for (const std::chrono::duration &duration) + const + { + return future_status::ready; + } + void get () { } };