From patchwork Sun Oct 29 17:35:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 78687 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 32DE0387546B for ; Sun, 29 Oct 2023 17:40:00 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id D42953861894 for ; Sun, 29 Oct 2023 17:38:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D42953861894 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D42953861894 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698601114; cv=none; b=SIlz1c2+WiREvBJlxivkqxMdKwnXPETz/sCZ+e0pWcHhjC53aStKEIxMFI5tjym38oW7NFjRrQVjTfpdufaaCcRuGdU4zUGVJ/vErxEWtA0LLihxns+hwqY7GMPHdwsv9Vh6nZrKWeqRmehmseEM1dKTIiEWMf0jrl+/y1bTELU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698601114; c=relaxed/simple; bh=OBzJ27ByNGTNBMuNu9GE8K8SWvZvHn8XcCzH6zSGCCo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=e+LYM7b8kBKFiUQK/vLl/Rh7HxcP4NoC+JM01q6aAr0+IeOHoKekvnQ55RF7RUOuFlCEf+IqD2+Z6mE5XL00Uibrt0vofKXnPF/iQpIljePHJ0cvKLDtO8pGs12Ilhpa/2XnzPxoploqzkC83Qe2Q/+iD22m9KOrXVK+vgTBIgI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5002a.ext.cloudfilter.net ([10.0.29.215]) by cmsmtp with ESMTPS id x4TWqA6f66nOZx9k3qvsTy; Sun, 29 Oct 2023 17:38:27 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id x9k2qh6ErF1O4x9k3q4W6k; Sun, 29 Oct 2023 17:38:27 +0000 X-Authority-Analysis: v=2.4 cv=CcwbWZnl c=1 sm=1 tr=0 ts=653e9893 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=bhdUkHdE2iEA:10 a=Qbun_eYptAEA:10 a=bPD8YYKBUqYfeLPULJ0A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=A7QXYNuqWYlIbn0b0kLZ/o5Sjt6RpG0dTERaEypmyT0=; b=afzLX+Two+zHmK8xEyRBheli3m 57n8JmL0ae5TK6rUE42XOn8fxptGu/8t5Clf0Z6PG7mCkO7Y0IeVthZ4UgoDGWZiUPUToSX4mrx8Y wk/Nhh12/2siaES1yGJr9XQTl; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:47472 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1qx9k2-000nop-23; Sun, 29 Oct 2023 11:38:26 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/15] Lazy language setting Date: Sun, 29 Oct 2023 11:35:31 -0600 Message-ID: <20231029173839.471514-13-tom@tromey.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231029173839.471514-1-tom@tromey.com> References: <20231029173839.471514-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.77.73 X-Source-L: No X-Exim-ID: 1qx9k2-000nop-23 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:47472 X-Source-Auth: tom+tromey.com X-Email-Count: 13 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfPdVtlsXLsKjvamJSH03nC6P1a1Sbu78zxZ7E+031VHjramWO8JbVn11K6H6zGSK3V6vOHYkWrgjVlKm3+XTJ5cB3aJEYrRlnM3hFZ5wa+NCkze8Q3j1 DvQ4EKGxB1xDnyPP/jO/qq/9xlbqrybIL29lXtUyP8IGk76BAE/s+VsTXUyaoXfaPuqytweq3sZO2DQ6ETd0wRgi1+7+kVx80I4= X-Spam-Status: No, score=-3024.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org When gdb starts up with a symbol file, it uses the program's "main" to decide the "static context" and the initial language. With background DWARF reading, this means that gdb has to wait for a significant amount of DWARF to be read synchronously. This patch introduces lazy language setting. The idea here is that in many cases, the prompt can show up early, making gdb feel more responsive. --- gdb/gdbthread.h | 3 ++- gdb/language.c | 35 +++++++++++++++++++++++++++++++++++ gdb/language.h | 27 ++++++++++++++++++++------- gdb/symfile.c | 18 +++++++++++++----- gdb/thread.c | 8 +++----- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 48f32bb3a0b..ed00cbcf32e 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -35,6 +35,7 @@ struct symtab; #include "displaced-stepping.h" #include "gdbsupport/intrusive_list.h" #include "thread-fsm.h" +#include "language.h" struct inferior; struct process_stratum_target; @@ -888,7 +889,7 @@ class scoped_restore_current_thread /* Save/restore the language as well, because selecting a frame changes the current language to the frame's language if "set language auto". */ - enum language m_lang; + scoped_restore_current_language m_lang; }; /* Returns a pointer into the thread_info corresponding to diff --git a/gdb/language.c b/gdb/language.c index d38e2c04afb..acb11a74486 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -80,6 +80,7 @@ enum case_sensitivity case_sensitivity = case_sensitive_on; /* The current language and language_mode (see language.h). */ static const struct language_defn *global_current_language; +static lazily_set_language_ftype *lazy_language_setter; enum language_mode language_mode = language_mode_auto; /* See language.h. */ @@ -87,9 +88,41 @@ enum language_mode language_mode = language_mode_auto; const struct language_defn * get_current_language () { + if (lazy_language_setter != nullptr) + { + /* Avoid recursive calls -- set_language refers to + current_language. */ + lazily_set_language_ftype *call = lazy_language_setter; + lazy_language_setter = nullptr; + call (); + } return global_current_language; } +void +lazily_set_language (lazily_set_language_ftype *fun) +{ + lazy_language_setter = fun; +} + +scoped_restore_current_language::scoped_restore_current_language () + : m_lang (global_current_language), + m_fun (lazy_language_setter) +{ +} + +scoped_restore_current_language::~scoped_restore_current_language () +{ + /* If both are NULL, then that means dont_restore was called. */ + if (m_lang != nullptr || m_fun != nullptr) + { + global_current_language = m_lang; + lazy_language_setter = m_fun; + if (lazy_language_setter == nullptr) + set_range_case (); + } +} + /* The language that the user expects to be typing in (the language of main(), or the last language we notified them about, or C). */ @@ -185,6 +218,7 @@ set_language (const char *language) /* Found it! Go into manual mode, and use this language. */ language_mode = language_mode_manual; + lazy_language_setter = nullptr; global_current_language = lang; set_range_case (); expected_language = lang; @@ -372,6 +406,7 @@ set_range_case (void) void set_language (enum language lang) { + lazy_language_setter = nullptr; global_current_language = language_def (lang); set_range_case (); } diff --git a/gdb/language.h b/gdb/language.h index 6ff6f5eb95f..6cbcd119dac 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -787,6 +787,10 @@ extern void language_info (); extern void set_language (enum language lang); +typedef void lazily_set_language_ftype (); +extern void lazily_set_language (lazily_set_language_ftype *fun); + + /* Test a character to decide whether it can be printed in literal form or needs to be printed in another representation. For example, in C the literal form of the character with octal value 141 is 'a' @@ -837,14 +841,14 @@ class scoped_restore_current_language { public: - explicit scoped_restore_current_language () - : m_lang (current_language->la_language) - { - } + scoped_restore_current_language (); + ~scoped_restore_current_language (); - ~scoped_restore_current_language () + scoped_restore_current_language (scoped_restore_current_language &&other) { - set_language (m_lang); + m_lang = other.m_lang; + m_fun = other.m_fun; + other.dont_restore (); } scoped_restore_current_language (const scoped_restore_current_language &) @@ -852,9 +856,18 @@ class scoped_restore_current_language scoped_restore_current_language &operator= (const scoped_restore_current_language &) = delete; + /* Cancel restoring on scope exit. */ + void dont_restore () + { + /* This is implemented using a sentinel value. */ + m_lang = nullptr; + m_fun = nullptr; + } + private: - enum language m_lang; + const language_defn *m_lang; + lazily_set_language_ftype *m_fun; }; /* If language_mode is language_mode_auto, diff --git a/gdb/symfile.c b/gdb/symfile.c index a89876c6835..7b45343b5de 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1683,13 +1683,11 @@ symbol_file_command (const char *args, int from_tty) } } -/* Set the initial language. */ +/* Lazily set the initial language. */ -void -set_initial_language (void) +static void +set_initial_language_callback () { - if (language_mode == language_mode_manual) - return; enum language lang = main_language (); /* Make C the default language. */ enum language default_lang = language_c; @@ -1714,6 +1712,16 @@ set_initial_language (void) expected_language = current_language; /* Don't warn the user. */ } +/* Set the initial language. */ + +void +set_initial_language (void) +{ + if (language_mode == language_mode_manual) + return; + lazily_set_language (set_initial_language_callback); +} + /* Open the file specified by NAME and hand it off to BFD for preliminary analysis. Return a newly initialized bfd *, which includes a newly malloc'd` copy of NAME (tilde-expanded and made diff --git a/gdb/thread.c b/gdb/thread.c index c8145da59bc..94f2050c459 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1405,13 +1405,13 @@ scoped_restore_current_thread::restore () && target_has_stack () && target_has_memory ()) restore_selected_frame (m_selected_frame_id, m_selected_frame_level); - - set_language (m_lang); } scoped_restore_current_thread::~scoped_restore_current_thread () { - if (!m_dont_restore) + if (m_dont_restore) + m_lang.dont_restore (); + else restore (); } @@ -1419,8 +1419,6 @@ scoped_restore_current_thread::scoped_restore_current_thread () { m_inf = inferior_ref::new_reference (current_inferior ()); - m_lang = current_language->la_language; - if (inferior_ptid != null_ptid) { m_thread = thread_info_ref::new_reference (inferior_thread ());