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