mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-03 04:12:10 +08:00
9a3c826307
Note: I needed to split this patch in two, otherwise it's too big for the mailing list. This patch adds explicit casts to situations where a void pointer is assigned to a pointer to the "real" type. Building in C++ mode requires those assignments to use an explicit cast. This includes, for example: - callback arguments (cleanups, comparison functions, ...) - data attached to some object (objfile, program space, etc) in the form of a void pointer - "user data" passed to some function This patch comes from the commit "(mostly) auto-generated patch to insert casts needed for C++", taken from Pedro's C++ branch. Only files built on x86 with --enable-targets=all are modified, so the native files for other arches will need to be dealt with separately. I built-tested this with --enable-targets=all and reg-tested. To my surprise, a test case (selftest.exp) had to be adjusted. Here's the ChangeLog entry. Again, this was relatively quick to make despite the length, thanks to David Malcom's script, although I don't believe it's very useful information in that particular case... gdb/ChangeLog: * aarch64-tdep.c (aarch64_make_prologue_cache): Add cast(s). (aarch64_make_stub_cache): Likewise. (value_of_aarch64_user_reg): Likewise. * ada-lang.c (ada_inferior_data_cleanup): Likewise. (get_ada_inferior_data): Likewise. (get_ada_pspace_data): Likewise. (ada_pspace_data_cleanup): Likewise. (ada_complete_symbol_matcher): Likewise. (ada_exc_search_name_matches): Likewise. * ada-tasks.c (get_ada_tasks_pspace_data): Likewise. (get_ada_tasks_inferior_data): Likewise. * addrmap.c (addrmap_mutable_foreach_worker): Likewise. (splay_obstack_alloc): Likewise. (splay_obstack_free): Likewise. * alpha-linux-tdep.c (alpha_linux_supply_gregset): Likewise. (alpha_linux_collect_gregset): Likewise. (alpha_linux_supply_fpregset): Likewise. (alpha_linux_collect_fpregset): Likewise. * alpha-mdebug-tdep.c (alpha_mdebug_frame_unwind_cache): Likewise. * alpha-tdep.c (alpha_lds): Likewise. (alpha_sts): Likewise. (alpha_sigtramp_frame_unwind_cache): Likewise. (alpha_heuristic_frame_unwind_cache): Likewise. (alpha_supply_int_regs): Likewise. (alpha_fill_int_regs): Likewise. (alpha_supply_fp_regs): Likewise. (alpha_fill_fp_regs): Likewise. * alphanbsd-tdep.c (alphanbsd_supply_fpregset): Likewise. (alphanbsd_aout_supply_gregset): Likewise. (alphanbsd_supply_gregset): Likewise. * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise. (amd64_x32_linux_init_abi): Likewise. * amd64-nat.c (amd64_supply_native_gregset): Likewise. (amd64_collect_native_gregset): Likewise. * amd64-tdep.c (amd64_frame_cache): Likewise. (amd64_sigtramp_frame_cache): Likewise. (amd64_epilogue_frame_cache): Likewise. (amd64_supply_fxsave): Likewise. (amd64_supply_xsave): Likewise. (amd64_collect_fxsave): Likewise. (amd64_collect_xsave): Likewise. * amd64-windows-tdep.c (amd64_windows_frame_cache): Likewise. * amd64obsd-tdep.c (amd64obsd_trapframe_cache): Likewise. * arm-linux-tdep.c (arm_linux_supply_gregset): Likewise. (arm_linux_collect_gregset): Likewise. (arm_linux_supply_nwfpe): Likewise. (arm_linux_collect_nwfpe): Likewise. (arm_linux_supply_vfp): Likewise. (arm_linux_collect_vfp): Likewise. * arm-tdep.c (arm_find_mapping_symbol): Likewise. (arm_prologue_unwind_stop_reason): Likewise. (arm_prologue_this_id): Likewise. (arm_prologue_prev_register): Likewise. (arm_exidx_data_free): Likewise. (arm_find_exidx_entry): Likewise. (arm_stub_this_id): Likewise. (arm_m_exception_this_id): Likewise. (arm_m_exception_prev_register): Likewise. (arm_normal_frame_base): Likewise. (gdb_print_insn_arm): Likewise. (arm_objfile_data_free): Likewise. (arm_record_special_symbol): Likewise. (value_of_arm_user_reg): Likewise. * armbsd-tdep.c (armbsd_supply_fpregset): Likewise. (armbsd_supply_gregset): Likewise. * auto-load.c (auto_load_pspace_data_cleanup): Likewise. (get_auto_load_pspace_data): Likewise. (hash_loaded_script_entry): Likewise. (eq_loaded_script_entry): Likewise. (clear_section_scripts): Likewise. (collect_matching_scripts): Likewise. * auxv.c (auxv_inferior_data_cleanup): Likewise. (get_auxv_inferior_data): Likewise. * avr-tdep.c (avr_frame_unwind_cache): Likewise. * ax-general.c (do_free_agent_expr_cleanup): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. (target_bfd_xclose): Likewise. (target_bfd_get_section_table): Likewise. * bfin-tdep.c (bfin_frame_cache): Likewise. * block.c (find_block_in_blockvector): Likewise. (call_site_for_pc): Likewise. (block_find_non_opaque_type_preferred): Likewise. * break-catch-sig.c (signal_catchpoint_insert_location): Likewise. (signal_catchpoint_remove_location): Likewise. (signal_catchpoint_breakpoint_hit): Likewise. (signal_catchpoint_print_one): Likewise. (signal_catchpoint_print_mention): Likewise. (signal_catchpoint_print_recreate): Likewise. * break-catch-syscall.c (get_catch_syscall_inferior_data): Likewise. * breakpoint.c (do_cleanup_counted_command_line): Likewise. (bp_location_compare_addrs): Likewise. (get_first_locp_gte_addr): Likewise. (check_tracepoint_command): Likewise. (do_map_commands_command): Likewise. (get_breakpoint_objfile_data): Likewise. (free_breakpoint_probes): Likewise. (do_captured_breakpoint_query): Likewise. (compare_breakpoints): Likewise. (bp_location_compare): Likewise. (bpstat_remove_breakpoint_callback): Likewise. (do_delete_breakpoint_cleanup): Likewise. * bsd-uthread.c (bsd_uthread_set_supply_uthread): Likewise. (bsd_uthread_set_collect_uthread): Likewise. (bsd_uthread_activate): Likewise. (bsd_uthread_fetch_registers): Likewise. (bsd_uthread_store_registers): Likewise. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt_raw): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. (do_btrace_data_cleanup): Likewise. * c-typeprint.c (find_typedef_for_canonicalize): Likewise. * charset.c (cleanup_iconv): Likewise. (do_cleanup_iterator): Likewise. * cli-out.c (cli_uiout_dtor): Likewise. (cli_table_begin): Likewise. (cli_table_body): Likewise. (cli_table_end): Likewise. (cli_table_header): Likewise. (cli_begin): Likewise. (cli_end): Likewise. (cli_field_int): Likewise. (cli_field_skip): Likewise. (cli_field_string): Likewise. (cli_field_fmt): Likewise. (cli_spaces): Likewise. (cli_text): Likewise. (cli_message): Likewise. (cli_wrap_hint): Likewise. (cli_flush): Likewise. (cli_redirect): Likewise. (out_field_fmt): Likewise. (field_separator): Likewise. (cli_out_set_stream): Likewise. * cli/cli-cmds.c (compare_symtabs): Likewise. * cli/cli-dump.c (call_dump_func): Likewise. (restore_section_callback): Likewise. * cli/cli-script.c (clear_hook_in_cleanup): Likewise. (do_restore_user_call_depth): Likewise. (do_free_command_lines_cleanup): Likewise. * coff-pe-read.c (get_section_vmas): Likewise. (pe_as16): Likewise. (pe_as32): Likewise. * coffread.c (coff_symfile_read): Likewise. * common/agent.c (agent_look_up_symbols): Likewise. * common/filestuff.c (do_close_cleanup): Likewise. * common/format.c (free_format_pieces_cleanup): Likewise. * common/vec.c (vec_o_reserve): Likewise. * compile/compile-c-support.c (print_one_macro): Likewise. * compile/compile-c-symbols.c (hash_symbol_error): Likewise. (eq_symbol_error): Likewise. (del_symbol_error): Likewise. (error_symbol_once): Likewise. (gcc_convert_symbol): Likewise. (gcc_symbol_address): Likewise. (hash_symname): Likewise. (eq_symname): Likewise. * compile/compile-c-types.c (hash_type_map_instance): Likewise. (eq_type_map_instance): Likewise. (insert_type): Likewise. (convert_type): Likewise. * compile/compile-object-load.c (munmap_listp_free_cleanup): Likewise. (setup_sections): Likewise. (link_hash_table_free): Likewise. (copy_sections): Likewise. * compile/compile-object-run.c (do_module_cleanup): Likewise. * compile/compile.c (compile_print_value): Likewise. (do_rmdir): Likewise. (cleanup_compile_instance): Likewise. (cleanup_unlink_file): Likewise. * completer.c (free_completion_tracker): Likewise. * corelow.c (add_to_spuid_list): Likewise. * cp-namespace.c (reset_directive_searched): Likewise. * cp-support.c (reset_directive_searched): Likewise. * cris-tdep.c (cris_sigtramp_frame_unwind_cache): Likewise. (cris_frame_unwind_cache): Likewise. * d-lang.c (builtin_d_type): Likewise. * d-namespace.c (reset_directive_searched): Likewise. * dbxread.c (dbx_free_symfile_info): Likewise. (do_free_bincl_list_cleanup): Likewise. * disasm.c (hash_dis_line_entry): Likewise. (eq_dis_line_entry): Likewise. (dis_asm_print_address): Likewise. (fprintf_disasm): Likewise. (do_ui_file_delete): Likewise. * doublest.c (convert_floatformat_to_doublest): Likewise. * dummy-frame.c (pop_dummy_frame_bpt): Likewise. (dummy_frame_prev_register): Likewise. (dummy_frame_this_id): Likewise. * dwarf2-frame-tailcall.c (cache_hash): Likewise. (cache_eq): Likewise. (cache_find): Likewise. (tailcall_frame_this_id): Likewise. (dwarf2_tailcall_prev_register_first): Likewise. (tailcall_frame_prev_register): Likewise. (tailcall_frame_dealloc_cache): Likewise. (tailcall_frame_prev_arch): Likewise. * dwarf2-frame.c (dwarf2_frame_state_free): Likewise. (dwarf2_frame_set_init_reg): Likewise. (dwarf2_frame_init_reg): Likewise. (dwarf2_frame_set_signal_frame_p): Likewise. (dwarf2_frame_signal_frame_p): Likewise. (dwarf2_frame_set_adjust_regnum): Likewise. (dwarf2_frame_adjust_regnum): Likewise. (clear_pointer_cleanup): Likewise. (dwarf2_frame_cache): Likewise. (find_cie): Likewise. (dwarf2_frame_find_fde): Likewise. * dwarf2expr.c (dwarf_expr_address_type): Likewise. (free_dwarf_expr_context_cleanup): Likewise. * dwarf2loc.c (locexpr_find_frame_base_location): Likewise. (locexpr_get_frame_base): Likewise. (loclist_find_frame_base_location): Likewise. (loclist_get_frame_base): Likewise. (dwarf_expr_dwarf_call): Likewise. (dwarf_expr_get_base_type): Likewise. (dwarf_expr_push_dwarf_reg_entry_value): Likewise. (dwarf_expr_get_obj_addr): Likewise. (entry_data_value_coerce_ref): Likewise. (entry_data_value_copy_closure): Likewise. (entry_data_value_free_closure): Likewise. (get_frame_address_in_block_wrapper): Likewise. (dwarf2_evaluate_property): Likewise. (dwarf2_compile_property_to_c): Likewise. (needs_frame_read_addr_from_reg): Likewise. (needs_frame_get_reg_value): Likewise. (needs_frame_frame_base): Likewise. (needs_frame_frame_cfa): Likewise. (needs_frame_tls_address): Likewise. (needs_frame_dwarf_call): Likewise. (needs_dwarf_reg_entry_value): Likewise. (get_ax_pc): Likewise. (locexpr_read_variable): Likewise. (locexpr_read_variable_at_entry): Likewise. (locexpr_read_needs_frame): Likewise. (locexpr_describe_location): Likewise. (locexpr_tracepoint_var_ref): Likewise. (locexpr_generate_c_location): Likewise. (loclist_read_variable): Likewise. (loclist_read_variable_at_entry): Likewise. (loclist_describe_location): Likewise. (loclist_tracepoint_var_ref): Likewise. (loclist_generate_c_location): Likewise. * dwarf2read.c (line_header_hash_voidp): Likewise. (line_header_eq_voidp): Likewise. (dwarf2_has_info): Likewise. (dwarf2_get_section_info): Likewise. (locate_dwz_sections): Likewise. (hash_file_name_entry): Likewise. (eq_file_name_entry): Likewise. (delete_file_name_entry): Likewise. (dw2_setup): Likewise. (dw2_get_file_names_reader): Likewise. (dw2_find_pc_sect_compunit_symtab): Likewise. (hash_signatured_type): Likewise. (eq_signatured_type): Likewise. (add_signatured_type_cu_to_table): Likewise. (create_debug_types_hash_table): Likewise. (lookup_dwo_signatured_type): Likewise. (lookup_dwp_signatured_type): Likewise. (lookup_signatured_type): Likewise. (hash_type_unit_group): Likewise. (eq_type_unit_group): Likewise. (get_type_unit_group): Likewise. (process_psymtab_comp_unit_reader): Likewise. (sort_tu_by_abbrev_offset): Likewise. (process_skeletonless_type_unit): Likewise. (psymtabs_addrmap_cleanup): Likewise. (dwarf2_read_symtab): Likewise. (psymtab_to_symtab_1): Likewise. (die_hash): Likewise. (die_eq): Likewise. (load_full_comp_unit_reader): Likewise. (reset_die_in_process): Likewise. (free_cu_line_header): Likewise. (handle_DW_AT_stmt_list): Likewise. (hash_dwo_file): Likewise. (eq_dwo_file): Likewise. (hash_dwo_unit): Likewise. (eq_dwo_unit): Likewise. (create_dwo_cu_reader): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (lookup_dwo_unit_in_dwp): Likewise. (dwarf2_locate_dwo_sections): Likewise. (dwarf2_locate_common_dwp_sections): Likewise. (dwarf2_locate_v2_dwp_sections): Likewise. (hash_dwp_loaded_cutus): Likewise. (eq_dwp_loaded_cutus): Likewise. (lookup_dwo_cutu): Likewise. (abbrev_table_free_cleanup): Likewise. (dwarf2_free_abbrev_table): Likewise. (find_partial_die_in_comp_unit): Likewise. (free_line_header_voidp): Likewise. (follow_die_offset): Likewise. (follow_die_sig_1): Likewise. (free_heap_comp_unit): Likewise. (free_stack_comp_unit): Likewise. (dwarf2_free_objfile): Likewise. (per_cu_offset_and_type_hash): Likewise. (per_cu_offset_and_type_eq): Likewise. (get_die_type_at_offset): Likewise. (partial_die_hash): Likewise. (partial_die_eq): Likewise. (dwarf2_per_objfile_free): Likewise. (hash_strtab_entry): Likewise. (eq_strtab_entry): Likewise. (add_string): Likewise. (hash_symtab_entry): Likewise. (eq_symtab_entry): Likewise. (delete_symtab_entry): Likewise. (cleanup_mapped_symtab): Likewise. (add_indices_to_cpool): Likewise. (hash_psymtab_cu_index): Likewise. (eq_psymtab_cu_index): Likewise. (add_address_entry_worker): Likewise. (unlink_if_set): Likewise. (write_one_signatured_type): Likewise. (save_gdb_index_command): Likewise. * elfread.c (elf_symtab_read): Likewise. (elf_gnu_ifunc_cache_hash): Likewise. (elf_gnu_ifunc_cache_eq): Likewise. (elf_gnu_ifunc_record_cache): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_get_probes): Likewise. (probe_key_free): Likewise. * f-lang.c (builtin_f_type): Likewise. * frame-base.c (frame_base_append_sniffer): Likewise. (frame_base_set_default): Likewise. (frame_base_find_by_frame): Likewise. * frame-unwind.c (frame_unwind_prepend_unwinder): Likewise. (frame_unwind_append_unwinder): Likewise. (frame_unwind_find_by_frame): Likewise. * frame.c (frame_addr_hash): Likewise. (frame_addr_hash_eq): Likewise. (frame_stash_find): Likewise. (do_frame_register_read): Likewise. (unwind_to_current_frame): Likewise. (frame_cleanup_after_sniffer): Likewise. * frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise. * frv-tdep.c (frv_frame_unwind_cache): Likewise. * ft32-tdep.c (ft32_frame_cache): Likewise. * gcore.c (do_bfd_delete_cleanup): Likewise. (gcore_create_callback): Likewise. * gdb_bfd.c (hash_bfd): Likewise. (eq_bfd): Likewise. (gdb_bfd_open): Likewise. (free_one_bfd_section): Likewise. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (get_section_descriptor): Likewise. (gdb_bfd_map_section): Likewise. (gdb_bfd_crc): Likewise. (gdb_bfd_mark_parent): Likewise. (gdb_bfd_record_inclusion): Likewise. (gdb_bfd_requires_relocations): Likewise. (print_one_bfd): Likewise. * gdbtypes.c (type_pair_hash): Likewise. (type_pair_eq): Likewise. (builtin_type): Likewise. (objfile_type): Likewise. * gnu-v3-abi.c (vtable_ptrdiff_type): Likewise. (vtable_address_point_offset): Likewise. (gnuv3_get_vtable): Likewise. (hash_value_and_voffset): Likewise. (eq_value_and_voffset): Likewise. (compare_value_and_voffset): Likewise. (compute_vtable_size): Likewise. (gnuv3_get_typeid_type): Likewise. * go-lang.c (builtin_go_type): Likewise. * guile/scm-block.c (bkscm_hash_block_smob): Likewise. (bkscm_eq_block_smob): Likewise. (bkscm_objfile_block_map): Likewise. (bkscm_del_objfile_blocks): Likewise. * guile/scm-breakpoint.c (bpscm_build_bp_list): Likewise. * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): Likewise. (gdbscm_disasm_print_address): Likewise. * guile/scm-frame.c (frscm_hash_frame_smob): Likewise. (frscm_eq_frame_smob): Likewise. (frscm_inferior_frame_map): Likewise. (frscm_del_inferior_frames): Likewise. * guile/scm-gsmob.c (gdbscm_add_objfile_ref): Likewise. * guile/scm-objfile.c (ofscm_handle_objfile_deleted): Likewise. (ofscm_objfile_smob_from_objfile): Likewise. * guile/scm-ports.c (ioscm_write): Likewise. (ioscm_file_port_delete): Likewise. (ioscm_file_port_rewind): Likewise. (ioscm_file_port_put): Likewise. (ioscm_file_port_write): Likewise. * guile/scm-progspace.c (psscm_handle_pspace_deleted): Likewise. (psscm_pspace_smob_from_pspace): Likewise. * guile/scm-safe-call.c (scscm_recording_pre_unwind_handler): Likewise. (scscm_recording_unwind_handler): Likewise. (gdbscm_with_catch): Likewise. (scscm_call_0_body): Likewise. (scscm_call_1_body): Likewise. (scscm_call_2_body): Likewise. (scscm_call_3_body): Likewise. (scscm_call_4_body): Likewise. (scscm_apply_1_body): Likewise. (scscm_eval_scheme_string): Likewise. (gdbscm_safe_eval_string): Likewise. (scscm_source_scheme_script): Likewise. (gdbscm_safe_source_script): Likewise. * guile/scm-string.c (gdbscm_call_scm_to_stringn): Likewise. (gdbscm_call_scm_from_stringn): Likewise. * guile/scm-symbol.c (syscm_hash_symbol_smob): Likewise. (syscm_eq_symbol_smob): Likewise. (syscm_get_symbol_map): Likewise. (syscm_del_objfile_symbols): Likewise. * guile/scm-symtab.c (stscm_hash_symtab_smob): Likewise. (stscm_eq_symtab_smob): Likewise. (stscm_objfile_symtab_map): Likewise. (stscm_del_objfile_symtabs): Likewise. * guile/scm-type.c (tyscm_hash_type_smob): Likewise. (tyscm_eq_type_smob): Likewise. (tyscm_type_map): Likewise. (tyscm_copy_type_recursive): Likewise. (save_objfile_types): Likewise. * guile/scm-utils.c (extract_arg): Likewise. * h8300-tdep.c (h8300_frame_cache): Likewise. * hppa-linux-tdep.c (hppa_linux_sigtramp_frame_unwind_cache): Likewise. * hppa-tdep.c (compare_unwind_entries): Likewise. (find_unwind_entry): Likewise. (hppa_frame_cache): Likewise. (hppa_stub_frame_unwind_cache): Likewise. * hppanbsd-tdep.c (hppanbsd_supply_gregset): Likewise. * hppaobsd-tdep.c (hppaobsd_supply_gregset): Likewise. (hppaobsd_supply_fpregset): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * i386-tdep.c (i386_frame_cache): Likewise. (i386_epilogue_frame_cache): Likewise. (i386_sigtramp_frame_cache): Likewise. (i386_supply_gregset): Likewise. (i386_collect_gregset): Likewise. (i386_gdbarch_init): Likewise. * i386obsd-tdep.c (i386obsd_aout_supply_regset): Likewise. (i386obsd_trapframe_cache): Likewise. * i387-tdep.c (i387_supply_fsave): Likewise. (i387_collect_fsave): Likewise. (i387_supply_fxsave): Likewise. (i387_collect_fxsave): Likewise. (i387_supply_xsave): Likewise. (i387_collect_xsave): Likewise. * ia64-tdep.c (ia64_frame_cache): Likewise. (ia64_sigtramp_frame_cache): Likewise. * infcmd.c (attach_command_continuation): Likewise. (attach_command_continuation_free_args): Likewise. * inferior.c (restore_inferior): Likewise. (delete_thread_of_inferior): Likewise. * inflow.c (inflow_inferior_data_cleanup): Likewise. (get_inflow_inferior_data): Likewise. (inflow_inferior_exit): Likewise. * infrun.c (displaced_step_clear_cleanup): Likewise. (restore_current_uiout_cleanup): Likewise. (release_stop_context_cleanup): Likewise. (do_restore_infcall_suspend_state_cleanup): Likewise. (do_restore_infcall_control_state_cleanup): Likewise. (restore_inferior_ptid): Likewise. * inline-frame.c (block_starting_point_at): Likewise. * iq2000-tdep.c (iq2000_frame_cache): Likewise. * jit.c (get_jit_objfile_data): Likewise. (get_jit_program_space_data): Likewise. (jit_object_close_impl): Likewise. (jit_find_objf_with_entry_addr): Likewise. (jit_breakpoint_deleted): Likewise. (jit_unwind_reg_set_impl): Likewise. (jit_unwind_reg_get_impl): Likewise. (jit_dealloc_cache): Likewise. (jit_frame_sniffer): Likewise. (jit_frame_prev_register): Likewise. (jit_prepend_unwinder): Likewise. (jit_inferior_exit_hook): Likewise. (free_objfile_data): Likewise. * jv-lang.c (jv_per_objfile_free): Likewise. (get_dynamics_objfile): Likewise. (get_java_class_symtab): Likewise. (builtin_java_type): Likewise. * language.c (language_string_char_type): Likewise. (language_bool_type): Likewise. (language_lookup_primitive_type): Likewise. (language_lookup_primitive_type_as_symbol): Likewise. * linespec.c (hash_address_entry): Likewise. (eq_address_entry): Likewise. (iterate_inline_only): Likewise. (iterate_name_matcher): Likewise. (decode_line_2_compare_items): Likewise. (collect_one_symbol): Likewise. (compare_symbols): Likewise. (compare_msymbols): Likewise. (add_symtabs_to_list): Likewise. (collect_symbols): Likewise. (compare_msyms): Likewise. (add_minsym): Likewise. (cleanup_linespec_result): Likewise. * linux-fork.c (inferior_call_waitpid_cleanup): Likewise. * linux-nat.c (delete_lwp_cleanup): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (resume_stopped_resumed_lwps): Likewise. * linux-tdep.c (get_linux_gdbarch_data): Likewise. (invalidate_linux_cache_inf): Likewise. (get_linux_inferior_data): Likewise. (linux_find_memory_regions_thunk): Likewise. (linux_make_mappings_callback): Likewise. (linux_corefile_thread_callback): Likewise. (find_mapping_size): Likewise. * linux-thread-db.c (find_new_threads_callback): Likewise. * lm32-tdep.c (lm32_frame_cache): Likewise. * m2-lang.c (builtin_m2_type): Likewise. * m32c-tdep.c (m32c_analyze_frame_prologue): Likewise. * m32r-linux-tdep.c (m32r_linux_sigtramp_frame_cache): Likewise. (m32r_linux_supply_gregset): Likewise. (m32r_linux_collect_gregset): Likewise. * m32r-tdep.c (m32r_frame_unwind_cache): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * m68k-tdep.c (m68k_frame_cache): Likewise. * m68kbsd-tdep.c (m68kbsd_supply_fpregset): Likewise. (m68kbsd_supply_gregset): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise. * m88k-tdep.c (m88k_frame_cache): Likewise. (m88k_supply_gregset): Likewise. gdb/gdbserver/ChangeLog: * dll.c (match_dll): Add cast(s). (unloaded_dll): Likewise. * linux-low.c (second_thread_of_pid_p): Likewise. (delete_lwp_callback): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (linux_set_resume_request): Likewise. * server.c (accumulate_file_name_length): Likewise. (emit_dll_description): Likewise. (handle_qxfer_threads_worker): Likewise. (visit_actioned_threads): Likewise. * thread-db.c (any_thread_of): Likewise. * tracepoint.c (same_process_p): Likewise. (match_blocktype): Likewise. (build_traceframe_info_xml): Likewise. gdb/testsuite/ChangeLog: * gdb.gdb/selftest.exp (do_steps_and_nexts): Adjust expected source line.
1029 lines
24 KiB
C
1029 lines
24 KiB
C
/* Definitions for BFD wrappers used by GDB.
|
||
|
||
Copyright (C) 2011-2015 Free Software Foundation, Inc.
|
||
|
||
This file is part of GDB.
|
||
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
#include "defs.h"
|
||
#include "gdb_bfd.h"
|
||
#include "ui-out.h"
|
||
#include "gdbcmd.h"
|
||
#include "hashtab.h"
|
||
#include "filestuff.h"
|
||
#include "vec.h"
|
||
#ifdef HAVE_MMAP
|
||
#include <sys/mman.h>
|
||
#ifndef MAP_FAILED
|
||
#define MAP_FAILED ((void *) -1)
|
||
#endif
|
||
#endif
|
||
#include "target.h"
|
||
#include "gdb/fileio.h"
|
||
#include "inferior.h"
|
||
|
||
typedef bfd *bfdp;
|
||
DEF_VEC_P (bfdp);
|
||
|
||
/* An object of this type is stored in the section's user data when
|
||
mapping a section. */
|
||
|
||
struct gdb_bfd_section_data
|
||
{
|
||
/* Size of the data. */
|
||
bfd_size_type size;
|
||
/* If the data was mmapped, this is the length of the map. */
|
||
bfd_size_type map_len;
|
||
/* The data. If NULL, the section data has not been read. */
|
||
void *data;
|
||
/* If the data was mmapped, this is the map address. */
|
||
void *map_addr;
|
||
};
|
||
|
||
/* A hash table holding every BFD that gdb knows about. This is not
|
||
to be confused with 'gdb_bfd_cache', which is used for sharing
|
||
BFDs; in contrast, this hash is used just to implement
|
||
"maint info bfd". */
|
||
|
||
static htab_t all_bfds;
|
||
|
||
/* An object of this type is stored in each BFD's user data. */
|
||
|
||
struct gdb_bfd_data
|
||
{
|
||
/* The reference count. */
|
||
int refc;
|
||
|
||
/* The mtime of the BFD at the point the cache entry was made. */
|
||
time_t mtime;
|
||
|
||
/* The file size (in bytes) at the point the cache entry was made. */
|
||
off_t size;
|
||
|
||
/* The inode of the file at the point the cache entry was made. */
|
||
ino_t inode;
|
||
|
||
/* The device id of the file at the point the cache entry was made. */
|
||
dev_t device_id;
|
||
|
||
/* This is true if we have determined whether this BFD has any
|
||
sections requiring relocation. */
|
||
unsigned int relocation_computed : 1;
|
||
|
||
/* This is true if any section needs relocation. */
|
||
unsigned int needs_relocations : 1;
|
||
|
||
/* This is true if we have successfully computed the file's CRC. */
|
||
unsigned int crc_computed : 1;
|
||
|
||
/* The file's CRC. */
|
||
unsigned long crc;
|
||
|
||
/* If the BFD comes from an archive, this points to the archive's
|
||
BFD. Otherwise, this is NULL. */
|
||
bfd *archive_bfd;
|
||
|
||
/* Table of all the bfds this bfd has included. */
|
||
VEC (bfdp) *included_bfds;
|
||
|
||
/* The registry. */
|
||
REGISTRY_FIELDS;
|
||
};
|
||
|
||
#define GDB_BFD_DATA_ACCESSOR(ABFD) \
|
||
((struct gdb_bfd_data *) bfd_usrdata (ABFD))
|
||
|
||
DEFINE_REGISTRY (bfd, GDB_BFD_DATA_ACCESSOR)
|
||
|
||
/* A hash table storing all the BFDs maintained in the cache. */
|
||
|
||
static htab_t gdb_bfd_cache;
|
||
|
||
/* When true gdb will reuse an existing bfd object if the filename,
|
||
modification time, and file size all match. */
|
||
|
||
static int bfd_sharing = 1;
|
||
static void
|
||
show_bfd_sharing (struct ui_file *file, int from_tty,
|
||
struct cmd_list_element *c, const char *value)
|
||
{
|
||
fprintf_filtered (file, _("BFD sharing is %s.\n"), value);
|
||
}
|
||
|
||
/* When non-zero debugging of the bfd caches is enabled. */
|
||
|
||
static unsigned int debug_bfd_cache;
|
||
static void
|
||
show_bfd_cache_debug (struct ui_file *file, int from_tty,
|
||
struct cmd_list_element *c, const char *value)
|
||
{
|
||
fprintf_filtered (file, _("BFD cache debugging is %s.\n"), value);
|
||
}
|
||
|
||
/* The type of an object being looked up in gdb_bfd_cache. We use
|
||
htab's capability of storing one kind of object (BFD in this case)
|
||
and using a different sort of object for searching. */
|
||
|
||
struct gdb_bfd_cache_search
|
||
{
|
||
/* The filename. */
|
||
const char *filename;
|
||
/* The mtime. */
|
||
time_t mtime;
|
||
/* The file size (in bytes). */
|
||
off_t size;
|
||
/* The inode of the file. */
|
||
ino_t inode;
|
||
/* The device id of the file. */
|
||
dev_t device_id;
|
||
};
|
||
|
||
/* A hash function for BFDs. */
|
||
|
||
static hashval_t
|
||
hash_bfd (const void *b)
|
||
{
|
||
const bfd *abfd = (const struct bfd *) b;
|
||
|
||
/* It is simplest to just hash the filename. */
|
||
return htab_hash_string (bfd_get_filename (abfd));
|
||
}
|
||
|
||
/* An equality function for BFDs. Note that this expects the caller
|
||
to search using struct gdb_bfd_cache_search only, not BFDs. */
|
||
|
||
static int
|
||
eq_bfd (const void *a, const void *b)
|
||
{
|
||
const bfd *abfd = (const struct bfd *) a;
|
||
const struct gdb_bfd_cache_search *s
|
||
= (const struct gdb_bfd_cache_search *) b;
|
||
struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
|
||
return (gdata->mtime == s->mtime
|
||
&& gdata->size == s->size
|
||
&& gdata->inode == s->inode
|
||
&& gdata->device_id == s->device_id
|
||
&& strcmp (bfd_get_filename (abfd), s->filename) == 0);
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
is_target_filename (const char *name)
|
||
{
|
||
return startswith (name, TARGET_SYSROOT_PREFIX);
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
gdb_bfd_has_target_filename (struct bfd *abfd)
|
||
{
|
||
return is_target_filename (bfd_get_filename (abfd));
|
||
}
|
||
|
||
|
||
/* Return the system error number corresponding to ERRNUM. */
|
||
|
||
static int
|
||
fileio_errno_to_host (int errnum)
|
||
{
|
||
switch (errnum)
|
||
{
|
||
case FILEIO_EPERM:
|
||
return EPERM;
|
||
case FILEIO_ENOENT:
|
||
return ENOENT;
|
||
case FILEIO_EINTR:
|
||
return EINTR;
|
||
case FILEIO_EIO:
|
||
return EIO;
|
||
case FILEIO_EBADF:
|
||
return EBADF;
|
||
case FILEIO_EACCES:
|
||
return EACCES;
|
||
case FILEIO_EFAULT:
|
||
return EFAULT;
|
||
case FILEIO_EBUSY:
|
||
return EBUSY;
|
||
case FILEIO_EEXIST:
|
||
return EEXIST;
|
||
case FILEIO_ENODEV:
|
||
return ENODEV;
|
||
case FILEIO_ENOTDIR:
|
||
return ENOTDIR;
|
||
case FILEIO_EISDIR:
|
||
return EISDIR;
|
||
case FILEIO_EINVAL:
|
||
return EINVAL;
|
||
case FILEIO_ENFILE:
|
||
return ENFILE;
|
||
case FILEIO_EMFILE:
|
||
return EMFILE;
|
||
case FILEIO_EFBIG:
|
||
return EFBIG;
|
||
case FILEIO_ENOSPC:
|
||
return ENOSPC;
|
||
case FILEIO_ESPIPE:
|
||
return ESPIPE;
|
||
case FILEIO_EROFS:
|
||
return EROFS;
|
||
case FILEIO_ENOSYS:
|
||
return ENOSYS;
|
||
case FILEIO_ENAMETOOLONG:
|
||
return ENAMETOOLONG;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
/* Wrapper for target_fileio_open suitable for passing as the
|
||
OPEN_FUNC argument to gdb_bfd_openr_iovec. The supplied
|
||
OPEN_CLOSURE is unused. */
|
||
|
||
static void *
|
||
gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *inferior)
|
||
{
|
||
const char *filename = bfd_get_filename (abfd);
|
||
int fd, target_errno;
|
||
int *stream;
|
||
|
||
gdb_assert (is_target_filename (filename));
|
||
|
||
fd = target_fileio_open_warn_if_slow ((struct inferior *) inferior,
|
||
filename
|
||
+ strlen (TARGET_SYSROOT_PREFIX),
|
||
FILEIO_O_RDONLY, 0,
|
||
&target_errno);
|
||
if (fd == -1)
|
||
{
|
||
errno = fileio_errno_to_host (target_errno);
|
||
bfd_set_error (bfd_error_system_call);
|
||
return NULL;
|
||
}
|
||
|
||
stream = XCNEW (int);
|
||
*stream = fd;
|
||
return stream;
|
||
}
|
||
|
||
/* Wrapper for target_fileio_pread suitable for passing as the
|
||
PREAD_FUNC argument to gdb_bfd_openr_iovec. */
|
||
|
||
static file_ptr
|
||
gdb_bfd_iovec_fileio_pread (struct bfd *abfd, void *stream, void *buf,
|
||
file_ptr nbytes, file_ptr offset)
|
||
{
|
||
int fd = *(int *) stream;
|
||
int target_errno;
|
||
file_ptr pos, bytes;
|
||
|
||
pos = 0;
|
||
while (nbytes > pos)
|
||
{
|
||
QUIT;
|
||
|
||
bytes = target_fileio_pread (fd, (gdb_byte *) buf + pos,
|
||
nbytes - pos, offset + pos,
|
||
&target_errno);
|
||
if (bytes == 0)
|
||
/* Success, but no bytes, means end-of-file. */
|
||
break;
|
||
if (bytes == -1)
|
||
{
|
||
errno = fileio_errno_to_host (target_errno);
|
||
bfd_set_error (bfd_error_system_call);
|
||
return -1;
|
||
}
|
||
|
||
pos += bytes;
|
||
}
|
||
|
||
return pos;
|
||
}
|
||
|
||
/* Wrapper for target_fileio_close suitable for passing as the
|
||
CLOSE_FUNC argument to gdb_bfd_openr_iovec. */
|
||
|
||
static int
|
||
gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream)
|
||
{
|
||
int fd = *(int *) stream;
|
||
int target_errno;
|
||
|
||
xfree (stream);
|
||
|
||
/* Ignore errors on close. These may happen with remote
|
||
targets if the connection has already been torn down. */
|
||
target_fileio_close (fd, &target_errno);
|
||
|
||
/* Zero means success. */
|
||
return 0;
|
||
}
|
||
|
||
/* Wrapper for target_fileio_fstat suitable for passing as the
|
||
STAT_FUNC argument to gdb_bfd_openr_iovec. */
|
||
|
||
static int
|
||
gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream,
|
||
struct stat *sb)
|
||
{
|
||
int fd = *(int *) stream;
|
||
int target_errno;
|
||
int result;
|
||
|
||
result = target_fileio_fstat (fd, sb, &target_errno);
|
||
if (result == -1)
|
||
{
|
||
errno = fileio_errno_to_host (target_errno);
|
||
bfd_set_error (bfd_error_system_call);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
struct bfd *
|
||
gdb_bfd_open (const char *name, const char *target, int fd)
|
||
{
|
||
hashval_t hash;
|
||
void **slot;
|
||
bfd *abfd;
|
||
struct gdb_bfd_cache_search search;
|
||
struct stat st;
|
||
|
||
if (is_target_filename (name))
|
||
{
|
||
if (!target_filesystem_is_local ())
|
||
{
|
||
gdb_assert (fd == -1);
|
||
|
||
return gdb_bfd_openr_iovec (name, target,
|
||
gdb_bfd_iovec_fileio_open,
|
||
current_inferior (),
|
||
gdb_bfd_iovec_fileio_pread,
|
||
gdb_bfd_iovec_fileio_close,
|
||
gdb_bfd_iovec_fileio_fstat);
|
||
}
|
||
|
||
name += strlen (TARGET_SYSROOT_PREFIX);
|
||
}
|
||
|
||
if (gdb_bfd_cache == NULL)
|
||
gdb_bfd_cache = htab_create_alloc (1, hash_bfd, eq_bfd, NULL,
|
||
xcalloc, xfree);
|
||
|
||
if (fd == -1)
|
||
{
|
||
fd = gdb_open_cloexec (name, O_RDONLY | O_BINARY, 0);
|
||
if (fd == -1)
|
||
{
|
||
bfd_set_error (bfd_error_system_call);
|
||
return NULL;
|
||
}
|
||
}
|
||
|
||
search.filename = name;
|
||
if (fstat (fd, &st) < 0)
|
||
{
|
||
/* Weird situation here. */
|
||
search.mtime = 0;
|
||
search.size = 0;
|
||
search.inode = 0;
|
||
search.device_id = 0;
|
||
}
|
||
else
|
||
{
|
||
search.mtime = st.st_mtime;
|
||
search.size = st.st_size;
|
||
search.inode = st.st_ino;
|
||
search.device_id = st.st_dev;
|
||
}
|
||
|
||
/* Note that this must compute the same result as hash_bfd. */
|
||
hash = htab_hash_string (name);
|
||
/* Note that we cannot use htab_find_slot_with_hash here, because
|
||
opening the BFD may fail; and this would violate hashtab
|
||
invariants. */
|
||
abfd = (struct bfd *) htab_find_with_hash (gdb_bfd_cache, &search, hash);
|
||
if (bfd_sharing && abfd != NULL)
|
||
{
|
||
if (debug_bfd_cache)
|
||
fprintf_unfiltered (gdb_stdlog,
|
||
"Reusing cached bfd %s for %s\n",
|
||
host_address_to_string (abfd),
|
||
bfd_get_filename (abfd));
|
||
close (fd);
|
||
gdb_bfd_ref (abfd);
|
||
return abfd;
|
||
}
|
||
|
||
abfd = bfd_fopen (name, target, FOPEN_RB, fd);
|
||
if (abfd == NULL)
|
||
return NULL;
|
||
|
||
if (debug_bfd_cache)
|
||
fprintf_unfiltered (gdb_stdlog,
|
||
"Creating new bfd %s for %s\n",
|
||
host_address_to_string (abfd),
|
||
bfd_get_filename (abfd));
|
||
|
||
if (bfd_sharing)
|
||
{
|
||
slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
|
||
gdb_assert (!*slot);
|
||
*slot = abfd;
|
||
}
|
||
|
||
gdb_bfd_ref (abfd);
|
||
return abfd;
|
||
}
|
||
|
||
/* A helper function that releases any section data attached to the
|
||
BFD. */
|
||
|
||
static void
|
||
free_one_bfd_section (bfd *abfd, asection *sectp, void *ignore)
|
||
{
|
||
struct gdb_bfd_section_data *sect
|
||
= (struct gdb_bfd_section_data *) bfd_get_section_userdata (abfd, sectp);
|
||
|
||
if (sect != NULL && sect->data != NULL)
|
||
{
|
||
#ifdef HAVE_MMAP
|
||
if (sect->map_addr != NULL)
|
||
{
|
||
int res;
|
||
|
||
res = munmap (sect->map_addr, sect->map_len);
|
||
gdb_assert (res == 0);
|
||
}
|
||
else
|
||
#endif
|
||
xfree (sect->data);
|
||
}
|
||
}
|
||
|
||
/* Close ABFD, and warn if that fails. */
|
||
|
||
static int
|
||
gdb_bfd_close_or_warn (struct bfd *abfd)
|
||
{
|
||
int ret;
|
||
char *name = bfd_get_filename (abfd);
|
||
|
||
bfd_map_over_sections (abfd, free_one_bfd_section, NULL);
|
||
|
||
ret = bfd_close (abfd);
|
||
|
||
if (!ret)
|
||
warning (_("cannot close \"%s\": %s"),
|
||
name, bfd_errmsg (bfd_get_error ()));
|
||
|
||
return ret;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
void
|
||
gdb_bfd_ref (struct bfd *abfd)
|
||
{
|
||
struct stat buf;
|
||
struct gdb_bfd_data *gdata;
|
||
void **slot;
|
||
|
||
if (abfd == NULL)
|
||
return;
|
||
|
||
gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
|
||
if (debug_bfd_cache)
|
||
fprintf_unfiltered (gdb_stdlog,
|
||
"Increase reference count on bfd %s (%s)\n",
|
||
host_address_to_string (abfd),
|
||
bfd_get_filename (abfd));
|
||
|
||
if (gdata != NULL)
|
||
{
|
||
gdata->refc += 1;
|
||
return;
|
||
}
|
||
|
||
/* Ask BFD to decompress sections in bfd_get_full_section_contents. */
|
||
abfd->flags |= BFD_DECOMPRESS;
|
||
|
||
gdata
|
||
= (struct gdb_bfd_data *) bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
|
||
gdata->refc = 1;
|
||
gdata->mtime = bfd_get_mtime (abfd);
|
||
gdata->size = bfd_get_size (abfd);
|
||
gdata->archive_bfd = NULL;
|
||
if (bfd_stat (abfd, &buf) == 0)
|
||
{
|
||
gdata->inode = buf.st_ino;
|
||
gdata->device_id = buf.st_dev;
|
||
}
|
||
else
|
||
{
|
||
/* The stat failed. */
|
||
gdata->inode = 0;
|
||
gdata->device_id = 0;
|
||
}
|
||
bfd_usrdata (abfd) = gdata;
|
||
|
||
bfd_alloc_data (abfd);
|
||
|
||
/* This is the first we've seen it, so add it to the hash table. */
|
||
slot = htab_find_slot (all_bfds, abfd, INSERT);
|
||
gdb_assert (slot && !*slot);
|
||
*slot = abfd;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
void
|
||
gdb_bfd_unref (struct bfd *abfd)
|
||
{
|
||
int ix;
|
||
struct gdb_bfd_data *gdata;
|
||
struct gdb_bfd_cache_search search;
|
||
bfd *archive_bfd, *included_bfd;
|
||
|
||
if (abfd == NULL)
|
||
return;
|
||
|
||
gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
gdb_assert (gdata->refc >= 1);
|
||
|
||
gdata->refc -= 1;
|
||
if (gdata->refc > 0)
|
||
{
|
||
if (debug_bfd_cache)
|
||
fprintf_unfiltered (gdb_stdlog,
|
||
"Decrease reference count on bfd %s (%s)\n",
|
||
host_address_to_string (abfd),
|
||
bfd_get_filename (abfd));
|
||
return;
|
||
}
|
||
|
||
if (debug_bfd_cache)
|
||
fprintf_unfiltered (gdb_stdlog,
|
||
"Delete final reference count on bfd %s (%s)\n",
|
||
host_address_to_string (abfd),
|
||
bfd_get_filename (abfd));
|
||
|
||
archive_bfd = gdata->archive_bfd;
|
||
search.filename = bfd_get_filename (abfd);
|
||
|
||
if (gdb_bfd_cache && search.filename)
|
||
{
|
||
hashval_t hash = htab_hash_string (search.filename);
|
||
void **slot;
|
||
|
||
search.mtime = gdata->mtime;
|
||
search.size = gdata->size;
|
||
search.inode = gdata->inode;
|
||
search.device_id = gdata->device_id;
|
||
slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash,
|
||
NO_INSERT);
|
||
|
||
if (slot && *slot)
|
||
htab_clear_slot (gdb_bfd_cache, slot);
|
||
}
|
||
|
||
for (ix = 0;
|
||
VEC_iterate (bfdp, gdata->included_bfds, ix, included_bfd);
|
||
++ix)
|
||
gdb_bfd_unref (included_bfd);
|
||
VEC_free (bfdp, gdata->included_bfds);
|
||
|
||
bfd_free_data (abfd);
|
||
bfd_usrdata (abfd) = NULL; /* Paranoia. */
|
||
|
||
htab_remove_elt (all_bfds, abfd);
|
||
|
||
gdb_bfd_close_or_warn (abfd);
|
||
|
||
gdb_bfd_unref (archive_bfd);
|
||
}
|
||
|
||
/* A helper function that returns the section data descriptor
|
||
associated with SECTION. If no such descriptor exists, a new one
|
||
is allocated and cleared. */
|
||
|
||
static struct gdb_bfd_section_data *
|
||
get_section_descriptor (asection *section)
|
||
{
|
||
struct gdb_bfd_section_data *result;
|
||
|
||
result = ((struct gdb_bfd_section_data *)
|
||
bfd_get_section_userdata (section->owner, section));
|
||
|
||
if (result == NULL)
|
||
{
|
||
result = ((struct gdb_bfd_section_data *)
|
||
bfd_zalloc (section->owner, sizeof (*result)));
|
||
bfd_set_section_userdata (section->owner, section, result);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
const gdb_byte *
|
||
gdb_bfd_map_section (asection *sectp, bfd_size_type *size)
|
||
{
|
||
bfd *abfd;
|
||
struct gdb_bfd_section_data *descriptor;
|
||
bfd_byte *data;
|
||
|
||
gdb_assert ((sectp->flags & SEC_RELOC) == 0);
|
||
gdb_assert (size != NULL);
|
||
|
||
abfd = sectp->owner;
|
||
|
||
descriptor = get_section_descriptor (sectp);
|
||
|
||
/* If the data was already read for this BFD, just reuse it. */
|
||
if (descriptor->data != NULL)
|
||
goto done;
|
||
|
||
#ifdef HAVE_MMAP
|
||
if (!bfd_is_section_compressed (abfd, sectp))
|
||
{
|
||
/* The page size, used when mmapping. */
|
||
static int pagesize;
|
||
|
||
if (pagesize == 0)
|
||
pagesize = getpagesize ();
|
||
|
||
/* Only try to mmap sections which are large enough: we don't want
|
||
to waste space due to fragmentation. */
|
||
|
||
if (bfd_get_section_size (sectp) > 4 * pagesize)
|
||
{
|
||
descriptor->size = bfd_get_section_size (sectp);
|
||
descriptor->data = bfd_mmap (abfd, 0, descriptor->size, PROT_READ,
|
||
MAP_PRIVATE, sectp->filepos,
|
||
&descriptor->map_addr,
|
||
&descriptor->map_len);
|
||
|
||
if ((caddr_t)descriptor->data != MAP_FAILED)
|
||
{
|
||
#if HAVE_POSIX_MADVISE
|
||
posix_madvise (descriptor->map_addr, descriptor->map_len,
|
||
POSIX_MADV_WILLNEED);
|
||
#endif
|
||
goto done;
|
||
}
|
||
|
||
/* On failure, clear out the section data and try again. */
|
||
memset (descriptor, 0, sizeof (*descriptor));
|
||
}
|
||
}
|
||
#endif /* HAVE_MMAP */
|
||
|
||
/* Handle compressed sections, or ordinary uncompressed sections in
|
||
the no-mmap case. */
|
||
|
||
descriptor->size = bfd_get_section_size (sectp);
|
||
descriptor->data = NULL;
|
||
|
||
data = NULL;
|
||
if (!bfd_get_full_section_contents (abfd, sectp, &data))
|
||
error (_("Can't read data for section '%s' in file '%s'"),
|
||
bfd_get_section_name (abfd, sectp),
|
||
bfd_get_filename (abfd));
|
||
descriptor->data = data;
|
||
|
||
done:
|
||
gdb_assert (descriptor->data != NULL);
|
||
*size = descriptor->size;
|
||
return (const gdb_byte *) descriptor->data;
|
||
}
|
||
|
||
/* Return 32-bit CRC for ABFD. If successful store it to *FILE_CRC_RETURN and
|
||
return 1. Otherwise print a warning and return 0. ABFD seek position is
|
||
not preserved. */
|
||
|
||
static int
|
||
get_file_crc (bfd *abfd, unsigned long *file_crc_return)
|
||
{
|
||
unsigned long file_crc = 0;
|
||
|
||
if (bfd_seek (abfd, 0, SEEK_SET) != 0)
|
||
{
|
||
warning (_("Problem reading \"%s\" for CRC: %s"),
|
||
bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
|
||
return 0;
|
||
}
|
||
|
||
for (;;)
|
||
{
|
||
gdb_byte buffer[8 * 1024];
|
||
bfd_size_type count;
|
||
|
||
count = bfd_bread (buffer, sizeof (buffer), abfd);
|
||
if (count == (bfd_size_type) -1)
|
||
{
|
||
warning (_("Problem reading \"%s\" for CRC: %s"),
|
||
bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
|
||
return 0;
|
||
}
|
||
if (count == 0)
|
||
break;
|
||
file_crc = bfd_calc_gnu_debuglink_crc32 (file_crc, buffer, count);
|
||
}
|
||
|
||
*file_crc_return = file_crc;
|
||
return 1;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
gdb_bfd_crc (struct bfd *abfd, unsigned long *crc_out)
|
||
{
|
||
struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
|
||
if (!gdata->crc_computed)
|
||
gdata->crc_computed = get_file_crc (abfd, &gdata->crc);
|
||
|
||
if (gdata->crc_computed)
|
||
*crc_out = gdata->crc;
|
||
return gdata->crc_computed;
|
||
}
|
||
|
||
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_fopen (const char *filename, const char *target, const char *mode,
|
||
int fd)
|
||
{
|
||
bfd *result = bfd_fopen (filename, target, mode, fd);
|
||
|
||
if (result)
|
||
gdb_bfd_ref (result);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_openr (const char *filename, const char *target)
|
||
{
|
||
bfd *result = bfd_openr (filename, target);
|
||
|
||
if (result)
|
||
gdb_bfd_ref (result);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_openw (const char *filename, const char *target)
|
||
{
|
||
bfd *result = bfd_openw (filename, target);
|
||
|
||
if (result)
|
||
gdb_bfd_ref (result);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_openr_iovec (const char *filename, const char *target,
|
||
void *(*open_func) (struct bfd *nbfd,
|
||
void *open_closure),
|
||
void *open_closure,
|
||
file_ptr (*pread_func) (struct bfd *nbfd,
|
||
void *stream,
|
||
void *buf,
|
||
file_ptr nbytes,
|
||
file_ptr offset),
|
||
int (*close_func) (struct bfd *nbfd,
|
||
void *stream),
|
||
int (*stat_func) (struct bfd *abfd,
|
||
void *stream,
|
||
struct stat *sb))
|
||
{
|
||
bfd *result = bfd_openr_iovec (filename, target,
|
||
open_func, open_closure,
|
||
pread_func, close_func, stat_func);
|
||
|
||
if (result)
|
||
gdb_bfd_ref (result);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
void
|
||
gdb_bfd_mark_parent (bfd *child, bfd *parent)
|
||
{
|
||
struct gdb_bfd_data *gdata;
|
||
|
||
gdb_bfd_ref (child);
|
||
/* No need to stash the filename here, because we also keep a
|
||
reference on the parent archive. */
|
||
|
||
gdata = (struct gdb_bfd_data *) bfd_usrdata (child);
|
||
if (gdata->archive_bfd == NULL)
|
||
{
|
||
gdata->archive_bfd = parent;
|
||
gdb_bfd_ref (parent);
|
||
}
|
||
else
|
||
gdb_assert (gdata->archive_bfd == parent);
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous)
|
||
{
|
||
bfd *result = bfd_openr_next_archived_file (archive, previous);
|
||
|
||
if (result)
|
||
gdb_bfd_mark_parent (result, archive);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
void
|
||
gdb_bfd_record_inclusion (bfd *includer, bfd *includee)
|
||
{
|
||
struct gdb_bfd_data *gdata;
|
||
|
||
gdb_bfd_ref (includee);
|
||
gdata = (struct gdb_bfd_data *) bfd_usrdata (includer);
|
||
VEC_safe_push (bfdp, gdata->included_bfds, includee);
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
bfd *
|
||
gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
|
||
{
|
||
bfd *result = bfd_fdopenr (filename, target, fd);
|
||
|
||
if (result)
|
||
gdb_bfd_ref (result);
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
gdb_static_assert (ARRAY_SIZE (_bfd_std_section) == 4);
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
gdb_bfd_section_index (bfd *abfd, asection *section)
|
||
{
|
||
if (section == NULL)
|
||
return -1;
|
||
else if (section == bfd_com_section_ptr)
|
||
return bfd_count_sections (abfd);
|
||
else if (section == bfd_und_section_ptr)
|
||
return bfd_count_sections (abfd) + 1;
|
||
else if (section == bfd_abs_section_ptr)
|
||
return bfd_count_sections (abfd) + 2;
|
||
else if (section == bfd_ind_section_ptr)
|
||
return bfd_count_sections (abfd) + 3;
|
||
return section->index;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
gdb_bfd_count_sections (bfd *abfd)
|
||
{
|
||
return bfd_count_sections (abfd) + 4;
|
||
}
|
||
|
||
/* See gdb_bfd.h. */
|
||
|
||
int
|
||
gdb_bfd_requires_relocations (bfd *abfd)
|
||
{
|
||
struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
|
||
if (gdata->relocation_computed == 0)
|
||
{
|
||
asection *sect;
|
||
|
||
for (sect = abfd->sections; sect != NULL; sect = sect->next)
|
||
if ((sect->flags & SEC_RELOC) != 0)
|
||
{
|
||
gdata->needs_relocations = 1;
|
||
break;
|
||
}
|
||
|
||
gdata->relocation_computed = 1;
|
||
}
|
||
|
||
return gdata->needs_relocations;
|
||
}
|
||
|
||
|
||
|
||
/* A callback for htab_traverse that prints a single BFD. */
|
||
|
||
static int
|
||
print_one_bfd (void **slot, void *data)
|
||
{
|
||
bfd *abfd = (struct bfd *) *slot;
|
||
struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (abfd);
|
||
struct ui_out *uiout = (struct ui_out *) data;
|
||
struct cleanup *inner;
|
||
|
||
inner = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
|
||
ui_out_field_int (uiout, "refcount", gdata->refc);
|
||
ui_out_field_string (uiout, "addr", host_address_to_string (abfd));
|
||
ui_out_field_string (uiout, "filename", bfd_get_filename (abfd));
|
||
ui_out_text (uiout, "\n");
|
||
do_cleanups (inner);
|
||
|
||
return 1;
|
||
}
|
||
|
||
/* Implement the 'maint info bfd' command. */
|
||
|
||
static void
|
||
maintenance_info_bfds (char *arg, int from_tty)
|
||
{
|
||
struct cleanup *cleanup;
|
||
struct ui_out *uiout = current_uiout;
|
||
|
||
cleanup = make_cleanup_ui_out_table_begin_end (uiout, 3, -1, "bfds");
|
||
ui_out_table_header (uiout, 10, ui_left, "refcount", "Refcount");
|
||
ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
|
||
ui_out_table_header (uiout, 40, ui_left, "filename", "Filename");
|
||
|
||
ui_out_table_body (uiout);
|
||
htab_traverse (all_bfds, print_one_bfd, uiout);
|
||
|
||
do_cleanups (cleanup);
|
||
}
|
||
|
||
/* -Wmissing-prototypes */
|
||
extern initialize_file_ftype _initialize_gdb_bfd;
|
||
|
||
void
|
||
_initialize_gdb_bfd (void)
|
||
{
|
||
all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
|
||
NULL, xcalloc, xfree);
|
||
|
||
add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\
|
||
List the BFDs that are currently open."),
|
||
&maintenanceinfolist);
|
||
|
||
add_setshow_boolean_cmd ("bfd-sharing", no_class,
|
||
&bfd_sharing, _("\
|
||
Set whether gdb will share bfds that appear to be the same file."), _("\
|
||
Show whether gdb will share bfds that appear to be the same file."), _("\
|
||
When enabled gdb will reuse existing bfds rather than reopening the\n\
|
||
same file. To decide if two files are the same then gdb compares the\n\
|
||
filename, file size, file modification time, and file inode."),
|
||
NULL,
|
||
&show_bfd_sharing,
|
||
&maintenance_set_cmdlist,
|
||
&maintenance_show_cmdlist);
|
||
|
||
add_setshow_zuinteger_cmd ("bfd-cache", class_maintenance,
|
||
&debug_bfd_cache, _("\
|
||
Set bfd cache debugging."), _("\
|
||
Show bfd cache debugging."), _("\
|
||
When non-zero, bfd cache specific debugging is enabled."),
|
||
NULL,
|
||
&show_bfd_cache_debug,
|
||
&setdebuglist, &showdebuglist);
|
||
}
|