This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[6/7] RFC: lazily set the initial language


One difficulty I ran into with the threading patch is that gdb paused at
startup anyway.  This happened because set_initial_language needed to
find 'main', which meant waiting for the OBJF_MAIN psymtab (typically)
to be read in.

However, we don't really need the current language to be set
immediately, so this patch changes it to be set lazily.

This is a bit ugly because it turns current_language into a #define.
I could s/current_language/get_current_language ()/ easily enough, but I
didn't want to do that on my branch.

Tom

>From 359ca2de0f736d5e742ec48177cc5eb4d395ae5f Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Fri, 11 Jun 2010 15:53:18 -0600
Subject: [PATCH 6/7] lazily set initial language

2010-06-14  Tom Tromey  <tromey@redhat.com>

	* symfile.h (set_initial_language): Remove.
	* symfile.c (symbol_file_add_main_1): Use
	lazily_set_initial_language.
	(set_initial_language): Remove.
	* language.h (get_current_language): Declare.
	(current_language): Now a #define.
	(language_demangle): Rename 'current_language' argument.
	(lazily_set_initial_language): Declare.
	* language.c (real_current_language): Rename from
	'current_language'.  Now static.
	(set_language_command): Use lazily_set_initial_language,
	real_current_language.
	(set_language): Use real_current_language.
	(initial_language_set): New global.
	(lazily_set_initial_language): New function.
	(get_current_language): New function.
	(language_demangle): Rename 'current_language' argument.
	(language_class_name_from_physname): Likewise.
---
 gdb/language.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++--------
 gdb/language.h |    8 ++++-
 gdb/symfile.c  |   33 +-------------------------
 gdb/symfile.h  |    2 -
 4 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/gdb/language.c b/gdb/language.c
index 90bb228..4ad689e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -89,7 +89,8 @@ enum case_sensitivity case_sensitivity = case_sensitive_on;
 
 /* The current language and language_mode (see language.h) */
 
-const struct language_defn *current_language = &unknown_language_defn;
+static const struct language_defn *real_current_language
+     = &unknown_language_defn;
 enum language_mode language_mode = language_mode_auto;
 
 /* The language that the user expects to be typing in (the language
@@ -165,7 +166,7 @@ set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
 	      if (flang != language_unknown)
 		set_language (flang);
 	      else
-		set_initial_language ();
+		lazily_set_initial_language ();
 	      expected_language = current_language;
 	      return;
 	    }
@@ -173,7 +174,7 @@ set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
 	    {
 	      /* Enter manual mode.  Set the specified language.  */
 	      language_mode = language_mode_manual;
-	      current_language = languages[i];
+	      real_current_language = languages[i];
 	      set_type_range_case ();
 	      expected_language = current_language;
 	      return;
@@ -434,7 +435,7 @@ set_language (enum language lang)
     {
       if (languages[i]->la_language == lang)
 	{
-	  current_language = languages[i];
+	  real_current_language = languages[i];
 	  set_type_range_case ();
 	  break;
 	}
@@ -442,6 +443,53 @@ set_language (enum language lang)
 
   return prev_language;
 }
+
+static int initial_language_set = 1;
+
+/* Set the initial language.
+
+   FIXME: A better solution would be to record the language in the
+   psymtab when reading partial symbols, and then use it (if known) to
+   set the language.  This would be a win for formats that encode the
+   language in an easily discoverable place, such as DWARF.  For
+   stabs, we can jump through hoops looking for specially named
+   symbols or try to intuit the language from the specific type of
+   stabs we find, but we can't do that until later when we read in
+   full symbols.  */
+
+void
+lazily_set_initial_language (void)
+{
+  initial_language_set = 0;
+}
+
+const struct language_defn *
+get_current_language (void)
+{
+  if (!initial_language_set)
+    {
+      char *filename;
+      enum language lang = language_unknown;
+
+      initial_language_set = 1;
+
+      filename = find_main_filename ();
+      if (filename != NULL)
+	lang = deduce_language_from_filename (filename);
+
+      if (lang == language_unknown)
+	{
+	  /* Make C the default language */
+	  lang = language_c;
+	}
+
+      set_language (lang);
+      expected_language = real_current_language; /* Don't warn the user.  */
+    }
+
+  return real_current_language;
+}
+
 
 
 /* Print out the current language settings: language, range and
@@ -997,21 +1045,21 @@ skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
    FIXME: Sometimes the demangler is invoked when we don't know the
    language, so we can't use this everywhere.  */
 char *
