15796c8dcSSimon Schubert /* Dynamic architecture support for GDB, the GNU debugger.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1998-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert
225796c8dcSSimon Schubert #include "arch-utils.h"
235796c8dcSSimon Schubert #include "buildsym.h"
245796c8dcSSimon Schubert #include "gdbcmd.h"
25c50c785cSJohn Marino #include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */
265796c8dcSSimon Schubert #include "gdb_string.h"
275796c8dcSSimon Schubert #include "regcache.h"
285796c8dcSSimon Schubert #include "gdb_assert.h"
295796c8dcSSimon Schubert #include "sim-regno.h"
305796c8dcSSimon Schubert #include "gdbcore.h"
315796c8dcSSimon Schubert #include "osabi.h"
325796c8dcSSimon Schubert #include "target-descriptions.h"
335796c8dcSSimon Schubert #include "objfiles.h"
34*ef5ccd6cSJohn Marino #include "language.h"
355796c8dcSSimon Schubert
365796c8dcSSimon Schubert #include "version.h"
375796c8dcSSimon Schubert
385796c8dcSSimon Schubert #include "floatformat.h"
395796c8dcSSimon Schubert
405796c8dcSSimon Schubert
415796c8dcSSimon Schubert struct displaced_step_closure *
simple_displaced_step_copy_insn(struct gdbarch * gdbarch,CORE_ADDR from,CORE_ADDR to,struct regcache * regs)425796c8dcSSimon Schubert simple_displaced_step_copy_insn (struct gdbarch *gdbarch,
435796c8dcSSimon Schubert CORE_ADDR from, CORE_ADDR to,
445796c8dcSSimon Schubert struct regcache *regs)
455796c8dcSSimon Schubert {
465796c8dcSSimon Schubert size_t len = gdbarch_max_insn_length (gdbarch);
475796c8dcSSimon Schubert gdb_byte *buf = xmalloc (len);
485796c8dcSSimon Schubert
495796c8dcSSimon Schubert read_memory (from, buf, len);
505796c8dcSSimon Schubert write_memory (to, buf, len);
515796c8dcSSimon Schubert
525796c8dcSSimon Schubert if (debug_displaced)
535796c8dcSSimon Schubert {
545796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
555796c8dcSSimon Schubert paddress (gdbarch, from), paddress (gdbarch, to));
565796c8dcSSimon Schubert displaced_step_dump_bytes (gdb_stdlog, buf, len);
575796c8dcSSimon Schubert }
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert return (struct displaced_step_closure *) buf;
605796c8dcSSimon Schubert }
615796c8dcSSimon Schubert
625796c8dcSSimon Schubert
635796c8dcSSimon Schubert void
simple_displaced_step_free_closure(struct gdbarch * gdbarch,struct displaced_step_closure * closure)645796c8dcSSimon Schubert simple_displaced_step_free_closure (struct gdbarch *gdbarch,
655796c8dcSSimon Schubert struct displaced_step_closure *closure)
665796c8dcSSimon Schubert {
675796c8dcSSimon Schubert xfree (closure);
685796c8dcSSimon Schubert }
695796c8dcSSimon Schubert
705796c8dcSSimon Schubert int
default_displaced_step_hw_singlestep(struct gdbarch * gdbarch,struct displaced_step_closure * closure)715796c8dcSSimon Schubert default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
725796c8dcSSimon Schubert struct displaced_step_closure *closure)
735796c8dcSSimon Schubert {
745796c8dcSSimon Schubert return !gdbarch_software_single_step_p (gdbarch);
755796c8dcSSimon Schubert }
765796c8dcSSimon Schubert
775796c8dcSSimon Schubert CORE_ADDR
displaced_step_at_entry_point(struct gdbarch * gdbarch)785796c8dcSSimon Schubert displaced_step_at_entry_point (struct gdbarch *gdbarch)
795796c8dcSSimon Schubert {
805796c8dcSSimon Schubert CORE_ADDR addr;
815796c8dcSSimon Schubert int bp_len;
825796c8dcSSimon Schubert
835796c8dcSSimon Schubert addr = entry_point_address ();
845796c8dcSSimon Schubert
855796c8dcSSimon Schubert /* Inferior calls also use the entry point as a breakpoint location.
865796c8dcSSimon Schubert We don't want displaced stepping to interfere with those
875796c8dcSSimon Schubert breakpoints, so leave space. */
885796c8dcSSimon Schubert gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
895796c8dcSSimon Schubert addr += bp_len * 2;
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert return addr;
925796c8dcSSimon Schubert }
935796c8dcSSimon Schubert
945796c8dcSSimon Schubert int
legacy_register_sim_regno(struct gdbarch * gdbarch,int regnum)955796c8dcSSimon Schubert legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
965796c8dcSSimon Schubert {
975796c8dcSSimon Schubert /* Only makes sense to supply raw registers. */
985796c8dcSSimon Schubert gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
995796c8dcSSimon Schubert /* NOTE: cagney/2002-05-13: The old code did it this way and it is
1005796c8dcSSimon Schubert suspected that some GDB/SIM combinations may rely on this
1015796c8dcSSimon Schubert behavour. The default should be one2one_register_sim_regno
1025796c8dcSSimon Schubert (below). */
1035796c8dcSSimon Schubert if (gdbarch_register_name (gdbarch, regnum) != NULL
1045796c8dcSSimon Schubert && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
1055796c8dcSSimon Schubert return regnum;
1065796c8dcSSimon Schubert else
1075796c8dcSSimon Schubert return LEGACY_SIM_REGNO_IGNORE;
1085796c8dcSSimon Schubert }
1095796c8dcSSimon Schubert
1105796c8dcSSimon Schubert CORE_ADDR
generic_skip_trampoline_code(struct frame_info * frame,CORE_ADDR pc)1115796c8dcSSimon Schubert generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
1125796c8dcSSimon Schubert {
1135796c8dcSSimon Schubert return 0;
1145796c8dcSSimon Schubert }
1155796c8dcSSimon Schubert
1165796c8dcSSimon Schubert CORE_ADDR
generic_skip_solib_resolver(struct gdbarch * gdbarch,CORE_ADDR pc)1175796c8dcSSimon Schubert generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
1185796c8dcSSimon Schubert {
1195796c8dcSSimon Schubert return 0;
1205796c8dcSSimon Schubert }
1215796c8dcSSimon Schubert
1225796c8dcSSimon Schubert int
generic_in_solib_return_trampoline(struct gdbarch * gdbarch,CORE_ADDR pc,const char * name)1235796c8dcSSimon Schubert generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
124*ef5ccd6cSJohn Marino CORE_ADDR pc, const char *name)
1255796c8dcSSimon Schubert {
1265796c8dcSSimon Schubert return 0;
1275796c8dcSSimon Schubert }
1285796c8dcSSimon Schubert
1295796c8dcSSimon Schubert int
generic_in_function_epilogue_p(struct gdbarch * gdbarch,CORE_ADDR pc)1305796c8dcSSimon Schubert generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1315796c8dcSSimon Schubert {
1325796c8dcSSimon Schubert return 0;
1335796c8dcSSimon Schubert }
1345796c8dcSSimon Schubert
1355796c8dcSSimon Schubert /* Helper functions for gdbarch_inner_than */
1365796c8dcSSimon Schubert
1375796c8dcSSimon Schubert int
core_addr_lessthan(CORE_ADDR lhs,CORE_ADDR rhs)1385796c8dcSSimon Schubert core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
1395796c8dcSSimon Schubert {
1405796c8dcSSimon Schubert return (lhs < rhs);
1415796c8dcSSimon Schubert }
1425796c8dcSSimon Schubert
1435796c8dcSSimon Schubert int
core_addr_greaterthan(CORE_ADDR lhs,CORE_ADDR rhs)1445796c8dcSSimon Schubert core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
1455796c8dcSSimon Schubert {
1465796c8dcSSimon Schubert return (lhs > rhs);
1475796c8dcSSimon Schubert }
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert /* Misc helper functions for targets. */
1505796c8dcSSimon Schubert
1515796c8dcSSimon Schubert CORE_ADDR
core_addr_identity(struct gdbarch * gdbarch,CORE_ADDR addr)1525796c8dcSSimon Schubert core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
1535796c8dcSSimon Schubert {
1545796c8dcSSimon Schubert return addr;
1555796c8dcSSimon Schubert }
1565796c8dcSSimon Schubert
1575796c8dcSSimon Schubert CORE_ADDR
convert_from_func_ptr_addr_identity(struct gdbarch * gdbarch,CORE_ADDR addr,struct target_ops * targ)1585796c8dcSSimon Schubert convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
1595796c8dcSSimon Schubert struct target_ops *targ)
1605796c8dcSSimon Schubert {
1615796c8dcSSimon Schubert return addr;
1625796c8dcSSimon Schubert }
1635796c8dcSSimon Schubert
1645796c8dcSSimon Schubert int
no_op_reg_to_regnum(struct gdbarch * gdbarch,int reg)1655796c8dcSSimon Schubert no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
1665796c8dcSSimon Schubert {
1675796c8dcSSimon Schubert return reg;
1685796c8dcSSimon Schubert }
1695796c8dcSSimon Schubert
1705796c8dcSSimon Schubert void
default_elf_make_msymbol_special(asymbol * sym,struct minimal_symbol * msym)1715796c8dcSSimon Schubert default_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
1725796c8dcSSimon Schubert {
1735796c8dcSSimon Schubert return;
1745796c8dcSSimon Schubert }
1755796c8dcSSimon Schubert
1765796c8dcSSimon Schubert void
default_coff_make_msymbol_special(int val,struct minimal_symbol * msym)1775796c8dcSSimon Schubert default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
1785796c8dcSSimon Schubert {
1795796c8dcSSimon Schubert return;
1805796c8dcSSimon Schubert }
1815796c8dcSSimon Schubert
1825796c8dcSSimon Schubert int
cannot_register_not(struct gdbarch * gdbarch,int regnum)1835796c8dcSSimon Schubert cannot_register_not (struct gdbarch *gdbarch, int regnum)
1845796c8dcSSimon Schubert {
1855796c8dcSSimon Schubert return 0;
1865796c8dcSSimon Schubert }
1875796c8dcSSimon Schubert
1885796c8dcSSimon Schubert /* Legacy version of target_virtual_frame_pointer(). Assumes that
189c50c785cSJohn Marino there is an gdbarch_deprecated_fp_regnum and that it is the same,
190c50c785cSJohn Marino cooked or raw. */
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert void
legacy_virtual_frame_pointer(struct gdbarch * gdbarch,CORE_ADDR pc,int * frame_regnum,LONGEST * frame_offset)1935796c8dcSSimon Schubert legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
1945796c8dcSSimon Schubert CORE_ADDR pc,
1955796c8dcSSimon Schubert int *frame_regnum,
1965796c8dcSSimon Schubert LONGEST *frame_offset)
1975796c8dcSSimon Schubert {
1985796c8dcSSimon Schubert /* FIXME: cagney/2002-09-13: This code is used when identifying the
1995796c8dcSSimon Schubert frame pointer of the current PC. It is assuming that a single
2005796c8dcSSimon Schubert register and an offset can determine this. I think it should
2015796c8dcSSimon Schubert instead generate a byte code expression as that would work better
2025796c8dcSSimon Schubert with things like Dwarf2's CFI. */
2035796c8dcSSimon Schubert if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
2045796c8dcSSimon Schubert && gdbarch_deprecated_fp_regnum (gdbarch)
2055796c8dcSSimon Schubert < gdbarch_num_regs (gdbarch))
2065796c8dcSSimon Schubert *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
2075796c8dcSSimon Schubert else if (gdbarch_sp_regnum (gdbarch) >= 0
2085796c8dcSSimon Schubert && gdbarch_sp_regnum (gdbarch)
2095796c8dcSSimon Schubert < gdbarch_num_regs (gdbarch))
2105796c8dcSSimon Schubert *frame_regnum = gdbarch_sp_regnum (gdbarch);
2115796c8dcSSimon Schubert else
2125796c8dcSSimon Schubert /* Should this be an internal error? I guess so, it is reflecting
2135796c8dcSSimon Schubert an architectural limitation in the current design. */
214c50c785cSJohn Marino internal_error (__FILE__, __LINE__,
215c50c785cSJohn Marino _("No virtual frame pointer available"));
2165796c8dcSSimon Schubert *frame_offset = 0;
2175796c8dcSSimon Schubert }
2185796c8dcSSimon Schubert
2195796c8dcSSimon Schubert
2205796c8dcSSimon Schubert int
generic_convert_register_p(struct gdbarch * gdbarch,int regnum,struct type * type)2215796c8dcSSimon Schubert generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
2225796c8dcSSimon Schubert struct type *type)
2235796c8dcSSimon Schubert {
2245796c8dcSSimon Schubert return 0;
2255796c8dcSSimon Schubert }
2265796c8dcSSimon Schubert
2275796c8dcSSimon Schubert int
default_stabs_argument_has_addr(struct gdbarch * gdbarch,struct type * type)2285796c8dcSSimon Schubert default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
2295796c8dcSSimon Schubert {
2305796c8dcSSimon Schubert return 0;
2315796c8dcSSimon Schubert }
2325796c8dcSSimon Schubert
2335796c8dcSSimon Schubert int
generic_instruction_nullified(struct gdbarch * gdbarch,struct regcache * regcache)2345796c8dcSSimon Schubert generic_instruction_nullified (struct gdbarch *gdbarch,
2355796c8dcSSimon Schubert struct regcache *regcache)
2365796c8dcSSimon Schubert {
2375796c8dcSSimon Schubert return 0;
2385796c8dcSSimon Schubert }
2395796c8dcSSimon Schubert
2405796c8dcSSimon Schubert int
default_remote_register_number(struct gdbarch * gdbarch,int regno)2415796c8dcSSimon Schubert default_remote_register_number (struct gdbarch *gdbarch,
2425796c8dcSSimon Schubert int regno)
2435796c8dcSSimon Schubert {
2445796c8dcSSimon Schubert return regno;
2455796c8dcSSimon Schubert }
2465796c8dcSSimon Schubert
2475796c8dcSSimon Schubert
2485796c8dcSSimon Schubert /* Functions to manipulate the endianness of the target. */
2495796c8dcSSimon Schubert
2505796c8dcSSimon Schubert static int target_byte_order_user = BFD_ENDIAN_UNKNOWN;
2515796c8dcSSimon Schubert
2525796c8dcSSimon Schubert static const char endian_big[] = "big";
2535796c8dcSSimon Schubert static const char endian_little[] = "little";
2545796c8dcSSimon Schubert static const char endian_auto[] = "auto";
255*ef5ccd6cSJohn Marino static const char *const endian_enum[] =
2565796c8dcSSimon Schubert {
2575796c8dcSSimon Schubert endian_big,
2585796c8dcSSimon Schubert endian_little,
2595796c8dcSSimon Schubert endian_auto,
2605796c8dcSSimon Schubert NULL,
2615796c8dcSSimon Schubert };
2625796c8dcSSimon Schubert static const char *set_endian_string;
2635796c8dcSSimon Schubert
2645796c8dcSSimon Schubert enum bfd_endian
selected_byte_order(void)2655796c8dcSSimon Schubert selected_byte_order (void)
2665796c8dcSSimon Schubert {
2675796c8dcSSimon Schubert return target_byte_order_user;
2685796c8dcSSimon Schubert }
2695796c8dcSSimon Schubert
2705796c8dcSSimon Schubert /* Called by ``show endian''. */
2715796c8dcSSimon Schubert
2725796c8dcSSimon Schubert static void
show_endian(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)2735796c8dcSSimon Schubert show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
2745796c8dcSSimon Schubert const char *value)
2755796c8dcSSimon Schubert {
2765796c8dcSSimon Schubert if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
2775796c8dcSSimon Schubert if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
2785796c8dcSSimon Schubert fprintf_unfiltered (file, _("The target endianness is set automatically "
2795796c8dcSSimon Schubert "(currently big endian)\n"));
2805796c8dcSSimon Schubert else
2815796c8dcSSimon Schubert fprintf_unfiltered (file, _("The target endianness is set automatically "
2825796c8dcSSimon Schubert "(currently little endian)\n"));
2835796c8dcSSimon Schubert else
2845796c8dcSSimon Schubert if (target_byte_order_user == BFD_ENDIAN_BIG)
2855796c8dcSSimon Schubert fprintf_unfiltered (file,
2865796c8dcSSimon Schubert _("The target is assumed to be big endian\n"));
2875796c8dcSSimon Schubert else
2885796c8dcSSimon Schubert fprintf_unfiltered (file,
2895796c8dcSSimon Schubert _("The target is assumed to be little endian\n"));
2905796c8dcSSimon Schubert }
2915796c8dcSSimon Schubert
2925796c8dcSSimon Schubert static void
set_endian(char * ignore_args,int from_tty,struct cmd_list_element * c)2935796c8dcSSimon Schubert set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
2945796c8dcSSimon Schubert {
2955796c8dcSSimon Schubert struct gdbarch_info info;
2965796c8dcSSimon Schubert
2975796c8dcSSimon Schubert gdbarch_info_init (&info);
2985796c8dcSSimon Schubert
2995796c8dcSSimon Schubert if (set_endian_string == endian_auto)
3005796c8dcSSimon Schubert {
3015796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_UNKNOWN;
3025796c8dcSSimon Schubert if (! gdbarch_update_p (info))
3035796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3045796c8dcSSimon Schubert _("set_endian: architecture update failed"));
3055796c8dcSSimon Schubert }
3065796c8dcSSimon Schubert else if (set_endian_string == endian_little)
3075796c8dcSSimon Schubert {
3085796c8dcSSimon Schubert info.byte_order = BFD_ENDIAN_LITTLE;
3095796c8dcSSimon Schubert if (! gdbarch_update_p (info))
3105796c8dcSSimon Schubert printf_unfiltered (_("Little endian target not supported by GDB\n"));
3115796c8dcSSimon Schubert else
3125796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_LITTLE;
3135796c8dcSSimon Schubert }
3145796c8dcSSimon Schubert else if (set_endian_string == endian_big)
3155796c8dcSSimon Schubert {
3165796c8dcSSimon Schubert info.byte_order = BFD_ENDIAN_BIG;
3175796c8dcSSimon Schubert if (! gdbarch_update_p (info))
3185796c8dcSSimon Schubert printf_unfiltered (_("Big endian target not supported by GDB\n"));
3195796c8dcSSimon Schubert else
3205796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_BIG;
3215796c8dcSSimon Schubert }
3225796c8dcSSimon Schubert else
3235796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
3245796c8dcSSimon Schubert _("set_endian: bad value"));
3255796c8dcSSimon Schubert
3265796c8dcSSimon Schubert show_endian (gdb_stdout, from_tty, NULL, NULL);
3275796c8dcSSimon Schubert }
3285796c8dcSSimon Schubert
3295796c8dcSSimon Schubert /* Given SELECTED, a currently selected BFD architecture, and
3305796c8dcSSimon Schubert TARGET_DESC, the current target description, return what
3315796c8dcSSimon Schubert architecture to use.
3325796c8dcSSimon Schubert
3335796c8dcSSimon Schubert SELECTED may be NULL, in which case we return the architecture
3345796c8dcSSimon Schubert associated with TARGET_DESC. If SELECTED specifies a variant
3355796c8dcSSimon Schubert of the architecture associtated with TARGET_DESC, return the
3365796c8dcSSimon Schubert more specific of the two.
3375796c8dcSSimon Schubert
3385796c8dcSSimon Schubert If SELECTED is a different architecture, but it is accepted as
3395796c8dcSSimon Schubert compatible by the target, we can use the target architecture.
3405796c8dcSSimon Schubert
3415796c8dcSSimon Schubert If SELECTED is obviously incompatible, warn the user. */
3425796c8dcSSimon Schubert
3435796c8dcSSimon Schubert static const struct bfd_arch_info *
choose_architecture_for_target(const struct target_desc * target_desc,const struct bfd_arch_info * selected)3445796c8dcSSimon Schubert choose_architecture_for_target (const struct target_desc *target_desc,
3455796c8dcSSimon Schubert const struct bfd_arch_info *selected)
3465796c8dcSSimon Schubert {
3475796c8dcSSimon Schubert const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
3485796c8dcSSimon Schubert const struct bfd_arch_info *compat1, *compat2;
3495796c8dcSSimon Schubert
3505796c8dcSSimon Schubert if (selected == NULL)
3515796c8dcSSimon Schubert return from_target;
3525796c8dcSSimon Schubert
3535796c8dcSSimon Schubert if (from_target == NULL)
3545796c8dcSSimon Schubert return selected;
3555796c8dcSSimon Schubert
3565796c8dcSSimon Schubert /* struct bfd_arch_info objects are singletons: that is, there's
3575796c8dcSSimon Schubert supposed to be exactly one instance for a given machine. So you
3585796c8dcSSimon Schubert can tell whether two are equivalent by comparing pointers. */
3595796c8dcSSimon Schubert if (from_target == selected)
3605796c8dcSSimon Schubert return selected;
3615796c8dcSSimon Schubert
3625796c8dcSSimon Schubert /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
3635796c8dcSSimon Schubert incompatible. But if they are compatible, it returns the 'more
3645796c8dcSSimon Schubert featureful' of the two arches. That is, if A can run code
3655796c8dcSSimon Schubert written for B, but B can't run code written for A, then it'll
3665796c8dcSSimon Schubert return A.
3675796c8dcSSimon Schubert
3685796c8dcSSimon Schubert Some targets (e.g. MIPS as of 2006-12-04) don't fully
3695796c8dcSSimon Schubert implement this, instead always returning NULL or the first
3705796c8dcSSimon Schubert argument. We detect that case by checking both directions. */
3715796c8dcSSimon Schubert
3725796c8dcSSimon Schubert compat1 = selected->compatible (selected, from_target);
3735796c8dcSSimon Schubert compat2 = from_target->compatible (from_target, selected);
3745796c8dcSSimon Schubert
3755796c8dcSSimon Schubert if (compat1 == NULL && compat2 == NULL)
3765796c8dcSSimon Schubert {
377c50c785cSJohn Marino /* BFD considers the architectures incompatible. Check our
378c50c785cSJohn Marino target description whether it accepts SELECTED as compatible
379c50c785cSJohn Marino anyway. */
3805796c8dcSSimon Schubert if (tdesc_compatible_p (target_desc, selected))
3815796c8dcSSimon Schubert return from_target;
3825796c8dcSSimon Schubert
3835796c8dcSSimon Schubert warning (_("Selected architecture %s is not compatible "
3845796c8dcSSimon Schubert "with reported target architecture %s"),
3855796c8dcSSimon Schubert selected->printable_name, from_target->printable_name);
3865796c8dcSSimon Schubert return selected;
3875796c8dcSSimon Schubert }
3885796c8dcSSimon Schubert
3895796c8dcSSimon Schubert if (compat1 == NULL)
3905796c8dcSSimon Schubert return compat2;
3915796c8dcSSimon Schubert if (compat2 == NULL)
3925796c8dcSSimon Schubert return compat1;
3935796c8dcSSimon Schubert if (compat1 == compat2)
3945796c8dcSSimon Schubert return compat1;
3955796c8dcSSimon Schubert
396c50c785cSJohn Marino /* If the two didn't match, but one of them was a default
397c50c785cSJohn Marino architecture, assume the more specific one is correct. This
398c50c785cSJohn Marino handles the case where an executable or target description just
399c50c785cSJohn Marino says "mips", but the other knows which MIPS variant. */
4005796c8dcSSimon Schubert if (compat1->the_default)
4015796c8dcSSimon Schubert return compat2;
4025796c8dcSSimon Schubert if (compat2->the_default)
4035796c8dcSSimon Schubert return compat1;
4045796c8dcSSimon Schubert
4055796c8dcSSimon Schubert /* We have no idea which one is better. This is a bug, but not
4065796c8dcSSimon Schubert a critical problem; warn the user. */
4075796c8dcSSimon Schubert warning (_("Selected architecture %s is ambiguous with "
4085796c8dcSSimon Schubert "reported target architecture %s"),
4095796c8dcSSimon Schubert selected->printable_name, from_target->printable_name);
4105796c8dcSSimon Schubert return selected;
4115796c8dcSSimon Schubert }
4125796c8dcSSimon Schubert
413c50c785cSJohn Marino /* Functions to manipulate the architecture of the target. */
4145796c8dcSSimon Schubert
4155796c8dcSSimon Schubert enum set_arch { set_arch_auto, set_arch_manual };
4165796c8dcSSimon Schubert
4175796c8dcSSimon Schubert static const struct bfd_arch_info *target_architecture_user;
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert static const char *set_architecture_string;
4205796c8dcSSimon Schubert
4215796c8dcSSimon Schubert const char *
selected_architecture_name(void)4225796c8dcSSimon Schubert selected_architecture_name (void)
4235796c8dcSSimon Schubert {
4245796c8dcSSimon Schubert if (target_architecture_user == NULL)
4255796c8dcSSimon Schubert return NULL;
4265796c8dcSSimon Schubert else
4275796c8dcSSimon Schubert return set_architecture_string;
4285796c8dcSSimon Schubert }
4295796c8dcSSimon Schubert
4305796c8dcSSimon Schubert /* Called if the user enters ``show architecture'' without an
4315796c8dcSSimon Schubert argument. */
4325796c8dcSSimon Schubert
4335796c8dcSSimon Schubert static void
show_architecture(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4345796c8dcSSimon Schubert show_architecture (struct ui_file *file, int from_tty,
4355796c8dcSSimon Schubert struct cmd_list_element *c, const char *value)
4365796c8dcSSimon Schubert {
4375796c8dcSSimon Schubert if (target_architecture_user == NULL)
438c50c785cSJohn Marino fprintf_filtered (file, _("The target architecture is set "
439c50c785cSJohn Marino "automatically (currently %s)\n"),
4405796c8dcSSimon Schubert gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
4415796c8dcSSimon Schubert else
442c50c785cSJohn Marino fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
443c50c785cSJohn Marino set_architecture_string);
4445796c8dcSSimon Schubert }
4455796c8dcSSimon Schubert
4465796c8dcSSimon Schubert
4475796c8dcSSimon Schubert /* Called if the user enters ``set architecture'' with or without an
4485796c8dcSSimon Schubert argument. */
4495796c8dcSSimon Schubert
4505796c8dcSSimon Schubert static void
set_architecture(char * ignore_args,int from_tty,struct cmd_list_element * c)4515796c8dcSSimon Schubert set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
4525796c8dcSSimon Schubert {
4535796c8dcSSimon Schubert struct gdbarch_info info;
4545796c8dcSSimon Schubert
4555796c8dcSSimon Schubert gdbarch_info_init (&info);
4565796c8dcSSimon Schubert
4575796c8dcSSimon Schubert if (strcmp (set_architecture_string, "auto") == 0)
4585796c8dcSSimon Schubert {
4595796c8dcSSimon Schubert target_architecture_user = NULL;
4605796c8dcSSimon Schubert if (!gdbarch_update_p (info))
4615796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
4625796c8dcSSimon Schubert _("could not select an architecture automatically"));
4635796c8dcSSimon Schubert }
4645796c8dcSSimon Schubert else
4655796c8dcSSimon Schubert {
4665796c8dcSSimon Schubert info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
4675796c8dcSSimon Schubert if (info.bfd_arch_info == NULL)
4685796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
4695796c8dcSSimon Schubert _("set_architecture: bfd_scan_arch failed"));
4705796c8dcSSimon Schubert if (gdbarch_update_p (info))
4715796c8dcSSimon Schubert target_architecture_user = info.bfd_arch_info;
4725796c8dcSSimon Schubert else
4735796c8dcSSimon Schubert printf_unfiltered (_("Architecture `%s' not recognized.\n"),
4745796c8dcSSimon Schubert set_architecture_string);
4755796c8dcSSimon Schubert }
4765796c8dcSSimon Schubert show_architecture (gdb_stdout, from_tty, NULL, NULL);
4775796c8dcSSimon Schubert }
4785796c8dcSSimon Schubert
4795796c8dcSSimon Schubert /* Try to select a global architecture that matches "info". Return
4805796c8dcSSimon Schubert non-zero if the attempt succeds. */
4815796c8dcSSimon Schubert int
gdbarch_update_p(struct gdbarch_info info)4825796c8dcSSimon Schubert gdbarch_update_p (struct gdbarch_info info)
4835796c8dcSSimon Schubert {
4845796c8dcSSimon Schubert struct gdbarch *new_gdbarch;
4855796c8dcSSimon Schubert
4865796c8dcSSimon Schubert /* Check for the current file. */
4875796c8dcSSimon Schubert if (info.abfd == NULL)
4885796c8dcSSimon Schubert info.abfd = exec_bfd;
4895796c8dcSSimon Schubert if (info.abfd == NULL)
4905796c8dcSSimon Schubert info.abfd = core_bfd;
4915796c8dcSSimon Schubert
4925796c8dcSSimon Schubert /* Check for the current target description. */
4935796c8dcSSimon Schubert if (info.target_desc == NULL)
4945796c8dcSSimon Schubert info.target_desc = target_current_description ();
4955796c8dcSSimon Schubert
4965796c8dcSSimon Schubert new_gdbarch = gdbarch_find_by_info (info);
4975796c8dcSSimon Schubert
4985796c8dcSSimon Schubert /* If there no architecture by that name, reject the request. */
4995796c8dcSSimon Schubert if (new_gdbarch == NULL)
5005796c8dcSSimon Schubert {
5015796c8dcSSimon Schubert if (gdbarch_debug)
5025796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
5035796c8dcSSimon Schubert "Architecture not found\n");
5045796c8dcSSimon Schubert return 0;
5055796c8dcSSimon Schubert }
5065796c8dcSSimon Schubert
5075796c8dcSSimon Schubert /* If it is the same old architecture, accept the request (but don't
5085796c8dcSSimon Schubert swap anything). */
509*ef5ccd6cSJohn Marino if (new_gdbarch == target_gdbarch ())
5105796c8dcSSimon Schubert {
5115796c8dcSSimon Schubert if (gdbarch_debug)
5125796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
5135796c8dcSSimon Schubert "Architecture %s (%s) unchanged\n",
5145796c8dcSSimon Schubert host_address_to_string (new_gdbarch),
5155796c8dcSSimon Schubert gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
5165796c8dcSSimon Schubert return 1;
5175796c8dcSSimon Schubert }
5185796c8dcSSimon Schubert
5195796c8dcSSimon Schubert /* It's a new architecture, swap it in. */
5205796c8dcSSimon Schubert if (gdbarch_debug)
5215796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
5225796c8dcSSimon Schubert "New architecture %s (%s) selected\n",
5235796c8dcSSimon Schubert host_address_to_string (new_gdbarch),
5245796c8dcSSimon Schubert gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
525*ef5ccd6cSJohn Marino set_target_gdbarch (new_gdbarch);
5265796c8dcSSimon Schubert
5275796c8dcSSimon Schubert return 1;
5285796c8dcSSimon Schubert }
5295796c8dcSSimon Schubert
5305796c8dcSSimon Schubert /* Return the architecture for ABFD. If no suitable architecture
5315796c8dcSSimon Schubert could be find, return NULL. */
5325796c8dcSSimon Schubert
5335796c8dcSSimon Schubert struct gdbarch *
gdbarch_from_bfd(bfd * abfd)5345796c8dcSSimon Schubert gdbarch_from_bfd (bfd *abfd)
5355796c8dcSSimon Schubert {
5365796c8dcSSimon Schubert struct gdbarch_info info;
5375796c8dcSSimon Schubert gdbarch_info_init (&info);
538cf7f2e2dSJohn Marino
5395796c8dcSSimon Schubert info.abfd = abfd;
5405796c8dcSSimon Schubert return gdbarch_find_by_info (info);
5415796c8dcSSimon Schubert }
5425796c8dcSSimon Schubert
5435796c8dcSSimon Schubert /* Set the dynamic target-system-dependent parameters (architecture,
5445796c8dcSSimon Schubert byte-order) using information found in the BFD */
5455796c8dcSSimon Schubert
5465796c8dcSSimon Schubert void
set_gdbarch_from_file(bfd * abfd)5475796c8dcSSimon Schubert set_gdbarch_from_file (bfd *abfd)
5485796c8dcSSimon Schubert {
5495796c8dcSSimon Schubert struct gdbarch_info info;
5505796c8dcSSimon Schubert struct gdbarch *gdbarch;
5515796c8dcSSimon Schubert
5525796c8dcSSimon Schubert gdbarch_info_init (&info);
5535796c8dcSSimon Schubert info.abfd = abfd;
5545796c8dcSSimon Schubert info.target_desc = target_current_description ();
5555796c8dcSSimon Schubert gdbarch = gdbarch_find_by_info (info);
5565796c8dcSSimon Schubert
5575796c8dcSSimon Schubert if (gdbarch == NULL)
5585796c8dcSSimon Schubert error (_("Architecture of file not recognized."));
559*ef5ccd6cSJohn Marino set_target_gdbarch (gdbarch);
5605796c8dcSSimon Schubert }
5615796c8dcSSimon Schubert
5625796c8dcSSimon Schubert /* Initialize the current architecture. Update the ``set
5635796c8dcSSimon Schubert architecture'' command so that it specifies a list of valid
5645796c8dcSSimon Schubert architectures. */
5655796c8dcSSimon Schubert
5665796c8dcSSimon Schubert #ifdef DEFAULT_BFD_ARCH
5675796c8dcSSimon Schubert extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
5685796c8dcSSimon Schubert static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
5695796c8dcSSimon Schubert #else
5705796c8dcSSimon Schubert static const bfd_arch_info_type *default_bfd_arch;
5715796c8dcSSimon Schubert #endif
5725796c8dcSSimon Schubert
5735796c8dcSSimon Schubert #ifdef DEFAULT_BFD_VEC
5745796c8dcSSimon Schubert extern const bfd_target DEFAULT_BFD_VEC;
5755796c8dcSSimon Schubert static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
5765796c8dcSSimon Schubert #else
5775796c8dcSSimon Schubert static const bfd_target *default_bfd_vec;
5785796c8dcSSimon Schubert #endif
5795796c8dcSSimon Schubert
5805796c8dcSSimon Schubert static int default_byte_order = BFD_ENDIAN_UNKNOWN;
5815796c8dcSSimon Schubert
5825796c8dcSSimon Schubert void
initialize_current_architecture(void)5835796c8dcSSimon Schubert initialize_current_architecture (void)
5845796c8dcSSimon Schubert {
5855796c8dcSSimon Schubert const char **arches = gdbarch_printable_names ();
586cf7f2e2dSJohn Marino struct gdbarch_info info;
5875796c8dcSSimon Schubert
5885796c8dcSSimon Schubert /* determine a default architecture and byte order. */
5895796c8dcSSimon Schubert gdbarch_info_init (&info);
5905796c8dcSSimon Schubert
5915796c8dcSSimon Schubert /* Find a default architecture. */
5925796c8dcSSimon Schubert if (default_bfd_arch == NULL)
5935796c8dcSSimon Schubert {
5945796c8dcSSimon Schubert /* Choose the architecture by taking the first one
5955796c8dcSSimon Schubert alphabetically. */
5965796c8dcSSimon Schubert const char *chosen = arches[0];
5975796c8dcSSimon Schubert const char **arch;
5985796c8dcSSimon Schubert for (arch = arches; *arch != NULL; arch++)
5995796c8dcSSimon Schubert {
6005796c8dcSSimon Schubert if (strcmp (*arch, chosen) < 0)
6015796c8dcSSimon Schubert chosen = *arch;
6025796c8dcSSimon Schubert }
6035796c8dcSSimon Schubert if (chosen == NULL)
6045796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
6055796c8dcSSimon Schubert _("initialize_current_architecture: No arch"));
6065796c8dcSSimon Schubert default_bfd_arch = bfd_scan_arch (chosen);
6075796c8dcSSimon Schubert if (default_bfd_arch == NULL)
6085796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
6095796c8dcSSimon Schubert _("initialize_current_architecture: Arch not found"));
6105796c8dcSSimon Schubert }
6115796c8dcSSimon Schubert
6125796c8dcSSimon Schubert info.bfd_arch_info = default_bfd_arch;
6135796c8dcSSimon Schubert
6145796c8dcSSimon Schubert /* Take several guesses at a byte order. */
6155796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN
6165796c8dcSSimon Schubert && default_bfd_vec != NULL)
6175796c8dcSSimon Schubert {
6185796c8dcSSimon Schubert /* Extract BFD's default vector's byte order. */
6195796c8dcSSimon Schubert switch (default_bfd_vec->byteorder)
6205796c8dcSSimon Schubert {
6215796c8dcSSimon Schubert case BFD_ENDIAN_BIG:
6225796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_BIG;
6235796c8dcSSimon Schubert break;
6245796c8dcSSimon Schubert case BFD_ENDIAN_LITTLE:
6255796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_LITTLE;
6265796c8dcSSimon Schubert break;
6275796c8dcSSimon Schubert default:
6285796c8dcSSimon Schubert break;
6295796c8dcSSimon Schubert }
6305796c8dcSSimon Schubert }
6315796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN)
6325796c8dcSSimon Schubert {
6335796c8dcSSimon Schubert /* look for ``*el-*'' in the target name. */
6345796c8dcSSimon Schubert const char *chp;
6355796c8dcSSimon Schubert chp = strchr (target_name, '-');
6365796c8dcSSimon Schubert if (chp != NULL
6375796c8dcSSimon Schubert && chp - 2 >= target_name
6385796c8dcSSimon Schubert && strncmp (chp - 2, "el", 2) == 0)
6395796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_LITTLE;
6405796c8dcSSimon Schubert }
6415796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN)
6425796c8dcSSimon Schubert {
6435796c8dcSSimon Schubert /* Wire it to big-endian!!! */
6445796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_BIG;
6455796c8dcSSimon Schubert }
6465796c8dcSSimon Schubert
6475796c8dcSSimon Schubert info.byte_order = default_byte_order;
6485796c8dcSSimon Schubert info.byte_order_for_code = info.byte_order;
6495796c8dcSSimon Schubert
6505796c8dcSSimon Schubert if (! gdbarch_update_p (info))
6515796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
6525796c8dcSSimon Schubert _("initialize_current_architecture: Selection of "
6535796c8dcSSimon Schubert "initial architecture failed"));
6545796c8dcSSimon Schubert
6555796c8dcSSimon Schubert /* Create the ``set architecture'' command appending ``auto'' to the
6565796c8dcSSimon Schubert list of architectures. */
6575796c8dcSSimon Schubert {
6585796c8dcSSimon Schubert /* Append ``auto''. */
6595796c8dcSSimon Schubert int nr;
6605796c8dcSSimon Schubert for (nr = 0; arches[nr] != NULL; nr++);
6615796c8dcSSimon Schubert arches = xrealloc (arches, sizeof (char*) * (nr + 2));
6625796c8dcSSimon Schubert arches[nr + 0] = "auto";
6635796c8dcSSimon Schubert arches[nr + 1] = NULL;
6645796c8dcSSimon Schubert add_setshow_enum_cmd ("architecture", class_support,
665c50c785cSJohn Marino arches, &set_architecture_string,
666c50c785cSJohn Marino _("Set architecture of target."),
667c50c785cSJohn Marino _("Show architecture of target."), NULL,
6685796c8dcSSimon Schubert set_architecture, show_architecture,
6695796c8dcSSimon Schubert &setlist, &showlist);
6705796c8dcSSimon Schubert add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
6715796c8dcSSimon Schubert }
6725796c8dcSSimon Schubert }
6735796c8dcSSimon Schubert
6745796c8dcSSimon Schubert
6755796c8dcSSimon Schubert /* Initialize a gdbarch info to values that will be automatically
6765796c8dcSSimon Schubert overridden. Note: Originally, this ``struct info'' was initialized
6775796c8dcSSimon Schubert using memset(0). Unfortunately, that ran into problems, namely
6785796c8dcSSimon Schubert BFD_ENDIAN_BIG is zero. An explicit initialization function that
6795796c8dcSSimon Schubert can explicitly set each field to a well defined value is used. */
6805796c8dcSSimon Schubert
6815796c8dcSSimon Schubert void
gdbarch_info_init(struct gdbarch_info * info)6825796c8dcSSimon Schubert gdbarch_info_init (struct gdbarch_info *info)
6835796c8dcSSimon Schubert {
6845796c8dcSSimon Schubert memset (info, 0, sizeof (struct gdbarch_info));
6855796c8dcSSimon Schubert info->byte_order = BFD_ENDIAN_UNKNOWN;
6865796c8dcSSimon Schubert info->byte_order_for_code = info->byte_order;
6875796c8dcSSimon Schubert info->osabi = GDB_OSABI_UNINITIALIZED;
6885796c8dcSSimon Schubert }
6895796c8dcSSimon Schubert
6905796c8dcSSimon Schubert /* Similar to init, but this time fill in the blanks. Information is
6915796c8dcSSimon Schubert obtained from the global "set ..." options and explicitly
6925796c8dcSSimon Schubert initialized INFO fields. */
6935796c8dcSSimon Schubert
6945796c8dcSSimon Schubert void
gdbarch_info_fill(struct gdbarch_info * info)6955796c8dcSSimon Schubert gdbarch_info_fill (struct gdbarch_info *info)
6965796c8dcSSimon Schubert {
6975796c8dcSSimon Schubert /* "(gdb) set architecture ...". */
6985796c8dcSSimon Schubert if (info->bfd_arch_info == NULL
6995796c8dcSSimon Schubert && target_architecture_user)
7005796c8dcSSimon Schubert info->bfd_arch_info = target_architecture_user;
7015796c8dcSSimon Schubert /* From the file. */
7025796c8dcSSimon Schubert if (info->bfd_arch_info == NULL
7035796c8dcSSimon Schubert && info->abfd != NULL
7045796c8dcSSimon Schubert && bfd_get_arch (info->abfd) != bfd_arch_unknown
7055796c8dcSSimon Schubert && bfd_get_arch (info->abfd) != bfd_arch_obscure)
7065796c8dcSSimon Schubert info->bfd_arch_info = bfd_get_arch_info (info->abfd);
7075796c8dcSSimon Schubert /* From the target. */
7085796c8dcSSimon Schubert if (info->target_desc != NULL)
7095796c8dcSSimon Schubert info->bfd_arch_info = choose_architecture_for_target
7105796c8dcSSimon Schubert (info->target_desc, info->bfd_arch_info);
7115796c8dcSSimon Schubert /* From the default. */
7125796c8dcSSimon Schubert if (info->bfd_arch_info == NULL)
7135796c8dcSSimon Schubert info->bfd_arch_info = default_bfd_arch;
7145796c8dcSSimon Schubert
7155796c8dcSSimon Schubert /* "(gdb) set byte-order ...". */
7165796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN
7175796c8dcSSimon Schubert && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
7185796c8dcSSimon Schubert info->byte_order = target_byte_order_user;
7195796c8dcSSimon Schubert /* From the INFO struct. */
7205796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN
7215796c8dcSSimon Schubert && info->abfd != NULL)
7225796c8dcSSimon Schubert info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
7235796c8dcSSimon Schubert : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
7245796c8dcSSimon Schubert : BFD_ENDIAN_UNKNOWN);
7255796c8dcSSimon Schubert /* From the default. */
7265796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN)
7275796c8dcSSimon Schubert info->byte_order = default_byte_order;
7285796c8dcSSimon Schubert info->byte_order_for_code = info->byte_order;
7295796c8dcSSimon Schubert
7305796c8dcSSimon Schubert /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
7315796c8dcSSimon Schubert /* From the manual override, or from file. */
7325796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNINITIALIZED)
7335796c8dcSSimon Schubert info->osabi = gdbarch_lookup_osabi (info->abfd);
7345796c8dcSSimon Schubert /* From the target. */
7355796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
7365796c8dcSSimon Schubert info->osabi = tdesc_osabi (info->target_desc);
7375796c8dcSSimon Schubert /* From the configured default. */
7385796c8dcSSimon Schubert #ifdef GDB_OSABI_DEFAULT
7395796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNKNOWN)
7405796c8dcSSimon Schubert info->osabi = GDB_OSABI_DEFAULT;
7415796c8dcSSimon Schubert #endif
7425796c8dcSSimon Schubert
7435796c8dcSSimon Schubert /* Must have at least filled in the architecture. */
7445796c8dcSSimon Schubert gdb_assert (info->bfd_arch_info != NULL);
7455796c8dcSSimon Schubert }
7465796c8dcSSimon Schubert
747c50c785cSJohn Marino /* Return "current" architecture. If the target is running, this is
748c50c785cSJohn Marino the architecture of the selected frame. Otherwise, the "current"
749c50c785cSJohn Marino architecture defaults to the target architecture.
7505796c8dcSSimon Schubert
751c50c785cSJohn Marino This function should normally be called solely by the command
752c50c785cSJohn Marino interpreter routines to determine the architecture to execute a
753c50c785cSJohn Marino command in. */
7545796c8dcSSimon Schubert struct gdbarch *
get_current_arch(void)7555796c8dcSSimon Schubert get_current_arch (void)
7565796c8dcSSimon Schubert {
7575796c8dcSSimon Schubert if (has_stack_frames ())
7585796c8dcSSimon Schubert return get_frame_arch (get_selected_frame (NULL));
7595796c8dcSSimon Schubert else
760*ef5ccd6cSJohn Marino return target_gdbarch ();
7615796c8dcSSimon Schubert }
7625796c8dcSSimon Schubert
763cf7f2e2dSJohn Marino int
default_has_shared_address_space(struct gdbarch * gdbarch)764cf7f2e2dSJohn Marino default_has_shared_address_space (struct gdbarch *gdbarch)
765cf7f2e2dSJohn Marino {
766cf7f2e2dSJohn Marino /* Simply say no. In most unix-like targets each inferior/process
767cf7f2e2dSJohn Marino has its own address space. */
768cf7f2e2dSJohn Marino return 0;
769cf7f2e2dSJohn Marino }
770cf7f2e2dSJohn Marino
771cf7f2e2dSJohn Marino int
default_fast_tracepoint_valid_at(struct gdbarch * gdbarch,CORE_ADDR addr,int * isize,char ** msg)772cf7f2e2dSJohn Marino default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
773cf7f2e2dSJohn Marino CORE_ADDR addr, int *isize, char **msg)
774cf7f2e2dSJohn Marino {
775cf7f2e2dSJohn Marino /* We don't know if maybe the target has some way to do fast
776cf7f2e2dSJohn Marino tracepoints that doesn't need gdbarch, so always say yes. */
777cf7f2e2dSJohn Marino if (msg)
778cf7f2e2dSJohn Marino *msg = NULL;
779cf7f2e2dSJohn Marino return 1;
780cf7f2e2dSJohn Marino }
781cf7f2e2dSJohn Marino
782cf7f2e2dSJohn Marino void
default_remote_breakpoint_from_pc(struct gdbarch * gdbarch,CORE_ADDR * pcptr,int * kindptr)783cf7f2e2dSJohn Marino default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
784cf7f2e2dSJohn Marino int *kindptr)
785cf7f2e2dSJohn Marino {
786cf7f2e2dSJohn Marino gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
787cf7f2e2dSJohn Marino }
788cf7f2e2dSJohn Marino
789a45ae5f8SJohn Marino void
default_gen_return_address(struct gdbarch * gdbarch,struct agent_expr * ax,struct axs_value * value,CORE_ADDR scope)790a45ae5f8SJohn Marino default_gen_return_address (struct gdbarch *gdbarch,
791a45ae5f8SJohn Marino struct agent_expr *ax, struct axs_value *value,
792a45ae5f8SJohn Marino CORE_ADDR scope)
793a45ae5f8SJohn Marino {
794a45ae5f8SJohn Marino error (_("This architecture has no method to collect a return address."));
795a45ae5f8SJohn Marino }
796a45ae5f8SJohn Marino
797*ef5ccd6cSJohn Marino int
default_return_in_first_hidden_param_p(struct gdbarch * gdbarch,struct type * type)798*ef5ccd6cSJohn Marino default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
799*ef5ccd6cSJohn Marino struct type *type)
800*ef5ccd6cSJohn Marino {
801*ef5ccd6cSJohn Marino /* Usually, the return value's address is stored the in the "first hidden"
802*ef5ccd6cSJohn Marino parameter if the return value should be passed by reference, as
803*ef5ccd6cSJohn Marino specified in ABI. */
804*ef5ccd6cSJohn Marino return language_pass_by_reference (type);
805*ef5ccd6cSJohn Marino }
806*ef5ccd6cSJohn Marino
8075796c8dcSSimon Schubert /* */
8085796c8dcSSimon Schubert
809c50c785cSJohn Marino /* -Wmissing-prototypes */
810c50c785cSJohn Marino extern initialize_file_ftype _initialize_gdbarch_utils;
8115796c8dcSSimon Schubert
8125796c8dcSSimon Schubert void
_initialize_gdbarch_utils(void)8135796c8dcSSimon Schubert _initialize_gdbarch_utils (void)
8145796c8dcSSimon Schubert {
8155796c8dcSSimon Schubert add_setshow_enum_cmd ("endian", class_support,
816c50c785cSJohn Marino endian_enum, &set_endian_string,
817c50c785cSJohn Marino _("Set endianness of target."),
818c50c785cSJohn Marino _("Show endianness of target."),
819c50c785cSJohn Marino NULL, set_endian, show_endian,
8205796c8dcSSimon Schubert &setlist, &showlist);
8215796c8dcSSimon Schubert }
822