Home | History | Annotate | Line # | Download | only in gdb
arch-utils.c revision 1.8
      1  1.1  christos /* Dynamic architecture support for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.8  christos    Copyright (C) 1998-2019 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is part of GDB.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19  1.1  christos 
     20  1.1  christos #include "defs.h"
     21  1.1  christos 
     22  1.1  christos #include "arch-utils.h"
     23  1.1  christos #include "gdbcmd.h"
     24  1.1  christos #include "inferior.h"		/* enum CALL_DUMMY_LOCATION et al.  */
     25  1.3  christos #include "infrun.h"
     26  1.1  christos #include "regcache.h"
     27  1.1  christos #include "sim-regno.h"
     28  1.1  christos #include "gdbcore.h"
     29  1.1  christos #include "osabi.h"
     30  1.1  christos #include "target-descriptions.h"
     31  1.1  christos #include "objfiles.h"
     32  1.1  christos #include "language.h"
     33  1.3  christos #include "symtab.h"
     34  1.1  christos 
     35  1.8  christos #include "common/version.h"
     36  1.1  christos 
     37  1.1  christos #include "floatformat.h"
     38  1.1  christos 
     39  1.8  christos #include "dis-asm.h"
     40  1.1  christos 
     41  1.1  christos int
     42  1.1  christos default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
     43  1.1  christos 				      struct displaced_step_closure *closure)
     44  1.1  christos {
     45  1.1  christos   return !gdbarch_software_single_step_p (gdbarch);
     46  1.1  christos }
     47  1.1  christos 
     48  1.1  christos CORE_ADDR
     49  1.1  christos displaced_step_at_entry_point (struct gdbarch *gdbarch)
     50  1.1  christos {
     51  1.1  christos   CORE_ADDR addr;
     52  1.1  christos   int bp_len;
     53  1.1  christos 
     54  1.1  christos   addr = entry_point_address ();
     55  1.1  christos 
     56  1.1  christos   /* Inferior calls also use the entry point as a breakpoint location.
     57  1.1  christos      We don't want displaced stepping to interfere with those
     58  1.1  christos      breakpoints, so leave space.  */
     59  1.1  christos   gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
     60  1.1  christos   addr += bp_len * 2;
     61  1.1  christos 
     62  1.1  christos   return addr;
     63  1.1  christos }
     64  1.1  christos 
     65  1.1  christos int
     66  1.1  christos legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
     67  1.1  christos {
     68  1.1  christos   /* Only makes sense to supply raw registers.  */
     69  1.1  christos   gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
     70  1.1  christos   /* NOTE: cagney/2002-05-13: The old code did it this way and it is
     71  1.1  christos      suspected that some GDB/SIM combinations may rely on this
     72  1.1  christos      behavour.  The default should be one2one_register_sim_regno
     73  1.1  christos      (below).  */
     74  1.1  christos   if (gdbarch_register_name (gdbarch, regnum) != NULL
     75  1.1  christos       && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
     76  1.1  christos     return regnum;
     77  1.1  christos   else
     78  1.1  christos     return LEGACY_SIM_REGNO_IGNORE;
     79  1.1  christos }
     80  1.1  christos 
     81  1.1  christos CORE_ADDR
     82  1.1  christos generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
     83  1.1  christos {
     84  1.1  christos   return 0;
     85  1.1  christos }
     86  1.1  christos 
     87  1.1  christos CORE_ADDR
     88  1.1  christos generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
     89  1.1  christos {
     90  1.1  christos   return 0;
     91  1.1  christos }
     92  1.1  christos 
     93  1.1  christos int
     94  1.1  christos generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
     95  1.1  christos 				    CORE_ADDR pc, const char *name)
     96  1.1  christos {
     97  1.1  christos   return 0;
     98  1.1  christos }
     99  1.1  christos 
    100  1.1  christos int
    101  1.5  christos generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
    102  1.1  christos {
    103  1.1  christos   return 0;
    104  1.1  christos }
    105  1.1  christos 
    106  1.6  christos int
    107  1.6  christos default_code_of_frame_writable (struct gdbarch *gdbarch,
    108  1.6  christos 				struct frame_info *frame)
    109  1.6  christos {
    110  1.6  christos   return 1;
    111  1.6  christos }
    112  1.6  christos 
    113  1.1  christos /* Helper functions for gdbarch_inner_than */
    114  1.1  christos 
    115  1.1  christos int
    116  1.1  christos core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
    117  1.1  christos {
    118  1.1  christos   return (lhs < rhs);
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos int
    122  1.1  christos core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
    123  1.1  christos {
    124  1.1  christos   return (lhs > rhs);
    125  1.1  christos }
    126  1.1  christos 
    127  1.1  christos /* Misc helper functions for targets.  */
    128  1.1  christos 
    129  1.1  christos CORE_ADDR
    130  1.1  christos core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
    131  1.1  christos {
    132  1.1  christos   return addr;
    133  1.1  christos }
    134  1.1  christos 
    135  1.1  christos CORE_ADDR
    136  1.1  christos convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
    137  1.1  christos 				     struct target_ops *targ)
    138  1.1  christos {
    139  1.1  christos   return addr;
    140  1.1  christos }
    141  1.1  christos 
    142  1.1  christos int
    143  1.1  christos no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
    144  1.1  christos {
    145  1.1  christos   return reg;
    146  1.1  christos }
    147  1.1  christos 
    148  1.1  christos void
    149  1.3  christos default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
    150  1.1  christos {
    151  1.1  christos   return;
    152  1.1  christos }
    153  1.1  christos 
    154  1.3  christos /* See arch-utils.h.  */
    155  1.3  christos 
    156  1.1  christos void
    157  1.3  christos default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
    158  1.1  christos {
    159  1.1  christos   return;
    160  1.1  christos }
    161  1.1  christos 
    162  1.3  christos /* See arch-utils.h.  */
    163  1.3  christos 
    164  1.3  christos CORE_ADDR
    165  1.3  christos default_adjust_dwarf2_addr (CORE_ADDR pc)
    166  1.3  christos {
    167  1.3  christos   return pc;
    168  1.3  christos }
    169  1.3  christos 
    170  1.3  christos /* See arch-utils.h.  */
    171  1.3  christos 
    172  1.3  christos CORE_ADDR
    173  1.3  christos default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
    174  1.3  christos {
    175  1.3  christos   return addr;
    176  1.3  christos }
    177  1.3  christos 
    178  1.8  christos /* See arch-utils.h.  */
    179  1.8  christos 
    180  1.8  christos bool
    181  1.8  christos default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
    182  1.8  christos 				     struct dwarf2_frame_state *fs)
    183  1.8  christos {
    184  1.8  christos   return false;
    185  1.8  christos }
    186  1.8  christos 
    187  1.1  christos int
    188  1.1  christos cannot_register_not (struct gdbarch *gdbarch, int regnum)
    189  1.1  christos {
    190  1.1  christos   return 0;
    191  1.1  christos }
    192  1.1  christos 
    193  1.1  christos /* Legacy version of target_virtual_frame_pointer().  Assumes that
    194  1.1  christos    there is an gdbarch_deprecated_fp_regnum and that it is the same,
    195  1.1  christos    cooked or raw.  */
    196  1.1  christos 
    197  1.1  christos void
    198  1.1  christos legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
    199  1.1  christos 			      CORE_ADDR pc,
    200  1.1  christos 			      int *frame_regnum,
    201  1.1  christos 			      LONGEST *frame_offset)
    202  1.1  christos {
    203  1.1  christos   /* FIXME: cagney/2002-09-13: This code is used when identifying the
    204  1.1  christos      frame pointer of the current PC.  It is assuming that a single
    205  1.1  christos      register and an offset can determine this.  I think it should
    206  1.1  christos      instead generate a byte code expression as that would work better
    207  1.1  christos      with things like Dwarf2's CFI.  */
    208  1.1  christos   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
    209  1.1  christos       && gdbarch_deprecated_fp_regnum (gdbarch)
    210  1.1  christos 	   < gdbarch_num_regs (gdbarch))
    211  1.1  christos     *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
    212  1.1  christos   else if (gdbarch_sp_regnum (gdbarch) >= 0
    213  1.1  christos 	   && gdbarch_sp_regnum (gdbarch)
    214  1.1  christos 	        < gdbarch_num_regs (gdbarch))
    215  1.1  christos     *frame_regnum = gdbarch_sp_regnum (gdbarch);
    216  1.1  christos   else
    217  1.1  christos     /* Should this be an internal error?  I guess so, it is reflecting
    218  1.1  christos        an architectural limitation in the current design.  */
    219  1.1  christos     internal_error (__FILE__, __LINE__,
    220  1.1  christos 		    _("No virtual frame pointer available"));
    221  1.1  christos   *frame_offset = 0;
    222  1.1  christos }
    223  1.1  christos 
    224  1.7  christos /* Return a floating-point format for a floating-point variable of
    225  1.7  christos    length LEN in bits.  If non-NULL, NAME is the name of its type.
    226  1.7  christos    If no suitable type is found, return NULL.  */
    227  1.7  christos 
    228  1.7  christos const struct floatformat **
    229  1.7  christos default_floatformat_for_type (struct gdbarch *gdbarch,
    230  1.7  christos 			      const char *name, int len)
    231  1.7  christos {
    232  1.7  christos   const struct floatformat **format = NULL;
    233  1.7  christos 
    234  1.7  christos   if (len == gdbarch_half_bit (gdbarch))
    235  1.7  christos     format = gdbarch_half_format (gdbarch);
    236  1.7  christos   else if (len == gdbarch_float_bit (gdbarch))
    237  1.7  christos     format = gdbarch_float_format (gdbarch);
    238  1.7  christos   else if (len == gdbarch_double_bit (gdbarch))
    239  1.7  christos     format = gdbarch_double_format (gdbarch);
    240  1.7  christos   else if (len == gdbarch_long_double_bit (gdbarch))
    241  1.7  christos     format = gdbarch_long_double_format (gdbarch);
    242  1.7  christos   /* On i386 the 'long double' type takes 96 bits,
    243  1.7  christos      while the real number of used bits is only 80,
    244  1.7  christos      both in processor and in memory.
    245  1.7  christos      The code below accepts the real bit size.  */
    246  1.7  christos   else if (gdbarch_long_double_format (gdbarch) != NULL
    247  1.7  christos 	   && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
    248  1.7  christos     format = gdbarch_long_double_format (gdbarch);
    249  1.7  christos 
    250  1.7  christos   return format;
    251  1.7  christos }
    252  1.1  christos 
    253  1.1  christos int
    255  1.1  christos generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
    256  1.1  christos 			    struct type *type)
    257  1.1  christos {
    258  1.1  christos   return 0;
    259  1.1  christos }
    260  1.1  christos 
    261  1.1  christos int
    262  1.1  christos default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
    263  1.1  christos {
    264  1.1  christos   return 0;
    265  1.1  christos }
    266  1.1  christos 
    267  1.1  christos int
    268  1.1  christos generic_instruction_nullified (struct gdbarch *gdbarch,
    269  1.1  christos 			       struct regcache *regcache)
    270  1.1  christos {
    271  1.1  christos   return 0;
    272  1.1  christos }
    273  1.1  christos 
    274  1.1  christos int
    275  1.1  christos default_remote_register_number (struct gdbarch *gdbarch,
    276  1.1  christos 				int regno)
    277  1.1  christos {
    278  1.1  christos   return regno;
    279  1.1  christos }
    280  1.3  christos 
    281  1.3  christos /* See arch-utils.h.  */
    282  1.3  christos 
    283  1.3  christos int
    284  1.3  christos default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
    285  1.3  christos {
    286  1.3  christos   return 0;
    287  1.3  christos }
    288  1.1  christos 
    289  1.1  christos 
    290  1.1  christos /* Functions to manipulate the endianness of the target.  */
    292  1.1  christos 
    293  1.1  christos static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
    294  1.1  christos 
    295  1.1  christos static const char endian_big[] = "big";
    296  1.1  christos static const char endian_little[] = "little";
    297  1.1  christos static const char endian_auto[] = "auto";
    298  1.1  christos static const char *const endian_enum[] =
    299  1.1  christos {
    300  1.1  christos   endian_big,
    301  1.1  christos   endian_little,
    302  1.1  christos   endian_auto,
    303  1.1  christos   NULL,
    304  1.1  christos };
    305  1.1  christos static const char *set_endian_string;
    306  1.1  christos 
    307  1.1  christos enum bfd_endian
    308  1.1  christos selected_byte_order (void)
    309  1.1  christos {
    310  1.1  christos   return target_byte_order_user;
    311  1.1  christos }
    312  1.1  christos 
    313  1.1  christos /* Called by ``show endian''.  */
    314  1.1  christos 
    315  1.1  christos static void
    316  1.1  christos show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
    317  1.1  christos 	     const char *value)
    318  1.1  christos {
    319  1.1  christos   if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
    320  1.1  christos     if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
    321  1.1  christos       fprintf_unfiltered (file, _("The target endianness is set automatically "
    322  1.1  christos 				  "(currently big endian)\n"));
    323  1.1  christos     else
    324  1.1  christos       fprintf_unfiltered (file, _("The target endianness is set automatically "
    325  1.1  christos 				  "(currently little endian)\n"));
    326  1.1  christos   else
    327  1.1  christos     if (target_byte_order_user == BFD_ENDIAN_BIG)
    328  1.1  christos       fprintf_unfiltered (file,
    329  1.1  christos 			  _("The target is assumed to be big endian\n"));
    330  1.1  christos     else
    331  1.1  christos       fprintf_unfiltered (file,
    332  1.1  christos 			  _("The target is assumed to be little endian\n"));
    333  1.1  christos }
    334  1.8  christos 
    335  1.1  christos static void
    336  1.1  christos set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
    337  1.1  christos {
    338  1.1  christos   struct gdbarch_info info;
    339  1.1  christos 
    340  1.1  christos   gdbarch_info_init (&info);
    341  1.1  christos 
    342  1.1  christos   if (set_endian_string == endian_auto)
    343  1.1  christos     {
    344  1.1  christos       target_byte_order_user = BFD_ENDIAN_UNKNOWN;
    345  1.1  christos       if (! gdbarch_update_p (info))
    346  1.1  christos 	internal_error (__FILE__, __LINE__,
    347  1.1  christos 			_("set_endian: architecture update failed"));
    348  1.1  christos     }
    349  1.1  christos   else if (set_endian_string == endian_little)
    350  1.1  christos     {
    351  1.1  christos       info.byte_order = BFD_ENDIAN_LITTLE;
    352  1.1  christos       if (! gdbarch_update_p (info))
    353  1.1  christos 	printf_unfiltered (_("Little endian target not supported by GDB\n"));
    354  1.1  christos       else
    355  1.1  christos 	target_byte_order_user = BFD_ENDIAN_LITTLE;
    356  1.1  christos     }
    357  1.1  christos   else if (set_endian_string == endian_big)
    358  1.1  christos     {
    359  1.1  christos       info.byte_order = BFD_ENDIAN_BIG;
    360  1.1  christos       if (! gdbarch_update_p (info))
    361  1.1  christos 	printf_unfiltered (_("Big endian target not supported by GDB\n"));
    362  1.1  christos       else
    363  1.1  christos 	target_byte_order_user = BFD_ENDIAN_BIG;
    364  1.1  christos     }
    365  1.1  christos   else
    366  1.1  christos     internal_error (__FILE__, __LINE__,
    367  1.1  christos 		    _("set_endian: bad value"));
    368  1.1  christos 
    369  1.1  christos   show_endian (gdb_stdout, from_tty, NULL, NULL);
    370  1.1  christos }
    371  1.1  christos 
    372  1.1  christos /* Given SELECTED, a currently selected BFD architecture, and
    373  1.1  christos    TARGET_DESC, the current target description, return what
    374  1.1  christos    architecture to use.
    375  1.1  christos 
    376  1.1  christos    SELECTED may be NULL, in which case we return the architecture
    377  1.1  christos    associated with TARGET_DESC.  If SELECTED specifies a variant
    378  1.1  christos    of the architecture associtated with TARGET_DESC, return the
    379  1.1  christos    more specific of the two.
    380  1.1  christos 
    381  1.1  christos    If SELECTED is a different architecture, but it is accepted as
    382  1.1  christos    compatible by the target, we can use the target architecture.
    383  1.1  christos 
    384  1.1  christos    If SELECTED is obviously incompatible, warn the user.  */
    385  1.1  christos 
    386  1.1  christos static const struct bfd_arch_info *
    387  1.1  christos choose_architecture_for_target (const struct target_desc *target_desc,
    388  1.1  christos 				const struct bfd_arch_info *selected)
    389  1.1  christos {
    390  1.1  christos   const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
    391  1.1  christos   const struct bfd_arch_info *compat1, *compat2;
    392  1.1  christos 
    393  1.1  christos   if (selected == NULL)
    394  1.1  christos     return from_target;
    395  1.1  christos 
    396  1.1  christos   if (from_target == NULL)
    397  1.1  christos     return selected;
    398  1.1  christos 
    399  1.1  christos   /* struct bfd_arch_info objects are singletons: that is, there's
    400  1.1  christos      supposed to be exactly one instance for a given machine.  So you
    401  1.1  christos      can tell whether two are equivalent by comparing pointers.  */
    402  1.1  christos   if (from_target == selected)
    403  1.1  christos     return selected;
    404  1.1  christos 
    405  1.1  christos   /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
    406  1.1  christos      incompatible.  But if they are compatible, it returns the 'more
    407  1.1  christos      featureful' of the two arches.  That is, if A can run code
    408  1.1  christos      written for B, but B can't run code written for A, then it'll
    409  1.1  christos      return A.
    410  1.1  christos 
    411  1.1  christos      Some targets (e.g. MIPS as of 2006-12-04) don't fully
    412  1.1  christos      implement this, instead always returning NULL or the first
    413  1.1  christos      argument.  We detect that case by checking both directions.  */
    414  1.1  christos 
    415  1.1  christos   compat1 = selected->compatible (selected, from_target);
    416  1.1  christos   compat2 = from_target->compatible (from_target, selected);
    417  1.1  christos 
    418  1.1  christos   if (compat1 == NULL && compat2 == NULL)
    419  1.1  christos     {
    420  1.1  christos       /* BFD considers the architectures incompatible.  Check our
    421  1.1  christos 	 target description whether it accepts SELECTED as compatible
    422  1.1  christos 	 anyway.  */
    423  1.1  christos       if (tdesc_compatible_p (target_desc, selected))
    424  1.1  christos 	return from_target;
    425  1.1  christos 
    426  1.1  christos       warning (_("Selected architecture %s is not compatible "
    427  1.1  christos 		 "with reported target architecture %s"),
    428  1.1  christos 	       selected->printable_name, from_target->printable_name);
    429  1.1  christos       return selected;
    430  1.1  christos     }
    431  1.1  christos 
    432  1.1  christos   if (compat1 == NULL)
    433  1.1  christos     return compat2;
    434  1.1  christos   if (compat2 == NULL)
    435  1.1  christos     return compat1;
    436  1.1  christos   if (compat1 == compat2)
    437  1.1  christos     return compat1;
    438  1.1  christos 
    439  1.1  christos   /* If the two didn't match, but one of them was a default
    440  1.1  christos      architecture, assume the more specific one is correct.  This
    441  1.1  christos      handles the case where an executable or target description just
    442  1.1  christos      says "mips", but the other knows which MIPS variant.  */
    443  1.1  christos   if (compat1->the_default)
    444  1.1  christos     return compat2;
    445  1.1  christos   if (compat2->the_default)
    446  1.1  christos     return compat1;
    447  1.1  christos 
    448  1.1  christos   /* We have no idea which one is better.  This is a bug, but not
    449  1.1  christos      a critical problem; warn the user.  */
    450  1.1  christos   warning (_("Selected architecture %s is ambiguous with "
    451  1.1  christos 	     "reported target architecture %s"),
    452  1.1  christos 	   selected->printable_name, from_target->printable_name);
    453  1.1  christos   return selected;
    454  1.1  christos }
    455  1.1  christos 
    456  1.1  christos /* Functions to manipulate the architecture of the target.  */
    457  1.1  christos 
    458  1.1  christos enum set_arch { set_arch_auto, set_arch_manual };
    459  1.1  christos 
    460  1.1  christos static const struct bfd_arch_info *target_architecture_user;
    461  1.1  christos 
    462  1.1  christos static const char *set_architecture_string;
    463  1.1  christos 
    464  1.1  christos const char *
    465  1.1  christos selected_architecture_name (void)
    466  1.1  christos {
    467  1.1  christos   if (target_architecture_user == NULL)
    468  1.1  christos     return NULL;
    469  1.1  christos   else
    470  1.1  christos     return set_architecture_string;
    471  1.1  christos }
    472  1.1  christos 
    473  1.1  christos /* Called if the user enters ``show architecture'' without an
    474  1.1  christos    argument.  */
    475  1.1  christos 
    476  1.1  christos static void
    477  1.1  christos show_architecture (struct ui_file *file, int from_tty,
    478  1.1  christos 		   struct cmd_list_element *c, const char *value)
    479  1.1  christos {
    480  1.1  christos   if (target_architecture_user == NULL)
    481  1.1  christos     fprintf_filtered (file, _("The target architecture is set "
    482  1.1  christos 			      "automatically (currently %s)\n"),
    483  1.1  christos 		      gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
    484  1.1  christos   else
    485  1.1  christos     fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
    486  1.1  christos 		      set_architecture_string);
    487  1.1  christos }
    488  1.1  christos 
    489  1.1  christos 
    490  1.1  christos /* Called if the user enters ``set architecture'' with or without an
    491  1.1  christos    argument.  */
    492  1.8  christos 
    493  1.8  christos static void
    494  1.1  christos set_architecture (const char *ignore_args,
    495  1.1  christos 		  int from_tty, struct cmd_list_element *c)
    496  1.1  christos {
    497  1.1  christos   struct gdbarch_info info;
    498  1.1  christos 
    499  1.1  christos   gdbarch_info_init (&info);
    500  1.1  christos 
    501  1.1  christos   if (strcmp (set_architecture_string, "auto") == 0)
    502  1.1  christos     {
    503  1.1  christos       target_architecture_user = NULL;
    504  1.1  christos       if (!gdbarch_update_p (info))
    505  1.1  christos 	internal_error (__FILE__, __LINE__,
    506  1.1  christos 			_("could not select an architecture automatically"));
    507  1.1  christos     }
    508  1.1  christos   else
    509  1.1  christos     {
    510  1.1  christos       info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
    511  1.1  christos       if (info.bfd_arch_info == NULL)
    512  1.1  christos 	internal_error (__FILE__, __LINE__,
    513  1.1  christos 			_("set_architecture: bfd_scan_arch failed"));
    514  1.1  christos       if (gdbarch_update_p (info))
    515  1.1  christos 	target_architecture_user = info.bfd_arch_info;
    516  1.1  christos       else
    517  1.1  christos 	printf_unfiltered (_("Architecture `%s' not recognized.\n"),
    518  1.1  christos 			   set_architecture_string);
    519  1.1  christos     }
    520  1.1  christos   show_architecture (gdb_stdout, from_tty, NULL, NULL);
    521  1.1  christos }
    522  1.1  christos 
    523  1.1  christos /* Try to select a global architecture that matches "info".  Return
    524  1.1  christos    non-zero if the attempt succeeds.  */
    525  1.1  christos int
    526  1.1  christos gdbarch_update_p (struct gdbarch_info info)
    527  1.1  christos {
    528  1.1  christos   struct gdbarch *new_gdbarch;
    529  1.1  christos 
    530  1.1  christos   /* Check for the current file.  */
    531  1.1  christos   if (info.abfd == NULL)
    532  1.1  christos     info.abfd = exec_bfd;
    533  1.1  christos   if (info.abfd == NULL)
    534  1.1  christos     info.abfd = core_bfd;
    535  1.1  christos 
    536  1.1  christos   /* Check for the current target description.  */
    537  1.1  christos   if (info.target_desc == NULL)
    538  1.1  christos     info.target_desc = target_current_description ();
    539  1.1  christos 
    540  1.1  christos   new_gdbarch = gdbarch_find_by_info (info);
    541  1.1  christos 
    542  1.1  christos   /* If there no architecture by that name, reject the request.  */
    543  1.1  christos   if (new_gdbarch == NULL)
    544  1.1  christos     {
    545  1.1  christos       if (gdbarch_debug)
    546  1.1  christos 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
    547  1.1  christos 			    "Architecture not found\n");
    548  1.1  christos       return 0;
    549  1.1  christos     }
    550  1.1  christos 
    551  1.1  christos   /* If it is the same old architecture, accept the request (but don't
    552  1.1  christos      swap anything).  */
    553  1.1  christos   if (new_gdbarch == target_gdbarch ())
    554  1.1  christos     {
    555  1.1  christos       if (gdbarch_debug)
    556  1.1  christos 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
    557  1.1  christos 			    "Architecture %s (%s) unchanged\n",
    558  1.1  christos 			    host_address_to_string (new_gdbarch),
    559  1.1  christos 			    gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
    560  1.1  christos       return 1;
    561  1.1  christos     }
    562  1.1  christos 
    563  1.1  christos   /* It's a new architecture, swap it in.  */
    564  1.1  christos   if (gdbarch_debug)
    565  1.1  christos     fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
    566  1.1  christos 			"New architecture %s (%s) selected\n",
    567  1.1  christos 			host_address_to_string (new_gdbarch),
    568  1.1  christos 			gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
    569  1.1  christos   set_target_gdbarch (new_gdbarch);
    570  1.1  christos 
    571  1.1  christos   return 1;
    572  1.1  christos }
    573  1.1  christos 
    574  1.1  christos /* Return the architecture for ABFD.  If no suitable architecture
    575  1.1  christos    could be find, return NULL.  */
    576  1.1  christos 
    577  1.1  christos struct gdbarch *
    578  1.1  christos gdbarch_from_bfd (bfd *abfd)
    579  1.1  christos {
    580  1.1  christos   struct gdbarch_info info;
    581  1.1  christos   gdbarch_info_init (&info);
    582  1.1  christos 
    583  1.1  christos   info.abfd = abfd;
    584  1.1  christos   return gdbarch_find_by_info (info);
    585  1.1  christos }
    586  1.1  christos 
    587  1.1  christos /* Set the dynamic target-system-dependent parameters (architecture,
    588  1.1  christos    byte-order) using information found in the BFD */
    589  1.1  christos 
    590  1.1  christos void
    591  1.1  christos set_gdbarch_from_file (bfd *abfd)
    592  1.1  christos {
    593  1.1  christos   struct gdbarch_info info;
    594  1.1  christos   struct gdbarch *gdbarch;
    595  1.1  christos 
    596  1.1  christos   gdbarch_info_init (&info);
    597  1.1  christos   info.abfd = abfd;
    598  1.1  christos   info.target_desc = target_current_description ();
    599  1.1  christos   gdbarch = gdbarch_find_by_info (info);
    600  1.1  christos 
    601  1.1  christos   if (gdbarch == NULL)
    602  1.1  christos     error (_("Architecture of file not recognized."));
    603  1.1  christos   set_target_gdbarch (gdbarch);
    604  1.1  christos }
    605  1.1  christos 
    606  1.1  christos /* Initialize the current architecture.  Update the ``set
    607  1.1  christos    architecture'' command so that it specifies a list of valid
    608  1.1  christos    architectures.  */
    609  1.1  christos 
    610  1.1  christos #ifdef DEFAULT_BFD_ARCH
    611  1.1  christos extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
    612  1.1  christos static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
    613  1.1  christos #else
    614  1.1  christos static const bfd_arch_info_type *default_bfd_arch;
    615  1.1  christos #endif
    616  1.1  christos 
    617  1.1  christos #ifdef DEFAULT_BFD_VEC
    618  1.1  christos extern const bfd_target DEFAULT_BFD_VEC;
    619  1.1  christos static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
    620  1.1  christos #else
    621  1.1  christos static const bfd_target *default_bfd_vec;
    622  1.6  christos #endif
    623  1.1  christos 
    624  1.1  christos static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
    625  1.1  christos 
    626  1.1  christos void
    627  1.1  christos initialize_current_architecture (void)
    628  1.1  christos {
    629  1.1  christos   const char **arches = gdbarch_printable_names ();
    630  1.1  christos   struct gdbarch_info info;
    631  1.1  christos 
    632  1.1  christos   /* determine a default architecture and byte order.  */
    633  1.1  christos   gdbarch_info_init (&info);
    634  1.1  christos 
    635  1.1  christos   /* Find a default architecture.  */
    636  1.1  christos   if (default_bfd_arch == NULL)
    637  1.1  christos     {
    638  1.1  christos       /* Choose the architecture by taking the first one
    639  1.1  christos 	 alphabetically.  */
    640  1.1  christos       const char *chosen = arches[0];
    641  1.1  christos       const char **arch;
    642  1.1  christos       for (arch = arches; *arch != NULL; arch++)
    643  1.1  christos 	{
    644  1.1  christos 	  if (strcmp (*arch, chosen) < 0)
    645  1.1  christos 	    chosen = *arch;
    646  1.1  christos 	}
    647  1.1  christos       if (chosen == NULL)
    648  1.1  christos 	internal_error (__FILE__, __LINE__,
    649  1.1  christos 			_("initialize_current_architecture: No arch"));
    650  1.1  christos       default_bfd_arch = bfd_scan_arch (chosen);
    651  1.1  christos       if (default_bfd_arch == NULL)
    652  1.1  christos 	internal_error (__FILE__, __LINE__,
    653  1.1  christos 			_("initialize_current_architecture: Arch not found"));
    654  1.1  christos     }
    655  1.1  christos 
    656  1.1  christos   info.bfd_arch_info = default_bfd_arch;
    657  1.1  christos 
    658  1.1  christos   /* Take several guesses at a byte order.  */
    659  1.1  christos   if (default_byte_order == BFD_ENDIAN_UNKNOWN
    660  1.1  christos       && default_bfd_vec != NULL)
    661  1.1  christos     {
    662  1.1  christos       /* Extract BFD's default vector's byte order.  */
    663  1.1  christos       switch (default_bfd_vec->byteorder)
    664  1.1  christos 	{
    665  1.1  christos 	case BFD_ENDIAN_BIG:
    666  1.1  christos 	  default_byte_order = BFD_ENDIAN_BIG;
    667  1.1  christos 	  break;
    668  1.1  christos 	case BFD_ENDIAN_LITTLE:
    669  1.1  christos 	  default_byte_order = BFD_ENDIAN_LITTLE;
    670  1.1  christos 	  break;
    671  1.1  christos 	default:
    672  1.1  christos 	  break;
    673  1.1  christos 	}
    674  1.1  christos     }
    675  1.1  christos   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
    676  1.1  christos     {
    677  1.1  christos       /* look for ``*el-*'' in the target name.  */
    678  1.1  christos       const char *chp;
    679  1.1  christos       chp = strchr (target_name, '-');
    680  1.5  christos       if (chp != NULL
    681  1.1  christos 	  && chp - 2 >= target_name
    682  1.1  christos 	  && startswith (chp - 2, "el"))
    683  1.1  christos 	default_byte_order = BFD_ENDIAN_LITTLE;
    684  1.1  christos     }
    685  1.1  christos   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
    686  1.1  christos     {
    687  1.1  christos       /* Wire it to big-endian!!! */
    688  1.1  christos       default_byte_order = BFD_ENDIAN_BIG;
    689  1.1  christos     }
    690  1.1  christos 
    691  1.1  christos   info.byte_order = default_byte_order;
    692  1.1  christos   info.byte_order_for_code = info.byte_order;
    693  1.1  christos 
    694  1.1  christos   if (! gdbarch_update_p (info))
    695  1.1  christos     internal_error (__FILE__, __LINE__,
    696  1.1  christos 		    _("initialize_current_architecture: Selection of "
    697  1.1  christos 		      "initial architecture failed"));
    698  1.1  christos 
    699  1.1  christos   /* Create the ``set architecture'' command appending ``auto'' to the
    700  1.1  christos      list of architectures.  */
    701  1.1  christos   {
    702  1.1  christos     /* Append ``auto''.  */
    703  1.6  christos     int nr;
    704  1.1  christos     for (nr = 0; arches[nr] != NULL; nr++);
    705  1.1  christos     arches = XRESIZEVEC (const char *, arches, nr + 2);
    706  1.1  christos     arches[nr + 0] = "auto";
    707  1.1  christos     arches[nr + 1] = NULL;
    708  1.1  christos     add_setshow_enum_cmd ("architecture", class_support,
    709  1.1  christos 			  arches, &set_architecture_string,
    710  1.1  christos 			  _("Set architecture of target."),
    711  1.1  christos 			  _("Show architecture of target."), NULL,
    712  1.1  christos 			  set_architecture, show_architecture,
    713  1.1  christos 			  &setlist, &showlist);
    714  1.1  christos     add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
    715  1.1  christos   }
    716  1.1  christos }
    717  1.1  christos 
    718  1.1  christos 
    719  1.1  christos /* Initialize a gdbarch info to values that will be automatically
    720  1.1  christos    overridden.  Note: Originally, this ``struct info'' was initialized
    721  1.1  christos    using memset(0).  Unfortunately, that ran into problems, namely
    722  1.1  christos    BFD_ENDIAN_BIG is zero.  An explicit initialization function that
    723  1.1  christos    can explicitly set each field to a well defined value is used.  */
    724  1.1  christos 
    725  1.1  christos void
    726  1.1  christos gdbarch_info_init (struct gdbarch_info *info)
    727  1.1  christos {
    728  1.1  christos   memset (info, 0, sizeof (struct gdbarch_info));
    729  1.1  christos   info->byte_order = BFD_ENDIAN_UNKNOWN;
    730  1.1  christos   info->byte_order_for_code = info->byte_order;
    731  1.1  christos }
    732  1.1  christos 
    733  1.1  christos /* Similar to init, but this time fill in the blanks.  Information is
    734  1.1  christos    obtained from the global "set ..." options and explicitly
    735  1.1  christos    initialized INFO fields.  */
    736  1.1  christos 
    737  1.1  christos void
    738  1.1  christos gdbarch_info_fill (struct gdbarch_info *info)
    739  1.1  christos {
    740  1.1  christos   /* "(gdb) set architecture ...".  */
    741  1.1  christos   if (info->bfd_arch_info == NULL
    742  1.1  christos       && target_architecture_user)
    743  1.1  christos     info->bfd_arch_info = target_architecture_user;
    744  1.1  christos   /* From the file.  */
    745  1.1  christos   if (info->bfd_arch_info == NULL
    746  1.1  christos       && info->abfd != NULL
    747  1.1  christos       && bfd_get_arch (info->abfd) != bfd_arch_unknown
    748  1.1  christos       && bfd_get_arch (info->abfd) != bfd_arch_obscure)
    749  1.1  christos     info->bfd_arch_info = bfd_get_arch_info (info->abfd);
    750  1.1  christos   /* From the target.  */
    751  1.1  christos   if (info->target_desc != NULL)
    752  1.1  christos     info->bfd_arch_info = choose_architecture_for_target
    753  1.1  christos 			   (info->target_desc, info->bfd_arch_info);
    754  1.1  christos   /* From the default.  */
    755  1.1  christos   if (info->bfd_arch_info == NULL)
    756  1.1  christos     info->bfd_arch_info = default_bfd_arch;
    757  1.1  christos 
    758  1.1  christos   /* "(gdb) set byte-order ...".  */
    759  1.1  christos   if (info->byte_order == BFD_ENDIAN_UNKNOWN
    760  1.1  christos       && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
    761  1.1  christos     info->byte_order = target_byte_order_user;
    762  1.1  christos   /* From the INFO struct.  */
    763  1.1  christos   if (info->byte_order == BFD_ENDIAN_UNKNOWN
    764  1.1  christos       && info->abfd != NULL)
    765  1.1  christos     info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
    766  1.1  christos 			: bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
    767  1.1  christos 			: BFD_ENDIAN_UNKNOWN);
    768  1.1  christos   /* From the default.  */
    769  1.1  christos   if (info->byte_order == BFD_ENDIAN_UNKNOWN)
    770  1.8  christos     info->byte_order = default_byte_order;
    771  1.8  christos   info->byte_order_for_code = info->byte_order;
    772  1.1  christos   /* Wire the default to the last selected byte order.  */
    773  1.1  christos   default_byte_order = info->byte_order;
    774  1.1  christos 
    775  1.8  christos   /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
    776  1.1  christos   /* From the manual override, or from file.  */
    777  1.1  christos   if (info->osabi == GDB_OSABI_UNKNOWN)
    778  1.8  christos     info->osabi = gdbarch_lookup_osabi (info->abfd);
    779  1.1  christos   /* From the target.  */
    780  1.1  christos 
    781  1.1  christos   if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
    782  1.1  christos     info->osabi = tdesc_osabi (info->target_desc);
    783  1.1  christos   /* From the configured default.  */
    784  1.1  christos #ifdef GDB_OSABI_DEFAULT
    785  1.1  christos   if (info->osabi == GDB_OSABI_UNKNOWN)
    786  1.8  christos     info->osabi = GDB_OSABI_DEFAULT;
    787  1.8  christos #endif
    788  1.8  christos   /* If we still don't know which osabi to pick, pick none.  */
    789  1.1  christos   if (info->osabi == GDB_OSABI_UNKNOWN)
    790  1.1  christos     info->osabi = GDB_OSABI_NONE;
    791  1.1  christos 
    792  1.1  christos   /* Must have at least filled in the architecture.  */
    793  1.1  christos   gdb_assert (info->bfd_arch_info != NULL);
    794  1.1  christos }
    795  1.1  christos 
    796  1.1  christos /* Return "current" architecture.  If the target is running, this is
    797  1.1  christos    the architecture of the selected frame.  Otherwise, the "current"
    798  1.1  christos    architecture defaults to the target architecture.
    799  1.1  christos 
    800  1.1  christos    This function should normally be called solely by the command
    801  1.1  christos    interpreter routines to determine the architecture to execute a
    802  1.1  christos    command in.  */
    803  1.1  christos struct gdbarch *
    804  1.1  christos get_current_arch (void)
    805  1.1  christos {
    806  1.1  christos   if (has_stack_frames ())
    807  1.1  christos     return get_frame_arch (get_selected_frame (NULL));
    808  1.1  christos   else
    809  1.1  christos     return target_gdbarch ();
    810  1.1  christos }
    811  1.1  christos 
    812  1.1  christos int
    813  1.1  christos default_has_shared_address_space (struct gdbarch *gdbarch)
    814  1.1  christos {
    815  1.1  christos   /* Simply say no.  In most unix-like targets each inferior/process
    816  1.1  christos      has its own address space.  */
    817  1.1  christos   return 0;
    818  1.1  christos }
    819  1.6  christos 
    820  1.8  christos int
    821  1.1  christos default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
    822  1.1  christos 				  std::string *msg)
    823  1.1  christos {
    824  1.1  christos   /* We don't know if maybe the target has some way to do fast
    825  1.8  christos      tracepoints that doesn't need gdbarch, so always say yes.  */
    826  1.1  christos   if (msg)
    827  1.1  christos     msg->clear ();
    828  1.1  christos   return 1;
    829  1.7  christos }
    830  1.7  christos 
    831  1.7  christos const gdb_byte *
    832  1.7  christos default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
    833  1.7  christos 			    int *lenptr)
    834  1.7  christos {
    835  1.7  christos   int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
    836  1.7  christos 
    837  1.7  christos   return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
    838  1.7  christos }
    839  1.7  christos int
    840  1.7  christos default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
    841  1.1  christos 					    struct regcache *regcache,
    842  1.7  christos 					    CORE_ADDR *pcptr)
    843  1.1  christos {
    844  1.1  christos   return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
    845  1.7  christos }
    846  1.1  christos 
    847  1.1  christos 
    848  1.1  christos void
    849  1.1  christos default_gen_return_address (struct gdbarch *gdbarch,
    850  1.1  christos 			    struct agent_expr *ax, struct axs_value *value,
    851  1.1  christos 			    CORE_ADDR scope)
    852  1.1  christos {
    853  1.1  christos   error (_("This architecture has no method to collect a return address."));
    854  1.1  christos }
    855  1.1  christos 
    856  1.1  christos int
    857  1.1  christos default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
    858  1.1  christos 					struct type *type)
    859  1.1  christos {
    860  1.1  christos   /* Usually, the return value's address is stored the in the "first hidden"
    861  1.1  christos      parameter if the return value should be passed by reference, as
    862  1.1  christos      specified in ABI.  */
    863  1.1  christos   return language_pass_by_reference (type);
    864  1.3  christos }
    865  1.3  christos 
    866  1.3  christos int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
    867  1.3  christos {
    868  1.3  christos   return 0;
    869  1.3  christos }
    870  1.3  christos 
    871  1.3  christos int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
    872  1.3  christos {
    873  1.3  christos   return 0;
    874  1.3  christos }
    875  1.3  christos 
    876  1.3  christos int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
    877  1.3  christos {
    878  1.3  christos   return 0;
    879  1.3  christos }
    880  1.3  christos 
    881  1.3  christos void
    882  1.8  christos default_skip_permanent_breakpoint (struct regcache *regcache)
    883  1.3  christos {
    884  1.3  christos   struct gdbarch *gdbarch = regcache->arch ();
    885  1.3  christos   CORE_ADDR current_pc = regcache_read_pc (regcache);
    886  1.6  christos   int bp_len;
    887  1.3  christos 
    888  1.3  christos   gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
    889  1.3  christos   current_pc += bp_len;
    890  1.3  christos   regcache_write_pc (regcache, current_pc);
    891  1.3  christos }
    892  1.3  christos 
    893  1.3  christos CORE_ADDR
    894  1.3  christos default_infcall_mmap (CORE_ADDR size, unsigned prot)
    895  1.3  christos {
    896  1.3  christos   error (_("This target does not support inferior memory allocation by mmap."));
    897  1.5  christos }
    898  1.5  christos 
    899  1.5  christos void
    900  1.5  christos default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
    901  1.5  christos {
    902  1.5  christos   /* Memory reserved by inferior mmap is kept leaked.  */
    903  1.3  christos }
    904  1.3  christos 
    905  1.3  christos /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
    906  1.3  christos    created in inferior memory by GDB (normally it is set by ld.so).  */
    907  1.3  christos 
    908  1.3  christos char *
    909  1.3  christos default_gcc_target_options (struct gdbarch *gdbarch)
    910  1.3  christos {
    911  1.3  christos   return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
    912  1.3  christos 		     gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
    913  1.3  christos }
    914  1.3  christos 
    915  1.3  christos /* gdbarch gnu_triplet_regexp method.  */
    916  1.3  christos 
    917  1.3  christos const char *
    918  1.3  christos default_gnu_triplet_regexp (struct gdbarch *gdbarch)
    919  1.3  christos {
    920  1.1  christos   return gdbarch_bfd_arch_info (gdbarch)->arch_name;
    921  1.5  christos }
    922  1.5  christos 
    923  1.5  christos /* Default method for gdbarch_addressable_memory_unit_size.  By default, a memory byte has
    924  1.5  christos    a size of 1 octet.  */
    925  1.5  christos 
    926  1.5  christos int
    927  1.5  christos default_addressable_memory_unit_size (struct gdbarch *gdbarch)
    928  1.5  christos {
    929  1.5  christos   return 1;
    930  1.6  christos }
    931  1.6  christos 
    932  1.6  christos void
    933  1.6  christos default_guess_tracepoint_registers (struct gdbarch *gdbarch,
    934  1.6  christos 				    struct regcache *regcache,
    935  1.6  christos 				    CORE_ADDR addr)
    936  1.6  christos {
    937  1.6  christos   int pc_regno = gdbarch_pc_regnum (gdbarch);
    938  1.6  christos   gdb_byte *regs;
    939  1.6  christos 
    940  1.6  christos   /* This guessing code below only works if the PC register isn't
    941  1.6  christos      a pseudo-register.  The value of a pseudo-register isn't stored
    942  1.6  christos      in the (non-readonly) regcache -- instead it's recomputed
    943  1.6  christos      (probably from some other cached raw register) whenever the
    944  1.6  christos      register is read.  In this case, a custom method implementation
    945  1.6  christos      should be used by the architecture.  */
    946  1.6  christos   if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
    947  1.6  christos     return;
    948  1.6  christos 
    949  1.6  christos   regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
    950  1.8  christos   store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
    951  1.8  christos 			  gdbarch_byte_order (gdbarch), addr);
    952  1.8  christos   regcache->raw_supply (pc_regno, regs);
    953  1.8  christos }
    954  1.8  christos 
    955  1.8  christos int
    956  1.8  christos default_print_insn (bfd_vma memaddr, disassemble_info *info)
    957  1.8  christos {
    958  1.8  christos   disassembler_ftype disassemble_fn;
    959  1.8  christos 
    960  1.8  christos   disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
    961  1.8  christos 				 info->mach, exec_bfd);
    962  1.8  christos 
    963  1.6  christos   gdb_assert (disassemble_fn != NULL);
    964  1.6  christos   return (*disassemble_fn) (memaddr, info);
    965  1.7  christos }
    966  1.7  christos 
    967  1.7  christos /* See arch-utils.h.  */
    968  1.7  christos 
    969  1.7  christos CORE_ADDR
    970  1.7  christos gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
    971  1.7  christos {
    972  1.7  christos   CORE_ADDR new_pc = pc;
    973  1.7  christos 
    974  1.7  christos   TRY
    975  1.7  christos     {
    976  1.7  christos       new_pc = gdbarch_skip_prologue (gdbarch, pc);
    977  1.7  christos     }
    978  1.7  christos   CATCH (ex, RETURN_MASK_ALL)
    979  1.7  christos     {}
    980  1.7  christos   END_CATCH
    981  1.7  christos 
    982  1.7  christos   return new_pc;
    983  1.8  christos }
    984  1.8  christos 
    985  1.8  christos /* See arch-utils.h.  */
    986  1.8  christos 
    987  1.8  christos bool
    988  1.8  christos default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
    989  1.8  christos {
    990  1.8  christos   return false;
    991  1.8  christos }
    992  1.8  christos 
    993  1.8  christos /* See arch-utils.h.  */
    994  1.8  christos 
    995  1.8  christos ULONGEST
    996  1.8  christos default_type_align (struct gdbarch *gdbarch, struct type *type)
    997  1.8  christos {
    998  1.1  christos   return type_length_units (check_typedef (type));
    999  1.1  christos }
   1000  1.1  christos 
   1001  1.1  christos void
   1002  1.1  christos _initialize_gdbarch_utils (void)
   1003  1.1  christos {
   1004  1.1  christos   add_setshow_enum_cmd ("endian", class_support,
   1005  1.1  christos 			endian_enum, &set_endian_string,
   1006  1.1  christos 			_("Set endianness of target."),
   1007  1.1  christos 			_("Show endianness of target."),
   1008  1.1  christos 			NULL, set_endian, show_endian,
   1009                			&setlist, &showlist);
   1010                }
   1011