From patchwork Tue Dec 6 19:27:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 61605 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 B5584383B69E for ; Tue, 6 Dec 2022 19:28:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5584383B69E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670354896; bh=nqh1+euKOpBjz1ulXAOzepQLrd1l8zCO041lUug9NX4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tSILwh2XYQaPeDCKDq+1TCFBgHH+gdu8tQImqTdJs07eUtiHOxqdS6KXR/xOCmddb HQLp+MUY6dBhKm2Bt4m3PljZJQgtpTCXOM5FRENJXVTZAMUt78SQCyhCkF5gtxNULt MoOk56TiIobC9TwFWvKkCxssDn+YudGYYjraIXR4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 564B83875B62 for ; Tue, 6 Dec 2022 19:27:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 564B83875B62 Received: by mail-il1-x134.google.com with SMTP id o13so6924073ilc.7 for ; Tue, 06 Dec 2022 11:27:53 -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=nqh1+euKOpBjz1ulXAOzepQLrd1l8zCO041lUug9NX4=; b=d9EGZ8PsosLAj1MWI39ApHbkJLz+9Hznx0pg/jevhoQNV4U6qm6ZLL/1xm0AJac0b4 RJkmXVuGycnYEQvnnnfcc6GZWuHUfZQ57aj5DWmsxxUOX9vpHKB3zjdHNaSJIsCxQX98 E+B7o5dV+W6L3HlXw1mZ6XYcIWdq7CExiom/itiScHIHaPjC+IrF/6jXn/5OH2+1pvru O9Un2DrKLLP+J2xUOFwml8VUHwQxzGKambZ+Ye6+njlAOLnRRFasXlgxqqNYRCZ0axsx Ri3b1ixe1LjOPwh/wUgRVPITrWqzWcpTX8uGGWgxbMoFmlnlAKj8v8jNsanQsMj0dI91 bQzg== X-Gm-Message-State: ANoB5pn3UeGUjEG5N+AjlQLACZm1fnPTBk5aSqv69UWav4iHYRVyshj5 y/NNpq7Z5Rhxl/s7rKM0wrYRWveUneebet0F X-Google-Smtp-Source: AA0mqf76E2eiGZaz2DbaDuUOHkDYrAI/42Lk3ZhKQH80qQkwKQIIF1TMEaEAY2fxbNe66p8JmlSXBw== X-Received: by 2002:a92:cccd:0:b0:302:58d0:2510 with SMTP id u13-20020a92cccd000000b0030258d02510mr33959666ilq.27.1670354872520; Tue, 06 Dec 2022 11:27:52 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id n9-20020a056602340900b006e00556dc9esm3800185ioz.16.2022.12.06.11.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 11:27:52 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Let user C-c when waiting for DWARF index finalization Date: Tue, 6 Dec 2022 12:27:43 -0700 Message-Id: <20221206192743.2827834-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29854 --- gdb/dwarf2/cooked-index.c | 17 +++++++++++++++++ gdb/dwarf2/cooked-index.h | 11 +++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 0aa026c7779..a0b75a311b1 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -25,6 +25,7 @@ #include "ada-lang.h" #include "split-name.h" #include +#include /* Hash function for cooked_index_entry. */ @@ -282,6 +283,22 @@ cooked_index::find (gdb::string_view name, bool completing) return range (lower, upper); } +/* See cooked-index.h. */ + +void +cooked_index::wait (bool allow_quit) +{ + if (allow_quit) + { + using namespace std::chrono_literals; + auto duration = 15ms; + while (m_future.wait_for (duration) == std::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 2ea32781be5..5412149588a 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -212,10 +212,7 @@ class cooked_index void finalize (); /* Wait for this index's finalization to be complete. */ - void wait () - { - m_future.wait (); - } + void wait (bool allow_quit = true); friend class cooked_index_vector; @@ -325,8 +322,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. */