224c3ddb89
Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
1196 lines
36 KiB
C
1196 lines
36 KiB
C
/* Handle FR-V (FDPIC) shared libraries for GDB, the GNU Debugger.
|
|
Copyright (C) 2004-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 "inferior.h"
|
|
#include "gdbcore.h"
|
|
#include "solib.h"
|
|
#include "solist.h"
|
|
#include "frv-tdep.h"
|
|
#include "objfiles.h"
|
|
#include "symtab.h"
|
|
#include "language.h"
|
|
#include "command.h"
|
|
#include "gdbcmd.h"
|
|
#include "elf/frv.h"
|
|
#include "gdb_bfd.h"
|
|
|
|
/* Flag which indicates whether internal debug messages should be printed. */
|
|
static unsigned int solib_frv_debug;
|
|
|
|
/* FR-V pointers are four bytes wide. */
|
|
enum { FRV_PTR_SIZE = 4 };
|
|
|
|
/* Representation of loadmap and related structs for the FR-V FDPIC ABI. */
|
|
|
|
/* External versions; the size and alignment of the fields should be
|
|
the same as those on the target. When loaded, the placement of
|
|
the bits in each field will be the same as on the target. */
|
|
typedef gdb_byte ext_Elf32_Half[2];
|
|
typedef gdb_byte ext_Elf32_Addr[4];
|
|
typedef gdb_byte ext_Elf32_Word[4];
|
|
|
|
struct ext_elf32_fdpic_loadseg
|
|
{
|
|
/* Core address to which the segment is mapped. */
|
|
ext_Elf32_Addr addr;
|
|
/* VMA recorded in the program header. */
|
|
ext_Elf32_Addr p_vaddr;
|
|
/* Size of this segment in memory. */
|
|
ext_Elf32_Word p_memsz;
|
|
};
|
|
|
|
struct ext_elf32_fdpic_loadmap {
|
|
/* Protocol version number, must be zero. */
|
|
ext_Elf32_Half version;
|
|
/* Number of segments in this map. */
|
|
ext_Elf32_Half nsegs;
|
|
/* The actual memory map. */
|
|
struct ext_elf32_fdpic_loadseg segs[1 /* nsegs, actually */];
|
|
};
|
|
|
|
/* Internal versions; the types are GDB types and the data in each
|
|
of the fields is (or will be) decoded from the external struct
|
|
for ease of consumption. */
|
|
struct int_elf32_fdpic_loadseg
|
|
{
|
|
/* Core address to which the segment is mapped. */
|
|
CORE_ADDR addr;
|
|
/* VMA recorded in the program header. */
|
|
CORE_ADDR p_vaddr;
|
|
/* Size of this segment in memory. */
|
|
long p_memsz;
|
|
};
|
|
|
|
struct int_elf32_fdpic_loadmap {
|
|
/* Protocol version number, must be zero. */
|
|
int version;
|
|
/* Number of segments in this map. */
|
|
int nsegs;
|
|
/* The actual memory map. */
|
|
struct int_elf32_fdpic_loadseg segs[1 /* nsegs, actually */];
|
|
};
|
|
|
|
/* Given address LDMADDR, fetch and decode the loadmap at that address.
|
|
Return NULL if there is a problem reading the target memory or if
|
|
there doesn't appear to be a loadmap at the given address. The
|
|
allocated space (representing the loadmap) returned by this
|
|
function may be freed via a single call to xfree(). */
|
|
|
|
static struct int_elf32_fdpic_loadmap *
|
|
fetch_loadmap (CORE_ADDR ldmaddr)
|
|
{
|
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
|
struct ext_elf32_fdpic_loadmap ext_ldmbuf_partial;
|
|
struct ext_elf32_fdpic_loadmap *ext_ldmbuf;
|
|
struct int_elf32_fdpic_loadmap *int_ldmbuf;
|
|
int ext_ldmbuf_size, int_ldmbuf_size;
|
|
int version, seg, nsegs;
|
|
|
|
/* Fetch initial portion of the loadmap. */
|
|
if (target_read_memory (ldmaddr, (gdb_byte *) &ext_ldmbuf_partial,
|
|
sizeof ext_ldmbuf_partial))
|
|
{
|
|
/* Problem reading the target's memory. */
|
|
return NULL;
|
|
}
|
|
|
|
/* Extract the version. */
|
|
version = extract_unsigned_integer (ext_ldmbuf_partial.version,
|
|
sizeof ext_ldmbuf_partial.version,
|
|
byte_order);
|
|
if (version != 0)
|
|
{
|
|
/* We only handle version 0. */
|
|
return NULL;
|
|
}
|
|
|
|
/* Extract the number of segments. */
|
|
nsegs = extract_unsigned_integer (ext_ldmbuf_partial.nsegs,
|
|
sizeof ext_ldmbuf_partial.nsegs,
|
|
byte_order);
|
|
|
|
if (nsegs <= 0)
|
|
return NULL;
|
|
|
|
/* Allocate space for the complete (external) loadmap. */
|
|
ext_ldmbuf_size = sizeof (struct ext_elf32_fdpic_loadmap)
|
|
+ (nsegs - 1) * sizeof (struct ext_elf32_fdpic_loadseg);
|
|
ext_ldmbuf = (struct ext_elf32_fdpic_loadmap *) xmalloc (ext_ldmbuf_size);
|
|
|
|
/* Copy over the portion of the loadmap that's already been read. */
|
|
memcpy (ext_ldmbuf, &ext_ldmbuf_partial, sizeof ext_ldmbuf_partial);
|
|
|
|
/* Read the rest of the loadmap from the target. */
|
|
if (target_read_memory (ldmaddr + sizeof ext_ldmbuf_partial,
|
|
(gdb_byte *) ext_ldmbuf + sizeof ext_ldmbuf_partial,
|
|
ext_ldmbuf_size - sizeof ext_ldmbuf_partial))
|
|
{
|
|
/* Couldn't read rest of the loadmap. */
|
|
xfree (ext_ldmbuf);
|
|
return NULL;
|
|
}
|
|
|
|
/* Allocate space into which to put information extract from the
|
|
external loadsegs. I.e, allocate the internal loadsegs. */
|
|
int_ldmbuf_size = sizeof (struct int_elf32_fdpic_loadmap)
|
|
+ (nsegs - 1) * sizeof (struct int_elf32_fdpic_loadseg);
|
|
int_ldmbuf = (struct int_elf32_fdpic_loadmap *) xmalloc (int_ldmbuf_size);
|
|
|
|
/* Place extracted information in internal structs. */
|
|
int_ldmbuf->version = version;
|
|
int_ldmbuf->nsegs = nsegs;
|
|
for (seg = 0; seg < nsegs; seg++)
|
|
{
|
|
int_ldmbuf->segs[seg].addr
|
|
= extract_unsigned_integer (ext_ldmbuf->segs[seg].addr,
|
|
sizeof (ext_ldmbuf->segs[seg].addr),
|
|
byte_order);
|
|
int_ldmbuf->segs[seg].p_vaddr
|
|
= extract_unsigned_integer (ext_ldmbuf->segs[seg].p_vaddr,
|
|
sizeof (ext_ldmbuf->segs[seg].p_vaddr),
|
|
byte_order);
|
|
int_ldmbuf->segs[seg].p_memsz
|
|
= extract_unsigned_integer (ext_ldmbuf->segs[seg].p_memsz,
|
|
sizeof (ext_ldmbuf->segs[seg].p_memsz),
|
|
byte_order);
|
|
}
|
|
|
|
xfree (ext_ldmbuf);
|
|
return int_ldmbuf;
|
|
}
|
|
|
|
/* External link_map and elf32_fdpic_loadaddr struct definitions. */
|
|
|
|
typedef gdb_byte ext_ptr[4];
|
|
|
|
struct ext_elf32_fdpic_loadaddr
|
|
{
|
|
ext_ptr map; /* struct elf32_fdpic_loadmap *map; */
|
|
ext_ptr got_value; /* void *got_value; */
|
|
};
|
|
|
|
struct ext_link_map
|
|
{
|
|
struct ext_elf32_fdpic_loadaddr l_addr;
|
|
|
|
/* Absolute file name object was found in. */
|
|
ext_ptr l_name; /* char *l_name; */
|
|
|
|
/* Dynamic section of the shared object. */
|
|
ext_ptr l_ld; /* ElfW(Dyn) *l_ld; */
|
|
|
|
/* Chain of loaded objects. */
|
|
ext_ptr l_next, l_prev; /* struct link_map *l_next, *l_prev; */
|
|
};
|
|
|
|
/* Link map info to include in an allocated so_list entry. */
|
|
|
|
struct lm_info
|
|
{
|
|
/* The loadmap, digested into an easier to use form. */
|
|
struct int_elf32_fdpic_loadmap *map;
|
|
/* The GOT address for this link map entry. */
|
|
CORE_ADDR got_value;
|
|
/* The link map address, needed for frv_fetch_objfile_link_map(). */
|
|
CORE_ADDR lm_addr;
|
|
|
|
/* Cached dynamic symbol table and dynamic relocs initialized and
|
|
used only by find_canonical_descriptor_in_load_object().
|
|
|
|
Note: kevinb/2004-02-26: It appears that calls to
|
|
bfd_canonicalize_dynamic_reloc() will use the same symbols as
|
|
those supplied to the first call to this function. Therefore,
|
|
it's important to NOT free the asymbol ** data structure
|
|
supplied to the first call. Thus the caching of the dynamic
|
|
symbols (dyn_syms) is critical for correct operation. The
|
|
caching of the dynamic relocations could be dispensed with. */
|
|
asymbol **dyn_syms;
|
|
arelent **dyn_relocs;
|
|
int dyn_reloc_count; /* Number of dynamic relocs. */
|
|
|
|
};
|
|
|
|
/* The load map, got value, etc. are not available from the chain
|
|
of loaded shared objects. ``main_executable_lm_info'' provides
|
|
a way to get at this information so that it doesn't need to be
|
|
frequently recomputed. Initialized by frv_relocate_main_executable(). */
|
|
static struct lm_info *main_executable_lm_info;
|
|
|
|
static void frv_relocate_main_executable (void);
|
|
static CORE_ADDR main_got (void);
|
|
static int enable_break2 (void);
|
|
|
|
/* Implement the "open_symbol_file_object" target_so_ops method. */
|
|
|
|
static int
|
|
open_symbol_file_object (void *from_ttyp)
|
|
{
|
|
/* Unimplemented. */
|
|
return 0;
|
|
}
|
|
|
|
/* Cached value for lm_base(), below. */
|
|
static CORE_ADDR lm_base_cache = 0;
|
|
|
|
/* Link map address for main module. */
|
|
static CORE_ADDR main_lm_addr = 0;
|
|
|
|
/* Return the address from which the link map chain may be found. On
|
|
the FR-V, this may be found in a number of ways. Assuming that the
|
|
main executable has already been relocated, the easiest way to find
|
|
this value is to look up the address of _GLOBAL_OFFSET_TABLE_. A
|
|
pointer to the start of the link map will be located at the word found
|
|
at _GLOBAL_OFFSET_TABLE_ + 8. (This is part of the dynamic linker
|
|
reserve area mandated by the ABI.) */
|
|
|
|
static CORE_ADDR
|
|
lm_base (void)
|
|
{
|
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
|
struct bound_minimal_symbol got_sym;
|
|
CORE_ADDR addr;
|
|
gdb_byte buf[FRV_PTR_SIZE];
|
|
|
|
/* One of our assumptions is that the main executable has been relocated.
|
|
Bail out if this has not happened. (Note that post_create_inferior()
|
|
in infcmd.c will call solib_add prior to solib_create_inferior_hook().
|
|
If we allow this to happen, lm_base_cache will be initialized with
|
|
a bogus value. */
|
|
if (main_executable_lm_info == 0)
|
|
return 0;
|
|
|
|
/* If we already have a cached value, return it. */
|
|
if (lm_base_cache)
|
|
return lm_base_cache;
|
|
|
|
got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_", NULL,
|
|
symfile_objfile);
|
|
if (got_sym.minsym == 0)
|
|
{
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"lm_base: _GLOBAL_OFFSET_TABLE_ not found.\n");
|
|
return 0;
|
|
}
|
|
|
|
addr = BMSYMBOL_VALUE_ADDRESS (got_sym) + 8;
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"lm_base: _GLOBAL_OFFSET_TABLE_ + 8 = %s\n",
|
|
hex_string_custom (addr, 8));
|
|
|
|
if (target_read_memory (addr, buf, sizeof buf) != 0)
|
|
return 0;
|
|
lm_base_cache = extract_unsigned_integer (buf, sizeof buf, byte_order);
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"lm_base: lm_base_cache = %s\n",
|
|
hex_string_custom (lm_base_cache, 8));
|
|
|
|
return lm_base_cache;
|
|
}
|
|
|
|
|
|
/* Implement the "current_sos" target_so_ops method. */
|
|
|
|
static struct so_list *
|
|
frv_current_sos (void)
|
|
{
|
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
|
CORE_ADDR lm_addr, mgot;
|
|
struct so_list *sos_head = NULL;
|
|
struct so_list **sos_next_ptr = &sos_head;
|
|
|
|
/* Make sure that the main executable has been relocated. This is
|
|
required in order to find the address of the global offset table,
|
|
which in turn is used to find the link map info. (See lm_base()
|
|
for details.)
|
|
|
|
Note that the relocation of the main executable is also performed
|
|
by solib_create_inferior_hook(), however, in the case of core
|
|
files, this hook is called too late in order to be of benefit to
|
|
solib_add. solib_add eventually calls this this function,
|
|
frv_current_sos, and also precedes the call to
|
|
solib_create_inferior_hook(). (See post_create_inferior() in
|
|
infcmd.c.) */
|
|
if (main_executable_lm_info == 0 && core_bfd != NULL)
|
|
frv_relocate_main_executable ();
|
|
|
|
/* Fetch the GOT corresponding to the main executable. */
|
|
mgot = main_got ();
|
|
|
|
/* Locate the address of the first link map struct. */
|
|
lm_addr = lm_base ();
|
|
|
|
/* We have at least one link map entry. Fetch the lot of them,
|
|
building the solist chain. */
|
|
while (lm_addr)
|
|
{
|
|
struct ext_link_map lm_buf;
|
|
CORE_ADDR got_addr;
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"current_sos: reading link_map entry at %s\n",
|
|
hex_string_custom (lm_addr, 8));
|
|
|
|
if (target_read_memory (lm_addr, (gdb_byte *) &lm_buf,
|
|
sizeof (lm_buf)) != 0)
|
|
{
|
|
warning (_("frv_current_sos: Unable to read link map entry. "
|
|
"Shared object chain may be incomplete."));
|
|
break;
|
|
}
|
|
|
|
got_addr
|
|
= extract_unsigned_integer (lm_buf.l_addr.got_value,
|
|
sizeof (lm_buf.l_addr.got_value),
|
|
byte_order);
|
|
/* If the got_addr is the same as mgotr, then we're looking at the
|
|
entry for the main executable. By convention, we don't include
|
|
this in the list of shared objects. */
|
|
if (got_addr != mgot)
|
|
{
|
|
int errcode;
|
|
char *name_buf;
|
|
struct int_elf32_fdpic_loadmap *loadmap;
|
|
struct so_list *sop;
|
|
CORE_ADDR addr;
|
|
|
|
/* Fetch the load map address. */
|
|
addr = extract_unsigned_integer (lm_buf.l_addr.map,
|
|
sizeof lm_buf.l_addr.map,
|
|
byte_order);
|
|
loadmap = fetch_loadmap (addr);
|
|
if (loadmap == NULL)
|
|
{
|
|
warning (_("frv_current_sos: Unable to fetch load map. "
|
|
"Shared object chain may be incomplete."));
|
|
break;
|
|
}
|
|
|
|
sop = XCNEW (struct so_list);
|
|
sop->lm_info = XCNEW (struct lm_info);
|
|
sop->lm_info->map = loadmap;
|
|
sop->lm_info->got_value = got_addr;
|
|
sop->lm_info->lm_addr = lm_addr;
|
|
/* Fetch the name. */
|
|
addr = extract_unsigned_integer (lm_buf.l_name,
|
|
sizeof (lm_buf.l_name),
|
|
byte_order);
|
|
target_read_string (addr, &name_buf, SO_NAME_MAX_PATH_SIZE - 1,
|
|
&errcode);
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog, "current_sos: name = %s\n",
|
|
name_buf);
|
|
|
|
if (errcode != 0)
|
|
warning (_("Can't read pathname for link map entry: %s."),
|
|
safe_strerror (errcode));
|
|
else
|
|
{
|
|
strncpy (sop->so_name, name_buf, SO_NAME_MAX_PATH_SIZE - 1);
|
|
sop->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
|
|
xfree (name_buf);
|
|
strcpy (sop->so_original_name, sop->so_name);
|
|
}
|
|
|
|
*sos_next_ptr = sop;
|
|
sos_next_ptr = &sop->next;
|
|
}
|
|
else
|
|
{
|
|
main_lm_addr = lm_addr;
|
|
}
|
|
|
|
lm_addr = extract_unsigned_integer (lm_buf.l_next,
|
|
sizeof (lm_buf.l_next), byte_order);
|
|
}
|
|
|
|
enable_break2 ();
|
|
|
|
return sos_head;
|
|
}
|
|
|
|
|
|
/* Return 1 if PC lies in the dynamic symbol resolution code of the
|
|
run time loader. */
|
|
|
|
static CORE_ADDR interp_text_sect_low;
|
|
static CORE_ADDR interp_text_sect_high;
|
|
static CORE_ADDR interp_plt_sect_low;
|
|
static CORE_ADDR interp_plt_sect_high;
|
|
|
|
static int
|
|
frv_in_dynsym_resolve_code (CORE_ADDR pc)
|
|
{
|
|
return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
|
|
|| (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
|
|
|| in_plt_section (pc));
|
|
}
|
|
|
|
/* Given a loadmap and an address, return the displacement needed
|
|
to relocate the address. */
|
|
|
|
static CORE_ADDR
|
|
displacement_from_map (struct int_elf32_fdpic_loadmap *map,
|
|
CORE_ADDR addr)
|
|
{
|
|
int seg;
|
|
|
|
for (seg = 0; seg < map->nsegs; seg++)
|
|
{
|
|
if (map->segs[seg].p_vaddr <= addr
|
|
&& addr < map->segs[seg].p_vaddr + map->segs[seg].p_memsz)
|
|
{
|
|
return map->segs[seg].addr - map->segs[seg].p_vaddr;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Print a warning about being unable to set the dynamic linker
|
|
breakpoint. */
|
|
|
|
static void
|
|
enable_break_failure_warning (void)
|
|
{
|
|
warning (_("Unable to find dynamic linker breakpoint function.\n"
|
|
"GDB will be unable to debug shared library initializers\n"
|
|
"and track explicitly loaded dynamic code."));
|
|
}
|
|
|
|
/* Helper function for gdb_bfd_lookup_symbol. */
|
|
|
|
static int
|
|
cmp_name (asymbol *sym, void *data)
|
|
{
|
|
return (strcmp (sym->name, (const char *) data) == 0);
|
|
}
|
|
|
|
/* Arrange for dynamic linker to hit breakpoint.
|
|
|
|
The dynamic linkers has, as part of its debugger interface, support
|
|
for arranging for the inferior to hit a breakpoint after mapping in
|
|
the shared libraries. This function enables that breakpoint.
|
|
|
|
On the FR-V, using the shared library (FDPIC) ABI, the symbol
|
|
_dl_debug_addr points to the r_debug struct which contains
|
|
a field called r_brk. r_brk is the address of the function
|
|
descriptor upon which a breakpoint must be placed. Being a
|
|
function descriptor, we must extract the entry point in order
|
|
to set the breakpoint.
|
|
|
|
Our strategy will be to get the .interp section from the
|
|
executable. This section will provide us with the name of the
|
|
interpreter. We'll open the interpreter and then look up
|
|
the address of _dl_debug_addr. We then relocate this address
|
|
using the interpreter's loadmap. Once the relocated address
|
|
is known, we fetch the value (address) corresponding to r_brk
|
|
and then use that value to fetch the entry point of the function
|
|
we're interested in. */
|
|
|
|
static int enable_break2_done = 0;
|
|
|
|
static int
|
|
enable_break2 (void)
|
|
{
|
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
|
int success = 0;
|
|
char **bkpt_namep;
|
|
asection *interp_sect;
|
|
|
|
if (enable_break2_done)
|
|
return 1;
|
|
|
|
interp_text_sect_low = interp_text_sect_high = 0;
|
|
interp_plt_sect_low = interp_plt_sect_high = 0;
|
|
|
|
/* Find the .interp section; if not found, warn the user and drop
|
|
into the old breakpoint at symbol code. */
|
|
interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
|
|
if (interp_sect)
|
|
{
|
|
unsigned int interp_sect_size;
|
|
char *buf;
|
|
bfd *tmp_bfd = NULL;
|
|
int status;
|
|
CORE_ADDR addr, interp_loadmap_addr;
|
|
gdb_byte addr_buf[FRV_PTR_SIZE];
|
|
struct int_elf32_fdpic_loadmap *ldm;
|
|
|
|
/* Read the contents of the .interp section into a local buffer;
|
|
the contents specify the dynamic linker this program uses. */
|
|
interp_sect_size = bfd_section_size (exec_bfd, interp_sect);
|
|
buf = (char *) alloca (interp_sect_size);
|
|
bfd_get_section_contents (exec_bfd, interp_sect,
|
|
buf, 0, interp_sect_size);
|
|
|
|
/* Now we need to figure out where the dynamic linker was
|
|
loaded so that we can load its symbols and place a breakpoint
|
|
in the dynamic linker itself.
|
|
|
|
This address is stored on the stack. However, I've been unable
|
|
to find any magic formula to find it for Solaris (appears to
|
|
be trivial on GNU/Linux). Therefore, we have to try an alternate
|
|
mechanism to find the dynamic linker's base address. */
|
|
|
|
TRY
|
|
{
|
|
tmp_bfd = solib_bfd_open (buf);
|
|
}
|
|
CATCH (ex, RETURN_MASK_ALL)
|
|
{
|
|
}
|
|
END_CATCH
|
|
|
|
if (tmp_bfd == NULL)
|
|
{
|
|
enable_break_failure_warning ();
|
|
return 0;
|
|
}
|
|
|
|
status = frv_fdpic_loadmap_addresses (target_gdbarch (),
|
|
&interp_loadmap_addr, 0);
|
|
if (status < 0)
|
|
{
|
|
warning (_("Unable to determine dynamic linker loadmap address."));
|
|
enable_break_failure_warning ();
|
|
gdb_bfd_unref (tmp_bfd);
|
|
return 0;
|
|
}
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: interp_loadmap_addr = %s\n",
|
|
hex_string_custom (interp_loadmap_addr, 8));
|
|
|
|
ldm = fetch_loadmap (interp_loadmap_addr);
|
|
if (ldm == NULL)
|
|
{
|
|
warning (_("Unable to load dynamic linker loadmap at address %s."),
|
|
hex_string_custom (interp_loadmap_addr, 8));
|
|
enable_break_failure_warning ();
|
|
gdb_bfd_unref (tmp_bfd);
|
|
return 0;
|
|
}
|
|
|
|
/* Record the relocated start and end address of the dynamic linker
|
|
text and plt section for svr4_in_dynsym_resolve_code. */
|
|
interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
|
|
if (interp_sect)
|
|
{
|
|
interp_text_sect_low
|
|
= bfd_section_vma (tmp_bfd, interp_sect);
|
|
interp_text_sect_low
|
|
+= displacement_from_map (ldm, interp_text_sect_low);
|
|
interp_text_sect_high
|
|
= interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
|
|
}
|
|
interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
|
|
if (interp_sect)
|
|
{
|
|
interp_plt_sect_low =
|
|
bfd_section_vma (tmp_bfd, interp_sect);
|
|
interp_plt_sect_low
|
|
+= displacement_from_map (ldm, interp_plt_sect_low);
|
|
interp_plt_sect_high =
|
|
interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
|
|
}
|
|
|
|
addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");
|
|
|
|
if (addr == 0)
|
|
{
|
|
warning (_("Could not find symbol _dl_debug_addr "
|
|
"in dynamic linker"));
|
|
enable_break_failure_warning ();
|
|
gdb_bfd_unref (tmp_bfd);
|
|
return 0;
|
|
}
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: _dl_debug_addr "
|
|
"(prior to relocation) = %s\n",
|
|
hex_string_custom (addr, 8));
|
|
|
|
addr += displacement_from_map (ldm, addr);
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: _dl_debug_addr "
|
|
"(after relocation) = %s\n",
|
|
hex_string_custom (addr, 8));
|
|
|
|
/* Fetch the address of the r_debug struct. */
|
|
if (target_read_memory (addr, addr_buf, sizeof addr_buf) != 0)
|
|
{
|
|
warning (_("Unable to fetch contents of _dl_debug_addr "
|
|
"(at address %s) from dynamic linker"),
|
|
hex_string_custom (addr, 8));
|
|
}
|
|
addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: _dl_debug_addr[0..3] = %s\n",
|
|
hex_string_custom (addr, 8));
|
|
|
|
/* If it's zero, then the ldso hasn't initialized yet, and so
|
|
there are no shared libs yet loaded. */
|
|
if (addr == 0)
|
|
{
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: ldso not yet initialized\n");
|
|
/* Do not warn, but mark to run again. */
|
|
return 0;
|
|
}
|
|
|
|
/* Fetch the r_brk field. It's 8 bytes from the start of
|
|
_dl_debug_addr. */
|
|
if (target_read_memory (addr + 8, addr_buf, sizeof addr_buf) != 0)
|
|
{
|
|
warning (_("Unable to fetch _dl_debug_addr->r_brk "
|
|
"(at address %s) from dynamic linker"),
|
|
hex_string_custom (addr + 8, 8));
|
|
enable_break_failure_warning ();
|
|
gdb_bfd_unref (tmp_bfd);
|
|
return 0;
|
|
}
|
|
addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
|
|
|
|
/* Now fetch the function entry point. */
|
|
if (target_read_memory (addr, addr_buf, sizeof addr_buf) != 0)
|
|
{
|
|
warning (_("Unable to fetch _dl_debug_addr->.r_brk entry point "
|
|
"(at address %s) from dynamic linker"),
|
|
hex_string_custom (addr, 8));
|
|
enable_break_failure_warning ();
|
|
gdb_bfd_unref (tmp_bfd);
|
|
return 0;
|
|
}
|
|
addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
|
|
|
|
/* We're done with the temporary bfd. */
|
|
gdb_bfd_unref (tmp_bfd);
|
|
|
|
/* We're also done with the loadmap. */
|
|
xfree (ldm);
|
|
|
|
/* Remove all the solib event breakpoints. Their addresses
|
|
may have changed since the last time we ran the program. */
|
|
remove_solib_event_breakpoints ();
|
|
|
|
/* Now (finally!) create the solib breakpoint. */
|
|
create_solib_event_breakpoint (target_gdbarch (), addr);
|
|
|
|
enable_break2_done = 1;
|
|
|
|
return 1;
|
|
}
|
|
|
|
/* Tell the user we couldn't set a dynamic linker breakpoint. */
|
|
enable_break_failure_warning ();
|
|
|
|
/* Failure return. */
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
enable_break (void)
|
|
{
|
|
asection *interp_sect;
|
|
CORE_ADDR entry_point;
|
|
|
|
if (symfile_objfile == NULL)
|
|
{
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: No symbol file found.\n");
|
|
return 0;
|
|
}
|
|
|
|
if (!entry_point_address_query (&entry_point))
|
|
{
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: Symbol file has no entry point.\n");
|
|
return 0;
|
|
}
|
|
|
|
/* Check for the presence of a .interp section. If there is no
|
|
such section, the executable is statically linked. */
|
|
|
|
interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
|
|
|
|
if (interp_sect == NULL)
|
|
{
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: No .interp section found.\n");
|
|
return 0;
|
|
}
|
|
|
|
create_solib_event_breakpoint (target_gdbarch (), entry_point);
|
|
|
|
if (solib_frv_debug)
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
"enable_break: solib event breakpoint "
|
|
"placed at entry point: %s\n",
|
|
hex_string_custom (entry_point, 8));
|
|
return 1;
|
|
}
|
|
|
|
/* Implement the "special_symbol_handling" target_so_ops method. */
|
|
|
|
static void
|
|
frv_special_symbol_handling (void)
|
|
{
|
|
/* Nothing needed for FRV. */
|
|
}
|
|
|
|
static void
|
|
frv_relocate_main_executable (void)
|
|
{
|
|
int status;
|
|
CORE_ADDR exec_addr, interp_addr;
|
|
struct int_elf32_fdpic_loadmap *ldm;
|
|
struct cleanup *old_chain;
|
|
struct section_offsets *new_offsets;
|
|
int changed;
|
|
struct obj_section *osect;
|
|
|
|
status = frv_fdpic_loadmap_addresses (target_gdbarch (),
|
|
&interp_addr, &exec_addr);
|
|
|
|
if (status < 0 || (exec_addr == 0 && interp_addr == 0))
|
|
{
|
|
/* Not using FDPIC ABI, so do nothing. */
|
|
return;
|
|
}
|
|
|
|
/* Fetch the loadmap located at ``exec_addr''. */
|
|
ldm = fetch_loadmap (exec_addr);
|
|
if (ldm == NULL)
|
|
error (_("Unable to load the executable's loadmap."));
|
|
|
|
if (main_executable_lm_info)
|
|
xfree (main_executable_lm_info);
|
|
main_executable_lm_info = XCNEW (struct lm_info);
|
|
main_executable_lm_info->map = ldm;
|
|
|
|
new_offsets = XCNEWVEC (struct section_offsets,
|
|
symfile_objfile->num_sections);
|
|
old_chain = make_cleanup (xfree, new_offsets);
|
|
changed = 0;
|
|
|
|
ALL_OBJFILE_OSECTIONS (symfile_objfile, osect)
|
|
{
|
|
CORE_ADDR orig_addr, addr, offset;
|
|
int osect_idx;
|
|
int seg;
|
|
|
|
osect_idx = osect - symfile_objfile->sections;
|
|
|
|
/* Current address of section. */
|
|
addr = obj_section_addr (osect);
|
|
/* Offset from where this section started. */
|
|
offset = ANOFFSET (symfile_objfile->section_offsets, osect_idx);
|
|
/* Original address prior to any past relocations. */
|
|
orig_addr = addr - offset;
|
|
|
|
for (seg = 0; seg < ldm->nsegs; seg++)
|
|
{
|
|
if (ldm->segs[seg].p_vaddr <= orig_addr
|
|
&& orig_addr < ldm->segs[seg].p_vaddr + ldm->segs[seg].p_memsz)
|
|
{
|
|
new_offsets->offsets[osect_idx]
|
|
= ldm->segs[seg].addr - ldm->segs[seg].p_vaddr;
|
|
|
|
if (new_offsets->offsets[osect_idx] != offset)
|
|
changed = 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (changed)
|
|
objfile_relocate (symfile_objfile, new_offsets);
|
|
|
|
do_cleanups (old_chain);
|
|
|
|
/* Now that symfile_objfile has been relocated, we can compute the
|
|
GOT value and stash it away. */
|
|
main_executable_lm_info->got_value = main_got ();
|
|
}
|
|
|
|
/* Implement the "create_inferior_hook" target_solib_ops method.
|
|
|
|
For the FR-V shared library ABI (FDPIC), the main executable needs
|
|
to be relocated. The shared library breakpoints also need to be
|
|
enabled. */
|
|
|
|
static void
|
|
frv_solib_create_inferior_hook (int from_tty)
|
|
{
|
|
/* Relocate main executable. */
|
|
frv_relocate_main_executable ();
|
|
|
|
/* Enable shared library breakpoints. */
|
|
if (!enable_break ())
|
|
{
|
|
warning (_("shared library handler failed to enable breakpoint"));
|
|
return;
|
|
}
|
|
}
|
|
|
|
static void
|
|
frv_clear_solib (void)
|
|
{
|
|
lm_base_cache = 0;
|
|
enable_break2_done = 0;
|
|
main_lm_addr = 0;
|
|
if (main_executable_lm_info != 0)
|
|
{
|
|
xfree (main_executable_lm_info->map);
|
|
xfree (main_executable_lm_info->dyn_syms);
|
|
xfree (main_executable_lm_info->dyn_relocs);
|
|
xfree (main_executable_lm_info);
|
|
main_executable_lm_info = 0;
|
|
}
|
|
}
|
|
|
|
static void
|
|
frv_free_so (struct so_list *so)
|
|
{
|
|
xfree (so->lm_info->map);
|
|
xfree (so->lm_info->dyn_syms);
|
|
xfree (so->lm_info->dyn_relocs);
|
|
xfree (so->lm_info);
|
|
}
|
|
|
|
static void
|
|
frv_relocate_section_addresses (struct so_list *so,
|
|
struct target_section *sec)
|
|
{
|
|
int seg;
|
|
struct int_elf32_fdpic_loadmap *map;
|
|
|
|
map = so->lm_info->map;
|
|
|
|
for (seg = 0; seg < map->nsegs; seg++)
|
|
{
|
|
if (map->segs[seg].p_vaddr <= sec->addr
|
|
&& sec->addr < map->segs[seg].p_vaddr + map->segs[seg].p_memsz)
|
|
{
|
|
CORE_ADDR displ = map->segs[seg].addr - map->segs[seg].p_vaddr;
|
|
|
|
sec->addr += displ;
|
|
sec->endaddr += displ;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Return the GOT address associated with the main executable. Return
|
|
0 if it can't be found. */
|
|
|
|
static CORE_ADDR
|
|
main_got (void)
|
|
{
|
|
struct bound_minimal_symbol got_sym;
|
|
|
|
got_sym = lookup_minimal_symbol ("_GLOBAL_OFFSET_TABLE_",
|
|
NULL, symfile_objfile);
|
|
if (got_sym.minsym == 0)
|
|
return 0;
|
|
|
|
return BMSYMBOL_VALUE_ADDRESS (got_sym);
|
|
}
|
|
|
|
/* Find the global pointer for the given function address ADDR. */
|
|
|
|
CORE_ADDR
|
|
frv_fdpic_find_global_pointer (CORE_ADDR addr)
|
|
{
|
|
struct so_list *so;
|
|
|
|
so = master_so_list ();
|
|
while (so)
|
|
{
|
|
int seg;
|
|
struct int_elf32_fdpic_loadmap *map;
|
|
|
|
map = so->lm_info->map;
|
|
|
|
for (seg = 0; seg < map->nsegs; seg++)
|
|
{
|
|
if (map->segs[seg].addr <= addr
|
|
&& addr < map->segs[seg].addr + map->segs[seg].p_memsz)
|
|
return so->lm_info->got_value;
|
|
}
|
|
|
|
so = so->next;
|
|
}
|
|
|
|
/* Didn't find it in any of the shared objects. So assume it's in the
|
|
main executable. */
|
|
return main_got ();
|
|
}
|
|
|
|
/* Forward declarations for frv_fdpic_find_canonical_descriptor(). */
|
|
static CORE_ADDR find_canonical_descriptor_in_load_object
|
|
(CORE_ADDR, CORE_ADDR, const char *, bfd *, struct lm_info *);
|
|
|
|
/* Given a function entry point, attempt to find the canonical descriptor
|
|
associated with that entry point. Return 0 if no canonical descriptor
|
|
could be found. */
|
|
|
|
CORE_ADDR
|
|
frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point)
|
|
{
|
|
const char *name;
|
|
CORE_ADDR addr;
|
|
CORE_ADDR got_value;
|
|
struct int_elf32_fdpic_loadmap *ldm = 0;
|
|
struct symbol *sym;
|
|
|
|
/* Fetch the corresponding global pointer for the entry point. */
|
|
got_value = frv_fdpic_find_global_pointer (entry_point);
|
|
|
|
/* Attempt to find the name of the function. If the name is available,
|
|
it'll be used as an aid in finding matching functions in the dynamic
|
|
symbol table. */
|
|
sym = find_pc_function (entry_point);
|
|
if (sym == 0)
|
|
name = 0;
|
|
else
|
|
name = SYMBOL_LINKAGE_NAME (sym);
|
|
|
|
/* Check the main executable. */
|
|
addr = find_canonical_descriptor_in_load_object
|
|
(entry_point, got_value, name, symfile_objfile->obfd,
|
|
main_executable_lm_info);
|
|
|
|
/* If descriptor not found via main executable, check each load object
|
|
in list of shared objects. */
|
|
if (addr == 0)
|
|
{
|
|
struct so_list *so;
|
|
|
|
so = master_so_list ();
|
|
while (so)
|
|
{
|
|
addr = find_canonical_descriptor_in_load_object
|
|
(entry_point, got_value, name, so->abfd, so->lm_info);
|
|
|
|
if (addr != 0)
|
|
break;
|
|
|
|
so = so->next;
|
|
}
|
|
}
|
|
|
|
return addr;
|
|
}
|
|
|
|
static CORE_ADDR
|
|
find_canonical_descriptor_in_load_object
|
|
(CORE_ADDR entry_point, CORE_ADDR got_value, const char *name, bfd *abfd,
|
|
struct lm_info *lm)
|
|
{
|
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
|
arelent *rel;
|
|
unsigned int i;
|
|
CORE_ADDR addr = 0;
|
|
|
|
/* Nothing to do if no bfd. */
|
|
if (abfd == 0)
|
|
return 0;
|
|
|
|
/* Nothing to do if no link map. */
|
|
if (lm == 0)
|
|
return 0;
|
|
|
|
/* We want to scan the dynamic relocs for R_FRV_FUNCDESC relocations.
|
|
(More about this later.) But in order to fetch the relocs, we
|
|
need to first fetch the dynamic symbols. These symbols need to
|
|
be cached due to the way that bfd_canonicalize_dynamic_reloc()
|
|
works. (See the comments in the declaration of struct lm_info
|
|
for more information.) */
|
|
if (lm->dyn_syms == NULL)
|
|
{
|
|
long storage_needed;
|
|
unsigned int number_of_symbols;
|
|
|
|
/* Determine amount of space needed to hold the dynamic symbol table. */
|
|
storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
|
|
|
|
/* If there are no dynamic symbols, there's nothing to do. */
|
|
if (storage_needed <= 0)
|
|
return 0;
|
|
|
|
/* Allocate space for the dynamic symbol table. */
|
|
lm->dyn_syms = (asymbol **) xmalloc (storage_needed);
|
|
|
|
/* Fetch the dynamic symbol table. */
|
|
number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, lm->dyn_syms);
|
|
|
|
if (number_of_symbols == 0)
|
|
return 0;
|
|
}
|
|
|
|
/* Fetch the dynamic relocations if not already cached. */
|
|
if (lm->dyn_relocs == NULL)
|
|
{
|
|
long storage_needed;
|
|
|
|
/* Determine amount of space needed to hold the dynamic relocs. */
|
|
storage_needed = bfd_get_dynamic_reloc_upper_bound (abfd);
|
|
|
|
/* Bail out if there are no dynamic relocs. */
|
|
if (storage_needed <= 0)
|
|
return 0;
|
|
|
|
/* Allocate space for the relocs. */
|
|
lm->dyn_relocs = (arelent **) xmalloc (storage_needed);
|
|
|
|
/* Fetch the dynamic relocs. */
|
|
lm->dyn_reloc_count
|
|
= bfd_canonicalize_dynamic_reloc (abfd, lm->dyn_relocs, lm->dyn_syms);
|
|
}
|
|
|
|
/* Search the dynamic relocs. */
|
|
for (i = 0; i < lm->dyn_reloc_count; i++)
|
|
{
|
|
rel = lm->dyn_relocs[i];
|
|
|
|
/* Relocs of interest are those which meet the following
|
|
criteria:
|
|
|
|
- the names match (assuming the caller could provide
|
|
a name which matches ``entry_point'').
|
|
- the relocation type must be R_FRV_FUNCDESC. Relocs
|
|
of this type are used (by the dynamic linker) to
|
|
look up the address of a canonical descriptor (allocating
|
|
it if need be) and initializing the GOT entry referred
|
|
to by the offset to the address of the descriptor.
|
|
|
|
These relocs of interest may be used to obtain a
|
|
candidate descriptor by first adjusting the reloc's
|
|
address according to the link map and then dereferencing
|
|
this address (which is a GOT entry) to obtain a descriptor
|
|
address. */
|
|
if ((name == 0 || strcmp (name, (*rel->sym_ptr_ptr)->name) == 0)
|
|
&& rel->howto->type == R_FRV_FUNCDESC)
|
|
{
|
|
gdb_byte buf [FRV_PTR_SIZE];
|
|
|
|
/* Compute address of address of candidate descriptor. */
|
|
addr = rel->address + displacement_from_map (lm->map, rel->address);
|
|
|
|
/* Fetch address of candidate descriptor. */
|
|
if (target_read_memory (addr, buf, sizeof buf) != 0)
|
|
continue;
|
|
addr = extract_unsigned_integer (buf, sizeof buf, byte_order);
|
|
|
|
/* Check for matching entry point. */
|
|
if (target_read_memory (addr, buf, sizeof buf) != 0)
|
|
continue;
|
|
if (extract_unsigned_integer (buf, sizeof buf, byte_order)
|
|
!= entry_point)
|
|
continue;
|
|
|
|
/* Check for matching got value. */
|
|
if (target_read_memory (addr + 4, buf, sizeof buf) != 0)
|
|
continue;
|
|
if (extract_unsigned_integer (buf, sizeof buf, byte_order)
|
|
!= got_value)
|
|
continue;
|
|
|
|
/* Match was successful! Exit loop. */
|
|
break;
|
|
}
|
|
}
|
|
|
|
return addr;
|
|
}
|
|
|
|
/* Given an objfile, return the address of its link map. This value is
|
|
needed for TLS support. */
|
|
CORE_ADDR
|
|
frv_fetch_objfile_link_map (struct objfile *objfile)
|
|
{
|
|
struct so_list *so;
|
|
|
|
/* Cause frv_current_sos() to be run if it hasn't been already. */
|
|
if (main_lm_addr == 0)
|
|
solib_add (0, 0, 0, 1);
|
|
|
|
/* frv_current_sos() will set main_lm_addr for the main executable. */
|
|
if (objfile == symfile_objfile)
|
|
return main_lm_addr;
|
|
|
|
/* The other link map addresses may be found by examining the list
|
|
of shared libraries. */
|
|
for (so = master_so_list (); so; so = so->next)
|
|
{
|
|
if (so->objfile == objfile)
|
|
return so->lm_info->lm_addr;
|
|
}
|
|
|
|
/* Not found! */
|
|
return 0;
|
|
}
|
|
|
|
struct target_so_ops frv_so_ops;
|
|
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
|
extern initialize_file_ftype _initialize_frv_solib;
|
|
|
|
void
|
|
_initialize_frv_solib (void)
|
|
{
|
|
frv_so_ops.relocate_section_addresses = frv_relocate_section_addresses;
|
|
frv_so_ops.free_so = frv_free_so;
|
|
frv_so_ops.clear_solib = frv_clear_solib;
|
|
frv_so_ops.solib_create_inferior_hook = frv_solib_create_inferior_hook;
|
|
frv_so_ops.special_symbol_handling = frv_special_symbol_handling;
|
|
frv_so_ops.current_sos = frv_current_sos;
|
|
frv_so_ops.open_symbol_file_object = open_symbol_file_object;
|
|
frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
|
|
frv_so_ops.bfd_open = solib_bfd_open;
|
|
|
|
/* Debug this file's internals. */
|
|
add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
|
|
&solib_frv_debug, _("\
|
|
Set internal debugging of shared library code for FR-V."), _("\
|
|
Show internal debugging of shared library code for FR-V."), _("\
|
|
When non-zero, FR-V solib specific internal debugging is enabled."),
|
|
NULL,
|
|
NULL, /* FIXME: i18n: */
|
|
&setdebuglist, &showdebuglist);
|
|
}
|