mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
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.
1104 lines
33 KiB
C
1104 lines
33 KiB
C
/* Native support code for PPC AIX, for GDB the GNU debugger.
|
|
|
|
Copyright (C) 2006-2015 Free Software Foundation, Inc.
|
|
|
|
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 "osabi.h"
|
|
#include "regcache.h"
|
|
#include "regset.h"
|
|
#include "gdbtypes.h"
|
|
#include "gdbcore.h"
|
|
#include "target.h"
|
|
#include "value.h"
|
|
#include "infcall.h"
|
|
#include "objfiles.h"
|
|
#include "breakpoint.h"
|
|
#include "rs6000-tdep.h"
|
|
#include "ppc-tdep.h"
|
|
#include "rs6000-aix-tdep.h"
|
|
#include "xcoffread.h"
|
|
#include "solib.h"
|
|
#include "solib-aix.h"
|
|
#include "xml-utils.h"
|
|
|
|
/* If the kernel has to deliver a signal, it pushes a sigcontext
|
|
structure on the stack and then calls the signal handler, passing
|
|
the address of the sigcontext in an argument register. Usually
|
|
the signal handler doesn't save this register, so we have to
|
|
access the sigcontext structure via an offset from the signal handler
|
|
frame.
|
|
The following constants were determined by experimentation on AIX 3.2. */
|
|
#define SIG_FRAME_PC_OFFSET 96
|
|
#define SIG_FRAME_LR_OFFSET 108
|
|
#define SIG_FRAME_FP_OFFSET 284
|
|
|
|
|
|
/* Core file support. */
|
|
|
|
static struct ppc_reg_offsets rs6000_aix32_reg_offsets =
|
|
{
|
|
/* General-purpose registers. */
|
|
208, /* r0_offset */
|
|
4, /* gpr_size */
|
|
4, /* xr_size */
|
|
24, /* pc_offset */
|
|
28, /* ps_offset */
|
|
32, /* cr_offset */
|
|
36, /* lr_offset */
|
|
40, /* ctr_offset */
|
|
44, /* xer_offset */
|
|
48, /* mq_offset */
|
|
|
|
/* Floating-point registers. */
|
|
336, /* f0_offset */
|
|
56, /* fpscr_offset */
|
|
4, /* fpscr_size */
|
|
|
|
/* AltiVec registers. */
|
|
-1, /* vr0_offset */
|
|
-1, /* vscr_offset */
|
|
-1 /* vrsave_offset */
|
|
};
|
|
|
|
static struct ppc_reg_offsets rs6000_aix64_reg_offsets =
|
|
{
|
|
/* General-purpose registers. */
|
|
0, /* r0_offset */
|
|
8, /* gpr_size */
|
|
4, /* xr_size */
|
|
264, /* pc_offset */
|
|
256, /* ps_offset */
|
|
288, /* cr_offset */
|
|
272, /* lr_offset */
|
|
280, /* ctr_offset */
|
|
292, /* xer_offset */
|
|
-1, /* mq_offset */
|
|
|
|
/* Floating-point registers. */
|
|
312, /* f0_offset */
|
|
296, /* fpscr_offset */
|
|
4, /* fpscr_size */
|
|
|
|
/* AltiVec registers. */
|
|
-1, /* vr0_offset */
|
|
-1, /* vscr_offset */
|
|
-1 /* vrsave_offset */
|
|
};
|
|
|
|
|
|
/* Supply register REGNUM in the general-purpose register set REGSET
|
|
from the buffer specified by GREGS and LEN to register cache
|
|
REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
|
|
|
|
static void
|
|
rs6000_aix_supply_regset (const struct regset *regset,
|
|
struct regcache *regcache, int regnum,
|
|
const void *gregs, size_t len)
|
|
{
|
|
ppc_supply_gregset (regset, regcache, regnum, gregs, len);
|
|
ppc_supply_fpregset (regset, regcache, regnum, gregs, len);
|
|
}
|
|
|
|
/* Collect register REGNUM in the general-purpose register set
|
|
REGSET, from register cache REGCACHE into the buffer specified by
|
|
GREGS and LEN. If REGNUM is -1, do this for all registers in
|
|
REGSET. */
|
|
|
|
static void
|
|
rs6000_aix_collect_regset (const struct regset *regset,
|
|
const struct regcache *regcache, int regnum,
|
|
void *gregs, size_t len)
|
|
{
|
|
ppc_collect_gregset (regset, regcache, regnum, gregs, len);
|
|
ppc_collect_fpregset (regset, regcache, regnum, gregs, len);
|
|
}
|
|
|
|
/* AIX register set. */
|
|
|
|
static const struct regset rs6000_aix32_regset =
|
|
{
|
|
&rs6000_aix32_reg_offsets,
|
|
rs6000_aix_supply_regset,
|
|
rs6000_aix_collect_regset,
|
|
};
|
|
|
|
static const struct regset rs6000_aix64_regset =
|
|
{
|
|
&rs6000_aix64_reg_offsets,
|
|
rs6000_aix_supply_regset,
|
|
rs6000_aix_collect_regset,
|
|
};
|
|
|
|
/* Iterate over core file register note sections. */
|
|
|
|
static void
|
|
rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
|
|
iterate_over_regset_sections_cb *cb,
|
|
void *cb_data,
|
|
const struct regcache *regcache)
|
|
{
|
|
if (gdbarch_tdep (gdbarch)->wordsize == 4)
|
|
cb (".reg", 592, &rs6000_aix32_regset, NULL, cb_data);
|
|
else
|
|
cb (".reg", 576, &rs6000_aix64_regset, NULL, cb_data);
|
|
}
|
|
|
|
|
|
/* Pass the arguments in either registers, or in the stack. In RS/6000,
|
|
the first eight words of the argument list (that might be less than
|
|
eight parameters if some parameters occupy more than one word) are
|
|
passed in r3..r10 registers. Float and double parameters are
|
|
passed in fpr's, in addition to that. Rest of the parameters if any
|
|
are passed in user stack. There might be cases in which half of the
|
|
parameter is copied into registers, the other half is pushed into
|
|
stack.
|
|
|
|
Stack must be aligned on 64-bit boundaries when synthesizing
|
|
function calls.
|
|
|
|
If the function is returning a structure, then the return address is passed
|
|
in r3, then the first 7 words of the parameters can be passed in registers,
|
|
starting from r4. */
|
|
|
|
static CORE_ADDR
|
|
rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
|
|
struct regcache *regcache, CORE_ADDR bp_addr,
|
|
int nargs, struct value **args, CORE_ADDR sp,
|
|
int struct_return, CORE_ADDR struct_addr)
|
|
{
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
int ii;
|
|
int len = 0;
|
|
int argno; /* current argument number */
|
|
int argbytes; /* current argument byte */
|
|
gdb_byte tmp_buffer[50];
|
|
int f_argno = 0; /* current floating point argno */
|
|
int wordsize = gdbarch_tdep (gdbarch)->wordsize;
|
|
CORE_ADDR func_addr = find_function_addr (function, NULL);
|
|
|
|
struct value *arg = 0;
|
|
struct type *type;
|
|
|
|
ULONGEST saved_sp;
|
|
|
|
/* The calling convention this function implements assumes the
|
|
processor has floating-point registers. We shouldn't be using it
|
|
on PPC variants that lack them. */
|
|
gdb_assert (ppc_floating_point_unit_p (gdbarch));
|
|
|
|
/* The first eight words of ther arguments are passed in registers.
|
|
Copy them appropriately. */
|
|
ii = 0;
|
|
|
|
/* If the function is returning a `struct', then the first word
|
|
(which will be passed in r3) is used for struct return address.
|
|
In that case we should advance one word and start from r4
|
|
register to copy parameters. */
|
|
if (struct_return)
|
|
{
|
|
regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
|
|
struct_addr);
|
|
ii++;
|
|
}
|
|
|
|
/* effectively indirect call... gcc does...
|
|
|
|
return_val example( float, int);
|
|
|
|
eabi:
|
|
float in fp0, int in r3
|
|
offset of stack on overflow 8/16
|
|
for varargs, must go by type.
|
|
power open:
|
|
float in r3&r4, int in r5
|
|
offset of stack on overflow different
|
|
both:
|
|
return in r3 or f0. If no float, must study how gcc emulates floats;
|
|
pay attention to arg promotion.
|
|
User may have to cast\args to handle promotion correctly
|
|
since gdb won't know if prototype supplied or not. */
|
|
|
|
for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
|
|
{
|
|
int reg_size = register_size (gdbarch, ii + 3);
|
|
|
|
arg = args[argno];
|
|
type = check_typedef (value_type (arg));
|
|
len = TYPE_LENGTH (type);
|
|
|
|
if (TYPE_CODE (type) == TYPE_CODE_FLT)
|
|
{
|
|
/* Floating point arguments are passed in fpr's, as well as gpr's.
|
|
There are 13 fpr's reserved for passing parameters. At this point
|
|
there is no way we would run out of them.
|
|
|
|
Always store the floating point value using the register's
|
|
floating-point format. */
|
|
const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
|
|
gdb_byte reg_val[MAX_REGISTER_SIZE];
|
|
struct type *reg_type = register_type (gdbarch, fp_regnum);
|
|
|
|
gdb_assert (len <= 8);
|
|
|
|
convert_typed_floating (value_contents (arg), type,
|
|
reg_val, reg_type);
|
|
regcache_cooked_write (regcache, fp_regnum, reg_val);
|
|
++f_argno;
|
|
}
|
|
|
|
if (len > reg_size)
|
|
{
|
|
|
|
/* Argument takes more than one register. */
|
|
while (argbytes < len)
|
|
{
|
|
gdb_byte word[MAX_REGISTER_SIZE];
|
|
memset (word, 0, reg_size);
|
|
memcpy (word,
|
|
((char *) value_contents (arg)) + argbytes,
|
|
(len - argbytes) > reg_size
|
|
? reg_size : len - argbytes);
|
|
regcache_cooked_write (regcache,
|
|
tdep->ppc_gp0_regnum + 3 + ii,
|
|
word);
|
|
++ii, argbytes += reg_size;
|
|
|
|
if (ii >= 8)
|
|
goto ran_out_of_registers_for_arguments;
|
|
}
|
|
argbytes = 0;
|
|
--ii;
|
|
}
|
|
else
|
|
{
|
|
/* Argument can fit in one register. No problem. */
|
|
int adj = gdbarch_byte_order (gdbarch)
|
|
== BFD_ENDIAN_BIG ? reg_size - len : 0;
|
|
gdb_byte word[MAX_REGISTER_SIZE];
|
|
|
|
memset (word, 0, reg_size);
|
|
memcpy (word, value_contents (arg), len);
|
|
regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3 +ii, word);
|
|
}
|
|
++argno;
|
|
}
|
|
|
|
ran_out_of_registers_for_arguments:
|
|
|
|
regcache_cooked_read_unsigned (regcache,
|
|
gdbarch_sp_regnum (gdbarch),
|
|
&saved_sp);
|
|
|
|
/* Location for 8 parameters are always reserved. */
|
|
sp -= wordsize * 8;
|
|
|
|
/* Another six words for back chain, TOC register, link register, etc. */
|
|
sp -= wordsize * 6;
|
|
|
|
/* Stack pointer must be quadword aligned. */
|
|
sp &= -16;
|
|
|
|
/* If there are more arguments, allocate space for them in
|
|
the stack, then push them starting from the ninth one. */
|
|
|
|
if ((argno < nargs) || argbytes)
|
|
{
|
|
int space = 0, jj;
|
|
|
|
if (argbytes)
|
|
{
|
|
space += ((len - argbytes + 3) & -4);
|
|
jj = argno + 1;
|
|
}
|
|
else
|
|
jj = argno;
|
|
|
|
for (; jj < nargs; ++jj)
|
|
{
|
|
struct value *val = args[jj];
|
|
space += ((TYPE_LENGTH (value_type (val))) + 3) & -4;
|
|
}
|
|
|
|
/* Add location required for the rest of the parameters. */
|
|
space = (space + 15) & -16;
|
|
sp -= space;
|
|
|
|
/* This is another instance we need to be concerned about
|
|
securing our stack space. If we write anything underneath %sp
|
|
(r1), we might conflict with the kernel who thinks he is free
|
|
to use this area. So, update %sp first before doing anything
|
|
else. */
|
|
|
|
regcache_raw_write_signed (regcache,
|
|
gdbarch_sp_regnum (gdbarch), sp);
|
|
|
|
/* If the last argument copied into the registers didn't fit there
|
|
completely, push the rest of it into stack. */
|
|
|
|
if (argbytes)
|
|
{
|
|
write_memory (sp + 24 + (ii * 4),
|
|
value_contents (arg) + argbytes,
|
|
len - argbytes);
|
|
++argno;
|
|
ii += ((len - argbytes + 3) & -4) / 4;
|
|
}
|
|
|
|
/* Push the rest of the arguments into stack. */
|
|
for (; argno < nargs; ++argno)
|
|
{
|
|
|
|
arg = args[argno];
|
|
type = check_typedef (value_type (arg));
|
|
len = TYPE_LENGTH (type);
|
|
|
|
|
|
/* Float types should be passed in fpr's, as well as in the
|
|
stack. */
|
|
if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13)
|
|
{
|
|
|
|
gdb_assert (len <= 8);
|
|
|
|
regcache_cooked_write (regcache,
|
|
tdep->ppc_fp0_regnum + 1 + f_argno,
|
|
value_contents (arg));
|
|
++f_argno;
|
|
}
|
|
|
|
write_memory (sp + 24 + (ii * 4), value_contents (arg), len);
|
|
ii += ((len + 3) & -4) / 4;
|
|
}
|
|
}
|
|
|
|
/* Set the stack pointer. According to the ABI, the SP is meant to
|
|
be set _before_ the corresponding stack space is used. On AIX,
|
|
this even applies when the target has been completely stopped!
|
|
Not doing this can lead to conflicts with the kernel which thinks
|
|
that it still has control over this not-yet-allocated stack
|
|
region. */
|
|
regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
|
|
|
|
/* Set back chain properly. */
|
|
store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp);
|
|
write_memory (sp, tmp_buffer, wordsize);
|
|
|
|
/* Point the inferior function call's return address at the dummy's
|
|
breakpoint. */
|
|
regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
|
|
|
|
/* Set the TOC register value. */
|
|
regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum,
|
|
solib_aix_get_toc_value (func_addr));
|
|
|
|
target_store_registers (regcache, -1);
|
|
return sp;
|
|
}
|
|
|
|
static enum return_value_convention
|
|
rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
|
|
struct type *valtype, struct regcache *regcache,
|
|
gdb_byte *readbuf, const gdb_byte *writebuf)
|
|
{
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
|
|
/* The calling convention this function implements assumes the
|
|
processor has floating-point registers. We shouldn't be using it
|
|
on PowerPC variants that lack them. */
|
|
gdb_assert (ppc_floating_point_unit_p (gdbarch));
|
|
|
|
/* AltiVec extension: Functions that declare a vector data type as a
|
|
return value place that return value in VR2. */
|
|
if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype)
|
|
&& TYPE_LENGTH (valtype) == 16)
|
|
{
|
|
if (readbuf)
|
|
regcache_cooked_read (regcache, tdep->ppc_vr0_regnum + 2, readbuf);
|
|
if (writebuf)
|
|
regcache_cooked_write (regcache, tdep->ppc_vr0_regnum + 2, writebuf);
|
|
|
|
return RETURN_VALUE_REGISTER_CONVENTION;
|
|
}
|
|
|
|
/* If the called subprogram returns an aggregate, there exists an
|
|
implicit first argument, whose value is the address of a caller-
|
|
allocated buffer into which the callee is assumed to store its
|
|
return value. All explicit parameters are appropriately
|
|
relabeled. */
|
|
if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|
|
|| TYPE_CODE (valtype) == TYPE_CODE_UNION
|
|
|| TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
|
|
return RETURN_VALUE_STRUCT_CONVENTION;
|
|
|
|
/* Scalar floating-point values are returned in FPR1 for float or
|
|
double, and in FPR1:FPR2 for quadword precision. Fortran
|
|
complex*8 and complex*16 are returned in FPR1:FPR2, and
|
|
complex*32 is returned in FPR1:FPR4. */
|
|
if (TYPE_CODE (valtype) == TYPE_CODE_FLT
|
|
&& (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8))
|
|
{
|
|
struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
|
|
gdb_byte regval[8];
|
|
|
|
/* FIXME: kettenis/2007-01-01: Add support for quadword
|
|
precision and complex. */
|
|
|
|
if (readbuf)
|
|
{
|
|
regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
|
|
convert_typed_floating (regval, regtype, readbuf, valtype);
|
|
}
|
|
if (writebuf)
|
|
{
|
|
convert_typed_floating (writebuf, valtype, regval, regtype);
|
|
regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
|
|
}
|
|
|
|
return RETURN_VALUE_REGISTER_CONVENTION;
|
|
}
|
|
|
|
/* Values of the types int, long, short, pointer, and char (length
|
|
is less than or equal to four bytes), as well as bit values of
|
|
lengths less than or equal to 32 bits, must be returned right
|
|
justified in GPR3 with signed values sign extended and unsigned
|
|
values zero extended, as necessary. */
|
|
if (TYPE_LENGTH (valtype) <= tdep->wordsize)
|
|
{
|
|
if (readbuf)
|
|
{
|
|
ULONGEST regval;
|
|
|
|
/* For reading we don't have to worry about sign extension. */
|
|
regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
|
|
®val);
|
|
store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order,
|
|
regval);
|
|
}
|
|
if (writebuf)
|
|
{
|
|
/* For writing, use unpack_long since that should handle any
|
|
required sign extension. */
|
|
regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
|
|
unpack_long (valtype, writebuf));
|
|
}
|
|
|
|
return RETURN_VALUE_REGISTER_CONVENTION;
|
|
}
|
|
|
|
/* Eight-byte non-floating-point scalar values must be returned in
|
|
GPR3:GPR4. */
|
|
|
|
if (TYPE_LENGTH (valtype) == 8)
|
|
{
|
|
gdb_assert (TYPE_CODE (valtype) != TYPE_CODE_FLT);
|
|
gdb_assert (tdep->wordsize == 4);
|
|
|
|
if (readbuf)
|
|
{
|
|
gdb_byte regval[8];
|
|
|
|
regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 3, regval);
|
|
regcache_cooked_read (regcache, tdep->ppc_gp0_regnum + 4,
|
|
regval + 4);
|
|
memcpy (readbuf, regval, 8);
|
|
}
|
|
if (writebuf)
|
|
{
|
|
regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 3, writebuf);
|
|
regcache_cooked_write (regcache, tdep->ppc_gp0_regnum + 4,
|
|
writebuf + 4);
|
|
}
|
|
|
|
return RETURN_VALUE_REGISTER_CONVENTION;
|
|
}
|
|
|
|
return RETURN_VALUE_STRUCT_CONVENTION;
|
|
}
|
|
|
|
/* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
|
|
|
|
Usually a function pointer's representation is simply the address
|
|
of the function. On the RS/6000 however, a function pointer is
|
|
represented by a pointer to an OPD entry. This OPD entry contains
|
|
three words, the first word is the address of the function, the
|
|
second word is the TOC pointer (r2), and the third word is the
|
|
static chain value. Throughout GDB it is currently assumed that a
|
|
function pointer contains the address of the function, which is not
|
|
easy to fix. In addition, the conversion of a function address to
|
|
a function pointer would require allocation of an OPD entry in the
|
|
inferior's memory space, with all its drawbacks. To be able to
|
|
call C++ virtual methods in the inferior (which are called via
|
|
function pointers), find_function_addr uses this function to get the
|
|
function address from a function pointer. */
|
|
|
|
/* Return real function address if ADDR (a function pointer) is in the data
|
|
space and is therefore a special function pointer. */
|
|
|
|
static CORE_ADDR
|
|
rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
|
|
CORE_ADDR addr,
|
|
struct target_ops *targ)
|
|
{
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
struct obj_section *s;
|
|
|
|
s = find_pc_section (addr);
|
|
|
|
/* Normally, functions live inside a section that is executable.
|
|
So, if ADDR points to a non-executable section, then treat it
|
|
as a function descriptor and return the target address iff
|
|
the target address itself points to a section that is executable. */
|
|
if (s && (s->the_bfd_section->flags & SEC_CODE) == 0)
|
|
{
|
|
CORE_ADDR pc = 0;
|
|
struct obj_section *pc_section;
|
|
|
|
TRY
|
|
{
|
|
pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
|
|
}
|
|
CATCH (e, RETURN_MASK_ERROR)
|
|
{
|
|
/* An error occured during reading. Probably a memory error
|
|
due to the section not being loaded yet. This address
|
|
cannot be a function descriptor. */
|
|
return addr;
|
|
}
|
|
END_CATCH
|
|
|
|
pc_section = find_pc_section (pc);
|
|
|
|
if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
|
|
return pc;
|
|
}
|
|
|
|
return addr;
|
|
}
|
|
|
|
|
|
/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
|
|
|
|
static CORE_ADDR
|
|
branch_dest (struct frame_info *frame, int opcode, int instr,
|
|
CORE_ADDR pc, CORE_ADDR safety)
|
|
{
|
|
struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
CORE_ADDR dest;
|
|
int immediate;
|
|
int absolute;
|
|
int ext_op;
|
|
|
|
absolute = (int) ((instr >> 1) & 1);
|
|
|
|
switch (opcode)
|
|
{
|
|
case 18:
|
|
immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
|
|
if (absolute)
|
|
dest = immediate;
|
|
else
|
|
dest = pc + immediate;
|
|
break;
|
|
|
|
case 16:
|
|
immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
|
|
if (absolute)
|
|
dest = immediate;
|
|
else
|
|
dest = pc + immediate;
|
|
break;
|
|
|
|
case 19:
|
|
ext_op = (instr >> 1) & 0x3ff;
|
|
|
|
if (ext_op == 16) /* br conditional register */
|
|
{
|
|
dest = get_frame_register_unsigned (frame, tdep->ppc_lr_regnum) & ~3;
|
|
|
|
/* If we are about to return from a signal handler, dest is
|
|
something like 0x3c90. The current frame is a signal handler
|
|
caller frame, upon completion of the sigreturn system call
|
|
execution will return to the saved PC in the frame. */
|
|
if (dest < AIX_TEXT_SEGMENT_BASE)
|
|
dest = read_memory_unsigned_integer
|
|
(get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
|
|
tdep->wordsize, byte_order);
|
|
}
|
|
|
|
else if (ext_op == 528) /* br cond to count reg */
|
|
{
|
|
dest = get_frame_register_unsigned (frame,
|
|
tdep->ppc_ctr_regnum) & ~3;
|
|
|
|
/* If we are about to execute a system call, dest is something
|
|
like 0x22fc or 0x3b00. Upon completion the system call
|
|
will return to the address in the link register. */
|
|
if (dest < AIX_TEXT_SEGMENT_BASE)
|
|
dest = get_frame_register_unsigned (frame,
|
|
tdep->ppc_lr_regnum) & ~3;
|
|
}
|
|
else
|
|
return -1;
|
|
break;
|
|
|
|
default:
|
|
return -1;
|
|
}
|
|
return (dest < AIX_TEXT_SEGMENT_BASE) ? safety : dest;
|
|
}
|
|
|
|
/* AIX does not support PT_STEP. Simulate it. */
|
|
|
|
static int
|
|
rs6000_software_single_step (struct frame_info *frame)
|
|
{
|
|
struct gdbarch *gdbarch = get_frame_arch (frame);
|
|
struct address_space *aspace = get_frame_address_space (frame);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
int ii, insn;
|
|
CORE_ADDR loc;
|
|
CORE_ADDR breaks[2];
|
|
int opcode;
|
|
|
|
loc = get_frame_pc (frame);
|
|
|
|
insn = read_memory_integer (loc, 4, byte_order);
|
|
|
|
if (ppc_deal_with_atomic_sequence (frame))
|
|
return 1;
|
|
|
|
breaks[0] = loc + PPC_INSN_SIZE;
|
|
opcode = insn >> 26;
|
|
breaks[1] = branch_dest (frame, opcode, insn, loc, breaks[0]);
|
|
|
|
/* Don't put two breakpoints on the same address. */
|
|
if (breaks[1] == breaks[0])
|
|
breaks[1] = -1;
|
|
|
|
for (ii = 0; ii < 2; ++ii)
|
|
{
|
|
/* ignore invalid breakpoint. */
|
|
if (breaks[ii] == -1)
|
|
continue;
|
|
insert_single_step_breakpoint (gdbarch, aspace, breaks[ii]);
|
|
}
|
|
|
|
errno = 0; /* FIXME, don't ignore errors! */
|
|
/* What errors? {read,write}_memory call error(). */
|
|
return 1;
|
|
}
|
|
|
|
/* Implement the "auto_wide_charset" gdbarch method for this platform. */
|
|
|
|
static const char *
|
|
rs6000_aix_auto_wide_charset (void)
|
|
{
|
|
return "UTF-16";
|
|
}
|
|
|
|
/* Implement an osabi sniffer for RS6000/AIX.
|
|
|
|
This function assumes that ABFD's flavour is XCOFF. In other words,
|
|
it should be registered as a sniffer for bfd_target_xcoff_flavour
|
|
objfiles only. A failed assertion will be raised if this condition
|
|
is not met. */
|
|
|
|
static enum gdb_osabi
|
|
rs6000_aix_osabi_sniffer (bfd *abfd)
|
|
{
|
|
gdb_assert (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
|
|
|
|
/* The only noticeable difference between Lynx178 XCOFF files and
|
|
AIX XCOFF files comes from the fact that there are no shared
|
|
libraries on Lynx178. On AIX, we are betting that an executable
|
|
linked with no shared library will never exist. */
|
|
if (xcoff_get_n_import_files (abfd) <= 0)
|
|
return GDB_OSABI_UNKNOWN;
|
|
|
|
return GDB_OSABI_AIX;
|
|
}
|
|
|
|
/* A structure encoding the offset and size of a field within
|
|
a struct. */
|
|
|
|
struct field_info
|
|
{
|
|
int offset;
|
|
int size;
|
|
};
|
|
|
|
/* A structure describing the layout of all the fields of interest
|
|
in AIX's struct ld_info. Each field in this struct corresponds
|
|
to the field of the same name in struct ld_info. */
|
|
|
|
struct ld_info_desc
|
|
{
|
|
struct field_info ldinfo_next;
|
|
struct field_info ldinfo_fd;
|
|
struct field_info ldinfo_textorg;
|
|
struct field_info ldinfo_textsize;
|
|
struct field_info ldinfo_dataorg;
|
|
struct field_info ldinfo_datasize;
|
|
struct field_info ldinfo_filename;
|
|
};
|
|
|
|
/* The following data has been generated by compiling and running
|
|
the following program on AIX 5.3. */
|
|
|
|
#if 0
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#define __LDINFO_PTRACE32__
|
|
#define __LDINFO_PTRACE64__
|
|
#include <sys/ldr.h>
|
|
|
|
#define pinfo(type,member) \
|
|
{ \
|
|
struct type ldi = {0}; \
|
|
\
|
|
printf (" {%d, %d},\t/* %s */\n", \
|
|
offsetof (struct type, member), \
|
|
sizeof (ldi.member), \
|
|
#member); \
|
|
} \
|
|
while (0)
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
|
|
pinfo (__ld_info32, ldinfo_next);
|
|
pinfo (__ld_info32, ldinfo_fd);
|
|
pinfo (__ld_info32, ldinfo_textorg);
|
|
pinfo (__ld_info32, ldinfo_textsize);
|
|
pinfo (__ld_info32, ldinfo_dataorg);
|
|
pinfo (__ld_info32, ldinfo_datasize);
|
|
pinfo (__ld_info32, ldinfo_filename);
|
|
printf ("};\n");
|
|
|
|
printf ("\n");
|
|
|
|
printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
|
|
pinfo (__ld_info64, ldinfo_next);
|
|
pinfo (__ld_info64, ldinfo_fd);
|
|
pinfo (__ld_info64, ldinfo_textorg);
|
|
pinfo (__ld_info64, ldinfo_textsize);
|
|
pinfo (__ld_info64, ldinfo_dataorg);
|
|
pinfo (__ld_info64, ldinfo_datasize);
|
|
pinfo (__ld_info64, ldinfo_filename);
|
|
printf ("};\n");
|
|
|
|
return 0;
|
|
}
|
|
#endif /* 0 */
|
|
|
|
/* Layout of the 32bit version of struct ld_info. */
|
|
|
|
static const struct ld_info_desc ld_info32_desc =
|
|
{
|
|
{0, 4}, /* ldinfo_next */
|
|
{4, 4}, /* ldinfo_fd */
|
|
{8, 4}, /* ldinfo_textorg */
|
|
{12, 4}, /* ldinfo_textsize */
|
|
{16, 4}, /* ldinfo_dataorg */
|
|
{20, 4}, /* ldinfo_datasize */
|
|
{24, 2}, /* ldinfo_filename */
|
|
};
|
|
|
|
/* Layout of the 64bit version of struct ld_info. */
|
|
|
|
static const struct ld_info_desc ld_info64_desc =
|
|
{
|
|
{0, 4}, /* ldinfo_next */
|
|
{8, 4}, /* ldinfo_fd */
|
|
{16, 8}, /* ldinfo_textorg */
|
|
{24, 8}, /* ldinfo_textsize */
|
|
{32, 8}, /* ldinfo_dataorg */
|
|
{40, 8}, /* ldinfo_datasize */
|
|
{48, 2}, /* ldinfo_filename */
|
|
};
|
|
|
|
/* A structured representation of one entry read from the ld_info
|
|
binary data provided by the AIX loader. */
|
|
|
|
struct ld_info
|
|
{
|
|
ULONGEST next;
|
|
int fd;
|
|
CORE_ADDR textorg;
|
|
ULONGEST textsize;
|
|
CORE_ADDR dataorg;
|
|
ULONGEST datasize;
|
|
char *filename;
|
|
char *member_name;
|
|
};
|
|
|
|
/* Return a struct ld_info object corresponding to the entry at
|
|
LDI_BUF.
|
|
|
|
Note that the filename and member_name strings still point
|
|
to the data in LDI_BUF. So LDI_BUF must not be deallocated
|
|
while the struct ld_info object returned is in use. */
|
|
|
|
static struct ld_info
|
|
rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
|
|
const gdb_byte *ldi_buf)
|
|
{
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
|
struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
|
|
const struct ld_info_desc desc
|
|
= tdep->wordsize == 8 ? ld_info64_desc : ld_info32_desc;
|
|
struct ld_info info;
|
|
|
|
info.next = extract_unsigned_integer (ldi_buf + desc.ldinfo_next.offset,
|
|
desc.ldinfo_next.size,
|
|
byte_order);
|
|
info.fd = extract_signed_integer (ldi_buf + desc.ldinfo_fd.offset,
|
|
desc.ldinfo_fd.size,
|
|
byte_order);
|
|
info.textorg = extract_typed_address (ldi_buf + desc.ldinfo_textorg.offset,
|
|
ptr_type);
|
|
info.textsize
|
|
= extract_unsigned_integer (ldi_buf + desc.ldinfo_textsize.offset,
|
|
desc.ldinfo_textsize.size,
|
|
byte_order);
|
|
info.dataorg = extract_typed_address (ldi_buf + desc.ldinfo_dataorg.offset,
|
|
ptr_type);
|
|
info.datasize
|
|
= extract_unsigned_integer (ldi_buf + desc.ldinfo_datasize.offset,
|
|
desc.ldinfo_datasize.size,
|
|
byte_order);
|
|
info.filename = (char *) ldi_buf + desc.ldinfo_filename.offset;
|
|
info.member_name = info.filename + strlen (info.filename) + 1;
|
|
|
|
return info;
|
|
}
|
|
|
|
/* Append to OBJSTACK an XML string description of the shared library
|
|
corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
|
|
format. */
|
|
|
|
static void
|
|
rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
|
|
struct obstack *obstack)
|
|
{
|
|
char *p;
|
|
|
|
obstack_grow_str (obstack, "<library name=\"");
|
|
p = xml_escape_text (ldi->filename);
|
|
obstack_grow_str (obstack, p);
|
|
xfree (p);
|
|
obstack_grow_str (obstack, "\"");
|
|
|
|
if (ldi->member_name[0] != '\0')
|
|
{
|
|
obstack_grow_str (obstack, " member=\"");
|
|
p = xml_escape_text (ldi->member_name);
|
|
obstack_grow_str (obstack, p);
|
|
xfree (p);
|
|
obstack_grow_str (obstack, "\"");
|
|
}
|
|
|
|
obstack_grow_str (obstack, " text_addr=\"");
|
|
obstack_grow_str (obstack, core_addr_to_string (ldi->textorg));
|
|
obstack_grow_str (obstack, "\"");
|
|
|
|
obstack_grow_str (obstack, " text_size=\"");
|
|
obstack_grow_str (obstack, pulongest (ldi->textsize));
|
|
obstack_grow_str (obstack, "\"");
|
|
|
|
obstack_grow_str (obstack, " data_addr=\"");
|
|
obstack_grow_str (obstack, core_addr_to_string (ldi->dataorg));
|
|
obstack_grow_str (obstack, "\"");
|
|
|
|
obstack_grow_str (obstack, " data_size=\"");
|
|
obstack_grow_str (obstack, pulongest (ldi->datasize));
|
|
obstack_grow_str (obstack, "\"");
|
|
|
|
obstack_grow_str (obstack, "></library>");
|
|
}
|
|
|
|
/* Convert the ld_info binary data provided by the AIX loader into
|
|
an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
|
|
format.
|
|
|
|
LDI_BUF is a buffer containing the ld_info data.
|
|
READBUF, OFFSET and LEN follow the same semantics as target_ops'
|
|
to_xfer_partial target_ops method.
|
|
|
|
If CLOSE_LDINFO_FD is nonzero, then this routine also closes
|
|
the ldinfo_fd file descriptor. This is useful when the ldinfo
|
|
data is obtained via ptrace, as ptrace opens a file descriptor
|
|
for each and every entry; but we cannot use this descriptor
|
|
as the consumer of the XML library list might live in a different
|
|
process. */
|
|
|
|
ULONGEST
|
|
rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
|
|
gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
|
|
int close_ldinfo_fd)
|
|
{
|
|
struct obstack obstack;
|
|
const char *buf;
|
|
ULONGEST len_avail;
|
|
|
|
obstack_init (&obstack);
|
|
obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n");
|
|
|
|
while (1)
|
|
{
|
|
struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf);
|
|
|
|
rs6000_aix_shared_library_to_xml (&ldi, &obstack);
|
|
if (close_ldinfo_fd)
|
|
close (ldi.fd);
|
|
|
|
if (!ldi.next)
|
|
break;
|
|
ldi_buf = ldi_buf + ldi.next;
|
|
}
|
|
|
|
obstack_grow_str0 (&obstack, "</library-list-aix>\n");
|
|
|
|
buf = (const char *) obstack_finish (&obstack);
|
|
len_avail = strlen (buf);
|
|
if (offset >= len_avail)
|
|
len= 0;
|
|
else
|
|
{
|
|
if (len > len_avail - offset)
|
|
len = len_avail - offset;
|
|
memcpy (readbuf, buf + offset, len);
|
|
}
|
|
|
|
obstack_free (&obstack, NULL);
|
|
return len;
|
|
}
|
|
|
|
/* Implement the core_xfer_shared_libraries_aix gdbarch method. */
|
|
|
|
static ULONGEST
|
|
rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
|
|
gdb_byte *readbuf,
|
|
ULONGEST offset,
|
|
ULONGEST len)
|
|
{
|
|
struct bfd_section *ldinfo_sec;
|
|
int ldinfo_size;
|
|
gdb_byte *ldinfo_buf;
|
|
struct cleanup *cleanup;
|
|
LONGEST result;
|
|
|
|
ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
|
|
if (ldinfo_sec == NULL)
|
|
error (_("cannot find .ldinfo section from core file: %s"),
|
|
bfd_errmsg (bfd_get_error ()));
|
|
ldinfo_size = bfd_get_section_size (ldinfo_sec);
|
|
|
|
ldinfo_buf = (gdb_byte *) xmalloc (ldinfo_size);
|
|
cleanup = make_cleanup (xfree, ldinfo_buf);
|
|
|
|
if (! bfd_get_section_contents (core_bfd, ldinfo_sec,
|
|
ldinfo_buf, 0, ldinfo_size))
|
|
error (_("unable to read .ldinfo section from core file: %s"),
|
|
bfd_errmsg (bfd_get_error ()));
|
|
|
|
result = rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf, readbuf,
|
|
offset, len, 0);
|
|
|
|
do_cleanups (cleanup);
|
|
return result;
|
|
}
|
|
|
|
static void
|
|
rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
|
|
{
|
|
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
|
|
|
|
/* RS6000/AIX does not support PT_STEP. Has to be simulated. */
|
|
set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
|
|
|
|
/* Displaced stepping is currently not supported in combination with
|
|
software single-stepping. */
|
|
set_gdbarch_displaced_step_copy_insn (gdbarch, NULL);
|
|
set_gdbarch_displaced_step_fixup (gdbarch, NULL);
|
|
set_gdbarch_displaced_step_free_closure (gdbarch, NULL);
|
|
set_gdbarch_displaced_step_location (gdbarch, NULL);
|
|
|
|
set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
|
|
set_gdbarch_return_value (gdbarch, rs6000_return_value);
|
|
set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
|
|
|
|
/* Handle RS/6000 function pointers (which are really function
|
|
descriptors). */
|
|
set_gdbarch_convert_from_func_ptr_addr
|
|
(gdbarch, rs6000_convert_from_func_ptr_addr);
|
|
|
|
/* Core file support. */
|
|
set_gdbarch_iterate_over_regset_sections
|
|
(gdbarch, rs6000_aix_iterate_over_regset_sections);
|
|
set_gdbarch_core_xfer_shared_libraries_aix
|
|
(gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
|
|
|
|
if (tdep->wordsize == 8)
|
|
tdep->lr_frame_offset = 16;
|
|
else
|
|
tdep->lr_frame_offset = 8;
|
|
|
|
if (tdep->wordsize == 4)
|
|
/* PowerOpen / AIX 32 bit. The saved area or red zone consists of
|
|
19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
|
|
Problem is, 220 isn't frame (16 byte) aligned. Round it up to
|
|
224. */
|
|
set_gdbarch_frame_red_zone_size (gdbarch, 224);
|
|
else
|
|
set_gdbarch_frame_red_zone_size (gdbarch, 0);
|
|
|
|
set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
|
|
|
|
set_solib_ops (gdbarch, &solib_aix_so_ops);
|
|
}
|
|
|
|
/* Provide a prototype to silence -Wmissing-prototypes. */
|
|
extern initialize_file_ftype _initialize_rs6000_aix_tdep;
|
|
|
|
void
|
|
_initialize_rs6000_aix_tdep (void)
|
|
{
|
|
gdbarch_register_osabi_sniffer (bfd_arch_rs6000,
|
|
bfd_target_xcoff_flavour,
|
|
rs6000_aix_osabi_sniffer);
|
|
gdbarch_register_osabi_sniffer (bfd_arch_powerpc,
|
|
bfd_target_xcoff_flavour,
|
|
rs6000_aix_osabi_sniffer);
|
|
|
|
gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX,
|
|
rs6000_aix_init_osabi);
|
|
gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX,
|
|
rs6000_aix_init_osabi);
|
|
}
|
|
|