make language_of_main static
authorTom Tromey <tromey@redhat.com>
Tue, 31 Dec 2013 03:05:34 +0000 (20:05 -0700)
committerTom Tromey <tromey@redhat.com>
Wed, 15 Jan 2014 19:06:04 +0000 (12:06 -0700)
This makes the global language_of_main static.  Now it can be set only
via a new argument to set_main_name.

2014-01-15  Tom Tromey  <tromey@redhat.com>

* dbxread.c (process_one_symbol): Update.
* dwarf2read.c (read_partial_die): Update.
* symfile.c (set_initial_language): Call main_language.
* symtab.c (language_of_main): Now static.
(set_main_name): Add 'lang' parameter.
(find_main_name): Update.
(main_language): New function.
(symtab_observer_executable_changed): Update.
* symtab.h (set_main_name): Update.
(language_of_main): Remove.
(main_language): Declare.

gdb/ChangeLog
gdb/dbxread.c
gdb/dwarf2read.c
gdb/symfile.c
gdb/symtab.c
gdb/symtab.h

index 0e28f6544c9f296376838540ab06e65af60f4b58..ae6d843aca10417f6d6aee52c2cca1485f4f1b5e 100644 (file)
@@ -1,3 +1,17 @@
+2014-01-15  Tom Tromey  <tromey@redhat.com>
+
+       * dbxread.c (process_one_symbol): Update.
+       * dwarf2read.c (read_partial_die): Update.
+       * symfile.c (set_initial_language): Call main_language.
+       * symtab.c (language_of_main): Now static.
+       (set_main_name): Add 'lang' parameter.
+       (find_main_name): Update.
+       (main_language): New function.
+       (symtab_observer_executable_changed): Update.
+       * symtab.h (set_main_name): Update.
+       (language_of_main): Remove.
+       (main_language): Declare.
+
 2014-01-15  Tom Tromey  <tromey@redhat.com>
 
        * symfile.c (init_entry_point_info): Use new "initialized" field.
index 9a10a1f1017b2c8b748ab52c54bb61cb6333f1ad..eab5113386d1b909c8370b0f860888f7fcb37648 100644 (file)
@@ -3250,7 +3250,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
         N_MAIN within a given objfile, complain() and choose
         arbitrarily.  (kingdon) */
       if (name != NULL)
-       set_main_name (name);
+       set_main_name (name, language_unknown);
       break;
 
       /* The following symbol types can be ignored.  */
index 609698b2e3765cdd5cff2a50f60c5be3aee5f425..0c3d16cd122dd836302e1b7418ed1ac51f143fef 100644 (file)
@@ -15322,13 +15322,7 @@ read_partial_die (const struct die_reader_specs *reader,
             practice.  */
          if (DW_UNSND (&attr) == DW_CC_program
              && cu->language == language_fortran)
-           {
-             set_main_name (part_die->name);
-
-             /* As this DIE has a static linkage the name would be difficult
-                to look up later.  */
-             language_of_main = language_fortran;
-           }
+           set_main_name (part_die->name, language_fortran);
          break;
        case DW_AT_inline:
          if (DW_UNSND (&attr) == DW_INL_inlined
index a567f6ddd29d6bb906a3f9340cc743f4737f72a5..06d2119072640d715fd311529accf996bd930f24 100644 (file)
@@ -1654,11 +1654,9 @@ symbol_file_command (char *args, int from_tty)
 void
 set_initial_language (void)
 {
-  enum language lang = language_unknown;
+  enum language lang = main_language ();
 
-  if (language_of_main != language_unknown)
-    lang = language_of_main;
-  else
+  if (lang == language_unknown)
     {
       char *name = main_name ();
       struct symbol *sym = lookup_symbol (name, NULL, VAR_DOMAIN, NULL);
index 5e988c88efceebfbc90192151e57938884ce62ea..a8073b8ef7e8027566949952b9115631e33a5f5f 100644 (file)
@@ -4999,10 +4999,10 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
 \f
 /* Track MAIN */
 static char *name_of_main;
-enum language language_of_main = language_unknown;
+static enum language language_of_main = language_unknown;
 
 void
-set_main_name (const char *name)
+set_main_name (const char *name, enum language lang)
 {
   if (name_of_main != NULL)
     {
@@ -5013,7 +5013,7 @@ set_main_name (const char *name)
   if (name != NULL)
     {
       name_of_main = xstrdup (name);
-      language_of_main = language_unknown;
+      language_of_main = lang;
     }
 }
 
@@ -5044,27 +5044,27 @@ find_main_name (void)
   new_main_name = ada_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_ada);
       return;
     }
 
   new_main_name = go_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_go);
       return;
     }
 
   new_main_name = pascal_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_pascal);
       return;
     }
 
   /* The languages above didn't identify the name of the main procedure.
      Fallback to "main".  */
-  set_main_name ("main");
+  set_main_name ("main", language_unknown);
 }
 
 char *
@@ -5076,13 +5076,22 @@ main_name (void)
   return name_of_main;
 }
 
+/* Return the language of the main function.  If it is not known,
+   return language_unknown.  */
+
+enum language
+main_language (void)
+{
+  return language_of_main;
+}
+
 /* Handle ``executable_changed'' events for the symtab module.  */
 
 static void
 symtab_observer_executable_changed (void)
 {
   /* NAME_OF_MAIN may no longer be the same, so reset it for now.  */
-  set_main_name (NULL);
+  set_main_name (NULL, language_unknown);
 }
 
 /* Return 1 if the supplied producer string matches the ARM RealView
index 97e9ad7b761cefe2eb0e76177452dce7463af671..4a933747ed168eb202cafdf3eab7b6be09d762ec 100644 (file)
@@ -1324,9 +1324,9 @@ extern struct cleanup *make_cleanup_free_search_symbols (struct symbol_search
    FIXME: cagney/2001-03-20: Can't make main_name() const since some
    of the calling code currently assumes that the string isn't
    const.  */
-extern void set_main_name (const char *name);
+extern void set_main_name (const char *name, enum language lang);
 extern /*const */ char *main_name (void);
-extern enum language language_of_main;
+extern enum language main_language (void);
 
 /* Check global symbols in objfile.  */
 struct symbol *lookup_global_symbol_from_objfile (const struct objfile *,