]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change new_objfile observer to take an objfile reference
authorAndrew Burgess <aburgess@redhat.com>
Tue, 17 Mar 2026 14:53:48 +0000 (14:53 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 19 Mar 2026 14:36:25 +0000 (14:36 +0000)
I was looking at the new_objfile observer and noticed a comment in
reread_symbols (symfile.c) that seemed out of date, it talked about
calling the new objfile observer with a NULL objfile argument.

A little digging indicates that the comment is indeed out of date, and
that we never call the new_objfile observer with a NULL argument any
more.

So in this commit I have:

  1. Updated the out of date comment in reread_symbols.

  2. Changed the argument type for the new_objfile observer from
     'objfile *' to 'objfile &'.  Passing a NULL pointer is no longer
     an option.

  3. Updated the existing new_objfile observers to take 'objfile &'
     and updated their implementations as needed.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
16 files changed:
gdb/ada-lang.c
gdb/ada-tasks.c
gdb/agent.c
gdb/aix-thread.c
gdb/arm-tdep.c
gdb/auto-load.c
gdb/auto-load.h
gdb/linux-thread-db.c
gdb/main.c
gdb/observable.h
gdb/python/py-inferior.c
gdb/remote.c
gdb/sol-thread.c
gdb/symfile.c
gdb/symtab.c
gdb/tui/tui-hooks.c

index 4ab2e4d19a82d5b84bf5b7e2c019e734a7e6addc..1d1c021a51ac84416687435144357abb9a62779c 100644 (file)
@@ -14042,9 +14042,9 @@ static struct cmd_list_element *show_ada_list;
 /* This module's 'new_objfile' observer.  */
 
 static void
-ada_new_objfile_observer (struct objfile *objfile)
+ada_new_objfile_observer (struct objfile &objfile)
 {
-  ada_clear_symbol_cache (objfile->pspace ());
+  ada_clear_symbol_cache (objfile.pspace ());
 }
 
 /* This module's 'free_objfile' observer.  */
index bae54e86bf681d1f794aa2084b54e8a47f677022..848c832785e5b514fa0c2892d1825d74bcecfd9d 100644 (file)
@@ -1466,9 +1466,9 @@ ada_tasks_clear_pspace_data (program_space *pspace)
 /* Called when a new objfile was added.  */
 
 static void
-ada_tasks_new_objfile_observer (objfile *objfile)
+ada_tasks_new_objfile_observer (objfile &objfile)
 {
-  ada_tasks_clear_pspace_data (objfile->pspace ());
+  ada_tasks_clear_pspace_data (objfile.pspace ());
 }
 
 /* The qcs command line flags for the "task apply" commands.  Keep
index beeaf62b5524c86916bfb3851dc1a3fd8daece0e..4c8c237b3ae147378fdde7a5fcb3afe03a8bd14c 100644 (file)
@@ -62,7 +62,7 @@ set_can_use_agent (const char *args, int from_tty, struct cmd_list_element *c)
 }
 
 static void
-agent_new_objfile (struct objfile *objfile)
+agent_new_objfile (struct objfile &objfile)
 {
   if (agent_loaded_p ())
     return;
@@ -70,7 +70,7 @@ agent_new_objfile (struct objfile *objfile)
   if (can_use_agent == can_use_agent_off)
     return;
 
-  agent_look_up_symbols (objfile);
+  agent_look_up_symbols (&objfile);
 }
 
 INIT_GDB_FILE (agent)
index 823fb13cb29145124e25a173ac8abf7603411188..c2e6b6d2bd6f5af9ac04d1cfb760da7ff1307b90 100644 (file)
@@ -1011,7 +1011,7 @@ pd_disable (inferior *inf)
    for thread debugging.  */
 
 static void
-new_objfile (struct objfile *objfile)
+new_objfile (struct objfile &objfile)
 {
   pd_enable (current_inferior ());
 }
index 83dc71cc9da89da4c8176ae8d87b1d846e6aa6b4..1da16833ada3b853826ec330fb23b008d29bb54a 100644 (file)
@@ -2530,7 +2530,7 @@ arm_obj_section_from_vma (struct objfile *objfile, bfd_vma vma)
    retrieval by the arm_find_exidx_entry routine.  */
 
 static void
-arm_exidx_new_objfile (struct objfile *objfile)
+arm_exidx_new_objfile (struct objfile &objfile)
 {
   struct arm_exidx_data *data;
   asection *exidx, *extab;
@@ -2538,11 +2538,11 @@ arm_exidx_new_objfile (struct objfile *objfile)
   LONGEST i;
 
   /* If we've already touched this file, do nothing.  */
-  if (arm_exidx_data_key.get (objfile->obfd.get ()) != nullptr)
+  if (arm_exidx_data_key.get (objfile.obfd.get ()) != nullptr)
     return;
 
   /* Read contents of exception table and index.  */
-  exidx = bfd_get_section_by_name (objfile->obfd.get (),
+  exidx = bfd_get_section_by_name (objfile.obfd.get (),
                                   ELF_STRING_ARM_unwind);
   gdb::byte_vector exidx_data;
   if (exidx)
@@ -2550,35 +2550,35 @@ arm_exidx_new_objfile (struct objfile *objfile)
       exidx_vma = bfd_section_vma (exidx);
       exidx_data.resize (bfd_section_size (exidx));
 
-      if (!bfd_get_section_contents (objfile->obfd.get (), exidx,
+      if (!bfd_get_section_contents (objfile.obfd.get (), exidx,
                                     exidx_data.data (), 0,
                                     exidx_data.size ()))
        return;
     }
 
-  extab = bfd_get_section_by_name (objfile->obfd.get (), ".ARM.extab");
+  extab = bfd_get_section_by_name (objfile.obfd.get (), ".ARM.extab");
   gdb::byte_vector extab_data;
   if (extab)
     {
       extab_vma = bfd_section_vma (extab);
       extab_data.resize (bfd_section_size (extab));
 
-      if (!bfd_get_section_contents (objfile->obfd.get (), extab,
+      if (!bfd_get_section_contents (objfile.obfd.get (), extab,
                                     extab_data.data (), 0,
                                     extab_data.size ()))
        return;
     }
 
   /* Allocate exception table data structure.  */
-  data = &arm_exidx_data_key.emplace (objfile->obfd.get ());
-  data->section_maps.resize (objfile->obfd->section_count);
+  data = &arm_exidx_data_key.emplace (objfile.obfd.get ());
+  data->section_maps.resize (objfile.obfd->section_count);
 
   /* Fill in exception table.  */
   for (i = 0; i < exidx_data.size () / 8; i++)
     {
       struct arm_exidx_entry new_exidx_entry;
-      bfd_vma idx = bfd_h_get_32 (objfile->obfd, exidx_data.data () + i * 8);
-      bfd_vma val = bfd_h_get_32 (objfile->obfd,
+      bfd_vma idx = bfd_h_get_32 (objfile.obfd, exidx_data.data () + i * 8);
+      bfd_vma val = bfd_h_get_32 (objfile.obfd,
                                  exidx_data.data () + i * 8 + 4);
       bfd_vma addr = 0, word = 0;
       int n_bytes = 0, n_words = 0;
@@ -2590,7 +2590,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
       idx += exidx_vma + i * 8;
 
       /* Find section containing function and compute section offset.  */
-      sec = arm_obj_section_from_vma (objfile, idx);
+      sec = arm_obj_section_from_vma (&objfile, idx);
       if (sec == NULL)
        continue;
       idx -= bfd_section_vma (sec->the_bfd_section);
@@ -2615,7 +2615,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
 
          if (addr >= extab_vma && addr + 4 <= extab_vma + extab_data.size ())
            {
-             word = bfd_h_get_32 (objfile->obfd,
+             word = bfd_h_get_32 (objfile.obfd,
                                   extab_data.data () + addr - extab_vma);
              addr += 4;
 
@@ -2643,7 +2643,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
 
                  /* Check whether we've got one of the variants of the
                     GNU personality routines.  */
-                 pers_sec = arm_obj_section_from_vma (objfile, pers);
+                 pers_sec = arm_obj_section_from_vma (&objfile, pers);
                  if (pers_sec)
                    {
                      static const char *personality[] =
@@ -2660,7 +2660,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
 
                      for (k = 0; personality[k]; k++)
                        if (lookup_minimal_symbol_by_pc_name
-                             (pc, personality[k], objfile))
+                             (pc, personality[k], &objfile))
                          {
                            gnu_personality = 1;
                            break;
@@ -2673,7 +2673,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
                  if (gnu_personality
                      && addr + 4 <= extab_vma + extab_data.size ())
                    {
-                     word = bfd_h_get_32 (objfile->obfd,
+                     word = bfd_h_get_32 (objfile.obfd,
                                           (extab_data.data ()
                                            + addr - extab_vma));
                      addr += 4;
@@ -2696,7 +2696,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
       if (n_bytes || n_words)
        {
          gdb_byte *p = entry
-           = (gdb_byte *) obstack_alloc (&objfile->per_bfd->storage_obstack,
+           = (gdb_byte *) obstack_alloc (&objfile.per_bfd->storage_obstack,
                                          n_bytes + n_words * 4 + 1);
 
          while (n_bytes--)
@@ -2704,7 +2704,7 @@ arm_exidx_new_objfile (struct objfile *objfile)
 
          while (n_words--)
            {
-             word = bfd_h_get_32 (objfile->obfd,
+             word = bfd_h_get_32 (objfile.obfd,
                                   extab_data.data () + addr - extab_vma);
              addr += 4;
 
index 7bb062ed432220cb979f79498821427409937167..bf9e6734ca939d934121325a9c1027a490a1ce5b 100644 (file)
@@ -1199,23 +1199,23 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name)
    2) from .debug_gdb_scripts section  */
 
 void
-load_auto_scripts_for_objfile (struct objfile *objfile)
+load_auto_scripts_for_objfile (struct objfile &objfile)
 {
   /* Return immediately if auto-loading has been globally disabled.
      This is to handle sequencing of operations during gdb startup.
      Also return immediately if OBJFILE was not created from a file
      on the local filesystem.  */
   if (!global_auto_load
-      || (objfile->flags & OBJF_NOT_FILENAME) != 0
-      || is_target_filename (objfile->original_name))
+      || (objfile.flags & OBJF_NOT_FILENAME) != 0
+      || is_target_filename (objfile.original_name))
     return;
 
   /* Load any extension language scripts for this objfile.
      E.g., foo-gdb.gdb, foo-gdb.py.  */
-  auto_load_ext_lang_scripts_for_objfile (objfile);
+  auto_load_ext_lang_scripts_for_objfile (&objfile);
 
   /* Load any scripts mentioned in AUTO_SECTION_NAME (.debug_gdb_scripts).  */
-  auto_load_section_scripts (objfile, AUTO_SECTION_NAME);
+  auto_load_section_scripts (&objfile, AUTO_SECTION_NAME);
 }
 
 /* Collect scripts to be printed in a vec.  */
index 35c7b31f0fda9290a2ad1f5895387f66199cee2d..d03c8493df07f0fe69ae75be8ba0883dd7e6ef22 100644 (file)
@@ -54,7 +54,7 @@ extern struct auto_load_pspace_info *
   get_auto_load_pspace_data_for_loading (struct program_space *pspace);
 extern void auto_load_objfile_script (struct objfile *objfile,
                                      const struct extension_language_defn *);
-extern void load_auto_scripts_for_objfile (struct objfile *objfile);
+extern void load_auto_scripts_for_objfile (struct objfile &objfile);
 extern char auto_load_info_scripts_pattern_nl[];
 extern void auto_load_info_scripts (program_space *pspace, const char *pattern,
                                    int from_tty,
index f276031184c4dcdf04361ab1e0cc067004abbcf7..0753d2e791525eb105e7c228ed83d1b49f7ffd2f 100644 (file)
@@ -1269,7 +1269,7 @@ check_for_thread_db (void)
 /* This function is called via the new_objfile observer.  */
 
 static void
-thread_db_new_objfile (struct objfile *objfile)
+thread_db_new_objfile (struct objfile &objfile)
 {
   /* This observer must always be called with inferior_ptid set
      correctly.  */
@@ -1279,7 +1279,7 @@ thread_db_new_objfile (struct objfile *objfile)
         the time gdb::observers::new_objfile.notify is called for the library itself.
         Static executables have their separate debug info loaded already
         before the inferior has started.  */
-      objfile->separate_debug_objfile_backlink == NULL
+      objfile.separate_debug_objfile_backlink == NULL
       /* Only check for thread_db if we loaded libpthread,
         or if this is the main symbol file.
         We need to check OBJF_MAINLINE to handle the case of debugging
@@ -1288,8 +1288,8 @@ thread_db_new_objfile (struct objfile *objfile)
         For dynamically linked executables, libpthread can be near the end
         of the list of shared libraries to load, and in an app of several
         thousand shared libraries, this can otherwise be painful.  */
-      && ((objfile->flags & OBJF_MAINLINE) != 0
-         || libpthread_objfile_p (objfile)))
+      && ((objfile.flags & OBJF_MAINLINE) != 0
+         || libpthread_objfile_p (&objfile)))
     check_for_thread_db ();
 }
 
index df40ee0b005d3703262ecebbe6514434dacc2bb0..7272862a3f8e19190b55ff1b181ee5d946ba6fad 100644 (file)
@@ -1334,7 +1334,7 @@ captured_main_1 (struct captured_main_args *context)
      path in local_gdbinit.  */
   global_auto_load = save_auto_load;
   for (objfile &objfile : current_program_space->objfiles ())
-    load_auto_scripts_for_objfile (&objfile);
+    load_auto_scripts_for_objfile (objfile);
 
   /* Process '-x' and '-ex' options.  */
   execute_cmdargs (&cmdarg_vec, CMDARG_FILE, CMDARG_COMMAND, &ret);
index 89877950a3c78a092b8cb626900e4e4579081713..9f1c33ba7100c5c59fe6c94c409c7ee904571f45 100644 (file)
@@ -112,7 +112,7 @@ extern observable<program_space *, const solib &/* solib */,
                  bool /* still_in_use */, bool /* silent */> solib_unloaded;
 
 /* The symbol file specified by OBJFILE has been loaded.  */
-extern observable<struct objfile */* objfile */> new_objfile;
+extern observable<struct objfile &/* objfile */> new_objfile;
 
 /*  All objfiles from PSPACE were removed.  */
 extern observable<program_space */* pspace */> all_objfiles_removed;
index ea9f884a397a0b5bc42686917b382360773b5257..1a30f4ee3784aeebc4fb39c8ccf7902180771e31 100644 (file)
@@ -163,19 +163,18 @@ python_inferior_exit (struct inferior *inf)
     gdbpy_print_stack ();
 }
 
-/* Callback used to notify Python listeners about new objfiles loaded in the
-   inferior.  OBJFILE may be NULL which means that the objfile list has been
-   cleared (emptied).  */
+/* Callback used to notify Python listeners that OBJFILE has been loaded in
+   to the current inferior.  */
 
 static void
-python_new_objfile (struct objfile *objfile)
+python_new_objfile (struct objfile &objfile)
 {
   if (!gdb_python_initialized)
     return;
 
-  gdbpy_enter enter_py (objfile->arch ());
+  gdbpy_enter enter_py (objfile.arch ());
 
-  if (emit_new_objfile_event (objfile) < 0)
+  if (emit_new_objfile_event (&objfile) < 0)
     gdbpy_print_stack ();
 }
 
index 46bc584b27dcbe4d3e8d5df4251ce2ef3a0cbf4a..e84a0dc578b34b3600118f295b01fe371e607ae8 100644 (file)
@@ -16224,9 +16224,9 @@ remote_objfile_changed_check_symbols (program_space *pspace)
 /* Function to be called whenever a new objfile (shlib) is detected.  */
 
 static void
-remote_new_objfile (struct objfile *objfile)
+remote_new_objfile (struct objfile &objfile)
 {
-  remote_objfile_changed_check_symbols (objfile->pspace ());
+  remote_objfile_changed_check_symbols (objfile.pspace ());
 }
 
 /* Pull all the tracepoints defined on the target and create local
index 066aa41c15291df41eb682104177a0a00d86c437..ec480186b59534ef3170082c2d8ccff094032aea 100644 (file)
@@ -666,7 +666,7 @@ check_for_thread_db (void)
    the library gets mapped and the symbol table is read in.  */
 
 static void
-sol_thread_new_objfile (struct objfile *objfile)
+sol_thread_new_objfile (struct objfile &objfile)
 {
   check_for_thread_db ();
 }
index 0d77d97b3afe0f01712546968f1fcf13ec200e34..c2844eb88a5745958e188aa0a42d78b0d40753ba 100644 (file)
@@ -1102,7 +1102,7 @@ symbol_file_add_with_addrs (const gdb_bfd_ref_ptr &abfd, const char *name,
   if (objfile->sf != nullptr)
     finish_new_objfile (objfile, add_flags);
 
-  gdb::observers::new_objfile.notify (objfile);
+  gdb::observers::new_objfile.notify (*objfile);
 
   return objfile;
 }
@@ -2662,11 +2662,11 @@ reread_symbols (int from_tty)
     {
       clear_symtab_users (0);
 
-      /* The registry for each objfile was cleared and
-        gdb::observers::new_objfile.notify (NULL) has been called by
+      /* The registry for each objfile was cleared and the
+        all_objfiles_removed observer was notified by the call to
         clear_symtab_users above.  Notify the new files now.  */
       for (auto iter : new_objfiles)
-       gdb::observers::new_objfile.notify (iter);
+       gdb::observers::new_objfile.notify (*iter);
     }
 }
 \f
index 812f9bcc5404022a7b3cc9fe45eaf3b19bcc4e88..9b2d2cf6d596eb31b5ebddea9d8e0151b63ec4e6 100644 (file)
@@ -1698,9 +1698,9 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty)
 /* This module's 'new_objfile' observer.  */
 
 static void
-symtab_new_objfile_observer (struct objfile *objfile)
+symtab_new_objfile_observer (struct objfile &objfile)
 {
-  symbol_cache_flush (objfile->pspace ());
+  symbol_cache_flush (objfile.pspace ());
 }
 
 /* This module's 'all_objfiles_removed' observer.  */
index dff0eeca118c1d2fa8579368d075693a9ceb17c6..17ae8e7a590d02081c088b06ec2a748b4e52fc4f 100644 (file)
@@ -38,7 +38,7 @@
 #include "tui/tui-wingeneral.h"
 
 static void
-tui_new_objfile_hook (struct objfileobjfile)
+tui_new_objfile_hook (struct objfile &objfile)
 {
   if (tui_active)
     tui_display_main ();