-language_demangle (const struct language_defn *current_language, 
-				const char *mangled, int options)
+language_demangle (const struct language_defn *lang, 
+		   const char *mangled, int options)
 {
-  if (current_language != NULL && current_language->la_demangle)
-    return current_language->la_demangle (mangled, options);
+  if (lang != NULL && lang->la_demangle)
+    return lang->la_demangle (mangled, options);
   return NULL;
 }
 
 /* Return class name from physname or NULL.  */
 char *
-language_class_name_from_physname (const struct language_defn *current_language,
+language_class_name_from_physname (const struct language_defn *lang,
 				   const char *physname)
 {
-  if (current_language != NULL && current_language->la_class_name_from_physname)
-    return current_language->la_class_name_from_physname (physname);
+  if (lang != NULL && lang->la_class_name_from_physname)
+    return lang->la_class_name_from_physname (physname);
   return NULL;
 }
 
diff --git a/gdb/language.h b/gdb/language.h
index 0c04208..364608c 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -342,7 +342,9 @@ struct language_defn
    the language of symbol files (e.g. detecting when ".c" files are
    C++), it should be a separate setting from the current_language.  */
 
-extern const struct language_defn *current_language;
+
+extern const struct language_defn *get_current_language (void);
+#define current_language get_current_language ()
 
 /* Pointer to the language_defn expected by the user, e.g. the language
    of main(), or the language we last mentioned in a message, or C.  */
@@ -489,7 +491,7 @@ extern enum language get_frame_language (void);	/* In stack.c */
 extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc);
 
 /* Return demangled language symbol, or NULL.  */
-extern char *language_demangle (const struct language_defn *current_language, 
+extern char *language_demangle (const struct language_defn *lang, 
 				const char *mangled, int options);
 
 /* Return class name from physname, or NULL.  */
@@ -523,4 +525,6 @@ void default_get_string (struct value *value, gdb_byte **buffer, int *length,
 void c_get_string (struct value *value, gdb_byte **buffer, int *length,
 		   struct type **char_type, const char **charset);
 
+void lazily_set_initial_language (void);
+
 #endif /* defined (LANGUAGE_H) */
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 169b482..6a22562 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1243,7 +1243,7 @@ symbol_file_add_main_1 (char *args, int from_tty, int flags)
      what is frameless.  */
   reinit_frame_cache ();
 
-  set_initial_language ();
+  lazily_set_initial_language ();
 }
 
 void
@@ -1542,37 +1542,6 @@ symbol_file_command (char *args, int from_tty)
     }
 }
 
-/* Set the initial language.
-
-   FIXME: A better solution would be to record the language in the
-   psymtab when reading partial symbols, and then use it (if known) to
-   set the language.  This would be a win for formats that encode the
-   language in an easily discoverable place, such as DWARF.  For
-   stabs, we can jump through hoops looking for specially named
-   symbols or try to intuit the language from the specific type of
-   stabs we find, but we can't do that until later when we read in
-   full symbols.  */
-
-void
-set_initial_language (void)
-{
-  char *filename;
-  enum language lang = language_unknown;
-
-  filename = find_main_filename ();
-  if (filename != NULL)
-    lang = deduce_language_from_filename (filename);
-
-  if (lang == language_unknown)
-    {
-      /* Make C the default language */
-      lang = language_c;
-    }
-
-  set_language (lang);
-  expected_language = current_language; /* Don't warn the user.  */
-}
-
 /* If NAME is a remote name open the file using remote protocol, otherwise
    open it normally.  */
 
diff --git a/gdb/symfile.h b/gdb/symfile.h
index f1024dc..0ee730d 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -444,8 +444,6 @@ extern int auto_solib_limit;
 
 /* From symfile.c */
 
-extern void set_initial_language (void);
-
 extern void find_lowest_section (bfd *, asection *, void *);
 
 extern bfd *symfile_bfd_open (char *);
-- 
1.6.2.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]