1*5796c8dcSSimon Schubert /* Dynamic architecture support for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 4*5796c8dcSSimon Schubert 2008, 2009 Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert This file is part of GDB. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 9*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 10*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 11*5796c8dcSSimon Schubert (at your option) any later version. 12*5796c8dcSSimon Schubert 13*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 14*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 15*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*5796c8dcSSimon Schubert GNU General Public License for more details. 17*5796c8dcSSimon Schubert 18*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 19*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20*5796c8dcSSimon Schubert 21*5796c8dcSSimon Schubert #include "defs.h" 22*5796c8dcSSimon Schubert 23*5796c8dcSSimon Schubert #include "arch-utils.h" 24*5796c8dcSSimon Schubert #include "buildsym.h" 25*5796c8dcSSimon Schubert #include "gdbcmd.h" 26*5796c8dcSSimon Schubert #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */ 27*5796c8dcSSimon Schubert #include "gdb_string.h" 28*5796c8dcSSimon Schubert #include "regcache.h" 29*5796c8dcSSimon Schubert #include "gdb_assert.h" 30*5796c8dcSSimon Schubert #include "sim-regno.h" 31*5796c8dcSSimon Schubert #include "gdbcore.h" 32*5796c8dcSSimon Schubert #include "osabi.h" 33*5796c8dcSSimon Schubert #include "target-descriptions.h" 34*5796c8dcSSimon Schubert #include "objfiles.h" 35*5796c8dcSSimon Schubert 36*5796c8dcSSimon Schubert #include "version.h" 37*5796c8dcSSimon Schubert 38*5796c8dcSSimon Schubert #include "floatformat.h" 39*5796c8dcSSimon Schubert 40*5796c8dcSSimon Schubert 41*5796c8dcSSimon Schubert struct displaced_step_closure * 42*5796c8dcSSimon Schubert simple_displaced_step_copy_insn (struct gdbarch *gdbarch, 43*5796c8dcSSimon Schubert CORE_ADDR from, CORE_ADDR to, 44*5796c8dcSSimon Schubert struct regcache *regs) 45*5796c8dcSSimon Schubert { 46*5796c8dcSSimon Schubert size_t len = gdbarch_max_insn_length (gdbarch); 47*5796c8dcSSimon Schubert gdb_byte *buf = xmalloc (len); 48*5796c8dcSSimon Schubert 49*5796c8dcSSimon Schubert read_memory (from, buf, len); 50*5796c8dcSSimon Schubert write_memory (to, buf, len); 51*5796c8dcSSimon Schubert 52*5796c8dcSSimon Schubert if (debug_displaced) 53*5796c8dcSSimon Schubert { 54*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", 55*5796c8dcSSimon Schubert paddress (gdbarch, from), paddress (gdbarch, to)); 56*5796c8dcSSimon Schubert displaced_step_dump_bytes (gdb_stdlog, buf, len); 57*5796c8dcSSimon Schubert } 58*5796c8dcSSimon Schubert 59*5796c8dcSSimon Schubert return (struct displaced_step_closure *) buf; 60*5796c8dcSSimon Schubert } 61*5796c8dcSSimon Schubert 62*5796c8dcSSimon Schubert 63*5796c8dcSSimon Schubert void 64*5796c8dcSSimon Schubert simple_displaced_step_free_closure (struct gdbarch *gdbarch, 65*5796c8dcSSimon Schubert struct displaced_step_closure *closure) 66*5796c8dcSSimon Schubert { 67*5796c8dcSSimon Schubert xfree (closure); 68*5796c8dcSSimon Schubert } 69*5796c8dcSSimon Schubert 70*5796c8dcSSimon Schubert int 71*5796c8dcSSimon Schubert default_displaced_step_hw_singlestep (struct gdbarch *gdbarch, 72*5796c8dcSSimon Schubert struct displaced_step_closure *closure) 73*5796c8dcSSimon Schubert { 74*5796c8dcSSimon Schubert return !gdbarch_software_single_step_p (gdbarch); 75*5796c8dcSSimon Schubert } 76*5796c8dcSSimon Schubert 77*5796c8dcSSimon Schubert CORE_ADDR 78*5796c8dcSSimon Schubert displaced_step_at_entry_point (struct gdbarch *gdbarch) 79*5796c8dcSSimon Schubert { 80*5796c8dcSSimon Schubert CORE_ADDR addr; 81*5796c8dcSSimon Schubert int bp_len; 82*5796c8dcSSimon Schubert 83*5796c8dcSSimon Schubert addr = entry_point_address (); 84*5796c8dcSSimon Schubert 85*5796c8dcSSimon Schubert /* Inferior calls also use the entry point as a breakpoint location. 86*5796c8dcSSimon Schubert We don't want displaced stepping to interfere with those 87*5796c8dcSSimon Schubert breakpoints, so leave space. */ 88*5796c8dcSSimon Schubert gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len); 89*5796c8dcSSimon Schubert addr += bp_len * 2; 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert return addr; 92*5796c8dcSSimon Schubert } 93*5796c8dcSSimon Schubert 94*5796c8dcSSimon Schubert int 95*5796c8dcSSimon Schubert legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum) 96*5796c8dcSSimon Schubert { 97*5796c8dcSSimon Schubert /* Only makes sense to supply raw registers. */ 98*5796c8dcSSimon Schubert gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); 99*5796c8dcSSimon Schubert /* NOTE: cagney/2002-05-13: The old code did it this way and it is 100*5796c8dcSSimon Schubert suspected that some GDB/SIM combinations may rely on this 101*5796c8dcSSimon Schubert behavour. The default should be one2one_register_sim_regno 102*5796c8dcSSimon Schubert (below). */ 103*5796c8dcSSimon Schubert if (gdbarch_register_name (gdbarch, regnum) != NULL 104*5796c8dcSSimon Schubert && gdbarch_register_name (gdbarch, regnum)[0] != '\0') 105*5796c8dcSSimon Schubert return regnum; 106*5796c8dcSSimon Schubert else 107*5796c8dcSSimon Schubert return LEGACY_SIM_REGNO_IGNORE; 108*5796c8dcSSimon Schubert } 109*5796c8dcSSimon Schubert 110*5796c8dcSSimon Schubert CORE_ADDR 111*5796c8dcSSimon Schubert generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) 112*5796c8dcSSimon Schubert { 113*5796c8dcSSimon Schubert return 0; 114*5796c8dcSSimon Schubert } 115*5796c8dcSSimon Schubert 116*5796c8dcSSimon Schubert CORE_ADDR 117*5796c8dcSSimon Schubert generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) 118*5796c8dcSSimon Schubert { 119*5796c8dcSSimon Schubert return 0; 120*5796c8dcSSimon Schubert } 121*5796c8dcSSimon Schubert 122*5796c8dcSSimon Schubert int 123*5796c8dcSSimon Schubert generic_in_solib_return_trampoline (struct gdbarch *gdbarch, 124*5796c8dcSSimon Schubert CORE_ADDR pc, char *name) 125*5796c8dcSSimon Schubert { 126*5796c8dcSSimon Schubert return 0; 127*5796c8dcSSimon Schubert } 128*5796c8dcSSimon Schubert 129*5796c8dcSSimon Schubert int 130*5796c8dcSSimon Schubert generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) 131*5796c8dcSSimon Schubert { 132*5796c8dcSSimon Schubert return 0; 133*5796c8dcSSimon Schubert } 134*5796c8dcSSimon Schubert 135*5796c8dcSSimon Schubert /* Helper functions for gdbarch_inner_than */ 136*5796c8dcSSimon Schubert 137*5796c8dcSSimon Schubert int 138*5796c8dcSSimon Schubert core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs) 139*5796c8dcSSimon Schubert { 140*5796c8dcSSimon Schubert return (lhs < rhs); 141*5796c8dcSSimon Schubert } 142*5796c8dcSSimon Schubert 143*5796c8dcSSimon Schubert int 144*5796c8dcSSimon Schubert core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs) 145*5796c8dcSSimon Schubert { 146*5796c8dcSSimon Schubert return (lhs > rhs); 147*5796c8dcSSimon Schubert } 148*5796c8dcSSimon Schubert 149*5796c8dcSSimon Schubert /* Misc helper functions for targets. */ 150*5796c8dcSSimon Schubert 151*5796c8dcSSimon Schubert CORE_ADDR 152*5796c8dcSSimon Schubert core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr) 153*5796c8dcSSimon Schubert { 154*5796c8dcSSimon Schubert return addr; 155*5796c8dcSSimon Schubert } 156*5796c8dcSSimon Schubert 157*5796c8dcSSimon Schubert CORE_ADDR 158*5796c8dcSSimon Schubert convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr, 159*5796c8dcSSimon Schubert struct target_ops *targ) 160*5796c8dcSSimon Schubert { 161*5796c8dcSSimon Schubert return addr; 162*5796c8dcSSimon Schubert } 163*5796c8dcSSimon Schubert 164*5796c8dcSSimon Schubert int 165*5796c8dcSSimon Schubert no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg) 166*5796c8dcSSimon Schubert { 167*5796c8dcSSimon Schubert return reg; 168*5796c8dcSSimon Schubert } 169*5796c8dcSSimon Schubert 170*5796c8dcSSimon Schubert void 171*5796c8dcSSimon Schubert default_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) 172*5796c8dcSSimon Schubert { 173*5796c8dcSSimon Schubert return; 174*5796c8dcSSimon Schubert } 175*5796c8dcSSimon Schubert 176*5796c8dcSSimon Schubert void 177*5796c8dcSSimon Schubert default_coff_make_msymbol_special (int val, struct minimal_symbol *msym) 178*5796c8dcSSimon Schubert { 179*5796c8dcSSimon Schubert return; 180*5796c8dcSSimon Schubert } 181*5796c8dcSSimon Schubert 182*5796c8dcSSimon Schubert int 183*5796c8dcSSimon Schubert cannot_register_not (struct gdbarch *gdbarch, int regnum) 184*5796c8dcSSimon Schubert { 185*5796c8dcSSimon Schubert return 0; 186*5796c8dcSSimon Schubert } 187*5796c8dcSSimon Schubert 188*5796c8dcSSimon Schubert /* Legacy version of target_virtual_frame_pointer(). Assumes that 189*5796c8dcSSimon Schubert there is an gdbarch_deprecated_fp_regnum and that it is the same, cooked or 190*5796c8dcSSimon Schubert raw. */ 191*5796c8dcSSimon Schubert 192*5796c8dcSSimon Schubert void 193*5796c8dcSSimon Schubert legacy_virtual_frame_pointer (struct gdbarch *gdbarch, 194*5796c8dcSSimon Schubert CORE_ADDR pc, 195*5796c8dcSSimon Schubert int *frame_regnum, 196*5796c8dcSSimon Schubert LONGEST *frame_offset) 197*5796c8dcSSimon Schubert { 198*5796c8dcSSimon Schubert /* FIXME: cagney/2002-09-13: This code is used when identifying the 199*5796c8dcSSimon Schubert frame pointer of the current PC. It is assuming that a single 200*5796c8dcSSimon Schubert register and an offset can determine this. I think it should 201*5796c8dcSSimon Schubert instead generate a byte code expression as that would work better 202*5796c8dcSSimon Schubert with things like Dwarf2's CFI. */ 203*5796c8dcSSimon Schubert if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0 204*5796c8dcSSimon Schubert && gdbarch_deprecated_fp_regnum (gdbarch) 205*5796c8dcSSimon Schubert < gdbarch_num_regs (gdbarch)) 206*5796c8dcSSimon Schubert *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch); 207*5796c8dcSSimon Schubert else if (gdbarch_sp_regnum (gdbarch) >= 0 208*5796c8dcSSimon Schubert && gdbarch_sp_regnum (gdbarch) 209*5796c8dcSSimon Schubert < gdbarch_num_regs (gdbarch)) 210*5796c8dcSSimon Schubert *frame_regnum = gdbarch_sp_regnum (gdbarch); 211*5796c8dcSSimon Schubert else 212*5796c8dcSSimon Schubert /* Should this be an internal error? I guess so, it is reflecting 213*5796c8dcSSimon Schubert an architectural limitation in the current design. */ 214*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("No virtual frame pointer available")); 215*5796c8dcSSimon Schubert *frame_offset = 0; 216*5796c8dcSSimon Schubert } 217*5796c8dcSSimon Schubert 218*5796c8dcSSimon Schubert 219*5796c8dcSSimon Schubert int 220*5796c8dcSSimon Schubert generic_convert_register_p (struct gdbarch *gdbarch, int regnum, 221*5796c8dcSSimon Schubert struct type *type) 222*5796c8dcSSimon Schubert { 223*5796c8dcSSimon Schubert return 0; 224*5796c8dcSSimon Schubert } 225*5796c8dcSSimon Schubert 226*5796c8dcSSimon Schubert int 227*5796c8dcSSimon Schubert default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type) 228*5796c8dcSSimon Schubert { 229*5796c8dcSSimon Schubert return 0; 230*5796c8dcSSimon Schubert } 231*5796c8dcSSimon Schubert 232*5796c8dcSSimon Schubert int 233*5796c8dcSSimon Schubert generic_instruction_nullified (struct gdbarch *gdbarch, 234*5796c8dcSSimon Schubert struct regcache *regcache) 235*5796c8dcSSimon Schubert { 236*5796c8dcSSimon Schubert return 0; 237*5796c8dcSSimon Schubert } 238*5796c8dcSSimon Schubert 239*5796c8dcSSimon Schubert int 240*5796c8dcSSimon Schubert default_remote_register_number (struct gdbarch *gdbarch, 241*5796c8dcSSimon Schubert int regno) 242*5796c8dcSSimon Schubert { 243*5796c8dcSSimon Schubert return regno; 244*5796c8dcSSimon Schubert } 245*5796c8dcSSimon Schubert 246*5796c8dcSSimon Schubert 247*5796c8dcSSimon Schubert /* Functions to manipulate the endianness of the target. */ 248*5796c8dcSSimon Schubert 249*5796c8dcSSimon Schubert static int target_byte_order_user = BFD_ENDIAN_UNKNOWN; 250*5796c8dcSSimon Schubert 251*5796c8dcSSimon Schubert static const char endian_big[] = "big"; 252*5796c8dcSSimon Schubert static const char endian_little[] = "little"; 253*5796c8dcSSimon Schubert static const char endian_auto[] = "auto"; 254*5796c8dcSSimon Schubert static const char *endian_enum[] = 255*5796c8dcSSimon Schubert { 256*5796c8dcSSimon Schubert endian_big, 257*5796c8dcSSimon Schubert endian_little, 258*5796c8dcSSimon Schubert endian_auto, 259*5796c8dcSSimon Schubert NULL, 260*5796c8dcSSimon Schubert }; 261*5796c8dcSSimon Schubert static const char *set_endian_string; 262*5796c8dcSSimon Schubert 263*5796c8dcSSimon Schubert enum bfd_endian 264*5796c8dcSSimon Schubert selected_byte_order (void) 265*5796c8dcSSimon Schubert { 266*5796c8dcSSimon Schubert return target_byte_order_user; 267*5796c8dcSSimon Schubert } 268*5796c8dcSSimon Schubert 269*5796c8dcSSimon Schubert /* Called by ``show endian''. */ 270*5796c8dcSSimon Schubert 271*5796c8dcSSimon Schubert static void 272*5796c8dcSSimon Schubert show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c, 273*5796c8dcSSimon Schubert const char *value) 274*5796c8dcSSimon Schubert { 275*5796c8dcSSimon Schubert if (target_byte_order_user == BFD_ENDIAN_UNKNOWN) 276*5796c8dcSSimon Schubert if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG) 277*5796c8dcSSimon Schubert fprintf_unfiltered (file, _("The target endianness is set automatically " 278*5796c8dcSSimon Schubert "(currently big endian)\n")); 279*5796c8dcSSimon Schubert else 280*5796c8dcSSimon Schubert fprintf_unfiltered (file, _("The target endianness is set automatically " 281*5796c8dcSSimon Schubert "(currently little endian)\n")); 282*5796c8dcSSimon Schubert else 283*5796c8dcSSimon Schubert if (target_byte_order_user == BFD_ENDIAN_BIG) 284*5796c8dcSSimon Schubert fprintf_unfiltered (file, 285*5796c8dcSSimon Schubert _("The target is assumed to be big endian\n")); 286*5796c8dcSSimon Schubert else 287*5796c8dcSSimon Schubert fprintf_unfiltered (file, 288*5796c8dcSSimon Schubert _("The target is assumed to be little endian\n")); 289*5796c8dcSSimon Schubert } 290*5796c8dcSSimon Schubert 291*5796c8dcSSimon Schubert static void 292*5796c8dcSSimon Schubert set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c) 293*5796c8dcSSimon Schubert { 294*5796c8dcSSimon Schubert struct gdbarch_info info; 295*5796c8dcSSimon Schubert 296*5796c8dcSSimon Schubert gdbarch_info_init (&info); 297*5796c8dcSSimon Schubert 298*5796c8dcSSimon Schubert if (set_endian_string == endian_auto) 299*5796c8dcSSimon Schubert { 300*5796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_UNKNOWN; 301*5796c8dcSSimon Schubert if (! gdbarch_update_p (info)) 302*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 303*5796c8dcSSimon Schubert _("set_endian: architecture update failed")); 304*5796c8dcSSimon Schubert } 305*5796c8dcSSimon Schubert else if (set_endian_string == endian_little) 306*5796c8dcSSimon Schubert { 307*5796c8dcSSimon Schubert info.byte_order = BFD_ENDIAN_LITTLE; 308*5796c8dcSSimon Schubert if (! gdbarch_update_p (info)) 309*5796c8dcSSimon Schubert printf_unfiltered (_("Little endian target not supported by GDB\n")); 310*5796c8dcSSimon Schubert else 311*5796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_LITTLE; 312*5796c8dcSSimon Schubert } 313*5796c8dcSSimon Schubert else if (set_endian_string == endian_big) 314*5796c8dcSSimon Schubert { 315*5796c8dcSSimon Schubert info.byte_order = BFD_ENDIAN_BIG; 316*5796c8dcSSimon Schubert if (! gdbarch_update_p (info)) 317*5796c8dcSSimon Schubert printf_unfiltered (_("Big endian target not supported by GDB\n")); 318*5796c8dcSSimon Schubert else 319*5796c8dcSSimon Schubert target_byte_order_user = BFD_ENDIAN_BIG; 320*5796c8dcSSimon Schubert } 321*5796c8dcSSimon Schubert else 322*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 323*5796c8dcSSimon Schubert _("set_endian: bad value")); 324*5796c8dcSSimon Schubert 325*5796c8dcSSimon Schubert show_endian (gdb_stdout, from_tty, NULL, NULL); 326*5796c8dcSSimon Schubert } 327*5796c8dcSSimon Schubert 328*5796c8dcSSimon Schubert /* Given SELECTED, a currently selected BFD architecture, and 329*5796c8dcSSimon Schubert TARGET_DESC, the current target description, return what 330*5796c8dcSSimon Schubert architecture to use. 331*5796c8dcSSimon Schubert 332*5796c8dcSSimon Schubert SELECTED may be NULL, in which case we return the architecture 333*5796c8dcSSimon Schubert associated with TARGET_DESC. If SELECTED specifies a variant 334*5796c8dcSSimon Schubert of the architecture associtated with TARGET_DESC, return the 335*5796c8dcSSimon Schubert more specific of the two. 336*5796c8dcSSimon Schubert 337*5796c8dcSSimon Schubert If SELECTED is a different architecture, but it is accepted as 338*5796c8dcSSimon Schubert compatible by the target, we can use the target architecture. 339*5796c8dcSSimon Schubert 340*5796c8dcSSimon Schubert If SELECTED is obviously incompatible, warn the user. */ 341*5796c8dcSSimon Schubert 342*5796c8dcSSimon Schubert static const struct bfd_arch_info * 343*5796c8dcSSimon Schubert choose_architecture_for_target (const struct target_desc *target_desc, 344*5796c8dcSSimon Schubert const struct bfd_arch_info *selected) 345*5796c8dcSSimon Schubert { 346*5796c8dcSSimon Schubert const struct bfd_arch_info *from_target = tdesc_architecture (target_desc); 347*5796c8dcSSimon Schubert const struct bfd_arch_info *compat1, *compat2; 348*5796c8dcSSimon Schubert 349*5796c8dcSSimon Schubert if (selected == NULL) 350*5796c8dcSSimon Schubert return from_target; 351*5796c8dcSSimon Schubert 352*5796c8dcSSimon Schubert if (from_target == NULL) 353*5796c8dcSSimon Schubert return selected; 354*5796c8dcSSimon Schubert 355*5796c8dcSSimon Schubert /* struct bfd_arch_info objects are singletons: that is, there's 356*5796c8dcSSimon Schubert supposed to be exactly one instance for a given machine. So you 357*5796c8dcSSimon Schubert can tell whether two are equivalent by comparing pointers. */ 358*5796c8dcSSimon Schubert if (from_target == selected) 359*5796c8dcSSimon Schubert return selected; 360*5796c8dcSSimon Schubert 361*5796c8dcSSimon Schubert /* BFD's 'A->compatible (A, B)' functions return zero if A and B are 362*5796c8dcSSimon Schubert incompatible. But if they are compatible, it returns the 'more 363*5796c8dcSSimon Schubert featureful' of the two arches. That is, if A can run code 364*5796c8dcSSimon Schubert written for B, but B can't run code written for A, then it'll 365*5796c8dcSSimon Schubert return A. 366*5796c8dcSSimon Schubert 367*5796c8dcSSimon Schubert Some targets (e.g. MIPS as of 2006-12-04) don't fully 368*5796c8dcSSimon Schubert implement this, instead always returning NULL or the first 369*5796c8dcSSimon Schubert argument. We detect that case by checking both directions. */ 370*5796c8dcSSimon Schubert 371*5796c8dcSSimon Schubert compat1 = selected->compatible (selected, from_target); 372*5796c8dcSSimon Schubert compat2 = from_target->compatible (from_target, selected); 373*5796c8dcSSimon Schubert 374*5796c8dcSSimon Schubert if (compat1 == NULL && compat2 == NULL) 375*5796c8dcSSimon Schubert { 376*5796c8dcSSimon Schubert /* BFD considers the architectures incompatible. Check our target 377*5796c8dcSSimon Schubert description whether it accepts SELECTED as compatible anyway. */ 378*5796c8dcSSimon Schubert if (tdesc_compatible_p (target_desc, selected)) 379*5796c8dcSSimon Schubert return from_target; 380*5796c8dcSSimon Schubert 381*5796c8dcSSimon Schubert warning (_("Selected architecture %s is not compatible " 382*5796c8dcSSimon Schubert "with reported target architecture %s"), 383*5796c8dcSSimon Schubert selected->printable_name, from_target->printable_name); 384*5796c8dcSSimon Schubert return selected; 385*5796c8dcSSimon Schubert } 386*5796c8dcSSimon Schubert 387*5796c8dcSSimon Schubert if (compat1 == NULL) 388*5796c8dcSSimon Schubert return compat2; 389*5796c8dcSSimon Schubert if (compat2 == NULL) 390*5796c8dcSSimon Schubert return compat1; 391*5796c8dcSSimon Schubert if (compat1 == compat2) 392*5796c8dcSSimon Schubert return compat1; 393*5796c8dcSSimon Schubert 394*5796c8dcSSimon Schubert /* If the two didn't match, but one of them was a default architecture, 395*5796c8dcSSimon Schubert assume the more specific one is correct. This handles the case 396*5796c8dcSSimon Schubert where an executable or target description just says "mips", but 397*5796c8dcSSimon Schubert the other knows which MIPS variant. */ 398*5796c8dcSSimon Schubert if (compat1->the_default) 399*5796c8dcSSimon Schubert return compat2; 400*5796c8dcSSimon Schubert if (compat2->the_default) 401*5796c8dcSSimon Schubert return compat1; 402*5796c8dcSSimon Schubert 403*5796c8dcSSimon Schubert /* We have no idea which one is better. This is a bug, but not 404*5796c8dcSSimon Schubert a critical problem; warn the user. */ 405*5796c8dcSSimon Schubert warning (_("Selected architecture %s is ambiguous with " 406*5796c8dcSSimon Schubert "reported target architecture %s"), 407*5796c8dcSSimon Schubert selected->printable_name, from_target->printable_name); 408*5796c8dcSSimon Schubert return selected; 409*5796c8dcSSimon Schubert } 410*5796c8dcSSimon Schubert 411*5796c8dcSSimon Schubert /* Functions to manipulate the architecture of the target */ 412*5796c8dcSSimon Schubert 413*5796c8dcSSimon Schubert enum set_arch { set_arch_auto, set_arch_manual }; 414*5796c8dcSSimon Schubert 415*5796c8dcSSimon Schubert static const struct bfd_arch_info *target_architecture_user; 416*5796c8dcSSimon Schubert 417*5796c8dcSSimon Schubert static const char *set_architecture_string; 418*5796c8dcSSimon Schubert 419*5796c8dcSSimon Schubert const char * 420*5796c8dcSSimon Schubert selected_architecture_name (void) 421*5796c8dcSSimon Schubert { 422*5796c8dcSSimon Schubert if (target_architecture_user == NULL) 423*5796c8dcSSimon Schubert return NULL; 424*5796c8dcSSimon Schubert else 425*5796c8dcSSimon Schubert return set_architecture_string; 426*5796c8dcSSimon Schubert } 427*5796c8dcSSimon Schubert 428*5796c8dcSSimon Schubert /* Called if the user enters ``show architecture'' without an 429*5796c8dcSSimon Schubert argument. */ 430*5796c8dcSSimon Schubert 431*5796c8dcSSimon Schubert static void 432*5796c8dcSSimon Schubert show_architecture (struct ui_file *file, int from_tty, 433*5796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 434*5796c8dcSSimon Schubert { 435*5796c8dcSSimon Schubert if (target_architecture_user == NULL) 436*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 437*5796c8dcSSimon Schubert The target architecture is set automatically (currently %s)\n"), 438*5796c8dcSSimon Schubert gdbarch_bfd_arch_info (get_current_arch ())->printable_name); 439*5796c8dcSSimon Schubert else 440*5796c8dcSSimon Schubert fprintf_filtered (file, _("\ 441*5796c8dcSSimon Schubert The target architecture is assumed to be %s\n"), set_architecture_string); 442*5796c8dcSSimon Schubert } 443*5796c8dcSSimon Schubert 444*5796c8dcSSimon Schubert 445*5796c8dcSSimon Schubert /* Called if the user enters ``set architecture'' with or without an 446*5796c8dcSSimon Schubert argument. */ 447*5796c8dcSSimon Schubert 448*5796c8dcSSimon Schubert static void 449*5796c8dcSSimon Schubert set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c) 450*5796c8dcSSimon Schubert { 451*5796c8dcSSimon Schubert struct gdbarch_info info; 452*5796c8dcSSimon Schubert 453*5796c8dcSSimon Schubert gdbarch_info_init (&info); 454*5796c8dcSSimon Schubert 455*5796c8dcSSimon Schubert if (strcmp (set_architecture_string, "auto") == 0) 456*5796c8dcSSimon Schubert { 457*5796c8dcSSimon Schubert target_architecture_user = NULL; 458*5796c8dcSSimon Schubert if (!gdbarch_update_p (info)) 459*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 460*5796c8dcSSimon Schubert _("could not select an architecture automatically")); 461*5796c8dcSSimon Schubert } 462*5796c8dcSSimon Schubert else 463*5796c8dcSSimon Schubert { 464*5796c8dcSSimon Schubert info.bfd_arch_info = bfd_scan_arch (set_architecture_string); 465*5796c8dcSSimon Schubert if (info.bfd_arch_info == NULL) 466*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 467*5796c8dcSSimon Schubert _("set_architecture: bfd_scan_arch failed")); 468*5796c8dcSSimon Schubert if (gdbarch_update_p (info)) 469*5796c8dcSSimon Schubert target_architecture_user = info.bfd_arch_info; 470*5796c8dcSSimon Schubert else 471*5796c8dcSSimon Schubert printf_unfiltered (_("Architecture `%s' not recognized.\n"), 472*5796c8dcSSimon Schubert set_architecture_string); 473*5796c8dcSSimon Schubert } 474*5796c8dcSSimon Schubert show_architecture (gdb_stdout, from_tty, NULL, NULL); 475*5796c8dcSSimon Schubert } 476*5796c8dcSSimon Schubert 477*5796c8dcSSimon Schubert /* Try to select a global architecture that matches "info". Return 478*5796c8dcSSimon Schubert non-zero if the attempt succeds. */ 479*5796c8dcSSimon Schubert int 480*5796c8dcSSimon Schubert gdbarch_update_p (struct gdbarch_info info) 481*5796c8dcSSimon Schubert { 482*5796c8dcSSimon Schubert struct gdbarch *new_gdbarch; 483*5796c8dcSSimon Schubert 484*5796c8dcSSimon Schubert /* Check for the current file. */ 485*5796c8dcSSimon Schubert if (info.abfd == NULL) 486*5796c8dcSSimon Schubert info.abfd = exec_bfd; 487*5796c8dcSSimon Schubert if (info.abfd == NULL) 488*5796c8dcSSimon Schubert info.abfd = core_bfd; 489*5796c8dcSSimon Schubert 490*5796c8dcSSimon Schubert /* Check for the current target description. */ 491*5796c8dcSSimon Schubert if (info.target_desc == NULL) 492*5796c8dcSSimon Schubert info.target_desc = target_current_description (); 493*5796c8dcSSimon Schubert 494*5796c8dcSSimon Schubert new_gdbarch = gdbarch_find_by_info (info); 495*5796c8dcSSimon Schubert 496*5796c8dcSSimon Schubert /* If there no architecture by that name, reject the request. */ 497*5796c8dcSSimon Schubert if (new_gdbarch == NULL) 498*5796c8dcSSimon Schubert { 499*5796c8dcSSimon Schubert if (gdbarch_debug) 500*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " 501*5796c8dcSSimon Schubert "Architecture not found\n"); 502*5796c8dcSSimon Schubert return 0; 503*5796c8dcSSimon Schubert } 504*5796c8dcSSimon Schubert 505*5796c8dcSSimon Schubert /* If it is the same old architecture, accept the request (but don't 506*5796c8dcSSimon Schubert swap anything). */ 507*5796c8dcSSimon Schubert if (new_gdbarch == target_gdbarch) 508*5796c8dcSSimon Schubert { 509*5796c8dcSSimon Schubert if (gdbarch_debug) 510*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " 511*5796c8dcSSimon Schubert "Architecture %s (%s) unchanged\n", 512*5796c8dcSSimon Schubert host_address_to_string (new_gdbarch), 513*5796c8dcSSimon Schubert gdbarch_bfd_arch_info (new_gdbarch)->printable_name); 514*5796c8dcSSimon Schubert return 1; 515*5796c8dcSSimon Schubert } 516*5796c8dcSSimon Schubert 517*5796c8dcSSimon Schubert /* It's a new architecture, swap it in. */ 518*5796c8dcSSimon Schubert if (gdbarch_debug) 519*5796c8dcSSimon Schubert fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: " 520*5796c8dcSSimon Schubert "New architecture %s (%s) selected\n", 521*5796c8dcSSimon Schubert host_address_to_string (new_gdbarch), 522*5796c8dcSSimon Schubert gdbarch_bfd_arch_info (new_gdbarch)->printable_name); 523*5796c8dcSSimon Schubert deprecated_target_gdbarch_select_hack (new_gdbarch); 524*5796c8dcSSimon Schubert 525*5796c8dcSSimon Schubert return 1; 526*5796c8dcSSimon Schubert } 527*5796c8dcSSimon Schubert 528*5796c8dcSSimon Schubert /* Return the architecture for ABFD. If no suitable architecture 529*5796c8dcSSimon Schubert could be find, return NULL. */ 530*5796c8dcSSimon Schubert 531*5796c8dcSSimon Schubert struct gdbarch * 532*5796c8dcSSimon Schubert gdbarch_from_bfd (bfd *abfd) 533*5796c8dcSSimon Schubert { 534*5796c8dcSSimon Schubert struct gdbarch_info info; 535*5796c8dcSSimon Schubert gdbarch_info_init (&info); 536*5796c8dcSSimon Schubert info.abfd = abfd; 537*5796c8dcSSimon Schubert return gdbarch_find_by_info (info); 538*5796c8dcSSimon Schubert } 539*5796c8dcSSimon Schubert 540*5796c8dcSSimon Schubert /* Set the dynamic target-system-dependent parameters (architecture, 541*5796c8dcSSimon Schubert byte-order) using information found in the BFD */ 542*5796c8dcSSimon Schubert 543*5796c8dcSSimon Schubert void 544*5796c8dcSSimon Schubert set_gdbarch_from_file (bfd *abfd) 545*5796c8dcSSimon Schubert { 546*5796c8dcSSimon Schubert struct gdbarch_info info; 547*5796c8dcSSimon Schubert struct gdbarch *gdbarch; 548*5796c8dcSSimon Schubert 549*5796c8dcSSimon Schubert gdbarch_info_init (&info); 550*5796c8dcSSimon Schubert info.abfd = abfd; 551*5796c8dcSSimon Schubert info.target_desc = target_current_description (); 552*5796c8dcSSimon Schubert gdbarch = gdbarch_find_by_info (info); 553*5796c8dcSSimon Schubert 554*5796c8dcSSimon Schubert if (gdbarch == NULL) 555*5796c8dcSSimon Schubert error (_("Architecture of file not recognized.")); 556*5796c8dcSSimon Schubert deprecated_target_gdbarch_select_hack (gdbarch); 557*5796c8dcSSimon Schubert } 558*5796c8dcSSimon Schubert 559*5796c8dcSSimon Schubert /* Initialize the current architecture. Update the ``set 560*5796c8dcSSimon Schubert architecture'' command so that it specifies a list of valid 561*5796c8dcSSimon Schubert architectures. */ 562*5796c8dcSSimon Schubert 563*5796c8dcSSimon Schubert #ifdef DEFAULT_BFD_ARCH 564*5796c8dcSSimon Schubert extern const bfd_arch_info_type DEFAULT_BFD_ARCH; 565*5796c8dcSSimon Schubert static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH; 566*5796c8dcSSimon Schubert #else 567*5796c8dcSSimon Schubert static const bfd_arch_info_type *default_bfd_arch; 568*5796c8dcSSimon Schubert #endif 569*5796c8dcSSimon Schubert 570*5796c8dcSSimon Schubert #ifdef DEFAULT_BFD_VEC 571*5796c8dcSSimon Schubert extern const bfd_target DEFAULT_BFD_VEC; 572*5796c8dcSSimon Schubert static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC; 573*5796c8dcSSimon Schubert #else 574*5796c8dcSSimon Schubert static const bfd_target *default_bfd_vec; 575*5796c8dcSSimon Schubert #endif 576*5796c8dcSSimon Schubert 577*5796c8dcSSimon Schubert static int default_byte_order = BFD_ENDIAN_UNKNOWN; 578*5796c8dcSSimon Schubert 579*5796c8dcSSimon Schubert void 580*5796c8dcSSimon Schubert initialize_current_architecture (void) 581*5796c8dcSSimon Schubert { 582*5796c8dcSSimon Schubert const char **arches = gdbarch_printable_names (); 583*5796c8dcSSimon Schubert 584*5796c8dcSSimon Schubert /* determine a default architecture and byte order. */ 585*5796c8dcSSimon Schubert struct gdbarch_info info; 586*5796c8dcSSimon Schubert gdbarch_info_init (&info); 587*5796c8dcSSimon Schubert 588*5796c8dcSSimon Schubert /* Find a default architecture. */ 589*5796c8dcSSimon Schubert if (default_bfd_arch == NULL) 590*5796c8dcSSimon Schubert { 591*5796c8dcSSimon Schubert /* Choose the architecture by taking the first one 592*5796c8dcSSimon Schubert alphabetically. */ 593*5796c8dcSSimon Schubert const char *chosen = arches[0]; 594*5796c8dcSSimon Schubert const char **arch; 595*5796c8dcSSimon Schubert for (arch = arches; *arch != NULL; arch++) 596*5796c8dcSSimon Schubert { 597*5796c8dcSSimon Schubert if (strcmp (*arch, chosen) < 0) 598*5796c8dcSSimon Schubert chosen = *arch; 599*5796c8dcSSimon Schubert } 600*5796c8dcSSimon Schubert if (chosen == NULL) 601*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 602*5796c8dcSSimon Schubert _("initialize_current_architecture: No arch")); 603*5796c8dcSSimon Schubert default_bfd_arch = bfd_scan_arch (chosen); 604*5796c8dcSSimon Schubert if (default_bfd_arch == NULL) 605*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 606*5796c8dcSSimon Schubert _("initialize_current_architecture: Arch not found")); 607*5796c8dcSSimon Schubert } 608*5796c8dcSSimon Schubert 609*5796c8dcSSimon Schubert info.bfd_arch_info = default_bfd_arch; 610*5796c8dcSSimon Schubert 611*5796c8dcSSimon Schubert /* Take several guesses at a byte order. */ 612*5796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN 613*5796c8dcSSimon Schubert && default_bfd_vec != NULL) 614*5796c8dcSSimon Schubert { 615*5796c8dcSSimon Schubert /* Extract BFD's default vector's byte order. */ 616*5796c8dcSSimon Schubert switch (default_bfd_vec->byteorder) 617*5796c8dcSSimon Schubert { 618*5796c8dcSSimon Schubert case BFD_ENDIAN_BIG: 619*5796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_BIG; 620*5796c8dcSSimon Schubert break; 621*5796c8dcSSimon Schubert case BFD_ENDIAN_LITTLE: 622*5796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_LITTLE; 623*5796c8dcSSimon Schubert break; 624*5796c8dcSSimon Schubert default: 625*5796c8dcSSimon Schubert break; 626*5796c8dcSSimon Schubert } 627*5796c8dcSSimon Schubert } 628*5796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN) 629*5796c8dcSSimon Schubert { 630*5796c8dcSSimon Schubert /* look for ``*el-*'' in the target name. */ 631*5796c8dcSSimon Schubert const char *chp; 632*5796c8dcSSimon Schubert chp = strchr (target_name, '-'); 633*5796c8dcSSimon Schubert if (chp != NULL 634*5796c8dcSSimon Schubert && chp - 2 >= target_name 635*5796c8dcSSimon Schubert && strncmp (chp - 2, "el", 2) == 0) 636*5796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_LITTLE; 637*5796c8dcSSimon Schubert } 638*5796c8dcSSimon Schubert if (default_byte_order == BFD_ENDIAN_UNKNOWN) 639*5796c8dcSSimon Schubert { 640*5796c8dcSSimon Schubert /* Wire it to big-endian!!! */ 641*5796c8dcSSimon Schubert default_byte_order = BFD_ENDIAN_BIG; 642*5796c8dcSSimon Schubert } 643*5796c8dcSSimon Schubert 644*5796c8dcSSimon Schubert info.byte_order = default_byte_order; 645*5796c8dcSSimon Schubert info.byte_order_for_code = info.byte_order; 646*5796c8dcSSimon Schubert 647*5796c8dcSSimon Schubert if (! gdbarch_update_p (info)) 648*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 649*5796c8dcSSimon Schubert _("initialize_current_architecture: Selection of " 650*5796c8dcSSimon Schubert "initial architecture failed")); 651*5796c8dcSSimon Schubert 652*5796c8dcSSimon Schubert /* Create the ``set architecture'' command appending ``auto'' to the 653*5796c8dcSSimon Schubert list of architectures. */ 654*5796c8dcSSimon Schubert { 655*5796c8dcSSimon Schubert struct cmd_list_element *c; 656*5796c8dcSSimon Schubert /* Append ``auto''. */ 657*5796c8dcSSimon Schubert int nr; 658*5796c8dcSSimon Schubert for (nr = 0; arches[nr] != NULL; nr++); 659*5796c8dcSSimon Schubert arches = xrealloc (arches, sizeof (char*) * (nr + 2)); 660*5796c8dcSSimon Schubert arches[nr + 0] = "auto"; 661*5796c8dcSSimon Schubert arches[nr + 1] = NULL; 662*5796c8dcSSimon Schubert add_setshow_enum_cmd ("architecture", class_support, 663*5796c8dcSSimon Schubert arches, &set_architecture_string, _("\ 664*5796c8dcSSimon Schubert Set architecture of target."), _("\ 665*5796c8dcSSimon Schubert Show architecture of target."), NULL, 666*5796c8dcSSimon Schubert set_architecture, show_architecture, 667*5796c8dcSSimon Schubert &setlist, &showlist); 668*5796c8dcSSimon Schubert add_alias_cmd ("processor", "architecture", class_support, 1, &setlist); 669*5796c8dcSSimon Schubert } 670*5796c8dcSSimon Schubert } 671*5796c8dcSSimon Schubert 672*5796c8dcSSimon Schubert 673*5796c8dcSSimon Schubert /* Initialize a gdbarch info to values that will be automatically 674*5796c8dcSSimon Schubert overridden. Note: Originally, this ``struct info'' was initialized 675*5796c8dcSSimon Schubert using memset(0). Unfortunately, that ran into problems, namely 676*5796c8dcSSimon Schubert BFD_ENDIAN_BIG is zero. An explicit initialization function that 677*5796c8dcSSimon Schubert can explicitly set each field to a well defined value is used. */ 678*5796c8dcSSimon Schubert 679*5796c8dcSSimon Schubert void 680*5796c8dcSSimon Schubert gdbarch_info_init (struct gdbarch_info *info) 681*5796c8dcSSimon Schubert { 682*5796c8dcSSimon Schubert memset (info, 0, sizeof (struct gdbarch_info)); 683*5796c8dcSSimon Schubert info->byte_order = BFD_ENDIAN_UNKNOWN; 684*5796c8dcSSimon Schubert info->byte_order_for_code = info->byte_order; 685*5796c8dcSSimon Schubert info->osabi = GDB_OSABI_UNINITIALIZED; 686*5796c8dcSSimon Schubert } 687*5796c8dcSSimon Schubert 688*5796c8dcSSimon Schubert /* Similar to init, but this time fill in the blanks. Information is 689*5796c8dcSSimon Schubert obtained from the global "set ..." options and explicitly 690*5796c8dcSSimon Schubert initialized INFO fields. */ 691*5796c8dcSSimon Schubert 692*5796c8dcSSimon Schubert void 693*5796c8dcSSimon Schubert gdbarch_info_fill (struct gdbarch_info *info) 694*5796c8dcSSimon Schubert { 695*5796c8dcSSimon Schubert /* "(gdb) set architecture ...". */ 696*5796c8dcSSimon Schubert if (info->bfd_arch_info == NULL 697*5796c8dcSSimon Schubert && target_architecture_user) 698*5796c8dcSSimon Schubert info->bfd_arch_info = target_architecture_user; 699*5796c8dcSSimon Schubert /* From the file. */ 700*5796c8dcSSimon Schubert if (info->bfd_arch_info == NULL 701*5796c8dcSSimon Schubert && info->abfd != NULL 702*5796c8dcSSimon Schubert && bfd_get_arch (info->abfd) != bfd_arch_unknown 703*5796c8dcSSimon Schubert && bfd_get_arch (info->abfd) != bfd_arch_obscure) 704*5796c8dcSSimon Schubert info->bfd_arch_info = bfd_get_arch_info (info->abfd); 705*5796c8dcSSimon Schubert /* From the target. */ 706*5796c8dcSSimon Schubert if (info->target_desc != NULL) 707*5796c8dcSSimon Schubert info->bfd_arch_info = choose_architecture_for_target 708*5796c8dcSSimon Schubert (info->target_desc, info->bfd_arch_info); 709*5796c8dcSSimon Schubert /* From the default. */ 710*5796c8dcSSimon Schubert if (info->bfd_arch_info == NULL) 711*5796c8dcSSimon Schubert info->bfd_arch_info = default_bfd_arch; 712*5796c8dcSSimon Schubert 713*5796c8dcSSimon Schubert /* "(gdb) set byte-order ...". */ 714*5796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN 715*5796c8dcSSimon Schubert && target_byte_order_user != BFD_ENDIAN_UNKNOWN) 716*5796c8dcSSimon Schubert info->byte_order = target_byte_order_user; 717*5796c8dcSSimon Schubert /* From the INFO struct. */ 718*5796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN 719*5796c8dcSSimon Schubert && info->abfd != NULL) 720*5796c8dcSSimon Schubert info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG 721*5796c8dcSSimon Schubert : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE 722*5796c8dcSSimon Schubert : BFD_ENDIAN_UNKNOWN); 723*5796c8dcSSimon Schubert /* From the default. */ 724*5796c8dcSSimon Schubert if (info->byte_order == BFD_ENDIAN_UNKNOWN) 725*5796c8dcSSimon Schubert info->byte_order = default_byte_order; 726*5796c8dcSSimon Schubert info->byte_order_for_code = info->byte_order; 727*5796c8dcSSimon Schubert 728*5796c8dcSSimon Schubert /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */ 729*5796c8dcSSimon Schubert /* From the manual override, or from file. */ 730*5796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNINITIALIZED) 731*5796c8dcSSimon Schubert info->osabi = gdbarch_lookup_osabi (info->abfd); 732*5796c8dcSSimon Schubert /* From the target. */ 733*5796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL) 734*5796c8dcSSimon Schubert info->osabi = tdesc_osabi (info->target_desc); 735*5796c8dcSSimon Schubert /* From the configured default. */ 736*5796c8dcSSimon Schubert #ifdef GDB_OSABI_DEFAULT 737*5796c8dcSSimon Schubert if (info->osabi == GDB_OSABI_UNKNOWN) 738*5796c8dcSSimon Schubert info->osabi = GDB_OSABI_DEFAULT; 739*5796c8dcSSimon Schubert #endif 740*5796c8dcSSimon Schubert 741*5796c8dcSSimon Schubert /* Must have at least filled in the architecture. */ 742*5796c8dcSSimon Schubert gdb_assert (info->bfd_arch_info != NULL); 743*5796c8dcSSimon Schubert } 744*5796c8dcSSimon Schubert 745*5796c8dcSSimon Schubert /* Return "current" architecture. If the target is running, this is the 746*5796c8dcSSimon Schubert architecture of the selected frame. Otherwise, the "current" architecture 747*5796c8dcSSimon Schubert defaults to the target architecture. 748*5796c8dcSSimon Schubert 749*5796c8dcSSimon Schubert This function should normally be called solely by the command interpreter 750*5796c8dcSSimon Schubert routines to determine the architecture to execute a command in. */ 751*5796c8dcSSimon Schubert struct gdbarch * 752*5796c8dcSSimon Schubert get_current_arch (void) 753*5796c8dcSSimon Schubert { 754*5796c8dcSSimon Schubert if (has_stack_frames ()) 755*5796c8dcSSimon Schubert return get_frame_arch (get_selected_frame (NULL)); 756*5796c8dcSSimon Schubert else 757*5796c8dcSSimon Schubert return target_gdbarch; 758*5796c8dcSSimon Schubert } 759*5796c8dcSSimon Schubert 760*5796c8dcSSimon Schubert /* */ 761*5796c8dcSSimon Schubert 762*5796c8dcSSimon Schubert extern initialize_file_ftype _initialize_gdbarch_utils; /* -Wmissing-prototypes */ 763*5796c8dcSSimon Schubert 764*5796c8dcSSimon Schubert void 765*5796c8dcSSimon Schubert _initialize_gdbarch_utils (void) 766*5796c8dcSSimon Schubert { 767*5796c8dcSSimon Schubert struct cmd_list_element *c; 768*5796c8dcSSimon Schubert add_setshow_enum_cmd ("endian", class_support, 769*5796c8dcSSimon Schubert endian_enum, &set_endian_string, _("\ 770*5796c8dcSSimon Schubert Set endianness of target."), _("\ 771*5796c8dcSSimon Schubert Show endianness of target."), NULL, 772*5796c8dcSSimon Schubert set_endian, show_endian, 773*5796c8dcSSimon Schubert &setlist, &showlist); 774*5796c8dcSSimon Schubert } 775