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