[12/15] Lazy language setting
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
fail
|
Testing failed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
fail
|
Testing failed
|
Commit Message
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(-)
@@ -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
@@ -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 ();
}
@@ -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,
@@ -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
@@ -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 ());