From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 34FBC3854811; Tue, 7 Mar 2023 15:05:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34FBC3854811 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678201502; bh=MXeVrsTLZWnqREOsO/++NBuSZDV3KkM7oZhxbzTah5Y=; h=From:To:Subject:Date:From; b=eOjTBFJre6mXCCOk3+nxTqxFfHj8DZ+tsEey5F4FYJYacr2rfxvM8t7VSbqeZQPeY 6EbI1IMm78zZHnR1isXTsPU+jj991cVj9KXgLgf9CCn0oxpfSe5FKcd3BnU4u/WPPo EA9xzdcjUzqdKJSm6+7sojHgdmR6iLwPwYFB+tyc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Ensure index cache entry written in test X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: e9f59c6f6c02242c272171e28dd6dfec2fcf7a1c X-Git-Newrev: f0c3dcc1ca714cb17602f4c12c00b3604f36b035 Message-Id: <20230307150502.34FBC3854811@sourceware.org> Date: Tue, 7 Mar 2023 15:05:02 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df0c3dcc1ca71= 4cb17602f4c12c00b3604f36b035 commit f0c3dcc1ca714cb17602f4c12c00b3604f36b035 Author: Tom Tromey Date: Fri Mar 3 09:41:35 2023 -0700 Ensure index cache entry written in test =20 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. =20 This patch fixes the problem by introducing a new maintenance command to wait for all pending writes to the index cache. =20 Approved-By: Simon Marchi Reviewed-By: Eli Zaretskii Diff: --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 6 ++++++ gdb/dwarf2/cooked-index.c | 15 +++++++++++++++ gdb/testsuite/gdb.base/index-cache.exp | 8 +++++++- 4 files changed, 31 insertions(+), 1 deletion(-) 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. =20 +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. =20 +@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" =20 /* 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 (); } =20 +/* 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 =20 + 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.bas= e/index-cache.exp index 0614d4ee2db..ec69f0f11ad 100644 --- a/gdb/testsuite/gdb.base/index-cache.exp +++ b/gdb/testsuite/gdb.base/index-cache.exp @@ -84,6 +84,10 @@ proc run_test_with_flags { cache_dir cache_enabled code = } { =20 clean_restart ${testfile} =20 + # The tests generally want to check the cache, so make sure it + # has completed its work. + gdb_test_no_output "maintenance wait-for-index-cache" + uplevel 1 $code } } @@ -201,7 +205,9 @@ proc_with_prefix test_cache_enabled_hit { cache_dir } { global expecting_index_cache_use =20 # Just to populate the cache. - run_test_with_flags $cache_dir on {} + with_test_prefix "populate cache" { + run_test_with_flags $cache_dir on {} + } =20 lassign [ls_host $cache_dir] ret files_before