[binutils-gdb] gdb: change new_objfile observer to take an objfile reference
Andrew Burgess via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e9feb8a0104f7b21ee1c70535d8c07f0447a5b0c commit e9feb8a0104f7b21ee1c70535d8c07f0447a5b0c Author: Andrew Burgess <[email protected]> Date: Tue Mar 17 14:53:48 2026 +0000 gdb: change new_objfile observer to take an objfile reference 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 <[email protected]> Diff: --- gdb/ada-lang.c | 4 ++-- gdb/ada-tasks.c | 4 ++-- gdb/agent.c | 4 ++-- gdb/aix-thread.c | 2 +- gdb/arm-tdep.c | 34 +++++++++++++++++----------------- gdb/auto-load.c | 10 +++++----- gdb/auto-load.h | 2 +- gdb/linux-thread-db.c | 8 ++++---- gdb/main.c | 2 +- gdb/observable.h | 2 +- gdb/python/py-inferior.c | 11 +++++------ gdb/remote.c | 4 ++-- gdb/sol-thread.c | 2 +- gdb/symfile.c | 8 ++++---- gdb/symtab.c | 4 ++-- gdb/tui/tui-hooks.c | 2 +- 16 files changed, 51 insertions(+), 52 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 4ab2e4d19a8..1d1c021a51a 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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. */ diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index bae54e86bf6..848c832785e 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -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 diff --git a/gdb/agent.c b/gdb/agent.c index beeaf62b552..4c8c237b3ae 100644 --- a/gdb/agent.c +++ b/gdb/agent.c @@ -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) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 823fb13cb29..c2e6b6d2bd6 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -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 ()); } diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 83dc71cc9da..1da16833ada 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -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; diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 7bb062ed432..bf9e6734ca9 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -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. */ diff --git a/gdb/auto-load.h b/gdb/auto-load.h index 35c7b31f0fd..d03c8493df0 100644 --- a/gdb/auto-load.h +++ b/gdb/auto-load.h @@ -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, diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index f276031184c..0753d2e7915 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -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 (); } diff --git a/gdb/main.c b/gdb/main.c index df40ee0b005..7272862a3f8 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -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); diff --git a/gdb/observable.h b/gdb/observable.h index 89877950a3c..9f1c33ba710 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -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; diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index ea9f884a397..1a30f4ee378 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -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 (); } diff --git a/gdb/remote.c b/gdb/remote.c index 46bc584b27d..e84a0dc578b 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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 diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index 066aa41c152..ec480186b59 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -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 (); } diff --git a/gdb/symfile.c b/gdb/symfile.c index 0d77d97b3af..c2844eb88a5 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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); } } diff --git a/gdb/symtab.c b/gdb/symtab.c index 812f9bcc540..9b2d2cf6d59 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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. */ diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index dff0eeca118..17ae8e7a590 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -38,7 +38,7 @@ #include "tui/tui-wingeneral.h" static void -tui_new_objfile_hook (struct objfile* objfile) +tui_new_objfile_hook (struct objfile &objfile) { if (tui_active) tui_display_main ();