From patchwork Mon Mar 6 16:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66044 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 09731385B512 for ; Mon, 6 Mar 2023 16:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09731385B512 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678121192; bh=Bqs1l/Z7ms1FxlDFSWOnxXojDc2XXvsPnPh9bxpBeUc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DqXCm4DapRmKJxfPaFcuZIGFZA8Q3f2dRj80+y5+CWBPwdlnUDiV7FYztDwl5OpTf y+2GBq+UzYQDx5xe+cIbrqiDO1X2xBwjEamfv5UXUr58V4mSSFUVWzfnHdtaKDN03l IsSD0lCJEAOpgjcMPnDj6H3dXinG9WT8i0g/MYTU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 7DE873858D39 for ; Mon, 6 Mar 2023 16:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DE873858D39 Received: by mail-il1-x12d.google.com with SMTP id y9so5637110ill.3 for ; Mon, 06 Mar 2023 08:46:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678121169; 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=Bqs1l/Z7ms1FxlDFSWOnxXojDc2XXvsPnPh9bxpBeUc=; b=IvOYqIZOjAT8gNpwjB9fk4CLSRn5gTAs33iWunwrgH5SvvrQ7dfWvw8KKNW3XbuoDB tohW7T3mKsTuODvI/T30NTYH5lXULOFfvRg8k7CCWJPH2tmjPaygbDLN38F6gHyhyfYf XJIh+8jLpPWrb976stb7FILEzCwl2pXjMbfecRfgIDZc1/92WMHn06+iq9AHi0F1vCon Zf5LaJpNAwP/CHwAyb3aSbLpDwWdzteXz5aaq2L0wDeO7/rKIZFW7FaLssk+LcFbc5kZ sZQnQ7jHa80Li+v4EJh/3zWhqnB9TbyBzepsVK4uW1OQH1PBW++b24F4Dg9p0O7I+oMR W3WQ== X-Gm-Message-State: AO0yUKU9kYYUaBFUVcT08/AJ1XQtcqdgOkyBCR5XqwfayoKMiOHJdLaG wUiuIt3W48XmrPihOLbk+Q3Mx1rXO6v4tME2IQw= X-Google-Smtp-Source: AK7set9snFfIDH3uZLgpae41Os8ksIAtBqB7r1A3pF0q1FqM+Xa6kN8vCbMNfgxKFqzJIm3qqc7i4A== X-Received: by 2002:a92:7409:0:b0:315:554e:e73b with SMTP id p9-20020a927409000000b00315554ee73bmr7357603ilc.21.1678121168769; Mon, 06 Mar 2023 08:46:08 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id h8-20020a056638062800b003c4fb4bcd4dsm3392845jar.125.2023.03.06.08.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 08:46:08 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2] Ensure index cache entry written in test Date: Mon, 6 Mar 2023 09:45:53 -0700 Message-Id: <20230306164553.1449009-1-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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" Now that index cache files are written in the background, one test in index-cache.exp is racy -- it assumes that the cache file will have been written during startup. This patch fixes the problem by introducing a new maintenance command to wait for all pending writes to the index cache. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 6 ++++++ gdb/dwarf2/cooked-index.c | 15 +++++++++++++++ gdb/testsuite/gdb.base/index-cache.exp | 2 ++ 4 files changed, 26 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index c32ff92c98a..8827efaefb6 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -68,6 +68,9 @@ maintenance info frame-unwinders List the frame unwinders currently in effect, starting with the highest priority. +maintenance wait-for-index-cache + Wait until all pending writes to the index cache have completed. + set always-read-ctf on|off show always-read-ctf When off, CTF is only read if DWARF is not present. When on, CTF is diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bfda7edc4f7..954f1481dae 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41374,6 +41374,12 @@ give an error. For platforms that do support creating the backtrace this feature is @code{on} by default. +@kindex maint wait-for-index-cache +@item maint wait-for-index-cache +Wait until all pending writes to the index cache have completed. This +is used by the test suite to avoid races when the index cache is being +updated by a worker thread. + @kindex maint with @item maint with @var{setting} [@var{value}] [-- @var{command}] Like the @code{with} command, but works with @code{maintenance set} diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 47746aa9905..d09faed268d 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -33,6 +33,7 @@ #include "gdbsupport/selftest.h" #include #include +#include "cli/cli-cmds.h" /* We don't want gdb to exit while it is in the process of writing to the index cache. So, all live cooked index vectors are stored @@ -640,6 +641,14 @@ wait_for_index_cache (int) item->wait_completely (); } +/* A maint command to wait for the cache. */ + +static void +maintenance_wait_for_index_cache (const char *args, int from_tty) +{ + wait_for_index_cache (0); +} + void _initialize_cooked_index (); void _initialize_cooked_index () @@ -648,5 +657,11 @@ _initialize_cooked_index () selftests::register_test ("cooked_index_entry::compare", test_compare); #endif + add_cmd ("wait-for-index-cache", class_maintenance, + maintenance_wait_for_index_cache, _("\ +Usage: maintenance wait-for-index-cache\n\ +Wait until all pending writes to the index cache have completed."), + &maintenancelist); + gdb::observers::gdb_exiting.attach (wait_for_index_cache, "cooked-index"); } diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp index 0614d4ee2db..7fdf90c2c24 100644 --- a/gdb/testsuite/gdb.base/index-cache.exp +++ b/gdb/testsuite/gdb.base/index-cache.exp @@ -159,6 +159,8 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } { run_test_with_flags $cache_dir on { + gdb_test_no_output "maintenance wait-for-index-cache" + lassign [ls_host $cache_dir] ret files_after set nfiles_created [expr [llength $files_after] - [llength $files_before]] if { $expecting_index_cache_use } {