From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Let user C-c when waiting for DWARF index finalization
Date: Tue, 6 Dec 2022 12:27:43 -0700 [thread overview]
Message-ID: <20221206192743.2827834-1-tromey@adacore.com> (raw)
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 <algorithm>
+#include <chrono>
/* 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. */
--
2.34.3
next reply other threads:[~2022-12-06 19:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 19:27 Tom Tromey [this message]
2022-12-06 20:35 ` Simon Marchi
2022-12-14 14:49 ` Lancelot SIX
2022-12-14 18:00 ` Tom Tromey
2023-01-27 19:22 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221206192743.2827834-1-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).