From aed57c537116ae91f553ac835b3f96d1f87b3bb0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 23 Nov 2018 12:20:05 -0700 Subject: [PATCH] Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles --- gdb/ChangeLog | 59 +++++++++ gdb/ada-lang.c | 5 +- gdb/blockframe.c | 26 ++-- gdb/breakpoint.c | 211 +++++++++++++++---------------- gdb/compile/compile-object-run.c | 3 +- gdb/cp-support.c | 12 +- gdb/dwarf-index-write.c | 51 ++++---- gdb/dwarf2-frame.c | 4 +- gdb/guile/scm-objfile.c | 11 +- gdb/guile/scm-pretty-print.c | 25 ++-- gdb/hppa-tdep.c | 99 +++++++-------- gdb/jit.c | 4 +- gdb/linespec.c | 85 ++++++------- gdb/linux-thread-db.c | 8 +- gdb/main.c | 3 +- gdb/maint.c | 3 +- gdb/objc-lang.c | 4 +- gdb/objfiles.c | 49 +++---- gdb/ppc-linux-tdep.c | 4 +- gdb/probe.c | 38 +++--- gdb/psymtab.c | 159 +++++++++++------------ gdb/python/py-objfile.c | 8 +- gdb/python/py-prettyprint.c | 38 +++--- gdb/python/py-xmethods.c | 4 +- gdb/solib-spu.c | 3 +- gdb/solib.c | 12 +- gdb/source.c | 14 +- gdb/spu-tdep.c | 3 +- gdb/symfile.c | 61 ++++----- gdb/symmisc.c | 18 ++- gdb/symtab.c | 210 +++++++++++++++--------------- gdb/windows-tdep.c | 3 +- 32 files changed, 621 insertions(+), 616 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d7d1876415..00160cf74d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,62 @@ +2019-01-09 Tom Tromey + + * symtab.c (iterate_over_symtabs, matching_obj_sections) + (expand_symtab_containing_pc, lookup_static_symbol) + (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) + (find_symbol_at_address, find_line_symtab, find_main_name): Use + all_objfiles. + * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. + * breakpoint.c (create_overlay_event_breakpoint) + (create_longjmp_master_breakpoint) + (create_std_terminate_master_breakpoint) + (create_exception_master_breakpoint): Use all_objfiles. + * linux-thread-db.c (try_thread_db_load_from_pdir) + (has_libpthread): Use all_objfiles. + * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. + * linespec.c (iterate_over_all_matching_symtabs) + (search_minsyms_for_name): Use all_objfiles. + * maint.c (maintenance_info_sections): Use all_objfiles. + * main.c (captured_main_1): Use all_objfiles. + * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. + * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. + * guile/scm-pretty-print.c + (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. + * solib-spu.c (append_ocl_sos): Use all_objfiles. + * symmisc.c (maintenance_print_symbols): Use all_objfiles. + (maintenance_print_msymbols): Use all_objfiles. + * source.c (select_source_symtab): Use all_objfiles. + * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. + * symfile.c (remove_symbol_file_command) + (expand_symtabs_matching, map_symbol_filenames): Use + all_objfiles. + * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use + all_objfiles. + * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. + * objc-lang.c (find_methods): Use all_objfiles. + * objfiles.c (have_partial_symbols, have_full_symbols) + (have_minimal_symbols, qsort_cmp) + (default_iterate_over_objfiles_in_search_order): Use + all_objfiles. + * hppa-tdep.c (find_unwind_entry): Use all_objfiles. + * psymtab.c (maintenance_print_psymbols): Use all_objfiles. + (maintenance_check_psymtabs): Use all_objfiles. + (ALL_PSYMTABS): Remove. + * compile/compile-object-run.c (do_module_cleanup): Use + all_objfiles. + * blockframe.c (find_pc_partial_function): Use all_objfiles. + * cp-support.c (add_symbol_overload_list_qualified): Use + all_objfiles. + * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): + Use all_objfiles. + * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. + * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use + all_objfiles. + * python/py-objfile.c (objfpy_lookup_objfile_by_name) + (objfpy_lookup_objfile_by_build_id): Use all_objfiles. + * python/py-prettyprint.c (find_pretty_printer_from_objfiles): + Uses all_objfiles. + * solib.c (solib_read_symbols): Use all_objfiles + 2019-01-09 Tom Tromey * probe.c (parse_probes_in_pspace): Use all_objfiles. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 22f744967c..f462f684ec 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5604,7 +5604,6 @@ add_nonlocal_symbols (struct obstack *obstackp, const lookup_name_info &lookup_name, domain_enum domain, int global) { - struct objfile *objfile; struct compunit_symtab *cu; struct match_data data; @@ -5613,7 +5612,7 @@ add_nonlocal_symbols (struct obstack *obstackp, bool is_wild_match = lookup_name.ada ().wild_match_p (); - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { data.objfile = objfile; @@ -5646,7 +5645,7 @@ add_nonlocal_symbols (struct obstack *obstackp, const char *name = ada_lookup_name (lookup_name); std::string name1 = std::string ("<_ada_") + name + '>'; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { data.objfile = objfile; objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (), diff --git a/gdb/blockframe.c b/gdb/blockframe.c index 2854df96a4..106f8a49c2 100644 --- a/gdb/blockframe.c +++ b/gdb/blockframe.c @@ -217,7 +217,6 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, struct symbol *f; struct bound_minimal_symbol msymbol; struct compunit_symtab *compunit_symtab = NULL; - struct objfile *objfile; CORE_ADDR mapped_pc; /* To ensure that the symbol returned belongs to the correct setion @@ -237,18 +236,19 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, goto return_cached_value; msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section); - ALL_OBJFILES (objfile) - { - if (objfile->sf) - { - compunit_symtab - = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, - mapped_pc, section, - 0); - } - if (compunit_symtab != NULL) - break; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf) + { + compunit_symtab + = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, + mapped_pc, + section, + 0); + } + if (compunit_symtab != NULL) + break; + } if (compunit_symtab != NULL) { diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d54d496972..48a1c6414e 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -3203,10 +3203,9 @@ free_breakpoint_objfile_data (struct objfile *obj, void *data) static void create_overlay_event_breakpoint (void) { - struct objfile *objfile; const char *const func_name = "_ovly_debug_event"; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { struct breakpoint *b; struct breakpoint_objfile_data *bp_objfile_data; @@ -3262,95 +3261,93 @@ create_longjmp_master_breakpoint (void) ALL_PSPACES (pspace) { - struct objfile *objfile; - set_current_program_space (pspace); - ALL_OBJFILES (objfile) - { - int i; - struct gdbarch *gdbarch; - struct breakpoint_objfile_data *bp_objfile_data; + for (objfile *objfile : all_objfiles (current_program_space)) + { + int i; + struct gdbarch *gdbarch; + struct breakpoint_objfile_data *bp_objfile_data; - gdbarch = get_objfile_arch (objfile); + gdbarch = get_objfile_arch (objfile); - bp_objfile_data = get_breakpoint_objfile_data (objfile); + bp_objfile_data = get_breakpoint_objfile_data (objfile); - if (!bp_objfile_data->longjmp_searched) - { - std::vector ret - = find_probes_in_objfile (objfile, "libc", "longjmp"); + if (!bp_objfile_data->longjmp_searched) + { + std::vector ret + = find_probes_in_objfile (objfile, "libc", "longjmp"); - if (!ret.empty ()) - { - /* We are only interested in checking one element. */ - probe *p = ret[0]; + if (!ret.empty ()) + { + /* We are only interested in checking one element. */ + probe *p = ret[0]; - if (!p->can_evaluate_arguments ()) - { - /* We cannot use the probe interface here, because it does - not know how to evaluate arguments. */ - ret.clear (); - } - } - bp_objfile_data->longjmp_probes = ret; - bp_objfile_data->longjmp_searched = 1; - } + if (!p->can_evaluate_arguments ()) + { + /* We cannot use the probe interface here, because it does + not know how to evaluate arguments. */ + ret.clear (); + } + } + bp_objfile_data->longjmp_probes = ret; + bp_objfile_data->longjmp_searched = 1; + } - if (!bp_objfile_data->longjmp_probes.empty ()) - { - for (probe *p : bp_objfile_data->longjmp_probes) - { - struct breakpoint *b; + if (!bp_objfile_data->longjmp_probes.empty ()) + { + for (probe *p : bp_objfile_data->longjmp_probes) + { + struct breakpoint *b; + + b = create_internal_breakpoint (gdbarch, + p->get_relocated_address (objfile), + bp_longjmp_master, + &internal_breakpoint_ops); + b->location = new_probe_location ("-probe-stap libc:longjmp"); + b->enable_state = bp_disabled; + } - b = create_internal_breakpoint (gdbarch, - p->get_relocated_address (objfile), - bp_longjmp_master, - &internal_breakpoint_ops); - b->location = new_probe_location ("-probe-stap libc:longjmp"); - b->enable_state = bp_disabled; - } + continue; + } + if (!gdbarch_get_longjmp_target_p (gdbarch)) continue; - } - - if (!gdbarch_get_longjmp_target_p (gdbarch)) - continue; - for (i = 0; i < NUM_LONGJMP_NAMES; i++) - { - struct breakpoint *b; - const char *func_name; - CORE_ADDR addr; - struct explicit_location explicit_loc; + for (i = 0; i < NUM_LONGJMP_NAMES; i++) + { + struct breakpoint *b; + const char *func_name; + CORE_ADDR addr; + struct explicit_location explicit_loc; - if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) - continue; + if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) + continue; - func_name = longjmp_names[i]; - if (bp_objfile_data->longjmp_msym[i].minsym == NULL) - { - struct bound_minimal_symbol m; + func_name = longjmp_names[i]; + if (bp_objfile_data->longjmp_msym[i].minsym == NULL) + { + struct bound_minimal_symbol m; - m = lookup_minimal_symbol_text (func_name, objfile); - if (m.minsym == NULL) - { - /* Prevent future lookups in this objfile. */ - bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; - continue; - } - bp_objfile_data->longjmp_msym[i] = m; - } + m = lookup_minimal_symbol_text (func_name, objfile); + if (m.minsym == NULL) + { + /* Prevent future lookups in this objfile. */ + bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; + continue; + } + bp_objfile_data->longjmp_msym[i] = m; + } - addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); - b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, - &internal_breakpoint_ops); - initialize_explicit_location (&explicit_loc); - explicit_loc.function_name = ASTRDUP (func_name); - b->location = new_explicit_location (&explicit_loc); - b->enable_state = bp_disabled; - } - } + addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); + b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, + &internal_breakpoint_ops); + initialize_explicit_location (&explicit_loc); + explicit_loc.function_name = ASTRDUP (func_name); + b->location = new_explicit_location (&explicit_loc); + b->enable_state = bp_disabled; + } + } } } @@ -3365,46 +3362,45 @@ create_std_terminate_master_breakpoint (void) ALL_PSPACES (pspace) { - struct objfile *objfile; CORE_ADDR addr; set_current_program_space (pspace); - ALL_OBJFILES (objfile) - { - struct breakpoint *b; - struct breakpoint_objfile_data *bp_objfile_data; - struct explicit_location explicit_loc; + for (objfile *objfile : all_objfiles (current_program_space)) + { + struct breakpoint *b; + struct breakpoint_objfile_data *bp_objfile_data; + struct explicit_location explicit_loc; - bp_objfile_data = get_breakpoint_objfile_data (objfile); + bp_objfile_data = get_breakpoint_objfile_data (objfile); - if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) - continue; + if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) + continue; - if (bp_objfile_data->terminate_msym.minsym == NULL) - { - struct bound_minimal_symbol m; + if (bp_objfile_data->terminate_msym.minsym == NULL) + { + struct bound_minimal_symbol m; - m = lookup_minimal_symbol (func_name, NULL, objfile); - if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text - && MSYMBOL_TYPE (m.minsym) != mst_file_text)) - { - /* Prevent future lookups in this objfile. */ - bp_objfile_data->terminate_msym.minsym = &msym_not_found; - continue; - } - bp_objfile_data->terminate_msym = m; - } + m = lookup_minimal_symbol (func_name, NULL, objfile); + if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text + && MSYMBOL_TYPE (m.minsym) != mst_file_text)) + { + /* Prevent future lookups in this objfile. */ + bp_objfile_data->terminate_msym.minsym = &msym_not_found; + continue; + } + bp_objfile_data->terminate_msym = m; + } - addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); - b = create_internal_breakpoint (get_objfile_arch (objfile), addr, - bp_std_terminate_master, - &internal_breakpoint_ops); - initialize_explicit_location (&explicit_loc); - explicit_loc.function_name = ASTRDUP (func_name); - b->location = new_explicit_location (&explicit_loc); - b->enable_state = bp_disabled; - } + addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); + b = create_internal_breakpoint (get_objfile_arch (objfile), addr, + bp_std_terminate_master, + &internal_breakpoint_ops); + initialize_explicit_location (&explicit_loc); + explicit_loc.function_name = ASTRDUP (func_name); + b->location = new_explicit_location (&explicit_loc); + b->enable_state = bp_disabled; + } } } @@ -3413,10 +3409,9 @@ create_std_terminate_master_breakpoint (void) static void create_exception_master_breakpoint (void) { - struct objfile *objfile; const char *const func_name = "_Unwind_DebugHook"; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { struct breakpoint *b; struct gdbarch *gdbarch; diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c index 81453d0be0..8abe494218 100644 --- a/gdb/compile/compile-object-run.c +++ b/gdb/compile/compile-object-run.c @@ -62,7 +62,6 @@ static void do_module_cleanup (void *arg, int registers_valid) { struct do_module_cleanup *data = (struct do_module_cleanup *) arg; - struct objfile *objfile; if (data->executedp != NULL) { @@ -83,7 +82,7 @@ do_module_cleanup (void *arg, int registers_valid) } } - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) if ((objfile->flags & OBJF_USERLOADED) == 0 && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0)) { diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 489bcca2b8..a5349ed3e3 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1374,17 +1374,16 @@ add_symbol_overload_list_qualified (const char *func_name, std::vector *overload_list) { struct compunit_symtab *cust; - struct objfile *objfile; const struct block *b, *surrounding_static_block = 0; /* Look through the partial symtabs for all symbols which begin by matching FUNC_NAME. Make sure we read that symbol table in. */ - ALL_OBJFILES (objfile) - { - if (objfile->sf) - objfile->sf->qf->expand_symtabs_for_function (objfile, func_name); - } + for (objfile *objf : all_objfiles (current_program_space)) + { + if (objf->sf) + objf->sf->qf->expand_symtabs_for_function (objf, func_name); + } /* Search upwards from currently selected frame (so that we can complete on local vars. */ @@ -1397,6 +1396,7 @@ add_symbol_overload_list_qualified (const char *func_name, /* Go through the symtabs and check the externs and statics for symbols which match. */ + struct objfile *objfile; ALL_COMPUNITS (objfile, cust) { QUIT; diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c index c12ef1269d..f1118f722c 100644 --- a/gdb/dwarf-index-write.c +++ b/gdb/dwarf-index-write.c @@ -1640,7 +1640,6 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile, static void save_gdb_index_command (const char *arg, int from_tty) { - struct objfile *objfile; const char dwarf5space[] = "-dwarf-5 "; dw_index_kind index_kind = dw_index_kind::GDB_INDEX; @@ -1658,35 +1657,35 @@ save_gdb_index_command (const char *arg, int from_tty) if (!*arg) error (_("usage: save gdb-index [-dwarf-5] DIRECTORY")); - ALL_OBJFILES (objfile) - { - struct stat st; + for (objfile *objfile : all_objfiles (current_program_space)) + { + struct stat st; - /* If the objfile does not correspond to an actual file, skip it. */ - if (stat (objfile_name (objfile), &st) < 0) - continue; + /* If the objfile does not correspond to an actual file, skip it. */ + if (stat (objfile_name (objfile), &st) < 0) + continue; - struct dwarf2_per_objfile *dwarf2_per_objfile - = get_dwarf2_per_objfile (objfile); + struct dwarf2_per_objfile *dwarf2_per_objfile + = get_dwarf2_per_objfile (objfile); - if (dwarf2_per_objfile != NULL) - { - TRY - { - const char *basename = lbasename (objfile_name (objfile)); - write_psymtabs_to_index (dwarf2_per_objfile, arg, basename, - index_kind); - } - CATCH (except, RETURN_MASK_ERROR) - { - exception_fprintf (gdb_stderr, except, - _("Error while writing index for `%s': "), - objfile_name (objfile)); - } - END_CATCH - } + if (dwarf2_per_objfile != NULL) + { + TRY + { + const char *basename = lbasename (objfile_name (objfile)); + write_psymtabs_to_index (dwarf2_per_objfile, arg, basename, + index_kind); + } + CATCH (except, RETURN_MASK_ERROR) + { + exception_fprintf (gdb_stderr, except, + _("Error while writing index for `%s': "), + objfile_name (objfile)); + } + END_CATCH + } - } + } } void diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index 5eb280eee0..deb8a80029 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -1702,9 +1702,7 @@ bsearch_fde_cmp (const void *key, const void *element) static struct dwarf2_fde * dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { struct dwarf2_fde_table *fde_table; struct dwarf2_fde **p_fde; diff --git a/gdb/guile/scm-objfile.c b/gdb/guile/scm-objfile.c index b5f6172957..79b784aad6 100644 --- a/gdb/guile/scm-objfile.c +++ b/gdb/guile/scm-objfile.c @@ -366,17 +366,16 @@ gdbscm_get_current_objfile (void) static SCM gdbscm_objfiles (void) { - struct objfile *objf; SCM result; result = SCM_EOL; - ALL_OBJFILES (objf) - { - SCM item = ofscm_scm_from_objfile (objf); + for (objfile *objf : all_objfiles (current_program_space)) + { + SCM item = ofscm_scm_from_objfile (objf); - result = scm_cons (item, result); - } + result = scm_cons (item, result); + } return scm_reverse_x (result, SCM_EOL); } diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index 9cc4f7f6b2..d621ed5e91 100644 --- a/gdb/guile/scm-pretty-print.c +++ b/gdb/guile/scm-pretty-print.c @@ -427,19 +427,18 @@ ppscm_search_pp_list (SCM list, SCM value) static SCM ppscm_find_pretty_printer_from_objfiles (SCM value) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) - { - objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile); - SCM pp = ppscm_search_pp_list (ofscm_objfile_smob_pretty_printers (o_smob), - value); - - /* Note: This will return if pp is a object, - which is what we want. */ - if (gdbscm_is_true (pp)) - return pp; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + objfile_smob *o_smob = ofscm_objfile_smob_from_objfile (objfile); + SCM pp + = ppscm_search_pp_list (ofscm_objfile_smob_pretty_printers (o_smob), + value); + + /* Note: This will return if pp is a object, + which is what we want. */ + if (gdbscm_is_true (pp)) + return pp; + } return SCM_BOOL_F; } diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c index 7adc71cc63..d825bcea28 100644 --- a/gdb/hppa-tdep.c +++ b/gdb/hppa-tdep.c @@ -483,7 +483,6 @@ struct unwind_table_entry * find_unwind_entry (CORE_ADDR pc) { int first, middle, last; - struct objfile *objfile; struct hppa_objfile_private *priv; if (hppa_debug) @@ -498,61 +497,61 @@ find_unwind_entry (CORE_ADDR pc) return NULL; } - ALL_OBJFILES (objfile) - { - struct hppa_unwind_info *ui; - ui = NULL; - priv = ((struct hppa_objfile_private *) - objfile_data (objfile, hppa_objfile_priv_data)); - if (priv) - ui = ((struct hppa_objfile_private *) priv)->unwind_info; - - if (!ui) - { - read_unwind_info (objfile); - priv = ((struct hppa_objfile_private *) - objfile_data (objfile, hppa_objfile_priv_data)); - if (priv == NULL) - error (_("Internal error reading unwind information.")); - ui = ((struct hppa_objfile_private *) priv)->unwind_info; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + struct hppa_unwind_info *ui; + ui = NULL; + priv = ((struct hppa_objfile_private *) + objfile_data (objfile, hppa_objfile_priv_data)); + if (priv) + ui = ((struct hppa_objfile_private *) priv)->unwind_info; + + if (!ui) + { + read_unwind_info (objfile); + priv = ((struct hppa_objfile_private *) + objfile_data (objfile, hppa_objfile_priv_data)); + if (priv == NULL) + error (_("Internal error reading unwind information.")); + ui = ((struct hppa_objfile_private *) priv)->unwind_info; + } - /* First, check the cache. */ + /* First, check the cache. */ - if (ui->cache - && pc >= ui->cache->region_start - && pc <= ui->cache->region_end) - { - if (hppa_debug) - fprintf_unfiltered (gdb_stdlog, "%s (cached) }\n", - hex_string ((uintptr_t) ui->cache)); - return ui->cache; - } + if (ui->cache + && pc >= ui->cache->region_start + && pc <= ui->cache->region_end) + { + if (hppa_debug) + fprintf_unfiltered (gdb_stdlog, "%s (cached) }\n", + hex_string ((uintptr_t) ui->cache)); + return ui->cache; + } - /* Not in the cache, do a binary search. */ + /* Not in the cache, do a binary search. */ - first = 0; - last = ui->last; + first = 0; + last = ui->last; - while (first <= last) - { - middle = (first + last) / 2; - if (pc >= ui->table[middle].region_start - && pc <= ui->table[middle].region_end) - { - ui->cache = &ui->table[middle]; - if (hppa_debug) - fprintf_unfiltered (gdb_stdlog, "%s }\n", - hex_string ((uintptr_t) ui->cache)); - return &ui->table[middle]; - } + while (first <= last) + { + middle = (first + last) / 2; + if (pc >= ui->table[middle].region_start + && pc <= ui->table[middle].region_end) + { + ui->cache = &ui->table[middle]; + if (hppa_debug) + fprintf_unfiltered (gdb_stdlog, "%s }\n", + hex_string ((uintptr_t) ui->cache)); + return &ui->table[middle]; + } - if (pc < ui->table[middle].region_start) - last = middle - 1; - else - first = middle + 1; - } - } /* ALL_OBJFILES() */ + if (pc < ui->table[middle].region_start) + last = middle - 1; + else + first = middle + 1; + } + } if (hppa_debug) fprintf_unfiltered (gdb_stdlog, "NULL (not found) }\n"); diff --git a/gdb/jit.c b/gdb/jit.c index 576daf2352..e77c03ad59 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -986,9 +986,7 @@ jit_unregister_code (struct objfile *objfile) static struct objfile * jit_find_objf_with_entry_addr (CORE_ADDR entry_addr) { - struct objfile *objf; - - ALL_OBJFILES (objf) + for (objfile *objf : all_objfiles (current_program_space)) { struct jit_objfile_data *objf_data; diff --git a/gdb/linespec.c b/gdb/linespec.c index b1ca6fd032..0d08bbee94 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1130,7 +1130,6 @@ iterate_over_all_matching_symtabs struct program_space *search_pspace, bool include_inline, gdb::function_view callback) { - struct objfile *objfile; struct program_space *pspace; ALL_PSPACES (pspace) @@ -1142,46 +1141,48 @@ iterate_over_all_matching_symtabs set_current_program_space (pspace); - ALL_OBJFILES (objfile) - { - struct compunit_symtab *cu; + for (objfile *objfile : all_objfiles (current_program_space)) + { + struct compunit_symtab *cu; - if (objfile->sf) - objfile->sf->qf->expand_symtabs_matching (objfile, - NULL, - lookup_name, - NULL, NULL, - search_domain); + if (objfile->sf) + objfile->sf->qf->expand_symtabs_matching (objfile, + NULL, + lookup_name, + NULL, NULL, + search_domain); - ALL_OBJFILE_COMPUNITS (objfile, cu) - { - struct symtab *symtab = COMPUNIT_FILETABS (cu); + ALL_OBJFILE_COMPUNITS (objfile, cu) + { + struct symtab *symtab = COMPUNIT_FILETABS (cu); - iterate_over_file_blocks (symtab, lookup_name, name_domain, callback); + iterate_over_file_blocks (symtab, lookup_name, name_domain, + callback); - if (include_inline) - { - struct block *block; - int i; + if (include_inline) + { + struct block *block; + int i; - for (i = FIRST_LOCAL_BLOCK; - i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab)); - i++) - { - block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i); - state->language->la_iterate_over_symbols - (block, lookup_name, name_domain, [&] (block_symbol *bsym) - { - /* Restrict calls to CALLBACK to symbols - representing inline symbols only. */ - if (SYMBOL_INLINED (bsym->symbol)) - return callback (bsym); - return true; - }); - } - } - } - } + for (i = FIRST_LOCAL_BLOCK; + i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab)); + i++) + { + block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i); + state->language->la_iterate_over_symbols + (block, lookup_name, name_domain, + [&] (block_symbol *bsym) + { + /* Restrict calls to CALLBACK to symbols + representing inline symbols only. */ + if (SYMBOL_INLINED (bsym->symbol)) + return callback (bsym); + return true; + }); + } + } + } + } } } @@ -4351,8 +4352,6 @@ search_minsyms_for_name (struct collect_info *info, ALL_PSPACES (pspace) { - struct objfile *objfile; - if (search_pspace != NULL && search_pspace != pspace) continue; if (pspace->executing_startup) @@ -4360,17 +4359,17 @@ search_minsyms_for_name (struct collect_info *info, set_current_program_space (pspace); - ALL_OBJFILES (objfile) - { - iterate_over_minimal_symbols (objfile, name, - [&] (struct minimal_symbol *msym) + for (objfile *objfile : all_objfiles (current_program_space)) + { + iterate_over_minimal_symbols (objfile, name, + [&] (struct minimal_symbol *msym) { add_minsym (msym, objfile, nullptr, info->state->list_mode, &minsyms); return false; }); - } + } } } else diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 750822f7e3..d6cbc34f33 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1053,12 +1053,10 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj, const char *subdir) static int try_thread_db_load_from_pdir (const char *subdir) { - struct objfile *obj; - if (!auto_load_thread_db) return 0; - ALL_OBJFILES (obj) + for (objfile *obj : all_objfiles (current_program_space)) if (libpthread_name_p (objfile_name (obj))) { if (try_thread_db_load_from_pdir_1 (obj, subdir)) @@ -1167,9 +1165,7 @@ thread_db_load_search (void) static int has_libpthread (void) { - struct objfile *obj; - - ALL_OBJFILES (obj) + for (objfile *obj : all_objfiles (current_program_space)) if (libpthread_name_p (objfile_name (obj))) return 1; diff --git a/gdb/main.c b/gdb/main.c index 9e5f285f0e..7d9492b876 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -485,7 +485,6 @@ captured_main_1 (struct captured_main_args *context) int i; int save_auto_load; - struct objfile *objfile; int ret = 1; #ifdef HAVE_USEFUL_SBRK @@ -1124,7 +1123,7 @@ captured_main_1 (struct captured_main_args *context) We wait until now because it is common to add to the source search path in local_gdbinit. */ global_auto_load = save_auto_load; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) load_auto_scripts_for_objfile (objfile); /* Process '-x' and '-ex' options. */ diff --git a/gdb/maint.c b/gdb/maint.c index 13cf82b3db..01d04df75b 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -348,7 +348,6 @@ maintenance_info_sections (const char *arg, int from_tty) printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd)); if (arg && *arg && match_substring (arg, "ALLOBJ")) { - struct objfile *ofile; struct obj_section *osect; /* Only this function cares about the 'ALLOBJ' argument; @@ -358,7 +357,7 @@ maintenance_info_sections (const char *arg, int from_tty) if (strcmp (arg, "ALLOBJ") == 0) arg = NULL; - ALL_OBJFILES (ofile) + for (objfile *ofile : all_objfiles (current_program_space)) { printf_filtered (_(" Object file: %s\n"), bfd_get_filename (ofile->obfd)); diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index a3908f2b09..ec0ea56063 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -972,8 +972,6 @@ find_methods (char type, const char *theclass, const char *category, const char *selector, std::vector *symbol_names) { - struct objfile *objfile = NULL; - const char *symname = NULL; char ntype = '\0'; @@ -986,7 +984,7 @@ find_methods (char type, const char *theclass, const char *category, gdb_assert (symbol_names != NULL); - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { unsigned int *objc_csym; struct minimal_symbol *msymbol = NULL; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index f8a0dc27db..c9a727aff7 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1016,13 +1016,11 @@ objfile_has_symbols (struct objfile *objfile) int have_partial_symbols (void) { - struct objfile *ofp; - - ALL_OBJFILES (ofp) - { - if (objfile_has_partial_symbols (ofp)) - return 1; - } + for (objfile *ofp : all_objfiles (current_program_space)) + { + if (objfile_has_partial_symbols (ofp)) + return 1; + } return 0; } @@ -1033,13 +1031,11 @@ have_partial_symbols (void) int have_full_symbols (void) { - struct objfile *ofp; - - ALL_OBJFILES (ofp) - { - if (objfile_has_full_symbols (ofp)) - return 1; - } + for (objfile *ofp : all_objfiles (current_program_space)) + { + if (objfile_has_full_symbols (ofp)) + return 1; + } return 0; } @@ -1072,15 +1068,13 @@ objfile_purge_solibs (void) int have_minimal_symbols (void) { - struct objfile *ofp; - - ALL_OBJFILES (ofp) - { - if (ofp->per_bfd->minimal_symbol_count > 0) - { - return 1; - } - } + for (objfile *ofp : all_objfiles (current_program_space)) + { + if (ofp->per_bfd->minimal_symbol_count > 0) + { + return 1; + } + } return 0; } @@ -1145,9 +1139,7 @@ qsort_cmp (const void *a, const void *b) { /* Sort on sequence number of the objfile in the chain. */ - const struct objfile *objfile; - - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) if (objfile == objfile1) return -1; else if (objfile == objfile2) @@ -1502,7 +1494,7 @@ shared_objfile_contains_address_p (struct program_space *pspace, } /* The default implementation for the "iterate_over_objfiles_in_search_order" - gdbarch method. It is equivalent to use the ALL_OBJFILES macro, + gdbarch method. It is equivalent to use the all_objfiles iterable, searching the objfiles in the order they are stored internally, ignoring CURRENT_OBJFILE. @@ -1516,9 +1508,8 @@ default_iterate_over_objfiles_in_search_order void *cb_data, struct objfile *current_objfile) { int stop = 0; - struct objfile *objfile; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { stop = cb (objfile, cb_data); if (stop) diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 9c35fa4410..48bf56dd2f 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1788,10 +1788,8 @@ ppc_linux_spe_context_lookup (struct objfile *objfile) static void ppc_linux_spe_context_inferior_created (struct target_ops *t, int from_tty) { - struct objfile *objfile; - ppc_linux_spe_context_lookup (NULL); - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) ppc_linux_spe_context_lookup (objfile); } diff --git a/gdb/probe.c b/gdb/probe.c index 865c13f95b..7450e4cede 100644 --- a/gdb/probe.c +++ b/gdb/probe.c @@ -244,29 +244,28 @@ find_probes_in_objfile (struct objfile *objfile, const char *provider, struct bound_probe find_probe_by_pc (CORE_ADDR pc) { - struct objfile *objfile; struct bound_probe result; result.objfile = NULL; result.prob = NULL; - ALL_OBJFILES (objfile) - { - if (!objfile->sf || !objfile->sf->sym_probe_fns - || objfile->sect_index_text == -1) - continue; - - /* If this proves too inefficient, we can replace with a hash. */ - const std::vector &probes - = objfile->sf->sym_probe_fns->sym_get_probes (objfile); - for (probe *p : probes) - if (p->get_relocated_address (objfile) == pc) - { - result.objfile = objfile; - result.prob = p; - return result; - } - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (!objfile->sf || !objfile->sf->sym_probe_fns + || objfile->sect_index_text == -1) + continue; + + /* If this proves too inefficient, we can replace with a hash. */ + const std::vector &probes + = objfile->sf->sym_probe_fns->sym_get_probes (objfile); + for (probe *p : probes) + if (p->get_relocated_address (objfile) == pc) + { + result.objfile = objfile; + result.prob = p; + return result; + } + } return result; } @@ -282,7 +281,6 @@ static std::vector collect_probes (const std::string &objname, const std::string &provider, const std::string &probe_name, const static_probe_ops *spops) { - struct objfile *objfile; std::vector result; gdb::optional obj_pat, prov_pat, probe_pat; @@ -296,7 +294,7 @@ collect_probes (const std::string &objname, const std::string &provider, obj_pat.emplace (objname.c_str (), REG_NOSUB, _("Invalid object file regexp")); - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { if (! objfile->sf || ! objfile->sf->sym_probe_fns) continue; diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 804558e19b..cd1f5036f4 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -108,12 +108,6 @@ require_partial_symbols (struct objfile *objfile, int verbose) #undef ALL_OBJFILE_PSYMTABS -/* Traverse all psymtabs in all objfiles. */ - -#define ALL_PSYMTABS(objfile, p) \ - ALL_OBJFILES (objfile) \ - ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p) - /* Helper function for psym_map_symtabs_matching_filename that expands the symtabs and calls the iterator. */ @@ -1874,7 +1868,6 @@ maintenance_print_psymbols (const char *args, int from_tty) { struct ui_file *outfile = gdb_stdout; char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; - struct objfile *objfile; struct partial_symtab *ps; int i, outfile_idx, found; CORE_ADDR pc = 0; @@ -1944,7 +1937,7 @@ maintenance_print_psymbols (const char *args, int from_tty) } found = 0; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { int printed_objfile_header = 0; int print_for_objfile = 1; @@ -2148,93 +2141,93 @@ maintenance_check_psymtabs (const char *ignore, int from_tty) struct compunit_symtab *cust = NULL; struct partial_symtab *ps; const struct blockvector *bv; - struct objfile *objfile; struct block *b; int length; - ALL_PSYMTABS (objfile, ps) - { - struct gdbarch *gdbarch = get_objfile_arch (objfile); - - /* We don't call psymtab_to_symtab here because that may cause symtab - expansion. When debugging a problem it helps if checkers leave - things unchanged. */ - cust = ps->compunit_symtab; - - /* First do some checks that don't require the associated symtab. */ - if (ps->text_high (objfile) < ps->text_low (objfile)) + for (objfile *objfile : all_objfiles (current_program_space)) + ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps) { - printf_filtered ("Psymtab "); - puts_filtered (ps->filename); - printf_filtered (" covers bad range "); - fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), - gdb_stdout); - printf_filtered (" - "); - fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), - gdb_stdout); - printf_filtered ("\n"); - continue; - } + struct gdbarch *gdbarch = get_objfile_arch (objfile); - /* Now do checks requiring the associated symtab. */ - if (cust == NULL) - continue; - bv = COMPUNIT_BLOCKVECTOR (cust); - b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); - partial_symbol **psym = &objfile->static_psymbols[ps->statics_offset]; - length = ps->n_static_syms; - while (length--) - { - sym = block_lookup_symbol (b, symbol_search_name (*psym), - symbol_name_match_type::SEARCH_NAME, - (*psym)->domain); - if (!sym) + /* We don't call psymtab_to_symtab here because that may cause symtab + expansion. When debugging a problem it helps if checkers leave + things unchanged. */ + cust = ps->compunit_symtab; + + /* First do some checks that don't require the associated symtab. */ + if (ps->text_high (objfile) < ps->text_low (objfile)) { - printf_filtered ("Static symbol `"); - puts_filtered ((*psym)->name); - printf_filtered ("' only found in "); + printf_filtered ("Psymtab "); puts_filtered (ps->filename); - printf_filtered (" psymtab\n"); + printf_filtered (" covers bad range "); + fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), + gdb_stdout); + printf_filtered (" - "); + fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), + gdb_stdout); + printf_filtered ("\n"); + continue; } - psym++; - } - b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); - psym = &objfile->global_psymbols[ps->globals_offset]; - length = ps->n_global_syms; - while (length--) - { - sym = block_lookup_symbol (b, symbol_search_name (*psym), - symbol_name_match_type::SEARCH_NAME, - (*psym)->domain); - if (!sym) + + /* Now do checks requiring the associated symtab. */ + if (cust == NULL) + continue; + bv = COMPUNIT_BLOCKVECTOR (cust); + b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); + partial_symbol **psym = &objfile->static_psymbols[ps->statics_offset]; + length = ps->n_static_syms; + while (length--) + { + sym = block_lookup_symbol (b, symbol_search_name (*psym), + symbol_name_match_type::SEARCH_NAME, + (*psym)->domain); + if (!sym) + { + printf_filtered ("Static symbol `"); + puts_filtered ((*psym)->name); + printf_filtered ("' only found in "); + puts_filtered (ps->filename); + printf_filtered (" psymtab\n"); + } + psym++; + } + b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); + psym = &objfile->global_psymbols[ps->globals_offset]; + length = ps->n_global_syms; + while (length--) { - printf_filtered ("Global symbol `"); - puts_filtered ((*psym)->name); - printf_filtered ("' only found in "); + sym = block_lookup_symbol (b, symbol_search_name (*psym), + symbol_name_match_type::SEARCH_NAME, + (*psym)->domain); + if (!sym) + { + printf_filtered ("Global symbol `"); + puts_filtered ((*psym)->name); + printf_filtered ("' only found in "); + puts_filtered (ps->filename); + printf_filtered (" psymtab\n"); + } + psym++; + } + if (ps->raw_text_high () != 0 + && (ps->text_low (objfile) < BLOCK_START (b) + || ps->text_high (objfile) > BLOCK_END (b))) + { + printf_filtered ("Psymtab "); puts_filtered (ps->filename); - printf_filtered (" psymtab\n"); + printf_filtered (" covers "); + fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), + gdb_stdout); + printf_filtered (" - "); + fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), + gdb_stdout); + printf_filtered (" but symtab covers only "); + fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout); + printf_filtered (" - "); + fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout); + printf_filtered ("\n"); } - psym++; } - if (ps->raw_text_high () != 0 - && (ps->text_low (objfile) < BLOCK_START (b) - || ps->text_high (objfile) > BLOCK_END (b))) - { - printf_filtered ("Psymtab "); - puts_filtered (ps->filename); - printf_filtered (" covers "); - fputs_filtered (paddress (gdbarch, ps->text_low (objfile)), - gdb_stdout); - printf_filtered (" - "); - fputs_filtered (paddress (gdbarch, ps->text_high (objfile)), - gdb_stdout); - printf_filtered (" but symtab covers only "); - fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout); - printf_filtered (" - "); - fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout); - printf_filtered ("\n"); - } - } } void diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 5f61b734af..d9cf548adb 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -501,9 +501,7 @@ objfpy_build_id_matches (const struct bfd_build_id *build_id, static struct objfile * objfpy_lookup_objfile_by_name (const char *name) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { const char *filename; @@ -529,9 +527,7 @@ objfpy_lookup_objfile_by_name (const char *name) static struct objfile * objfpy_lookup_objfile_by_build_id (const char *build_id) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { const struct bfd_build_id *obfd_build_id; diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index ac0506f3e1..4092fdb79f 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -93,28 +93,26 @@ search_pp_list (PyObject *list, PyObject *value) static PyObject * find_pretty_printer_from_objfiles (PyObject *value) { - struct objfile *obj; + for (objfile *obj : all_objfiles (current_program_space)) + { + gdbpy_ref<> objf = objfile_to_objfile_object (obj); + if (objf == NULL) + { + /* Ignore the error and continue. */ + PyErr_Clear (); + continue; + } - ALL_OBJFILES (obj) - { - gdbpy_ref<> objf = objfile_to_objfile_object (obj); - if (objf == NULL) - { - /* Ignore the error and continue. */ - PyErr_Clear (); - continue; - } - - gdbpy_ref<> pp_list (objfpy_get_printers (objf.get (), NULL)); - gdbpy_ref<> function (search_pp_list (pp_list.get (), value)); - - /* If there is an error in any objfile list, abort the search and exit. */ - if (function == NULL) - return NULL; + gdbpy_ref<> pp_list (objfpy_get_printers (objf.get (), NULL)); + gdbpy_ref<> function (search_pp_list (pp_list.get (), value)); - if (function != Py_None) - return function.release (); - } + /* If there is an error in any objfile list, abort the search and exit. */ + if (function == NULL) + return NULL; + + if (function != Py_None) + return function.release (); + } Py_RETURN_NONE; } diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index a1f7b1da5c..acf521dfe3 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -121,8 +121,6 @@ gdbpy_get_matching_xmethod_workers struct type *obj_type, const char *method_name, std::vector *dm_vec) { - struct objfile *objfile; - gdb_assert (obj_type != NULL && method_name != NULL); gdbpy_enter enter_py (get_current_arch (), current_language); @@ -145,7 +143,7 @@ gdbpy_get_matching_xmethod_workers /* Gather debug method matchers registered with the object files. This could be done differently by iterating over each objfile's matcher list individually, but there's no data yet to show it's needed. */ - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile); diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c index 7a266c322c..d68150eb3c 100644 --- a/gdb/solib-spu.c +++ b/gdb/solib-spu.c @@ -101,9 +101,8 @@ static void append_ocl_sos (struct so_list **link_ptr) { CORE_ADDR *ocl_program_addr_base; - struct objfile *objfile; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { ocl_program_addr_base = (CORE_ADDR *) objfile_data (objfile, ocl_program_data_key); diff --git a/gdb/solib.c b/gdb/solib.c index 30d2ded805..24f40d1124 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -677,11 +677,15 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags) TRY { /* Have we already loaded this shared object? */ - ALL_OBJFILES (so->objfile) + so->objfile = nullptr; + for (objfile *objfile : all_objfiles (current_program_space)) { - if (filename_cmp (objfile_name (so->objfile), so->so_name) == 0 - && so->objfile->addr_low == so->addr_low) - break; + if (filename_cmp (objfile_name (objfile), so->so_name) == 0 + && objfile->addr_low == so->addr_low) + { + so->objfile = objfile; + break; + } } if (so->objfile == NULL) { diff --git a/gdb/source.c b/gdb/source.c index 85e15c3934..74c895c27b 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -288,13 +288,13 @@ select_source_symtab (struct symtab *s) if (current_source_symtab) return; - ALL_OBJFILES (ofp) - { - if (ofp->sf) - s = ofp->sf->qf->find_last_source_symtab (ofp); - if (s) - current_source_symtab = s; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf) + s = objfile->sf->qf->find_last_source_symtab (objfile); + if (s) + current_source_symtab = s; + } if (current_source_symtab) return; diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c index 3a9cac1fdd..0f6fb6dd72 100644 --- a/gdb/spu-tdep.c +++ b/gdb/spu-tdep.c @@ -2000,12 +2000,11 @@ spu_objfile_from_frame (struct frame_info *frame) { struct gdbarch *gdbarch = get_frame_arch (frame); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - struct objfile *obj; if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu) return NULL; - ALL_OBJFILES (obj) + for (objfile *obj : all_objfiles (current_program_space)) { if (obj->sections != obj->sections_end && SPUADDR_SPU (obj_section_addr (obj->sections)) == tdep->id) diff --git a/gdb/symfile.c b/gdb/symfile.c index 8858098f48..8d05173dd9 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2351,12 +2351,16 @@ remove_symbol_file_command (const char *args, int from_tty) addr = parse_and_eval_address (argv[1]); - ALL_OBJFILES (objf) + for (objfile *objfile : all_objfiles (current_program_space)) { - if ((objf->flags & OBJF_USERLOADED) != 0 - && (objf->flags & OBJF_SHARED) != 0 - && objf->pspace == pspace && is_addr_in_objfile (addr, objf)) - break; + if ((objfile->flags & OBJF_USERLOADED) != 0 + && (objfile->flags & OBJF_SHARED) != 0 + && objfile->pspace == pspace + && is_addr_in_objfile (addr, objfile)) + { + objf = objfile; + break; + } } } else if (argv[0] != NULL) @@ -2368,13 +2372,16 @@ remove_symbol_file_command (const char *args, int from_tty) gdb::unique_xmalloc_ptr filename (tilde_expand (argv[0])); - ALL_OBJFILES (objf) + for (objfile *objfile : all_objfiles (current_program_space)) { - if ((objf->flags & OBJF_USERLOADED) != 0 - && (objf->flags & OBJF_SHARED) != 0 - && objf->pspace == pspace - && filename_cmp (filename.get (), objfile_name (objf)) == 0) - break; + if ((objfile->flags & OBJF_USERLOADED) != 0 + && (objfile->flags & OBJF_SHARED) != 0 + && objfile->pspace == pspace + && filename_cmp (filename.get (), objfile_name (objfile)) == 0) + { + objf = objfile; + break; + } } } @@ -3791,16 +3798,14 @@ expand_symtabs_matching gdb::function_view expansion_notify, enum search_domain kind) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) - { - if (objfile->sf) - objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher, - lookup_name, - symbol_matcher, - expansion_notify, kind); - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf) + objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher, + lookup_name, + symbol_matcher, + expansion_notify, kind); + } } /* Wrapper around the quick_symbol_functions map_symbol_filenames "method". @@ -3811,14 +3816,12 @@ void map_symbol_filenames (symbol_filename_ftype *fun, void *data, int need_fullname) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) - { - if (objfile->sf) - objfile->sf->qf->map_symbol_filenames (objfile, fun, data, - need_fullname); - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf) + objfile->sf->qf->map_symbol_filenames (objfile, fun, data, + need_fullname); + } } #if GDB_SELF_TEST diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 24ecea39da..14e764994e 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -470,12 +470,11 @@ maintenance_print_symbols (const char *args, int from_tty) } else { - struct objfile *objfile; struct compunit_symtab *cu; struct symtab *s; int found = 0; - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { int print_for_objfile = 1; @@ -690,7 +689,6 @@ maintenance_print_msymbols (const char *args, int from_tty) { struct ui_file *outfile = gdb_stdout; char *objfile_arg = NULL; - struct objfile *objfile; int i, outfile_idx; dont_repeat (); @@ -734,13 +732,13 @@ maintenance_print_msymbols (const char *args, int from_tty) outfile = &arg_outfile; } - ALL_OBJFILES (objfile) - { - QUIT; - if (objfile_arg == NULL - || compare_filenames_for_search (objfile_name (objfile), objfile_arg)) - dump_msymbols (objfile, outfile); - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + QUIT; + if (objfile_arg == NULL + || compare_filenames_for_search (objfile_name (objfile), objfile_arg)) + dump_msymbols (objfile, outfile); + } } static void diff --git a/gdb/symtab.c b/gdb/symtab.c index aad60931b5..17ee94607e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -464,7 +464,6 @@ void iterate_over_symtabs (const char *name, gdb::function_view callback) { - struct objfile *objfile; gdb::unique_xmalloc_ptr real_path; /* Here we are interested in canonicalizing an absolute path, not @@ -475,7 +474,7 @@ iterate_over_symtabs (const char *name, gdb_assert (IS_ABSOLUTE_PATH (real_path.get ())); } - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { if (iterate_over_some_symtabs (name, real_path.get (), objfile->compunit_symtabs, NULL, @@ -486,7 +485,7 @@ iterate_over_symtabs (const char *name, /* Same search rules as above apply here, but now we look thru the psymtabs. */ - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { if (objfile->sf && objfile->sf->qf->map_symtabs_matching_filename (objfile, @@ -1013,9 +1012,12 @@ matching_obj_sections (struct obj_section *obj_first, /* Otherwise check that they are in corresponding objfiles. */ - ALL_OBJFILES (obj) - if (obj->obfd == first->owner) - break; + for (objfile *objfile : all_objfiles (current_program_space)) + if (objfile->obfd == first->owner) + { + obj = objfile; + break; + } gdb_assert (obj != NULL); if (obj->separate_debug_objfile != NULL @@ -1033,7 +1035,6 @@ matching_obj_sections (struct obj_section *obj_first, void expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section) { - struct objfile *objfile; struct bound_minimal_symbol msymbol; /* If we know that this is not a text address, return failure. This is @@ -1048,16 +1049,16 @@ expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section) || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss)) return; - ALL_OBJFILES (objfile) - { - struct compunit_symtab *cust = NULL; + for (objfile *objfile : all_objfiles (current_program_space)) + { + struct compunit_symtab *cust = NULL; - if (objfile->sf) - cust = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, - pc, section, 0); - if (cust) - return; - } + if (objfile->sf) + cust = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol, + pc, section, 0); + if (cust) + return; + } } /* Hash function for the symbol cache. */ @@ -2576,7 +2577,6 @@ struct block_symbol lookup_static_symbol (const char *name, const domain_enum domain) { struct symbol_cache *cache = get_symbol_cache (current_program_space); - struct objfile *objfile; struct block_symbol result; struct block_symbol_cache *bsc; struct symbol_cache_slot *slot; @@ -2592,7 +2592,7 @@ lookup_static_symbol (const char *name, const domain_enum domain) return result; } - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { result = lookup_symbol_in_objfile (objfile, STATIC_BLOCK, name, domain); if (result.symbol != NULL) @@ -2793,7 +2793,6 @@ basic_lookup_transparent_type_1 (struct objfile *objfile, int block_index, struct type * basic_lookup_transparent_type (const char *name) { - struct objfile *objfile; struct type *t; /* Now search all the global symbols. Do the symtab's first, then @@ -2801,19 +2800,19 @@ basic_lookup_transparent_type (const char *name) of the desired name as a global, then do psymtab-to-symtab conversion on the fly and return the found symbol. */ - ALL_OBJFILES (objfile) - { - t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name); - if (t) - return t; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name); + if (t) + return t; + } - ALL_OBJFILES (objfile) - { - t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name); - if (t) - return t; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name); + if (t) + return t; + } /* Now search the static file-level symbols. Not strictly correct, but more useful than an error. @@ -2822,19 +2821,19 @@ basic_lookup_transparent_type (const char *name) of the desired name as a file-level static, then do psymtab-to-symtab conversion on the fly and return the found symbol. */ - ALL_OBJFILES (objfile) - { - t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name); - if (t) - return t; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name); + if (t) + return t; + } - ALL_OBJFILES (objfile) - { - t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name); - if (t) - return t; - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name); + if (t) + return t; + } return (struct type *) 0; } @@ -2877,7 +2876,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) { struct compunit_symtab *cust; struct compunit_symtab *best_cust = NULL; - struct objfile *objfile; + struct objfile *obj_file; CORE_ADDR distance = 0; struct bound_minimal_symbol msymbol; @@ -2910,7 +2909,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) It also happens for objfiles that have their functions reordered. For these, the symtab we are looking for is not necessarily read in. */ - ALL_COMPUNITS (objfile, cust) + ALL_COMPUNITS (obj_file, cust) { struct block *b; const struct blockvector *bv; @@ -2929,15 +2928,15 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) /* In order to better support objfiles that contain both stabs and coff debugging info, we continue on if a psymtab can't be found. */ - if ((objfile->flags & OBJF_REORDERED) && objfile->sf) + if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf) { struct compunit_symtab *result; result - = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, - msymbol, - pc, section, - 0); + = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file, + msymbol, + pc, section, + 0); if (result != NULL) return result; } @@ -2948,8 +2947,8 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) ALL_BLOCK_SYMBOLS (b, iter, sym) { - fixup_symbol_section (sym, objfile); - if (matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, sym), + fixup_symbol_section (sym, obj_file); + if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file, sym), section)) break; } @@ -2967,19 +2966,19 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs). */ - ALL_OBJFILES (objfile) - { - struct compunit_symtab *result; - - if (!objfile->sf) - continue; - result = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, - msymbol, - pc, section, - 1); - if (result != NULL) - return result; - } + for (objfile *objf : all_objfiles (current_program_space)) + { + struct compunit_symtab *result; + + if (!objf->sf) + continue; + result = objf->sf->qf->find_pc_sect_compunit_symtab (objf, + msymbol, + pc, section, + 1); + if (result != NULL) + return result; + } return NULL; } @@ -2999,35 +2998,33 @@ find_pc_compunit_symtab (CORE_ADDR pc) struct symbol * find_symbol_at_address (CORE_ADDR address) { - struct objfile *objfile; - - ALL_OBJFILES (objfile) - { - if (objfile->sf == NULL - || objfile->sf->qf->find_compunit_symtab_by_address == NULL) - continue; - - struct compunit_symtab *symtab - = objfile->sf->qf->find_compunit_symtab_by_address (objfile, address); - if (symtab != NULL) - { - const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab); + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf == NULL + || objfile->sf->qf->find_compunit_symtab_by_address == NULL) + continue; - for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) - { - struct block *b = BLOCKVECTOR_BLOCK (bv, i); - struct block_iterator iter; - struct symbol *sym; + struct compunit_symtab *symtab + = objfile->sf->qf->find_compunit_symtab_by_address (objfile, address); + if (symtab != NULL) + { + const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (symtab); - ALL_BLOCK_SYMBOLS (b, iter, sym) + for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) { - if (SYMBOL_CLASS (sym) == LOC_STATIC - && SYMBOL_VALUE_ADDRESS (sym) == address) - return sym; + struct block *b = BLOCKVECTOR_BLOCK (bv, i); + struct block_iterator iter; + struct symbol *sym; + + ALL_BLOCK_SYMBOLS (b, iter, sym) + { + if (SYMBOL_CLASS (sym) == LOC_STATIC + && SYMBOL_VALUE_ADDRESS (sym) == address) + return sym; + } } - } - } - } + } + } return NULL; } @@ -3352,7 +3349,6 @@ find_line_symtab (struct symtab *symtab, int line, BEST_INDEX and BEST_LINETABLE identify the item for it. */ int best; - struct objfile *objfile; struct compunit_symtab *cu; struct symtab *s; @@ -3361,13 +3357,14 @@ find_line_symtab (struct symtab *symtab, int line, else best = 0; - ALL_OBJFILES (objfile) - { - if (objfile->sf) - objfile->sf->qf->expand_symtabs_with_fullname (objfile, - symtab_to_fullname (symtab)); - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + if (objfile->sf) + objfile->sf->qf->expand_symtabs_with_fullname + (objfile, symtab_to_fullname (symtab)); + } + struct objfile *objfile; ALL_FILETABS (objfile, cu, s) { struct linetable *l; @@ -5691,7 +5688,6 @@ 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 @@ -5699,15 +5695,15 @@ find_main_name (void) 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; - } - } + for (objfile *objfile : all_objfiles (current_program_space)) + { + 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 diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 614dc3bbc5..9258f39eca 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -415,7 +415,6 @@ windows_iterate_over_objfiles_in_search_order void *cb_data, struct objfile *current_objfile) { int stop; - struct objfile *objfile; if (current_objfile) { @@ -424,7 +423,7 @@ windows_iterate_over_objfiles_in_search_order return; } - ALL_OBJFILES (objfile) + for (objfile *objfile : all_objfiles (current_program_space)) { if (objfile != current_objfile) { -- 2.34.1