1 /* Dynamic architecture support for GDB, the GNU debugger.
3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "arch-utils.h"
24 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */
27 #include "sim-regno.h"
30 #include "target-descriptions.h"
35 #include "gdbsupport/version.h"
37 #include "floatformat.h"
42 default_displaced_step_hw_singlestep (struct gdbarch *gdbarch)
44 return !gdbarch_software_single_step_p (gdbarch);
48 displaced_step_at_entry_point (struct gdbarch *gdbarch)
53 addr = entry_point_address ();
55 /* Inferior calls also use the entry point as a breakpoint location.
56 We don't want displaced stepping to interfere with those
57 breakpoints, so leave space. */
58 gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
65 legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
67 /* Only makes sense to supply raw registers. */
68 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
69 /* NOTE: cagney/2002-05-13: The old code did it this way and it is
70 suspected that some GDB/SIM combinations may rely on this
71 behaviour. The default should be one2one_register_sim_regno
73 if (gdbarch_register_name (gdbarch, regnum) != NULL
74 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
77 return LEGACY_SIM_REGNO_IGNORE;
81 generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
87 generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
93 generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
94 CORE_ADDR pc, const char *name)
100 generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
106 default_code_of_frame_writable (struct gdbarch *gdbarch,
107 struct frame_info *frame)
112 /* Helper functions for gdbarch_inner_than */
115 core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
121 core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
126 /* Misc helper functions for targets. */
129 core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
135 convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
136 struct target_ops *targ)
142 no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
148 default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
153 /* See arch-utils.h. */
156 default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
161 /* See arch-utils.h. */
164 default_adjust_dwarf2_addr (CORE_ADDR pc)
169 /* See arch-utils.h. */
172 default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
177 /* See arch-utils.h. */
180 default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
181 struct dwarf2_frame_state *fs)
187 cannot_register_not (struct gdbarch *gdbarch, int regnum)
192 /* Legacy version of target_virtual_frame_pointer(). Assumes that
193 there is an gdbarch_deprecated_fp_regnum and that it is the same,
197 legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
200 LONGEST *frame_offset)
202 /* FIXME: cagney/2002-09-13: This code is used when identifying the
203 frame pointer of the current PC. It is assuming that a single
204 register and an offset can determine this. I think it should
205 instead generate a byte code expression as that would work better
206 with things like Dwarf2's CFI. */
207 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
208 && gdbarch_deprecated_fp_regnum (gdbarch)
209 < gdbarch_num_regs (gdbarch))
210 *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
211 else if (gdbarch_sp_regnum (gdbarch) >= 0
212 && gdbarch_sp_regnum (gdbarch)
213 < gdbarch_num_regs (gdbarch))
214 *frame_regnum = gdbarch_sp_regnum (gdbarch);
216 /* Should this be an internal error? I guess so, it is reflecting
217 an architectural limitation in the current design. */
218 internal_error (__FILE__, __LINE__,
219 _("No virtual frame pointer available"));
223 /* Return a floating-point format for a floating-point variable of
224 length LEN in bits. If non-NULL, NAME is the name of its type.
225 If no suitable type is found, return NULL. */
227 const struct floatformat **
228 default_floatformat_for_type (struct gdbarch *gdbarch,
229 const char *name, int len)
231 const struct floatformat **format = NULL;
233 if (len == gdbarch_half_bit (gdbarch))
234 format = gdbarch_half_format (gdbarch);
235 else if (len == gdbarch_float_bit (gdbarch))
236 format = gdbarch_float_format (gdbarch);
237 else if (len == gdbarch_double_bit (gdbarch))
238 format = gdbarch_double_format (gdbarch);
239 else if (len == gdbarch_long_double_bit (gdbarch))
240 format = gdbarch_long_double_format (gdbarch);
241 /* On i386 the 'long double' type takes 96 bits,
242 while the real number of used bits is only 80,
243 both in processor and in memory.
244 The code below accepts the real bit size. */
245 else if (gdbarch_long_double_format (gdbarch) != NULL
246 && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
247 format = gdbarch_long_double_format (gdbarch);
253 generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
260 default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
266 generic_instruction_nullified (struct gdbarch *gdbarch,
267 struct regcache *regcache)
273 default_remote_register_number (struct gdbarch *gdbarch,
279 /* See arch-utils.h. */
282 default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
288 /* Functions to manipulate the endianness of the target. */
290 static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
292 static const char endian_big[] = "big";
293 static const char endian_little[] = "little";
294 static const char endian_auto[] = "auto";
295 static const char *const endian_enum[] =
302 static const char *set_endian_string;
305 selected_byte_order (void)
307 return target_byte_order_user;
310 /* Called by ``show endian''. */
313 show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
316 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
317 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
318 fprintf_unfiltered (file, _("The target endianness is set automatically "
319 "(currently big endian).\n"));
321 fprintf_unfiltered (file, _("The target endianness is set automatically "
322 "(currently little endian).\n"));
324 if (target_byte_order_user == BFD_ENDIAN_BIG)
325 fprintf_unfiltered (file,
326 _("The target is set to big endian.\n"));
328 fprintf_unfiltered (file,
329 _("The target is set to little endian.\n"));
333 set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
335 struct gdbarch_info info;
337 gdbarch_info_init (&info);
339 if (set_endian_string == endian_auto)
341 target_byte_order_user = BFD_ENDIAN_UNKNOWN;
342 if (! gdbarch_update_p (info))
343 internal_error (__FILE__, __LINE__,
344 _("set_endian: architecture update failed"));
346 else if (set_endian_string == endian_little)
348 info.byte_order = BFD_ENDIAN_LITTLE;
349 if (! gdbarch_update_p (info))
350 printf_unfiltered (_("Little endian target not supported by GDB\n"));
352 target_byte_order_user = BFD_ENDIAN_LITTLE;
354 else if (set_endian_string == endian_big)
356 info.byte_order = BFD_ENDIAN_BIG;
357 if (! gdbarch_update_p (info))
358 printf_unfiltered (_("Big endian target not supported by GDB\n"));
360 target_byte_order_user = BFD_ENDIAN_BIG;
363 internal_error (__FILE__, __LINE__,
364 _("set_endian: bad value"));
366 show_endian (gdb_stdout, from_tty, NULL, NULL);
369 /* Given SELECTED, a currently selected BFD architecture, and
370 TARGET_DESC, the current target description, return what
373 SELECTED may be NULL, in which case we return the architecture
374 associated with TARGET_DESC. If SELECTED specifies a variant
375 of the architecture associated with TARGET_DESC, return the
376 more specific of the two.
378 If SELECTED is a different architecture, but it is accepted as
379 compatible by the target, we can use the target architecture.
381 If SELECTED is obviously incompatible, warn the user. */
383 static const struct bfd_arch_info *
384 choose_architecture_for_target (const struct target_desc *target_desc,
385 const struct bfd_arch_info *selected)
387 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
388 const struct bfd_arch_info *compat1, *compat2;
390 if (selected == NULL)
393 if (from_target == NULL)
396 /* struct bfd_arch_info objects are singletons: that is, there's
397 supposed to be exactly one instance for a given machine. So you
398 can tell whether two are equivalent by comparing pointers. */
399 if (from_target == selected)
402 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
403 incompatible. But if they are compatible, it returns the 'more
404 featureful' of the two arches. That is, if A can run code
405 written for B, but B can't run code written for A, then it'll
408 Some targets (e.g. MIPS as of 2006-12-04) don't fully
409 implement this, instead always returning NULL or the first
410 argument. We detect that case by checking both directions. */
412 compat1 = selected->compatible (selected, from_target);
413 compat2 = from_target->compatible (from_target, selected);
415 if (compat1 == NULL && compat2 == NULL)
417 /* BFD considers the architectures incompatible. Check our
418 target description whether it accepts SELECTED as compatible
420 if (tdesc_compatible_p (target_desc, selected))
423 warning (_("Selected architecture %s is not compatible "
424 "with reported target architecture %s"),
425 selected->printable_name, from_target->printable_name);
433 if (compat1 == compat2)
436 /* If the two didn't match, but one of them was a default
437 architecture, assume the more specific one is correct. This
438 handles the case where an executable or target description just
439 says "mips", but the other knows which MIPS variant. */
440 if (compat1->the_default)
442 if (compat2->the_default)
445 /* We have no idea which one is better. This is a bug, but not
446 a critical problem; warn the user. */
447 warning (_("Selected architecture %s is ambiguous with "
448 "reported target architecture %s"),
449 selected->printable_name, from_target->printable_name);
453 /* Functions to manipulate the architecture of the target. */
455 enum set_arch { set_arch_auto, set_arch_manual };
457 static const struct bfd_arch_info *target_architecture_user;
459 static const char *set_architecture_string;
462 selected_architecture_name (void)
464 if (target_architecture_user == NULL)
467 return set_architecture_string;
470 /* Called if the user enters ``show architecture'' without an
474 show_architecture (struct ui_file *file, int from_tty,
475 struct cmd_list_element *c, const char *value)
477 if (target_architecture_user == NULL)
478 fprintf_filtered (file, _("The target architecture is set to "
479 "\"auto\" (currently \"%s\").\n"),
480 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
482 fprintf_filtered (file, _("The target architecture is set to \"%s\".\n"),
483 set_architecture_string);
487 /* Called if the user enters ``set architecture'' with or without an
491 set_architecture (const char *ignore_args,
492 int from_tty, struct cmd_list_element *c)
494 struct gdbarch_info info;
496 gdbarch_info_init (&info);
498 if (strcmp (set_architecture_string, "auto") == 0)
500 target_architecture_user = NULL;
501 if (!gdbarch_update_p (info))
502 internal_error (__FILE__, __LINE__,
503 _("could not select an architecture automatically"));
507 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
508 if (info.bfd_arch_info == NULL)
509 internal_error (__FILE__, __LINE__,
510 _("set_architecture: bfd_scan_arch failed"));
511 if (gdbarch_update_p (info))
512 target_architecture_user = info.bfd_arch_info;
514 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
515 set_architecture_string);
517 show_architecture (gdb_stdout, from_tty, NULL, NULL);
520 /* Try to select a global architecture that matches "info". Return
521 non-zero if the attempt succeeds. */
523 gdbarch_update_p (struct gdbarch_info info)
525 struct gdbarch *new_gdbarch;
527 /* Check for the current file. */
528 if (info.abfd == NULL)
529 info.abfd = current_program_space->exec_bfd ();
530 if (info.abfd == NULL)
531 info.abfd = core_bfd;
533 /* Check for the current target description. */
534 if (info.target_desc == NULL)
535 info.target_desc = target_current_description ();
537 new_gdbarch = gdbarch_find_by_info (info);
539 /* If there no architecture by that name, reject the request. */
540 if (new_gdbarch == NULL)
543 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
544 "Architecture not found\n");
548 /* If it is the same old architecture, accept the request (but don't
550 if (new_gdbarch == target_gdbarch ())
553 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
554 "Architecture %s (%s) unchanged\n",
555 host_address_to_string (new_gdbarch),
556 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
560 /* It's a new architecture, swap it in. */
562 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
563 "New architecture %s (%s) selected\n",
564 host_address_to_string (new_gdbarch),
565 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
566 set_target_gdbarch (new_gdbarch);
571 /* Return the architecture for ABFD. If no suitable architecture
572 could be find, return NULL. */
575 gdbarch_from_bfd (bfd *abfd)
577 struct gdbarch_info info;
578 gdbarch_info_init (&info);
581 return gdbarch_find_by_info (info);
584 /* Set the dynamic target-system-dependent parameters (architecture,
585 byte-order) using information found in the BFD */
588 set_gdbarch_from_file (bfd *abfd)
590 struct gdbarch_info info;
591 struct gdbarch *gdbarch;
593 gdbarch_info_init (&info);
595 info.target_desc = target_current_description ();
596 gdbarch = gdbarch_find_by_info (info);
599 error (_("Architecture of file not recognized."));
600 set_target_gdbarch (gdbarch);
603 /* Initialize the current architecture. Update the ``set
604 architecture'' command so that it specifies a list of valid
607 #ifdef DEFAULT_BFD_ARCH
608 extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
609 static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
611 static const bfd_arch_info_type *default_bfd_arch;
614 #ifdef DEFAULT_BFD_VEC
615 extern const bfd_target DEFAULT_BFD_VEC;
616 static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
618 static const bfd_target *default_bfd_vec;
621 static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
624 initialize_current_architecture (void)
626 const char **arches = gdbarch_printable_names ();
627 struct gdbarch_info info;
629 /* determine a default architecture and byte order. */
630 gdbarch_info_init (&info);
632 /* Find a default architecture. */
633 if (default_bfd_arch == NULL)
635 /* Choose the architecture by taking the first one
637 const char *chosen = arches[0];
639 for (arch = arches; *arch != NULL; arch++)
641 if (strcmp (*arch, chosen) < 0)
645 internal_error (__FILE__, __LINE__,
646 _("initialize_current_architecture: No arch"));
647 default_bfd_arch = bfd_scan_arch (chosen);
648 if (default_bfd_arch == NULL)
649 internal_error (__FILE__, __LINE__,
650 _("initialize_current_architecture: Arch not found"));
653 info.bfd_arch_info = default_bfd_arch;
655 /* Take several guesses at a byte order. */
656 if (default_byte_order == BFD_ENDIAN_UNKNOWN
657 && default_bfd_vec != NULL)
659 /* Extract BFD's default vector's byte order. */
660 switch (default_bfd_vec->byteorder)
663 default_byte_order = BFD_ENDIAN_BIG;
665 case BFD_ENDIAN_LITTLE:
666 default_byte_order = BFD_ENDIAN_LITTLE;
672 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
674 /* look for ``*el-*'' in the target name. */
676 chp = strchr (target_name, '-');
678 && chp - 2 >= target_name
679 && startswith (chp - 2, "el"))
680 default_byte_order = BFD_ENDIAN_LITTLE;
682 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
684 /* Wire it to big-endian!!! */
685 default_byte_order = BFD_ENDIAN_BIG;
688 info.byte_order = default_byte_order;
689 info.byte_order_for_code = info.byte_order;
691 if (! gdbarch_update_p (info))
692 internal_error (__FILE__, __LINE__,
693 _("initialize_current_architecture: Selection of "
694 "initial architecture failed"));
696 /* Create the ``set architecture'' command appending ``auto'' to the
697 list of architectures. */
699 /* Append ``auto''. */
701 for (nr = 0; arches[nr] != NULL; nr++);
702 arches = XRESIZEVEC (const char *, arches, nr + 2);
703 arches[nr + 0] = "auto";
704 arches[nr + 1] = NULL;
705 add_setshow_enum_cmd ("architecture", class_support,
706 arches, &set_architecture_string,
707 _("Set architecture of target."),
708 _("Show architecture of target."), NULL,
709 set_architecture, show_architecture,
710 &setlist, &showlist);
711 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
716 /* Initialize a gdbarch info to values that will be automatically
717 overridden. Note: Originally, this ``struct info'' was initialized
718 using memset(0). Unfortunately, that ran into problems, namely
719 BFD_ENDIAN_BIG is zero. An explicit initialization function that
720 can explicitly set each field to a well defined value is used. */
723 gdbarch_info_init (struct gdbarch_info *info)
725 memset (info, 0, sizeof (struct gdbarch_info));
726 info->byte_order = BFD_ENDIAN_UNKNOWN;
727 info->byte_order_for_code = info->byte_order;
730 /* Similar to init, but this time fill in the blanks. Information is
731 obtained from the global "set ..." options and explicitly
732 initialized INFO fields. */
735 gdbarch_info_fill (struct gdbarch_info *info)
737 /* "(gdb) set architecture ...". */
738 if (info->bfd_arch_info == NULL
739 && target_architecture_user)
740 info->bfd_arch_info = target_architecture_user;
742 if (info->bfd_arch_info == NULL
743 && info->abfd != NULL
744 && bfd_get_arch (info->abfd) != bfd_arch_unknown
745 && bfd_get_arch (info->abfd) != bfd_arch_obscure)
746 info->bfd_arch_info = bfd_get_arch_info (info->abfd);
747 /* From the target. */
748 if (info->target_desc != NULL)
749 info->bfd_arch_info = choose_architecture_for_target
750 (info->target_desc, info->bfd_arch_info);
751 /* From the default. */
752 if (info->bfd_arch_info == NULL)
753 info->bfd_arch_info = default_bfd_arch;
755 /* "(gdb) set byte-order ...". */
756 if (info->byte_order == BFD_ENDIAN_UNKNOWN
757 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
758 info->byte_order = target_byte_order_user;
759 /* From the INFO struct. */
760 if (info->byte_order == BFD_ENDIAN_UNKNOWN
761 && info->abfd != NULL)
762 info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
763 : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
764 : BFD_ENDIAN_UNKNOWN);
765 /* From the default. */
766 if (info->byte_order == BFD_ENDIAN_UNKNOWN)
767 info->byte_order = default_byte_order;
768 info->byte_order_for_code = info->byte_order;
769 /* Wire the default to the last selected byte order. */
770 default_byte_order = info->byte_order;
772 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
773 /* From the manual override, or from file. */
774 if (info->osabi == GDB_OSABI_UNKNOWN)
775 info->osabi = gdbarch_lookup_osabi (info->abfd);
776 /* 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;
785 /* If we still don't know which osabi to pick, pick none. */
786 if (info->osabi == GDB_OSABI_UNKNOWN)
787 info->osabi = GDB_OSABI_NONE;
789 /* Must have at least filled in the architecture. */
790 gdb_assert (info->bfd_arch_info != NULL);
793 /* Return "current" architecture. If the target is running, this is
794 the architecture of the selected frame. Otherwise, the "current"
795 architecture defaults to the target architecture.
797 This function should normally be called solely by the command
798 interpreter routines to determine the architecture to execute a
801 get_current_arch (void)
803 if (has_stack_frames ())
804 return get_frame_arch (get_selected_frame (NULL));
806 return target_gdbarch ();
810 default_has_shared_address_space (struct gdbarch *gdbarch)
812 /* Simply say no. In most unix-like targets each inferior/process
813 has its own address space. */
818 default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
821 /* We don't know if maybe the target has some way to do fast
822 tracepoints that doesn't need gdbarch, so always say yes. */
829 default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
832 int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
834 return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
837 default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
838 struct regcache *regcache,
841 return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
846 default_gen_return_address (struct gdbarch *gdbarch,
847 struct agent_expr *ax, struct axs_value *value,
850 error (_("This architecture has no method to collect a return address."));
854 default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
857 /* Usually, the return value's address is stored the in the "first hidden"
858 parameter if the return value should be passed by reference, as
860 return !(language_pass_by_reference (type).trivially_copyable);
863 int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
868 int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
873 int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
878 /* See arch-utils.h. */
881 default_program_breakpoint_here_p (struct gdbarch *gdbarch,
885 const gdb_byte *bpoint = gdbarch_breakpoint_from_pc (gdbarch, &address, &len);
887 /* Software breakpoints unsupported? */
888 if (bpoint == nullptr)
891 gdb_byte *target_mem = (gdb_byte *) alloca (len);
893 /* Enable the automatic memory restoration from breakpoints while
894 we read the memory. Otherwise we may find temporary breakpoints, ones
895 inserted by GDB, and flag them as permanent breakpoints. */
896 scoped_restore restore_memory
897 = make_scoped_restore_show_memory_breakpoints (0);
899 if (target_read_memory (address, target_mem, len) == 0)
901 /* Check if this is a breakpoint instruction for this architecture,
902 including ones used by GDB. */
903 if (memcmp (target_mem, bpoint, len) == 0)
911 default_skip_permanent_breakpoint (struct regcache *regcache)
913 struct gdbarch *gdbarch = regcache->arch ();
914 CORE_ADDR current_pc = regcache_read_pc (regcache);
917 gdbarch_breakpoint_from_pc (gdbarch, ¤t_pc, &bp_len);
918 current_pc += bp_len;
919 regcache_write_pc (regcache, current_pc);
923 default_infcall_mmap (CORE_ADDR size, unsigned prot)
925 error (_("This target does not support inferior memory allocation by mmap."));
929 default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
931 /* Memory reserved by inferior mmap is kept leaked. */
934 /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
935 created in inferior memory by GDB (normally it is set by ld.so). */
938 default_gcc_target_options (struct gdbarch *gdbarch)
940 return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
941 (gdbarch_ptr_bit (gdbarch) == 64
942 ? " -mcmodel=large" : ""));
945 /* gdbarch gnu_triplet_regexp method. */
948 default_gnu_triplet_regexp (struct gdbarch *gdbarch)
950 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
953 /* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has
954 a size of 1 octet. */
957 default_addressable_memory_unit_size (struct gdbarch *gdbarch)
963 default_guess_tracepoint_registers (struct gdbarch *gdbarch,
964 struct regcache *regcache,
967 int pc_regno = gdbarch_pc_regnum (gdbarch);
970 /* This guessing code below only works if the PC register isn't
971 a pseudo-register. The value of a pseudo-register isn't stored
972 in the (non-readonly) regcache -- instead it's recomputed
973 (probably from some other cached raw register) whenever the
974 register is read. In this case, a custom method implementation
975 should be used by the architecture. */
976 if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
979 regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
980 store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
981 gdbarch_byte_order (gdbarch), addr);
982 regcache->raw_supply (pc_regno, regs);
986 default_print_insn (bfd_vma memaddr, disassemble_info *info)
988 disassembler_ftype disassemble_fn;
990 disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
991 info->mach, current_program_space->exec_bfd ());
993 gdb_assert (disassemble_fn != NULL);
994 return (*disassemble_fn) (memaddr, info);
997 /* See arch-utils.h. */
1000 gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
1002 CORE_ADDR new_pc = pc;
1006 new_pc = gdbarch_skip_prologue (gdbarch, pc);
1008 catch (const gdb_exception &ex)
1014 /* See arch-utils.h. */
1017 default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
1022 /* See arch-utils.h. */
1025 default_type_align (struct gdbarch *gdbarch, struct type *type)
1030 /* See arch-utils.h. */
1033 default_get_pc_address_flags (frame_info *frame, CORE_ADDR pc)
1038 /* See arch-utils.h. */
1040 default_read_core_file_mappings (struct gdbarch *gdbarch,
1042 gdb::function_view<void (ULONGEST count)>
1044 gdb::function_view<void (int num,
1048 const char *filename)>
1053 void _initialize_gdbarch_utils ();
1055 _initialize_gdbarch_utils ()
1057 add_setshow_enum_cmd ("endian", class_support,
1058 endian_enum, &set_endian_string,
1059 _("Set endianness of target."),
1060 _("Show endianness of target."),
1061 NULL, set_endian, show_endian,
1062 &setlist, &showlist);