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