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