GDB (API)
/home/stan/gdb/src/gdb/arch-utils.c
Go to the documentation of this file.
00001 /* Dynamic architecture support for GDB, the GNU debugger.
00002 
00003    Copyright (C) 1998-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 
00022 #include "arch-utils.h"
00023 #include "buildsym.h"
00024 #include "gdbcmd.h"
00025 #include "inferior.h"           /* enum CALL_DUMMY_LOCATION et al.  */
00026 #include "gdb_string.h"
00027 #include "regcache.h"
00028 #include "gdb_assert.h"
00029 #include "sim-regno.h"
00030 #include "gdbcore.h"
00031 #include "osabi.h"
00032 #include "target-descriptions.h"
00033 #include "objfiles.h"
00034 #include "language.h"
00035 
00036 #include "version.h"
00037 
00038 #include "floatformat.h"
00039 
00040 
00041 struct displaced_step_closure *
00042 simple_displaced_step_copy_insn (struct gdbarch *gdbarch,
00043                                  CORE_ADDR from, CORE_ADDR to,
00044                                  struct regcache *regs)
00045 {
00046   size_t len = gdbarch_max_insn_length (gdbarch);
00047   gdb_byte *buf = xmalloc (len);
00048 
00049   read_memory (from, buf, len);
00050   write_memory (to, buf, len);
00051 
00052   if (debug_displaced)
00053     {
00054       fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
00055                           paddress (gdbarch, from), paddress (gdbarch, to));
00056       displaced_step_dump_bytes (gdb_stdlog, buf, len);
00057     }
00058 
00059   return (struct displaced_step_closure *) buf;
00060 }
00061 
00062 
00063 void
00064 simple_displaced_step_free_closure (struct gdbarch *gdbarch,
00065                                     struct displaced_step_closure *closure)
00066 {
00067   xfree (closure);
00068 }
00069 
00070 int
00071 default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
00072                                       struct displaced_step_closure *closure)
00073 {
00074   return !gdbarch_software_single_step_p (gdbarch);
00075 }
00076 
00077 CORE_ADDR
00078 displaced_step_at_entry_point (struct gdbarch *gdbarch)
00079 {
00080   CORE_ADDR addr;
00081   int bp_len;
00082 
00083   addr = entry_point_address ();
00084 
00085   /* Inferior calls also use the entry point as a breakpoint location.
00086      We don't want displaced stepping to interfere with those
00087      breakpoints, so leave space.  */
00088   gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
00089   addr += bp_len * 2;
00090 
00091   return addr;
00092 }
00093 
00094 int
00095 legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
00096 {
00097   /* Only makes sense to supply raw registers.  */
00098   gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
00099   /* NOTE: cagney/2002-05-13: The old code did it this way and it is
00100      suspected that some GDB/SIM combinations may rely on this
00101      behavour.  The default should be one2one_register_sim_regno
00102      (below).  */
00103   if (gdbarch_register_name (gdbarch, regnum) != NULL
00104       && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
00105     return regnum;
00106   else
00107     return LEGACY_SIM_REGNO_IGNORE;
00108 }
00109 
00110 CORE_ADDR
00111 generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
00112 {
00113   return 0;
00114 }
00115 
00116 CORE_ADDR
00117 generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
00118 {
00119   return 0;
00120 }
00121 
00122 int
00123 generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
00124                                     CORE_ADDR pc, const char *name)
00125 {
00126   return 0;
00127 }
00128 
00129 int
00130 generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
00131 {
00132   return 0;
00133 }
00134 
00135 /* Helper functions for gdbarch_inner_than */
00136 
00137 int
00138 core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
00139 {
00140   return (lhs < rhs);
00141 }
00142 
00143 int
00144 core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
00145 {
00146   return (lhs > rhs);
00147 }
00148 
00149 /* Misc helper functions for targets.  */
00150 
00151 CORE_ADDR
00152 core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
00153 {
00154   return addr;
00155 }
00156 
00157 CORE_ADDR
00158 convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
00159                                      struct target_ops *targ)
00160 {
00161   return addr;
00162 }
00163 
00164 int
00165 no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
00166 {
00167   return reg;
00168 }
00169 
00170 void
00171 default_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
00172 {
00173   return;
00174 }
00175 
00176 void
00177 default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
00178 {
00179   return;
00180 }
00181 
00182 int
00183 cannot_register_not (struct gdbarch *gdbarch, int regnum)
00184 {
00185   return 0;
00186 }
00187 
00188 /* Legacy version of target_virtual_frame_pointer().  Assumes that
00189    there is an gdbarch_deprecated_fp_regnum and that it is the same,
00190    cooked or raw.  */
00191 
00192 void
00193 legacy_virtual_frame_pointer (struct gdbarch *gdbarch, 
00194                               CORE_ADDR pc,
00195                               int *frame_regnum,
00196                               LONGEST *frame_offset)
00197 {
00198   /* FIXME: cagney/2002-09-13: This code is used when identifying the
00199      frame pointer of the current PC.  It is assuming that a single
00200      register and an offset can determine this.  I think it should
00201      instead generate a byte code expression as that would work better
00202      with things like Dwarf2's CFI.  */
00203   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
00204       && gdbarch_deprecated_fp_regnum (gdbarch)
00205            < gdbarch_num_regs (gdbarch))
00206     *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
00207   else if (gdbarch_sp_regnum (gdbarch) >= 0
00208            && gdbarch_sp_regnum (gdbarch)
00209                 < gdbarch_num_regs (gdbarch))
00210     *frame_regnum = gdbarch_sp_regnum (gdbarch);
00211   else
00212     /* Should this be an internal error?  I guess so, it is reflecting
00213        an architectural limitation in the current design.  */
00214     internal_error (__FILE__, __LINE__, 
00215                     _("No virtual frame pointer available"));
00216   *frame_offset = 0;
00217 }
00218 
00219 
00220 int
00221 generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
00222                             struct type *type)
00223 {
00224   return 0;
00225 }
00226 
00227 int
00228 default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
00229 {
00230   return 0;
00231 }
00232 
00233 int
00234 generic_instruction_nullified (struct gdbarch *gdbarch,
00235                                struct regcache *regcache)
00236 {
00237   return 0;
00238 }
00239 
00240 int
00241 default_remote_register_number (struct gdbarch *gdbarch,
00242                                 int regno)
00243 {
00244   return regno;
00245 }
00246 
00247 
00248 /* Functions to manipulate the endianness of the target.  */
00249 
00250 static int target_byte_order_user = BFD_ENDIAN_UNKNOWN;
00251 
00252 static const char endian_big[] = "big";
00253 static const char endian_little[] = "little";
00254 static const char endian_auto[] = "auto";
00255 static const char *const endian_enum[] =
00256 {
00257   endian_big,
00258   endian_little,
00259   endian_auto,
00260   NULL,
00261 };
00262 static const char *set_endian_string;
00263 
00264 enum bfd_endian
00265 selected_byte_order (void)
00266 {
00267   return target_byte_order_user;
00268 }
00269 
00270 /* Called by ``show endian''.  */
00271 
00272 static void
00273 show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
00274              const char *value)
00275 {
00276   if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
00277     if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
00278       fprintf_unfiltered (file, _("The target endianness is set automatically "
00279                                   "(currently big endian)\n"));
00280     else
00281       fprintf_unfiltered (file, _("The target endianness is set automatically "
00282                                   "(currently little endian)\n"));
00283   else
00284     if (target_byte_order_user == BFD_ENDIAN_BIG)
00285       fprintf_unfiltered (file,
00286                           _("The target is assumed to be big endian\n"));
00287     else
00288       fprintf_unfiltered (file,
00289                           _("The target is assumed to be little endian\n"));
00290 }
00291 
00292 static void
00293 set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
00294 {
00295   struct gdbarch_info info;
00296 
00297   gdbarch_info_init (&info);
00298 
00299   if (set_endian_string == endian_auto)
00300     {
00301       target_byte_order_user = BFD_ENDIAN_UNKNOWN;
00302       if (! gdbarch_update_p (info))
00303         internal_error (__FILE__, __LINE__,
00304                         _("set_endian: architecture update failed"));
00305     }
00306   else if (set_endian_string == endian_little)
00307     {
00308       info.byte_order = BFD_ENDIAN_LITTLE;
00309       if (! gdbarch_update_p (info))
00310         printf_unfiltered (_("Little endian target not supported by GDB\n"));
00311       else
00312         target_byte_order_user = BFD_ENDIAN_LITTLE;
00313     }
00314   else if (set_endian_string == endian_big)
00315     {
00316       info.byte_order = BFD_ENDIAN_BIG;
00317       if (! gdbarch_update_p (info))
00318         printf_unfiltered (_("Big endian target not supported by GDB\n"));
00319       else
00320         target_byte_order_user = BFD_ENDIAN_BIG;
00321     }
00322   else
00323     internal_error (__FILE__, __LINE__,
00324                     _("set_endian: bad value"));
00325 
00326   show_endian (gdb_stdout, from_tty, NULL, NULL);
00327 }
00328 
00329 /* Given SELECTED, a currently selected BFD architecture, and
00330    TARGET_DESC, the current target description, return what
00331    architecture to use.
00332 
00333    SELECTED may be NULL, in which case we return the architecture
00334    associated with TARGET_DESC.  If SELECTED specifies a variant
00335    of the architecture associtated with TARGET_DESC, return the
00336    more specific of the two.
00337 
00338    If SELECTED is a different architecture, but it is accepted as
00339    compatible by the target, we can use the target architecture.
00340 
00341    If SELECTED is obviously incompatible, warn the user.  */
00342 
00343 static const struct bfd_arch_info *
00344 choose_architecture_for_target (const struct target_desc *target_desc,
00345                                 const struct bfd_arch_info *selected)
00346 {
00347   const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
00348   const struct bfd_arch_info *compat1, *compat2;
00349 
00350   if (selected == NULL)
00351     return from_target;
00352 
00353   if (from_target == NULL)
00354     return selected;
00355 
00356   /* struct bfd_arch_info objects are singletons: that is, there's
00357      supposed to be exactly one instance for a given machine.  So you
00358      can tell whether two are equivalent by comparing pointers.  */
00359   if (from_target == selected)
00360     return selected;
00361 
00362   /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
00363      incompatible.  But if they are compatible, it returns the 'more
00364      featureful' of the two arches.  That is, if A can run code
00365      written for B, but B can't run code written for A, then it'll
00366      return A.
00367 
00368      Some targets (e.g. MIPS as of 2006-12-04) don't fully
00369      implement this, instead always returning NULL or the first
00370      argument.  We detect that case by checking both directions.  */
00371 
00372   compat1 = selected->compatible (selected, from_target);
00373   compat2 = from_target->compatible (from_target, selected);
00374 
00375   if (compat1 == NULL && compat2 == NULL)
00376     {
00377       /* BFD considers the architectures incompatible.  Check our
00378          target description whether it accepts SELECTED as compatible
00379          anyway.  */
00380       if (tdesc_compatible_p (target_desc, selected))
00381         return from_target;
00382 
00383       warning (_("Selected architecture %s is not compatible "
00384                  "with reported target architecture %s"),
00385                selected->printable_name, from_target->printable_name);
00386       return selected;
00387     }
00388 
00389   if (compat1 == NULL)
00390     return compat2;
00391   if (compat2 == NULL)
00392     return compat1;
00393   if (compat1 == compat2)
00394     return compat1;
00395 
00396   /* If the two didn't match, but one of them was a default
00397      architecture, assume the more specific one is correct.  This
00398      handles the case where an executable or target description just
00399      says "mips", but the other knows which MIPS variant.  */
00400   if (compat1->the_default)
00401     return compat2;
00402   if (compat2->the_default)
00403     return compat1;
00404 
00405   /* We have no idea which one is better.  This is a bug, but not
00406      a critical problem; warn the user.  */
00407   warning (_("Selected architecture %s is ambiguous with "
00408              "reported target architecture %s"),
00409            selected->printable_name, from_target->printable_name);
00410   return selected;
00411 }
00412 
00413 /* Functions to manipulate the architecture of the target.  */
00414 
00415 enum set_arch { set_arch_auto, set_arch_manual };
00416 
00417 static const struct bfd_arch_info *target_architecture_user;
00418 
00419 static const char *set_architecture_string;
00420 
00421 const char *
00422 selected_architecture_name (void)
00423 {
00424   if (target_architecture_user == NULL)
00425     return NULL;
00426   else
00427     return set_architecture_string;
00428 }
00429 
00430 /* Called if the user enters ``show architecture'' without an
00431    argument.  */
00432 
00433 static void
00434 show_architecture (struct ui_file *file, int from_tty,
00435                    struct cmd_list_element *c, const char *value)
00436 {
00437   if (target_architecture_user == NULL)
00438     fprintf_filtered (file, _("The target architecture is set "
00439                               "automatically (currently %s)\n"),
00440                       gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
00441   else
00442     fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
00443                       set_architecture_string);
00444 }
00445 
00446 
00447 /* Called if the user enters ``set architecture'' with or without an
00448    argument.  */
00449 
00450 static void
00451 set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
00452 {
00453   struct gdbarch_info info;
00454 
00455   gdbarch_info_init (&info);
00456 
00457   if (strcmp (set_architecture_string, "auto") == 0)
00458     {
00459       target_architecture_user = NULL;
00460       if (!gdbarch_update_p (info))
00461         internal_error (__FILE__, __LINE__,
00462                         _("could not select an architecture automatically"));
00463     }
00464   else
00465     {
00466       info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
00467       if (info.bfd_arch_info == NULL)
00468         internal_error (__FILE__, __LINE__,
00469                         _("set_architecture: bfd_scan_arch failed"));
00470       if (gdbarch_update_p (info))
00471         target_architecture_user = info.bfd_arch_info;
00472       else
00473         printf_unfiltered (_("Architecture `%s' not recognized.\n"),
00474                            set_architecture_string);
00475     }
00476   show_architecture (gdb_stdout, from_tty, NULL, NULL);
00477 }
00478 
00479 /* Try to select a global architecture that matches "info".  Return
00480    non-zero if the attempt succeeds.  */
00481 int
00482 gdbarch_update_p (struct gdbarch_info info)
00483 {
00484   struct gdbarch *new_gdbarch;
00485 
00486   /* Check for the current file.  */
00487   if (info.abfd == NULL)
00488     info.abfd = exec_bfd;
00489   if (info.abfd == NULL)
00490     info.abfd = core_bfd;
00491 
00492   /* Check for the current target description.  */
00493   if (info.target_desc == NULL)
00494     info.target_desc = target_current_description ();
00495 
00496   new_gdbarch = gdbarch_find_by_info (info);
00497 
00498   /* If there no architecture by that name, reject the request.  */
00499   if (new_gdbarch == NULL)
00500     {
00501       if (gdbarch_debug)
00502         fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
00503                             "Architecture not found\n");
00504       return 0;
00505     }
00506 
00507   /* If it is the same old architecture, accept the request (but don't
00508      swap anything).  */
00509   if (new_gdbarch == target_gdbarch ())
00510     {
00511       if (gdbarch_debug)
00512         fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
00513                             "Architecture %s (%s) unchanged\n",
00514                             host_address_to_string (new_gdbarch),
00515                             gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
00516       return 1;
00517     }
00518 
00519   /* It's a new architecture, swap it in.  */
00520   if (gdbarch_debug)
00521     fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
00522                         "New architecture %s (%s) selected\n",
00523                         host_address_to_string (new_gdbarch),
00524                         gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
00525   set_target_gdbarch (new_gdbarch);
00526 
00527   return 1;
00528 }
00529 
00530 /* Return the architecture for ABFD.  If no suitable architecture
00531    could be find, return NULL.  */
00532 
00533 struct gdbarch *
00534 gdbarch_from_bfd (bfd *abfd)
00535 {
00536   struct gdbarch_info info;
00537   gdbarch_info_init (&info);
00538 
00539   info.abfd = abfd;
00540   return gdbarch_find_by_info (info);
00541 }
00542 
00543 /* Set the dynamic target-system-dependent parameters (architecture,
00544    byte-order) using information found in the BFD */
00545 
00546 void
00547 set_gdbarch_from_file (bfd *abfd)
00548 {
00549   struct gdbarch_info info;
00550   struct gdbarch *gdbarch;
00551 
00552   gdbarch_info_init (&info);
00553   info.abfd = abfd;
00554   info.target_desc = target_current_description ();
00555   gdbarch = gdbarch_find_by_info (info);
00556 
00557   if (gdbarch == NULL)
00558     error (_("Architecture of file not recognized."));
00559   set_target_gdbarch (gdbarch);
00560 }
00561 
00562 /* Initialize the current architecture.  Update the ``set
00563    architecture'' command so that it specifies a list of valid
00564    architectures.  */
00565 
00566 #ifdef DEFAULT_BFD_ARCH
00567 extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
00568 static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
00569 #else
00570 static const bfd_arch_info_type *default_bfd_arch;
00571 #endif
00572 
00573 #ifdef DEFAULT_BFD_VEC
00574 extern const bfd_target DEFAULT_BFD_VEC;
00575 static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
00576 #else
00577 static const bfd_target *default_bfd_vec;
00578 #endif
00579 
00580 static int default_byte_order = BFD_ENDIAN_UNKNOWN;
00581 
00582 void
00583 initialize_current_architecture (void)
00584 {
00585   const char **arches = gdbarch_printable_names ();
00586   struct gdbarch_info info;
00587 
00588   /* determine a default architecture and byte order.  */
00589   gdbarch_info_init (&info);
00590   
00591   /* Find a default architecture.  */
00592   if (default_bfd_arch == NULL)
00593     {
00594       /* Choose the architecture by taking the first one
00595          alphabetically.  */
00596       const char *chosen = arches[0];
00597       const char **arch;
00598       for (arch = arches; *arch != NULL; arch++)
00599         {
00600           if (strcmp (*arch, chosen) < 0)
00601             chosen = *arch;
00602         }
00603       if (chosen == NULL)
00604         internal_error (__FILE__, __LINE__,
00605                         _("initialize_current_architecture: No arch"));
00606       default_bfd_arch = bfd_scan_arch (chosen);
00607       if (default_bfd_arch == NULL)
00608         internal_error (__FILE__, __LINE__,
00609                         _("initialize_current_architecture: Arch not found"));
00610     }
00611 
00612   info.bfd_arch_info = default_bfd_arch;
00613 
00614   /* Take several guesses at a byte order.  */
00615   if (default_byte_order == BFD_ENDIAN_UNKNOWN
00616       && default_bfd_vec != NULL)
00617     {
00618       /* Extract BFD's default vector's byte order.  */
00619       switch (default_bfd_vec->byteorder)
00620         {
00621         case BFD_ENDIAN_BIG:
00622           default_byte_order = BFD_ENDIAN_BIG;
00623           break;
00624         case BFD_ENDIAN_LITTLE:
00625           default_byte_order = BFD_ENDIAN_LITTLE;
00626           break;
00627         default:
00628           break;
00629         }
00630     }
00631   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
00632     {
00633       /* look for ``*el-*'' in the target name.  */
00634       const char *chp;
00635       chp = strchr (target_name, '-');
00636       if (chp != NULL
00637           && chp - 2 >= target_name
00638           && strncmp (chp - 2, "el", 2) == 0)
00639         default_byte_order = BFD_ENDIAN_LITTLE;
00640     }
00641   if (default_byte_order == BFD_ENDIAN_UNKNOWN)
00642     {
00643       /* Wire it to big-endian!!! */
00644       default_byte_order = BFD_ENDIAN_BIG;
00645     }
00646 
00647   info.byte_order = default_byte_order;
00648   info.byte_order_for_code = info.byte_order;
00649 
00650   if (! gdbarch_update_p (info))
00651     internal_error (__FILE__, __LINE__,
00652                     _("initialize_current_architecture: Selection of "
00653                       "initial architecture failed"));
00654 
00655   /* Create the ``set architecture'' command appending ``auto'' to the
00656      list of architectures.  */
00657   {
00658     /* Append ``auto''.  */
00659     int nr;
00660     for (nr = 0; arches[nr] != NULL; nr++);
00661     arches = xrealloc (arches, sizeof (char*) * (nr + 2));
00662     arches[nr + 0] = "auto";
00663     arches[nr + 1] = NULL;
00664     add_setshow_enum_cmd ("architecture", class_support,
00665                           arches, &set_architecture_string, 
00666                           _("Set architecture of target."),
00667                           _("Show architecture of target."), NULL,
00668                           set_architecture, show_architecture,
00669                           &setlist, &showlist);
00670     add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
00671   }
00672 }
00673 
00674 
00675 /* Initialize a gdbarch info to values that will be automatically
00676    overridden.  Note: Originally, this ``struct info'' was initialized
00677    using memset(0).  Unfortunately, that ran into problems, namely
00678    BFD_ENDIAN_BIG is zero.  An explicit initialization function that
00679    can explicitly set each field to a well defined value is used.  */
00680 
00681 void
00682 gdbarch_info_init (struct gdbarch_info *info)
00683 {
00684   memset (info, 0, sizeof (struct gdbarch_info));
00685   info->byte_order = BFD_ENDIAN_UNKNOWN;
00686   info->byte_order_for_code = info->byte_order;
00687   info->osabi = GDB_OSABI_UNINITIALIZED;
00688 }
00689 
00690 /* Similar to init, but this time fill in the blanks.  Information is
00691    obtained from the global "set ..." options and explicitly
00692    initialized INFO fields.  */
00693 
00694 void
00695 gdbarch_info_fill (struct gdbarch_info *info)
00696 {
00697   /* "(gdb) set architecture ...".  */
00698   if (info->bfd_arch_info == NULL
00699       && target_architecture_user)
00700     info->bfd_arch_info = target_architecture_user;
00701   /* From the file.  */
00702   if (info->bfd_arch_info == NULL
00703       && info->abfd != NULL
00704       && bfd_get_arch (info->abfd) != bfd_arch_unknown
00705       && bfd_get_arch (info->abfd) != bfd_arch_obscure)
00706     info->bfd_arch_info = bfd_get_arch_info (info->abfd);
00707   /* From the target.  */
00708   if (info->target_desc != NULL)
00709     info->bfd_arch_info = choose_architecture_for_target
00710                            (info->target_desc, info->bfd_arch_info);
00711   /* From the default.  */
00712   if (info->bfd_arch_info == NULL)
00713     info->bfd_arch_info = default_bfd_arch;
00714 
00715   /* "(gdb) set byte-order ...".  */
00716   if (info->byte_order == BFD_ENDIAN_UNKNOWN
00717       && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
00718     info->byte_order = target_byte_order_user;
00719   /* From the INFO struct.  */
00720   if (info->byte_order == BFD_ENDIAN_UNKNOWN
00721       && info->abfd != NULL)
00722     info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
00723                         : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
00724                         : BFD_ENDIAN_UNKNOWN);
00725   /* From the default.  */
00726   if (info->byte_order == BFD_ENDIAN_UNKNOWN)
00727     info->byte_order = default_byte_order;
00728   info->byte_order_for_code = info->byte_order;
00729 
00730   /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
00731   /* From the manual override, or from file.  */
00732   if (info->osabi == GDB_OSABI_UNINITIALIZED)
00733     info->osabi = gdbarch_lookup_osabi (info->abfd);
00734   /* From the target.  */
00735   if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
00736     info->osabi = tdesc_osabi (info->target_desc);
00737   /* From the configured default.  */
00738 #ifdef GDB_OSABI_DEFAULT
00739   if (info->osabi == GDB_OSABI_UNKNOWN)
00740     info->osabi = GDB_OSABI_DEFAULT;
00741 #endif
00742 
00743   /* Must have at least filled in the architecture.  */
00744   gdb_assert (info->bfd_arch_info != NULL);
00745 }
00746 
00747 /* Return "current" architecture.  If the target is running, this is
00748    the architecture of the selected frame.  Otherwise, the "current"
00749    architecture defaults to the target architecture.
00750 
00751    This function should normally be called solely by the command
00752    interpreter routines to determine the architecture to execute a
00753    command in.  */
00754 struct gdbarch *
00755 get_current_arch (void)
00756 {
00757   if (has_stack_frames ())
00758     return get_frame_arch (get_selected_frame (NULL));
00759   else
00760     return target_gdbarch ();
00761 }
00762 
00763 int
00764 default_has_shared_address_space (struct gdbarch *gdbarch)
00765 {
00766   /* Simply say no.  In most unix-like targets each inferior/process
00767      has its own address space.  */
00768   return 0;
00769 }
00770 
00771 int
00772 default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
00773                                   CORE_ADDR addr, int *isize, char **msg)
00774 {
00775   /* We don't know if maybe the target has some way to do fast
00776      tracepoints that doesn't need gdbarch, so always say yes.  */
00777   if (msg)
00778     *msg = NULL;
00779   return 1;
00780 }
00781 
00782 void
00783 default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
00784                                    int *kindptr)
00785 {
00786   gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
00787 }
00788 
00789 void
00790 default_gen_return_address (struct gdbarch *gdbarch,
00791                             struct agent_expr *ax, struct axs_value *value,
00792                             CORE_ADDR scope)
00793 {
00794   error (_("This architecture has no method to collect a return address."));
00795 }
00796 
00797 int
00798 default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
00799                                         struct type *type)
00800 {
00801   /* Usually, the return value's address is stored the in the "first hidden"
00802      parameter if the return value should be passed by reference, as
00803      specified in ABI.  */
00804   return language_pass_by_reference (type);
00805 }
00806 
00807 /* */
00808 
00809 /* -Wmissing-prototypes */
00810 extern initialize_file_ftype _initialize_gdbarch_utils;
00811 
00812 void
00813 _initialize_gdbarch_utils (void)
00814 {
00815   add_setshow_enum_cmd ("endian", class_support,
00816                         endian_enum, &set_endian_string, 
00817                         _("Set endianness of target."),
00818                         _("Show endianness of target."),
00819                         NULL, set_endian, show_endian,
00820                         &setlist, &showlist);
00821 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines