gdb/arch-utils.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Dynamic architecture support for GDB, the GNU debugger.

  2.    Copyright (C) 1998-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"

  15. #include "arch-utils.h"
  16. #include "buildsym.h"
  17. #include "gdbcmd.h"
  18. #include "inferior.h"                /* enum CALL_DUMMY_LOCATION et al.  */
  19. #include "infrun.h"
  20. #include "regcache.h"
  21. #include "sim-regno.h"
  22. #include "gdbcore.h"
  23. #include "osabi.h"
  24. #include "target-descriptions.h"
  25. #include "objfiles.h"
  26. #include "language.h"
  27. #include "symtab.h"

  28. #include "version.h"

  29. #include "floatformat.h"


  30. struct displaced_step_closure *
  31. simple_displaced_step_copy_insn (struct gdbarch *gdbarch,
  32.                                  CORE_ADDR from, CORE_ADDR to,
  33.                                  struct regcache *regs)
  34. {
  35.   size_t len = gdbarch_max_insn_length (gdbarch);
  36.   gdb_byte *buf = xmalloc (len);

  37.   read_memory (from, buf, len);
  38.   write_memory (to, buf, len);

  39.   if (debug_displaced)
  40.     {
  41.       fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
  42.                           paddress (gdbarch, from), paddress (gdbarch, to));
  43.       displaced_step_dump_bytes (gdb_stdlog, buf, len);
  44.     }

  45.   return (struct displaced_step_closure *) buf;
  46. }


  47. void
  48. simple_displaced_step_free_closure (struct gdbarch *gdbarch,
  49.                                     struct displaced_step_closure *closure)
  50. {
  51.   xfree (closure);
  52. }

  53. int
  54. default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
  55.                                       struct displaced_step_closure *closure)
  56. {
  57.   return !gdbarch_software_single_step_p (gdbarch);
  58. }

  59. CORE_ADDR
  60. displaced_step_at_entry_point (struct gdbarch *gdbarch)
  61. {
  62.   CORE_ADDR addr;
  63.   int bp_len;

  64.   addr = entry_point_address ();

  65.   /* Inferior calls also use the entry point as a breakpoint location.
  66.      We don't want displaced stepping to interfere with those
  67.      breakpoints, so leave space.  */
  68.   gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
  69.   addr += bp_len * 2;

  70.   return addr;
  71. }

  72. int
  73. legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
  74. {
  75.   /* Only makes sense to supply raw registers.  */
  76.   gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
  77.   /* NOTE: cagney/2002-05-13: The old code did it this way and it is
  78.      suspected that some GDB/SIM combinations may rely on this
  79.      behavour.  The default should be one2one_register_sim_regno
  80.      (below).  */
  81.   if (gdbarch_register_name (gdbarch, regnum) != NULL
  82.       && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
  83.     return regnum;
  84.   else
  85.     return LEGACY_SIM_REGNO_IGNORE;
  86. }

  87. CORE_ADDR
  88. generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  89. {
  90.   return 0;
  91. }

  92. CORE_ADDR
  93. generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  94. {
  95.   return 0;
  96. }

  97. int
  98. generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
  99.                                     CORE_ADDR pc, const char *name)
  100. {
  101.   return 0;
  102. }

  103. int
  104. generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  105. {
  106.   return 0;
  107. }

  108. /* Helper functions for gdbarch_inner_than */

  109. int
  110. core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
  111. {
  112.   return (lhs < rhs);
  113. }

  114. int
  115. core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
  116. {
  117.   return (lhs > rhs);
  118. }

  119. /* Misc helper functions for targets.  */

  120. CORE_ADDR
  121. core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
  122. {
  123.   return addr;
  124. }

  125. CORE_ADDR
  126. convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
  127.                                      struct target_ops *targ)
  128. {
  129.   return addr;
  130. }

  131. int
  132. no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  133. {
  134.   return reg;
  135. }

  136. void
  137. default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
  138. {
  139.   return;
  140. }

  141. /* See arch-utils.h.  */

  142. void
  143. default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
  144. {
  145.   return;
  146. }

  147. /* See arch-utils.h.  */

  148. CORE_ADDR
  149. default_adjust_dwarf2_addr (CORE_ADDR pc)
  150. {
  151.   return pc;
  152. }

  153. /* See arch-utils.h.  */

  154. CORE_ADDR
  155. default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
  156. {
  157.   return addr;
  158. }

  159. int
  160. cannot_register_not (struct gdbarch *gdbarch, int regnum)
  161. {
  162.   return 0;
  163. }

  164. /* Legacy version of target_virtual_frame_pointer().  Assumes that
  165.    there is an gdbarch_deprecated_fp_regnum and that it is the same,
  166.    cooked or raw.  */

  167. void
  168. legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
  169.                               CORE_ADDR pc,
  170.                               int *frame_regnum,
  171.                               LONGEST *frame_offset)
  172. {
  173.   /* FIXME: cagney/2002-09-13: This code is used when identifying the
  174.      frame pointer of the current PC.  It is assuming that a single
  175.      register and an offset can determine this.  I think it should
  176.      instead generate a byte code expression as that would work better
  177.      with things like Dwarf2's CFI.  */
  178.   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
  179.       && gdbarch_deprecated_fp_regnum (gdbarch)
  180.            < gdbarch_num_regs (gdbarch))
  181.     *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
  182.   else if (gdbarch_sp_regnum (gdbarch) >= 0
  183.            && gdbarch_sp_regnum (gdbarch)
  184.                 < gdbarch_num_regs (gdbarch))
  185.     *frame_regnum = gdbarch_sp_regnum (gdbarch);
  186.   else
  187.     /* Should this be an internal errorI guess so, it is reflecting
  188.        an architectural limitation in the current design.  */
  189.     internal_error (__FILE__, __LINE__,
  190.                     _("No virtual frame pointer available"));
  191.   *frame_offset = 0;
  192. }


  193. int
  194. generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
  195.                             struct type *type)
  196. {
  197.   return 0;
  198. }

  199. int
  200. default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
  201. {
  202.   return 0;
  203. }

  204. int
  205. generic_instruction_nullified (struct gdbarch *gdbarch,
  206.                                struct regcache *regcache)
  207. {
  208.   return 0;
  209. }

  210. int
  211. default_remote_register_number (struct gdbarch *gdbarch,
  212.                                 int regno)
  213. {
  214.   return regno;
  215. }

  216. /* See arch-utils.h.  */

  217. int
  218. default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
  219. {
  220.   return 0;
  221. }


  222. /* Functions to manipulate the endianness of the target.  */

  223. static int target_byte_order_user = BFD_ENDIAN_UNKNOWN;

  224. static const char endian_big[] = "big";
  225. static const char endian_little[] = "little";
  226. static const char endian_auto[] = "auto";
  227. static const char *const endian_enum[] =
  228. {
  229.   endian_big,
  230.   endian_little,
  231.   endian_auto,
  232.   NULL,
  233. };
  234. static const char *set_endian_string;

  235. enum bfd_endian
  236. selected_byte_order (void)
  237. {
  238.   return target_byte_order_user;
  239. }

  240. /* Called by ``show endian''.  */

  241. static void
  242. show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
  243.              const char *value)
  244. {
  245.   if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
  246.     if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
  247.       fprintf_unfiltered (file, _("The target endianness is set automatically "
  248.                                   "(currently big endian)\n"));
  249.     else
  250.       fprintf_unfiltered (file, _("The target endianness is set automatically "
  251.                                   "(currently little endian)\n"));
  252.   else
  253.     if (target_byte_order_user == BFD_ENDIAN_BIG)
  254.       fprintf_unfiltered (file,
  255.                           _("The target is assumed to be big endian\n"));
  256.     else
  257.       fprintf_unfiltered (file,
  258.                           _("The target is assumed to be little endian\n"));
  259. }

  260. static void
  261. set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
  262. {
  263.   struct gdbarch_info info;

  264.   gdbarch_info_init (&info);

  265.   if (set_endian_string == endian_auto)
  266.     {
  267.       target_byte_order_user = BFD_ENDIAN_UNKNOWN;
  268.       if (! gdbarch_update_p (info))
  269.         internal_error (__FILE__, __LINE__,
  270.                         _("set_endian: architecture update failed"));
  271.     }
  272.   else if (set_endian_string == endian_little)
  273.     {
  274.       info.byte_order = BFD_ENDIAN_LITTLE;
  275.       if (! gdbarch_update_p (info))
  276.         printf_unfiltered (_("Little endian target not supported by GDB\n"));
  277.       else
  278.         target_byte_order_user = BFD_ENDIAN_LITTLE;
  279.     }
  280.   else if (set_endian_string == endian_big)
  281.     {
  282.       info.byte_order = BFD_ENDIAN_BIG;
  283.       if (! gdbarch_update_p (info))
  284.         printf_unfiltered (_("Big endian target not supported by GDB\n"));
  285.       else
  286.         target_byte_order_user = BFD_ENDIAN_BIG;
  287.     }
  288.   else
  289.     internal_error (__FILE__, __LINE__,
  290.                     _("set_endian: bad value"));

  291.   show_endian (gdb_stdout, from_tty, NULL, NULL);
  292. }

  293. /* Given SELECTED, a currently selected BFD architecture, and
  294.    TARGET_DESC, the current target description, return what
  295.    architecture to use.

  296.    SELECTED may be NULL, in which case we return the architecture
  297.    associated with TARGET_DESC.  If SELECTED specifies a variant
  298.    of the architecture associtated with TARGET_DESC, return the
  299.    more specific of the two.

  300.    If SELECTED is a different architecture, but it is accepted as
  301.    compatible by the target, we can use the target architecture.

  302.    If SELECTED is obviously incompatible, warn the user.  */

  303. static const struct bfd_arch_info *
  304. choose_architecture_for_target (const struct target_desc *target_desc,
  305.                                 const struct bfd_arch_info *selected)
  306. {
  307.   const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
  308.   const struct bfd_arch_info *compat1, *compat2;

  309.   if (selected == NULL)
  310.     return from_target;

  311.   if (from_target == NULL)
  312.     return selected;

  313.   /* struct bfd_arch_info objects are singletons: that is, there's
  314.      supposed to be exactly one instance for a given machine.  So you
  315.      can tell whether two are equivalent by comparing pointers.  */
  316.   if (from_target == selected)
  317.     return selected;

  318.   /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
  319.      incompatible.  But if they are compatible, it returns the 'more
  320.      featureful' of the two arches.  That is, if A can run code
  321.      written for B, but B can't run code written for A, then it'll
  322.      return A.

  323.      Some targets (e.g. MIPS as of 2006-12-04) don't fully
  324.      implement this, instead always returning NULL or the first
  325.      argument.  We detect that case by checking both directions.  */

  326.   compat1 = selected->compatible (selected, from_target);
  327.   compat2 = from_target->compatible (from_target, selected);

  328.   if (compat1 == NULL && compat2 == NULL)
  329.     {
  330.       /* BFD considers the architectures incompatible.  Check our
  331.          target description whether it accepts SELECTED as compatible
  332.          anyway.  */
  333.       if (tdesc_compatible_p (target_desc, selected))
  334.         return from_target;

  335.       warning (_("Selected architecture %s is not compatible "
  336.                  "with reported target architecture %s"),
  337.                selected->printable_name, from_target->printable_name);
  338.       return selected;
  339.     }

  340.   if (compat1 == NULL)
  341.     return compat2;
  342.   if (compat2 == NULL)
  343.     return compat1;
  344.   if (compat1 == compat2)
  345.     return compat1;

  346.   /* If the two didn't match, but one of them was a default
  347.      architecture, assume the more specific one is correct.  This
  348.      handles the case where an executable or target description just
  349.      says "mips", but the other knows which MIPS variant.  */
  350.   if (compat1->the_default)
  351.     return compat2;
  352.   if (compat2->the_default)
  353.     return compat1;

  354.   /* We have no idea which one is better.  This is a bug, but not
  355.      a critical problem; warn the user.  */
  356.   warning (_("Selected architecture %s is ambiguous with "
  357.              "reported target architecture %s"),
  358.            selected->printable_name, from_target->printable_name);
  359.   return selected;
  360. }

  361. /* Functions to manipulate the architecture of the target.  */

  362. enum set_arch { set_arch_auto, set_arch_manual };

  363. static const struct bfd_arch_info *target_architecture_user;

  364. static const char *set_architecture_string;

  365. const char *
  366. selected_architecture_name (void)
  367. {
  368.   if (target_architecture_user == NULL)
  369.     return NULL;
  370.   else
  371.     return set_architecture_string;
  372. }

  373. /* Called if the user enters ``show architecture'' without an
  374.    argument.  */

  375. static void
  376. show_architecture (struct ui_file *file, int from_tty,
  377.                    struct cmd_list_element *c, const char *value)
  378. {
  379.   if (target_architecture_user == NULL)
  380.     fprintf_filtered (file, _("The target architecture is set "
  381.                               "automatically (currently %s)\n"),
  382.                       gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
  383.   else
  384.     fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
  385.                       set_architecture_string);
  386. }


  387. /* Called if the user enters ``set architecture'' with or without an
  388.    argument.  */

  389. static void
  390. set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
  391. {
  392.   struct gdbarch_info info;

  393.   gdbarch_info_init (&info);

  394.   if (strcmp (set_architecture_string, "auto") == 0)
  395.     {
  396.       target_architecture_user = NULL;
  397.       if (!gdbarch_update_p (info))
  398.         internal_error (__FILE__, __LINE__,
  399.                         _("could not select an architecture automatically"));
  400.     }
  401.   else
  402.     {
  403.       info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
  404.       if (info.bfd_arch_info == NULL)
  405.         internal_error (__FILE__, __LINE__,
  406.                         _("set_architecture: bfd_scan_arch failed"));
  407.       if (gdbarch_update_p (info))
  408.         target_architecture_user = info.bfd_arch_info;
  409.       else
  410.         printf_unfiltered (_("Architecture `%s' not recognized.\n"),
  411.                            set_architecture_string);
  412.     }
  413.   show_architecture (gdb_stdout, from_tty, NULL, NULL);
  414. }

  415. /* Try to select a global architecture that matches "info".  Return
  416.    non-zero if the attempt succeeds.  */
  417. int
  418. gdbarch_update_p (struct gdbarch_info info)
  419. {
  420.   struct gdbarch *new_gdbarch;

  421.   /* Check for the current file.  */
  422.   if (info.abfd == NULL)
  423.     info.abfd = exec_bfd;
  424.   if (info.abfd == NULL)
  425.     info.abfd = core_bfd;

  426.   /* Check for the current target description.  */
  427.   if (info.target_desc == NULL)
  428.     info.target_desc = target_current_description ();

  429.   new_gdbarch = gdbarch_find_by_info (info);

  430.   /* If there no architecture by that name, reject the request.  */
  431.   if (new_gdbarch == NULL)
  432.     {
  433.       if (gdbarch_debug)
  434.         fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
  435.                             "Architecture not found\n");
  436.       return 0;
  437.     }

  438.   /* If it is the same old architecture, accept the request (but don't
  439.      swap anything).  */
  440.   if (new_gdbarch == target_gdbarch ())
  441.     {
  442.       if (gdbarch_debug)
  443.         fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
  444.                             "Architecture %s (%s) unchanged\n",
  445.                             host_address_to_string (new_gdbarch),
  446.                             gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
  447.       return 1;
  448.     }

  449.   /* It's a new architecture, swap it in.  */
  450.   if (gdbarch_debug)
  451.     fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
  452.                         "New architecture %s (%s) selected\n",
  453.                         host_address_to_string (new_gdbarch),
  454.                         gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
  455.   set_target_gdbarch (new_gdbarch);

  456.   return 1;
  457. }

  458. /* Return the architecture for ABFD.  If no suitable architecture
  459.    could be find, return NULL.  */

  460. struct gdbarch *
  461. gdbarch_from_bfd (bfd *abfd)
  462. {
  463.   struct gdbarch_info info;
  464.   gdbarch_info_init (&info);

  465.   info.abfd = abfd;
  466.   return gdbarch_find_by_info (info);
  467. }

  468. /* Set the dynamic target-system-dependent parameters (architecture,
  469.    byte-order) using information found in the BFD */

  470. void
  471. set_gdbarch_from_file (bfd *abfd)
  472. {
  473.   struct gdbarch_info info;
  474.   struct gdbarch *gdbarch;

  475.   gdbarch_info_init (&info);
  476.   info.abfd = abfd;
  477.   info.target_desc = target_current_description ();
  478.   gdbarch = gdbarch_find_by_info (info);

  479.   if (gdbarch == NULL)
  480.     error (_("Architecture of file not recognized."));
  481.   set_target_gdbarch (gdbarch);
  482. }

  483. /* Initialize the current architecture.  Update the ``set
  484.    architecture'' command so that it specifies a list of valid
  485.    architectures.  */

  486. #ifdef DEFAULT_BFD_ARCH
  487. extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
  488. static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
  489. #else
  490. static const bfd_arch_info_type *default_bfd_arch;
  491. #endif

  492. #ifdef DEFAULT_BFD_VEC
  493. extern const bfd_target DEFAULT_BFD_VEC;
  494. static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
  495. #else
  496. static const bfd_target *default_bfd_vec;
  497. #endif

  498. static int default_byte_order = BFD_ENDIAN_UNKNOWN;

  499. void
  500. initialize_current_architecture (void)
  501. {
  502.   const char **arches = gdbarch_printable_names ();
  503.   struct gdbarch_info info;

  504.   /* determine a default architecture and byte order.  */
  505.   gdbarch_info_init (&info);

  506.   /* Find a default architecture.  */
  507.   if (default_bfd_arch == NULL)
  508.     {
  509.       /* Choose the architecture by taking the first one
  510.          alphabetically.  */
  511.       const char *chosen = arches[0];
  512.       const char **arch;
  513.       for (arch = arches; *arch != NULL; arch++)
  514.         {
  515.           if (strcmp (*arch, chosen) < 0)
  516.             chosen = *arch;
  517.         }
  518.       if (chosen == NULL)
  519.         internal_error (__FILE__, __LINE__,
  520.                         _("initialize_current_architecture: No arch"));
  521.       default_bfd_arch = bfd_scan_arch (chosen);
  522.       if (default_bfd_arch == NULL)
  523.         internal_error (__FILE__, __LINE__,
  524.                         _("initialize_current_architecture: Arch not found"));
  525.     }

  526.   info.bfd_arch_info = default_bfd_arch;

  527.   /* Take several guesses at a byte order.  */
  528.   if (default_byte_order == BFD_ENDIAN_UNKNOWN
  529.       && default_bfd_vec != NULL)
  530.     {
  531.       /* Extract BFD's default vector's byte order.  */
  532.       switch (default_bfd_vec->byteorder)
  533.         {
  534.         case BFD_ENDIAN_BIG:
  535.           default_byte_order = BFD_ENDIAN_BIG;
  536.           break;
  537.         case BFD_ENDIAN_LITTLE:
  538.           default_byte_order = BFD_ENDIAN_LITTLE;
  539.           break;
  540.         default:
  541.           break;
  542.         }
  543.     }
  544.   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
  545.     {
  546.       /* look for ``*el-*'' in the target name.  */
  547.       const char *chp;
  548.       chp = strchr (target_name, '-');
  549.       if (chp != NULL
  550.           && chp - 2 >= target_name
  551.           && strncmp (chp - 2, "el", 2) == 0)
  552.         default_byte_order = BFD_ENDIAN_LITTLE;
  553.     }
  554.   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
  555.     {
  556.       /* Wire it to big-endian!!! */
  557.       default_byte_order = BFD_ENDIAN_BIG;
  558.     }

  559.   info.byte_order = default_byte_order;
  560.   info.byte_order_for_code = info.byte_order;

  561.   if (! gdbarch_update_p (info))
  562.     internal_error (__FILE__, __LINE__,
  563.                     _("initialize_current_architecture: Selection of "
  564.                       "initial architecture failed"));

  565.   /* Create the ``set architecture'' command appending ``auto'' to the
  566.      list of architectures.  */
  567.   {
  568.     /* Append ``auto''.  */
  569.     int nr;
  570.     for (nr = 0; arches[nr] != NULL; nr++);
  571.     arches = xrealloc (arches, sizeof (char*) * (nr + 2));
  572.     arches[nr + 0] = "auto";
  573.     arches[nr + 1] = NULL;
  574.     add_setshow_enum_cmd ("architecture", class_support,
  575.                           arches, &set_architecture_string,
  576.                           _("Set architecture of target."),
  577.                           _("Show architecture of target."), NULL,
  578.                           set_architecture, show_architecture,
  579.                           &setlist, &showlist);
  580.     add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
  581.   }
  582. }


  583. /* Initialize a gdbarch info to values that will be automatically
  584.    overridden.  Note: Originally, this ``struct info'' was initialized
  585.    using memset(0).  Unfortunately, that ran into problems, namely
  586.    BFD_ENDIAN_BIG is zero.  An explicit initialization function that
  587.    can explicitly set each field to a well defined value is used.  */

  588. void
  589. gdbarch_info_init (struct gdbarch_info *info)
  590. {
  591.   memset (info, 0, sizeof (struct gdbarch_info));
  592.   info->byte_order = BFD_ENDIAN_UNKNOWN;
  593.   info->byte_order_for_code = info->byte_order;
  594.   info->osabi = GDB_OSABI_UNINITIALIZED;
  595. }

  596. /* Similar to init, but this time fill in the blanks.  Information is
  597.    obtained from the global "set ..." options and explicitly
  598.    initialized INFO fields.  */

  599. void
  600. gdbarch_info_fill (struct gdbarch_info *info)
  601. {
  602.   /* "(gdb) set architecture ...".  */
  603.   if (info->bfd_arch_info == NULL
  604.       && target_architecture_user)
  605.     info->bfd_arch_info = target_architecture_user;
  606.   /* From the file.  */
  607.   if (info->bfd_arch_info == NULL
  608.       && info->abfd != NULL
  609.       && bfd_get_arch (info->abfd) != bfd_arch_unknown
  610.       && bfd_get_arch (info->abfd) != bfd_arch_obscure)
  611.     info->bfd_arch_info = bfd_get_arch_info (info->abfd);
  612.   /* From the target.  */
  613.   if (info->target_desc != NULL)
  614.     info->bfd_arch_info = choose_architecture_for_target
  615.                            (info->target_desc, info->bfd_arch_info);
  616.   /* From the default.  */
  617.   if (info->bfd_arch_info == NULL)
  618.     info->bfd_arch_info = default_bfd_arch;

  619.   /* "(gdb) set byte-order ...".  */
  620.   if (info->byte_order == BFD_ENDIAN_UNKNOWN
  621.       && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
  622.     info->byte_order = target_byte_order_user;
  623.   /* From the INFO struct.  */
  624.   if (info->byte_order == BFD_ENDIAN_UNKNOWN
  625.       && info->abfd != NULL)
  626.     info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
  627.                         : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
  628.                         : BFD_ENDIAN_UNKNOWN);
  629.   /* From the default.  */
  630.   if (info->byte_order == BFD_ENDIAN_UNKNOWN)
  631.     info->byte_order = default_byte_order;
  632.   info->byte_order_for_code = info->byte_order;

  633.   /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
  634.   /* From the manual override, or from file.  */
  635.   if (info->osabi == GDB_OSABI_UNINITIALIZED)
  636.     info->osabi = gdbarch_lookup_osabi (info->abfd);
  637.   /* From the target.  */
  638.   if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
  639.     info->osabi = tdesc_osabi (info->target_desc);
  640.   /* From the configured default.  */
  641. #ifdef GDB_OSABI_DEFAULT
  642.   if (info->osabi == GDB_OSABI_UNKNOWN)
  643.     info->osabi = GDB_OSABI_DEFAULT;
  644. #endif

  645.   /* Must have at least filled in the architecture.  */
  646.   gdb_assert (info->bfd_arch_info != NULL);
  647. }

  648. /* Return "current" architecture.  If the target is running, this is
  649.    the architecture of the selected frame.  Otherwise, the "current"
  650.    architecture defaults to the target architecture.

  651.    This function should normally be called solely by the command
  652.    interpreter routines to determine the architecture to execute a
  653.    command in.  */
  654. struct gdbarch *
  655. get_current_arch (void)
  656. {
  657.   if (has_stack_frames ())
  658.     return get_frame_arch (get_selected_frame (NULL));
  659.   else
  660.     return target_gdbarch ();
  661. }

  662. int
  663. default_has_shared_address_space (struct gdbarch *gdbarch)
  664. {
  665.   /* Simply say no.  In most unix-like targets each inferior/process
  666.      has its own address space.  */
  667.   return 0;
  668. }

  669. int
  670. default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
  671.                                   CORE_ADDR addr, int *isize, char **msg)
  672. {
  673.   /* We don't know if maybe the target has some way to do fast
  674.      tracepoints that doesn't need gdbarch, so always say yes.  */
  675.   if (msg)
  676.     *msg = NULL;
  677.   return 1;
  678. }

  679. void
  680. default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
  681.                                    int *kindptr)
  682. {
  683.   gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
  684. }

  685. void
  686. default_gen_return_address (struct gdbarch *gdbarch,
  687.                             struct agent_expr *ax, struct axs_value *value,
  688.                             CORE_ADDR scope)
  689. {
  690.   error (_("This architecture has no method to collect a return address."));
  691. }

  692. int
  693. default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
  694.                                         struct type *type)
  695. {
  696.   /* Usually, the return value's address is stored the in the "first hidden"
  697.      parameter if the return value should be passed by reference, as
  698.      specified in ABI.  */
  699.   return language_pass_by_reference (type);
  700. }

  701. int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
  702. {
  703.   return 0;
  704. }

  705. int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
  706. {
  707.   return 0;
  708. }

  709. int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
  710. {
  711.   return 0;
  712. }

  713. void
  714. default_skip_permanent_breakpoint (struct regcache *regcache)
  715. {
  716.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  717.   CORE_ADDR current_pc = regcache_read_pc (regcache);
  718.   const gdb_byte *bp_insn;
  719.   int bp_len;

  720.   bp_insn = gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
  721.   current_pc += bp_len;
  722.   regcache_write_pc (regcache, current_pc);
  723. }

  724. CORE_ADDR
  725. default_infcall_mmap (CORE_ADDR size, unsigned prot)
  726. {
  727.   error (_("This target does not support inferior memory allocation by mmap."));
  728. }

  729. /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
  730.    created in inferior memory by GDB (normally it is set by ld.so).  */

  731. char *
  732. default_gcc_target_options (struct gdbarch *gdbarch)
  733. {
  734.   return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
  735.                      gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
  736. }

  737. /* gdbarch gnu_triplet_regexp method.  */

  738. const char *
  739. default_gnu_triplet_regexp (struct gdbarch *gdbarch)
  740. {
  741.   return gdbarch_bfd_arch_info (gdbarch)->arch_name;
  742. }

  743. /* -Wmissing-prototypes */
  744. extern initialize_file_ftype _initialize_gdbarch_utils;

  745. void
  746. _initialize_gdbarch_utils (void)
  747. {
  748.   add_setshow_enum_cmd ("endian", class_support,
  749.                         endian_enum, &set_endian_string,
  750.                         _("Set endianness of target."),
  751.                         _("Show endianness of target."),
  752.                         NULL, set_endian, show_endian,
  753.                         &setlist, &showlist);
  754. }