]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
move the "main" data into the per-BFD object
authorTom Tromey <tromey@redhat.com>
Tue, 31 Dec 2013 03:34:16 +0000 (20:34 -0700)
committerTom Tromey <tromey@redhat.com>
Wed, 15 Jan 2014 19:06:04 +0000 (12:06 -0700)
This adds the "main"-related data into the per-BFD.  This is needed
because once symbol sharing across objfiles is complete, computing the
main name as a side effect of symbol reading will no longer work --
the symbols simply won't be re-read.

After this change, set_main_name is only used by the main_name
machinery itself, so this patch makes it static.

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

* dbxread.c (process_one_symbol): Use set_objfile_main_name.
* dwarf2read.c (read_partial_die): Use set_objfile_main_name.
* objfiles.c (get_objfile_bfd_data): Initialize language_of_main.
(set_objfile_main_name): New function.
* objfiles.h (struct objfile_per_bfd_storage) <name_of_main,
language_of_main>: New fields.
(set_objfile_main_name): Declare.
* symtab.c (find_main_name): Loop over objfiles to find the main
name and language.
(set_main_name): Now static.
(get_main_info): Add comment.
* symtab.h (set_main_name): Don't declare.

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

index 7125ca59459fd8896c9506565b96e441c8a86105..82f6fc6ffc17f753aebb286b5b7b54debce8976e 100644 (file)
@@ -1,3 +1,18 @@
+2014-01-15  Tom Tromey  <tromey@redhat.com>
+
+       * dbxread.c (process_one_symbol): Use set_objfile_main_name.
+       * dwarf2read.c (read_partial_die): Use set_objfile_main_name.
+       * objfiles.c (get_objfile_bfd_data): Initialize language_of_main.
+       (set_objfile_main_name): New function.
+       * objfiles.h (struct objfile_per_bfd_storage) <name_of_main,
+       language_of_main>: New fields.
+       (set_objfile_main_name): Declare.
+       * symtab.c (find_main_name): Loop over objfiles to find the main
+       name and language.
+       (set_main_name): Now static.
+       (get_main_info): Add comment.
+       * symtab.h (set_main_name): Don't declare.
+
 2014-01-15  Tom Tromey  <tromey@redhat.com>
 
        * symtab.c (main_progspace_key): New global.
index eab5113386d1b909c8370b0f860888f7fcb37648..ff56554fcb2ec231cb318c0d5df9bc3a16a7e82d 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, language_unknown);
+       set_objfile_main_name (objfile, name, language_unknown);
       break;
 
       /* The following symbol types can be ignored.  */
index 0c3d16cd122dd836302e1b7418ed1ac51f143fef..90c60cdb0d08c2e1ea6f377b5ff14ce0d80aff8e 100644 (file)
@@ -15322,7 +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, language_fortran);
+           set_objfile_main_name (objfile, part_die->name, language_fortran);
          break;
        case DW_AT_inline:
          if (DW_UNSND (&attr) == DW_INL_inlined
index c3f6e186ea7543dcfe440bf622385c7c9456412f..eccb44adbcb91f5a1744630d3224401b00feaf5e 100644 (file)
@@ -152,6 +152,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
       obstack_init (&storage->storage_obstack);
       storage->filename_cache = bcache_xmalloc (NULL, NULL);
       storage->macro_cache = bcache_xmalloc (NULL, NULL);
+      storage->language_of_main = language_unknown;
     }
 
   return storage;
@@ -186,6 +187,20 @@ set_objfile_per_bfd (struct objfile *objfile)
   objfile->per_bfd = get_objfile_bfd_data (objfile, objfile->obfd);
 }
 
+/* Set the objfile's per-BFD notion of the "main" name and
+   language.  */
+
+void
+set_objfile_main_name (struct objfile *objfile,
+                      const char *name, enum language lang)
+{
+  if (objfile->per_bfd->name_of_main == NULL
+      || strcmp (objfile->per_bfd->name_of_main, name) != 0)
+    objfile->per_bfd->name_of_main
+      = obstack_copy0 (&objfile->per_bfd->storage_obstack, name, strlen (name));
+  objfile->per_bfd->language_of_main = lang;
+}
+
 \f
 
 /* Called via bfd_map_over_sections to build up the section table that
index d448c9ef38f16b6104d948ed5848d3f5ad95091b..2de2f8d01fef5f9fc9cc7dbcf5e87d1cd9848dfe 100644 (file)
@@ -203,6 +203,13 @@ struct objfile_per_bfd_storage
      containing the entry point, and the scope of the user's main() func.  */
 
   struct entry_info ei;
+
+  /* The name and language of any "main" found in this objfile.  The
+     name can be NULL, which means that the information was not
+     recorded.  */
+
+  const char *name_of_main;
+  enum language language_of_main;
 };
 
 /* Master structure for keeping track of each file from which
@@ -691,4 +698,9 @@ void set_objfile_per_bfd (struct objfile *obj);
 
 const char *objfile_name (const struct objfile *objfile);
 
+/* Set the objfile's notion of the "main" name and language.  */
+
+extern void set_objfile_main_name (struct objfile *objfile,
+                                  const char *name, enum language lang);
+
 #endif /* !defined (OBJFILES_H) */
index 80a7dd676d59e0dfdcdd968364e8152268e81afc..09b2326ed5276026a772c3cf750f972a9af3fd2f 100644 (file)
@@ -5028,6 +5028,12 @@ get_main_info (void)
 
   if (info == NULL)
     {
+      /* It may seem strange to store the main name in the progspace
+        and also in whatever objfile happens to see a main name in
+        its debug info.  The reason for this is mainly historical:
+        gdb returned "main" as the name even if no function named
+        "main" was defined the program; and this approach lets us
+        keep compatibility.  */
       info = XCNEW (struct main_info);
       info->language_of_main = language_unknown;
       set_program_space_data (current_program_space, main_progspace_key,
@@ -5050,7 +5056,7 @@ main_info_cleanup (struct program_space *pspace, void *data)
   xfree (info);
 }
 
-void
+static void
 set_main_name (const char *name, enum language lang)
 {
   struct main_info *info = get_main_info ();
@@ -5075,6 +5081,23 @@ static void
 find_main_name (void)
 {
   const char *new_main_name;
+  struct objfile *objfile;
+
+  /* First check the objfiles to see whether a debuginfo reader has
+     picked up the appropriate main name.  Historically the main name
+     was found in a more or less random way; this approach instead
+     relies on the order of objfile creation -- which still isn't
+     guaranteed to get the correct answer, but is just probably more
+     accurate.  */
+  ALL_OBJFILES (objfile)
+  {
+    if (objfile->per_bfd->name_of_main != NULL)
+      {
+       set_main_name (objfile->per_bfd->name_of_main,
+                      objfile->per_bfd->language_of_main);
+       return;
+      }
+  }
 
   /* Try to see if the main procedure is in Ada.  */
   /* FIXME: brobecker/2005-03-07: Another way of doing this would
index 4a933747ed168eb202cafdf3eab7b6be09d762ec..25ac028eee1e6ea7935aeffc7f344ea69ca95a2a 100644 (file)
@@ -1324,7 +1324,6 @@ 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, enum language lang);
 extern /*const */ char *main_name (void);
 extern enum language main_language (void);