1 /* Dynamic architecture support for GDB, the GNU debugger.
3 Copyright (C) 1998-2021 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 /* See arch-utils.h */
84 default_memtag_to_string (struct gdbarch
*gdbarch
, struct value
*tag
)
86 error (_("This architecture has no method to convert a memory tag to"
90 /* See arch-utils.h */
93 default_tagged_address_p (struct gdbarch
*gdbarch
, struct value
*address
)
95 /* By default, assume the address is untagged. */
99 /* See arch-utils.h */
102 default_memtag_matches_p (struct gdbarch
*gdbarch
, struct value
*address
)
104 /* By default, assume the tags match. */
108 /* See arch-utils.h */
111 default_set_memtags (struct gdbarch
*gdbarch
, struct value
*address
,
112 size_t length
, const gdb::byte_vector
&tags
,
113 memtag_type tag_type
)
115 /* By default, return true (successful); */
119 /* See arch-utils.h */
122 default_get_memtag (struct gdbarch
*gdbarch
, struct value
*address
,
123 memtag_type tag_type
)
125 /* By default, return no tag. */
130 generic_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
136 generic_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
142 generic_in_solib_return_trampoline (struct gdbarch
*gdbarch
,
143 CORE_ADDR pc
, const char *name
)
149 generic_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
155 default_code_of_frame_writable (struct gdbarch
*gdbarch
,
156 struct frame_info
*frame
)
161 /* Helper functions for gdbarch_inner_than */
164 core_addr_lessthan (CORE_ADDR lhs
, CORE_ADDR rhs
)
170 core_addr_greaterthan (CORE_ADDR lhs
, CORE_ADDR rhs
)
175 /* Misc helper functions for targets. */
178 core_addr_identity (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
184 convert_from_func_ptr_addr_identity (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
185 struct target_ops
*targ
)
191 no_op_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
197 default_coff_make_msymbol_special (int val
, struct minimal_symbol
*msym
)
202 /* See arch-utils.h. */
205 default_make_symbol_special (struct symbol
*sym
, struct objfile
*objfile
)
210 /* See arch-utils.h. */
213 default_adjust_dwarf2_addr (CORE_ADDR pc
)
218 /* See arch-utils.h. */
221 default_adjust_dwarf2_line (CORE_ADDR addr
, int rel
)
226 /* See arch-utils.h. */
229 default_execute_dwarf_cfa_vendor_op (struct gdbarch
*gdbarch
, gdb_byte op
,
230 struct dwarf2_frame_state
*fs
)
236 cannot_register_not (struct gdbarch
*gdbarch
, int regnum
)
241 /* Legacy version of target_virtual_frame_pointer(). Assumes that
242 there is an gdbarch_deprecated_fp_regnum and that it is the same,
246 legacy_virtual_frame_pointer (struct gdbarch
*gdbarch
,
249 LONGEST
*frame_offset
)
251 /* FIXME: cagney/2002-09-13: This code is used when identifying the
252 frame pointer of the current PC. It is assuming that a single
253 register and an offset can determine this. I think it should
254 instead generate a byte code expression as that would work better
255 with things like Dwarf2's CFI. */
256 if (gdbarch_deprecated_fp_regnum (gdbarch
) >= 0
257 && gdbarch_deprecated_fp_regnum (gdbarch
)
258 < gdbarch_num_regs (gdbarch
))
259 *frame_regnum
= gdbarch_deprecated_fp_regnum (gdbarch
);
260 else if (gdbarch_sp_regnum (gdbarch
) >= 0
261 && gdbarch_sp_regnum (gdbarch
)
262 < gdbarch_num_regs (gdbarch
))
263 *frame_regnum
= gdbarch_sp_regnum (gdbarch
);
265 /* Should this be an internal error? I guess so, it is reflecting
266 an architectural limitation in the current design. */
267 internal_error (__FILE__
, __LINE__
,
268 _("No virtual frame pointer available"));
272 /* Return a floating-point format for a floating-point variable of
273 length LEN in bits. If non-NULL, NAME is the name of its type.
274 If no suitable type is found, return NULL. */
276 const struct floatformat
**
277 default_floatformat_for_type (struct gdbarch
*gdbarch
,
278 const char *name
, int len
)
280 const struct floatformat
**format
= NULL
;
282 if (len
== gdbarch_half_bit (gdbarch
))
283 format
= gdbarch_half_format (gdbarch
);
284 else if (len
== gdbarch_float_bit (gdbarch
))
285 format
= gdbarch_float_format (gdbarch
);
286 else if (len
== gdbarch_double_bit (gdbarch
))
287 format
= gdbarch_double_format (gdbarch
);
288 else if (len
== gdbarch_long_double_bit (gdbarch
))
289 format
= gdbarch_long_double_format (gdbarch
);
290 /* On i386 the 'long double' type takes 96 bits,
291 while the real number of used bits is only 80,
292 both in processor and in memory.
293 The code below accepts the real bit size. */
294 else if (gdbarch_long_double_format (gdbarch
) != NULL
295 && len
== gdbarch_long_double_format (gdbarch
)[0]->totalsize
)
296 format
= gdbarch_long_double_format (gdbarch
);
302 generic_convert_register_p (struct gdbarch
*gdbarch
, int regnum
,
309 default_stabs_argument_has_addr (struct gdbarch
*gdbarch
, struct type
*type
)
315 generic_instruction_nullified (struct gdbarch
*gdbarch
,
316 struct regcache
*regcache
)
322 default_remote_register_number (struct gdbarch
*gdbarch
,
328 /* See arch-utils.h. */
331 default_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
337 /* Functions to manipulate the endianness of the target. */
339 static enum bfd_endian target_byte_order_user
= BFD_ENDIAN_UNKNOWN
;
341 static const char endian_big
[] = "big";
342 static const char endian_little
[] = "little";
343 static const char endian_auto
[] = "auto";
344 static const char *const endian_enum
[] =
351 static const char *set_endian_string
;
354 selected_byte_order (void)
356 return target_byte_order_user
;
359 /* Called by ``show endian''. */
362 show_endian (struct ui_file
*file
, int from_tty
, struct cmd_list_element
*c
,
365 if (target_byte_order_user
== BFD_ENDIAN_UNKNOWN
)
366 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG
)
367 fprintf_unfiltered (file
, _("The target endianness is set automatically "
368 "(currently big endian).\n"));
370 fprintf_unfiltered (file
, _("The target endianness is set automatically "
371 "(currently little endian).\n"));
373 if (target_byte_order_user
== BFD_ENDIAN_BIG
)
374 fprintf_unfiltered (file
,
375 _("The target is set to big endian.\n"));
377 fprintf_unfiltered (file
,
378 _("The target is set to little endian.\n"));
382 set_endian (const char *ignore_args
, int from_tty
, struct cmd_list_element
*c
)
384 struct gdbarch_info info
;
386 gdbarch_info_init (&info
);
388 if (set_endian_string
== endian_auto
)
390 target_byte_order_user
= BFD_ENDIAN_UNKNOWN
;
391 if (! gdbarch_update_p (info
))
392 internal_error (__FILE__
, __LINE__
,
393 _("set_endian: architecture update failed"));
395 else if (set_endian_string
== endian_little
)
397 info
.byte_order
= BFD_ENDIAN_LITTLE
;
398 if (! gdbarch_update_p (info
))
399 printf_unfiltered (_("Little endian target not supported by GDB\n"));
401 target_byte_order_user
= BFD_ENDIAN_LITTLE
;
403 else if (set_endian_string
== endian_big
)
405 info
.byte_order
= BFD_ENDIAN_BIG
;
406 if (! gdbarch_update_p (info
))
407 printf_unfiltered (_("Big endian target not supported by GDB\n"));
409 target_byte_order_user
= BFD_ENDIAN_BIG
;
412 internal_error (__FILE__
, __LINE__
,
413 _("set_endian: bad value"));
415 show_endian (gdb_stdout
, from_tty
, NULL
, NULL
);
418 /* Given SELECTED, a currently selected BFD architecture, and
419 TARGET_DESC, the current target description, return what
422 SELECTED may be NULL, in which case we return the architecture
423 associated with TARGET_DESC. If SELECTED specifies a variant
424 of the architecture associated with TARGET_DESC, return the
425 more specific of the two.
427 If SELECTED is a different architecture, but it is accepted as
428 compatible by the target, we can use the target architecture.
430 If SELECTED is obviously incompatible, warn the user. */
432 static const struct bfd_arch_info
*
433 choose_architecture_for_target (const struct target_desc
*target_desc
,
434 const struct bfd_arch_info
*selected
)
436 const struct bfd_arch_info
*from_target
= tdesc_architecture (target_desc
);
437 const struct bfd_arch_info
*compat1
, *compat2
;
439 if (selected
== NULL
)
442 if (from_target
== NULL
)
445 /* struct bfd_arch_info objects are singletons: that is, there's
446 supposed to be exactly one instance for a given machine. So you
447 can tell whether two are equivalent by comparing pointers. */
448 if (from_target
== selected
)
451 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
452 incompatible. But if they are compatible, it returns the 'more
453 featureful' of the two arches. That is, if A can run code
454 written for B, but B can't run code written for A, then it'll
457 Some targets (e.g. MIPS as of 2006-12-04) don't fully
458 implement this, instead always returning NULL or the first
459 argument. We detect that case by checking both directions. */
461 compat1
= selected
->compatible (selected
, from_target
);
462 compat2
= from_target
->compatible (from_target
, selected
);
464 if (compat1
== NULL
&& compat2
== NULL
)
466 /* BFD considers the architectures incompatible. Check our
467 target description whether it accepts SELECTED as compatible
469 if (tdesc_compatible_p (target_desc
, selected
))
472 warning (_("Selected architecture %s is not compatible "
473 "with reported target architecture %s"),
474 selected
->printable_name
, from_target
->printable_name
);
482 if (compat1
== compat2
)
485 /* If the two didn't match, but one of them was a default
486 architecture, assume the more specific one is correct. This
487 handles the case where an executable or target description just
488 says "mips", but the other knows which MIPS variant. */
489 if (compat1
->the_default
)
491 if (compat2
->the_default
)
494 /* We have no idea which one is better. This is a bug, but not
495 a critical problem; warn the user. */
496 warning (_("Selected architecture %s is ambiguous with "
497 "reported target architecture %s"),
498 selected
->printable_name
, from_target
->printable_name
);
502 /* Functions to manipulate the architecture of the target. */
504 enum set_arch
{ set_arch_auto
, set_arch_manual
};
506 static const struct bfd_arch_info
*target_architecture_user
;
508 static const char *set_architecture_string
;
511 selected_architecture_name (void)
513 if (target_architecture_user
== NULL
)
516 return set_architecture_string
;
519 /* Called if the user enters ``show architecture'' without an
523 show_architecture (struct ui_file
*file
, int from_tty
,
524 struct cmd_list_element
*c
, const char *value
)
526 if (target_architecture_user
== NULL
)
527 fprintf_filtered (file
, _("The target architecture is set to "
528 "\"auto\" (currently \"%s\").\n"),
529 gdbarch_bfd_arch_info (get_current_arch ())->printable_name
);
531 fprintf_filtered (file
, _("The target architecture is set to \"%s\".\n"),
532 set_architecture_string
);
536 /* Called if the user enters ``set architecture'' with or without an
540 set_architecture (const char *ignore_args
,
541 int from_tty
, struct cmd_list_element
*c
)
543 struct gdbarch_info info
;
545 gdbarch_info_init (&info
);
547 if (strcmp (set_architecture_string
, "auto") == 0)
549 target_architecture_user
= NULL
;
550 if (!gdbarch_update_p (info
))
551 internal_error (__FILE__
, __LINE__
,
552 _("could not select an architecture automatically"));
556 info
.bfd_arch_info
= bfd_scan_arch (set_architecture_string
);
557 if (info
.bfd_arch_info
== NULL
)
558 internal_error (__FILE__
, __LINE__
,
559 _("set_architecture: bfd_scan_arch failed"));
560 if (gdbarch_update_p (info
))
561 target_architecture_user
= info
.bfd_arch_info
;
563 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
564 set_architecture_string
);
566 show_architecture (gdb_stdout
, from_tty
, NULL
, NULL
);
569 /* Try to select a global architecture that matches "info". Return
570 non-zero if the attempt succeeds. */
572 gdbarch_update_p (struct gdbarch_info info
)
574 struct gdbarch
*new_gdbarch
;
576 /* Check for the current file. */
577 if (info
.abfd
== NULL
)
578 info
.abfd
= current_program_space
->exec_bfd ();
579 if (info
.abfd
== NULL
)
580 info
.abfd
= core_bfd
;
582 /* Check for the current target description. */
583 if (info
.target_desc
== NULL
)
584 info
.target_desc
= target_current_description ();
586 new_gdbarch
= gdbarch_find_by_info (info
);
588 /* If there no architecture by that name, reject the request. */
589 if (new_gdbarch
== NULL
)
592 fprintf_unfiltered (gdb_stdlog
, "gdbarch_update_p: "
593 "Architecture not found\n");
597 /* If it is the same old architecture, accept the request (but don't
599 if (new_gdbarch
== target_gdbarch ())
602 fprintf_unfiltered (gdb_stdlog
, "gdbarch_update_p: "
603 "Architecture %s (%s) unchanged\n",
604 host_address_to_string (new_gdbarch
),
605 gdbarch_bfd_arch_info (new_gdbarch
)->printable_name
);
609 /* It's a new architecture, swap it in. */
611 fprintf_unfiltered (gdb_stdlog
, "gdbarch_update_p: "
612 "New architecture %s (%s) selected\n",
613 host_address_to_string (new_gdbarch
),
614 gdbarch_bfd_arch_info (new_gdbarch
)->printable_name
);
615 set_target_gdbarch (new_gdbarch
);
620 /* Return the architecture for ABFD. If no suitable architecture
621 could be find, return NULL. */
624 gdbarch_from_bfd (bfd
*abfd
)
626 struct gdbarch_info info
;
627 gdbarch_info_init (&info
);
630 return gdbarch_find_by_info (info
);
633 /* Set the dynamic target-system-dependent parameters (architecture,
634 byte-order) using information found in the BFD */
637 set_gdbarch_from_file (bfd
*abfd
)
639 struct gdbarch_info info
;
640 struct gdbarch
*gdbarch
;
642 gdbarch_info_init (&info
);
644 info
.target_desc
= target_current_description ();
645 gdbarch
= gdbarch_find_by_info (info
);
648 error (_("Architecture of file not recognized."));
649 set_target_gdbarch (gdbarch
);
652 /* Initialize the current architecture. Update the ``set
653 architecture'' command so that it specifies a list of valid
656 #ifdef DEFAULT_BFD_ARCH
657 extern const bfd_arch_info_type DEFAULT_BFD_ARCH
;
658 static const bfd_arch_info_type
*default_bfd_arch
= &DEFAULT_BFD_ARCH
;
660 static const bfd_arch_info_type
*default_bfd_arch
;
663 #ifdef DEFAULT_BFD_VEC
664 extern const bfd_target DEFAULT_BFD_VEC
;
665 static const bfd_target
*default_bfd_vec
= &DEFAULT_BFD_VEC
;
667 static const bfd_target
*default_bfd_vec
;
670 static enum bfd_endian default_byte_order
= BFD_ENDIAN_UNKNOWN
;
673 initialize_current_architecture (void)
675 const char **arches
= gdbarch_printable_names ();
676 struct gdbarch_info info
;
678 /* determine a default architecture and byte order. */
679 gdbarch_info_init (&info
);
681 /* Find a default architecture. */
682 if (default_bfd_arch
== NULL
)
684 /* Choose the architecture by taking the first one
686 const char *chosen
= arches
[0];
688 for (arch
= arches
; *arch
!= NULL
; arch
++)
690 if (strcmp (*arch
, chosen
) < 0)
694 internal_error (__FILE__
, __LINE__
,
695 _("initialize_current_architecture: No arch"));
696 default_bfd_arch
= bfd_scan_arch (chosen
);
697 if (default_bfd_arch
== NULL
)
698 internal_error (__FILE__
, __LINE__
,
699 _("initialize_current_architecture: Arch not found"));
702 info
.bfd_arch_info
= default_bfd_arch
;
704 /* Take several guesses at a byte order. */
705 if (default_byte_order
== BFD_ENDIAN_UNKNOWN
706 && default_bfd_vec
!= NULL
)
708 /* Extract BFD's default vector's byte order. */
709 switch (default_bfd_vec
->byteorder
)
712 default_byte_order
= BFD_ENDIAN_BIG
;
714 case BFD_ENDIAN_LITTLE
:
715 default_byte_order
= BFD_ENDIAN_LITTLE
;
721 if (default_byte_order
== BFD_ENDIAN_UNKNOWN
)
723 /* look for ``*el-*'' in the target name. */
725 chp
= strchr (target_name
, '-');
727 && chp
- 2 >= target_name
728 && startswith (chp
- 2, "el"))
729 default_byte_order
= BFD_ENDIAN_LITTLE
;
731 if (default_byte_order
== BFD_ENDIAN_UNKNOWN
)
733 /* Wire it to big-endian!!! */
734 default_byte_order
= BFD_ENDIAN_BIG
;
737 info
.byte_order
= default_byte_order
;
738 info
.byte_order_for_code
= info
.byte_order
;
740 if (! gdbarch_update_p (info
))
741 internal_error (__FILE__
, __LINE__
,
742 _("initialize_current_architecture: Selection of "
743 "initial architecture failed"));
745 /* Create the ``set architecture'' command appending ``auto'' to the
746 list of architectures. */
748 /* Append ``auto''. */
750 for (nr
= 0; arches
[nr
] != NULL
; nr
++);
751 arches
= XRESIZEVEC (const char *, arches
, nr
+ 2);
752 arches
[nr
+ 0] = "auto";
753 arches
[nr
+ 1] = NULL
;
754 add_setshow_enum_cmd ("architecture", class_support
,
755 arches
, &set_architecture_string
,
756 _("Set architecture of target."),
757 _("Show architecture of target."), NULL
,
758 set_architecture
, show_architecture
,
759 &setlist
, &showlist
);
760 add_alias_cmd ("processor", "architecture", class_support
, 1, &setlist
);
765 /* Initialize a gdbarch info to values that will be automatically
766 overridden. Note: Originally, this ``struct info'' was initialized
767 using memset(0). Unfortunately, that ran into problems, namely
768 BFD_ENDIAN_BIG is zero. An explicit initialization function that
769 can explicitly set each field to a well defined value is used. */
772 gdbarch_info_init (struct gdbarch_info
*info
)
774 memset (info
, 0, sizeof (struct gdbarch_info
));
775 info
->byte_order
= BFD_ENDIAN_UNKNOWN
;
776 info
->byte_order_for_code
= info
->byte_order
;
779 /* Similar to init, but this time fill in the blanks. Information is
780 obtained from the global "set ..." options and explicitly
781 initialized INFO fields. */
784 gdbarch_info_fill (struct gdbarch_info
*info
)
786 /* "(gdb) set architecture ...". */
787 if (info
->bfd_arch_info
== NULL
788 && target_architecture_user
)
789 info
->bfd_arch_info
= target_architecture_user
;
791 if (info
->bfd_arch_info
== NULL
792 && info
->abfd
!= NULL
793 && bfd_get_arch (info
->abfd
) != bfd_arch_unknown
794 && bfd_get_arch (info
->abfd
) != bfd_arch_obscure
)
795 info
->bfd_arch_info
= bfd_get_arch_info (info
->abfd
);
796 /* From the target. */
797 if (info
->target_desc
!= NULL
)
798 info
->bfd_arch_info
= choose_architecture_for_target
799 (info
->target_desc
, info
->bfd_arch_info
);
800 /* From the default. */
801 if (info
->bfd_arch_info
== NULL
)
802 info
->bfd_arch_info
= default_bfd_arch
;
804 /* "(gdb) set byte-order ...". */
805 if (info
->byte_order
== BFD_ENDIAN_UNKNOWN
806 && target_byte_order_user
!= BFD_ENDIAN_UNKNOWN
)
807 info
->byte_order
= target_byte_order_user
;
808 /* From the INFO struct. */
809 if (info
->byte_order
== BFD_ENDIAN_UNKNOWN
810 && info
->abfd
!= NULL
)
811 info
->byte_order
= (bfd_big_endian (info
->abfd
) ? BFD_ENDIAN_BIG
812 : bfd_little_endian (info
->abfd
) ? BFD_ENDIAN_LITTLE
813 : BFD_ENDIAN_UNKNOWN
);
814 /* From the default. */
815 if (info
->byte_order
== BFD_ENDIAN_UNKNOWN
)
816 info
->byte_order
= default_byte_order
;
817 info
->byte_order_for_code
= info
->byte_order
;
818 /* Wire the default to the last selected byte order. */
819 default_byte_order
= info
->byte_order
;
821 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
822 /* From the manual override, or from file. */
823 if (info
->osabi
== GDB_OSABI_UNKNOWN
)
824 info
->osabi
= gdbarch_lookup_osabi (info
->abfd
);
825 /* From the target. */
827 if (info
->osabi
== GDB_OSABI_UNKNOWN
&& info
->target_desc
!= NULL
)
828 info
->osabi
= tdesc_osabi (info
->target_desc
);
829 /* From the configured default. */
830 #ifdef GDB_OSABI_DEFAULT
831 if (info
->osabi
== GDB_OSABI_UNKNOWN
)
832 info
->osabi
= GDB_OSABI_DEFAULT
;
834 /* If we still don't know which osabi to pick, pick none. */
835 if (info
->osabi
== GDB_OSABI_UNKNOWN
)
836 info
->osabi
= GDB_OSABI_NONE
;
838 /* Must have at least filled in the architecture. */
839 gdb_assert (info
->bfd_arch_info
!= NULL
);
842 /* Return "current" architecture. If the target is running, this is
843 the architecture of the selected frame. Otherwise, the "current"
844 architecture defaults to the target architecture.
846 This function should normally be called solely by the command
847 interpreter routines to determine the architecture to execute a
850 get_current_arch (void)
852 if (has_stack_frames ())
853 return get_frame_arch (get_selected_frame (NULL
));
855 return target_gdbarch ();
859 default_has_shared_address_space (struct gdbarch
*gdbarch
)
861 /* Simply say no. In most unix-like targets each inferior/process
862 has its own address space. */
867 default_fast_tracepoint_valid_at (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
870 /* We don't know if maybe the target has some way to do fast
871 tracepoints that doesn't need gdbarch, so always say yes. */
878 default_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
,
881 int kind
= gdbarch_breakpoint_kind_from_pc (gdbarch
, pcptr
);
883 return gdbarch_sw_breakpoint_from_kind (gdbarch
, kind
, lenptr
);
886 default_breakpoint_kind_from_current_state (struct gdbarch
*gdbarch
,
887 struct regcache
*regcache
,
890 return gdbarch_breakpoint_kind_from_pc (gdbarch
, pcptr
);
895 default_gen_return_address (struct gdbarch
*gdbarch
,
896 struct agent_expr
*ax
, struct axs_value
*value
,
899 error (_("This architecture has no method to collect a return address."));
903 default_return_in_first_hidden_param_p (struct gdbarch
*gdbarch
,
906 /* Usually, the return value's address is stored the in the "first hidden"
907 parameter if the return value should be passed by reference, as
909 return !(language_pass_by_reference (type
).trivially_copyable
);
912 int default_insn_is_call (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
917 int default_insn_is_ret (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
922 int default_insn_is_jump (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
927 /* See arch-utils.h. */
930 default_program_breakpoint_here_p (struct gdbarch
*gdbarch
,
934 const gdb_byte
*bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &address
, &len
);
936 /* Software breakpoints unsupported? */
937 if (bpoint
== nullptr)
940 gdb_byte
*target_mem
= (gdb_byte
*) alloca (len
);
942 /* Enable the automatic memory restoration from breakpoints while
943 we read the memory. Otherwise we may find temporary breakpoints, ones
944 inserted by GDB, and flag them as permanent breakpoints. */
945 scoped_restore restore_memory
946 = make_scoped_restore_show_memory_breakpoints (0);
948 if (target_read_memory (address
, target_mem
, len
) == 0)
950 /* Check if this is a breakpoint instruction for this architecture,
951 including ones used by GDB. */
952 if (memcmp (target_mem
, bpoint
, len
) == 0)
960 default_skip_permanent_breakpoint (struct regcache
*regcache
)
962 struct gdbarch
*gdbarch
= regcache
->arch ();
963 CORE_ADDR current_pc
= regcache_read_pc (regcache
);
966 gdbarch_breakpoint_from_pc (gdbarch
, ¤t_pc
, &bp_len
);
967 current_pc
+= bp_len
;
968 regcache_write_pc (regcache
, current_pc
);
972 default_infcall_mmap (CORE_ADDR size
, unsigned prot
)
974 error (_("This target does not support inferior memory allocation by mmap."));
978 default_infcall_munmap (CORE_ADDR addr
, CORE_ADDR size
)
980 /* Memory reserved by inferior mmap is kept leaked. */
983 /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
984 created in inferior memory by GDB (normally it is set by ld.so). */
987 default_gcc_target_options (struct gdbarch
*gdbarch
)
989 return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch
),
990 (gdbarch_ptr_bit (gdbarch
) == 64
991 ? " -mcmodel=large" : ""));
994 /* gdbarch gnu_triplet_regexp method. */
997 default_gnu_triplet_regexp (struct gdbarch
*gdbarch
)
999 return gdbarch_bfd_arch_info (gdbarch
)->arch_name
;
1002 /* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has
1003 a size of 1 octet. */
1006 default_addressable_memory_unit_size (struct gdbarch
*gdbarch
)
1012 default_guess_tracepoint_registers (struct gdbarch
*gdbarch
,
1013 struct regcache
*regcache
,
1016 int pc_regno
= gdbarch_pc_regnum (gdbarch
);
1019 /* This guessing code below only works if the PC register isn't
1020 a pseudo-register. The value of a pseudo-register isn't stored
1021 in the (non-readonly) regcache -- instead it's recomputed
1022 (probably from some other cached raw register) whenever the
1023 register is read. In this case, a custom method implementation
1024 should be used by the architecture. */
1025 if (pc_regno
< 0 || pc_regno
>= gdbarch_num_regs (gdbarch
))
1028 regs
= (gdb_byte
*) alloca (register_size (gdbarch
, pc_regno
));
1029 store_unsigned_integer (regs
, register_size (gdbarch
, pc_regno
),
1030 gdbarch_byte_order (gdbarch
), addr
);
1031 regcache
->raw_supply (pc_regno
, regs
);
1035 default_print_insn (bfd_vma memaddr
, disassemble_info
*info
)
1037 disassembler_ftype disassemble_fn
;
1039 disassemble_fn
= disassembler (info
->arch
, info
->endian
== BFD_ENDIAN_BIG
,
1040 info
->mach
, current_program_space
->exec_bfd ());
1042 gdb_assert (disassemble_fn
!= NULL
);
1043 return (*disassemble_fn
) (memaddr
, info
);
1046 /* See arch-utils.h. */
1049 gdbarch_skip_prologue_noexcept (gdbarch
*gdbarch
, CORE_ADDR pc
) noexcept
1051 CORE_ADDR new_pc
= pc
;
1055 new_pc
= gdbarch_skip_prologue (gdbarch
, pc
);
1057 catch (const gdb_exception
&ex
)
1063 /* See arch-utils.h. */
1066 default_in_indirect_branch_thunk (gdbarch
*gdbarch
, CORE_ADDR pc
)
1071 /* See arch-utils.h. */
1074 default_type_align (struct gdbarch
*gdbarch
, struct type
*type
)
1079 /* See arch-utils.h. */
1082 default_get_pc_address_flags (frame_info
*frame
, CORE_ADDR pc
)
1087 /* See arch-utils.h. */
1089 default_read_core_file_mappings (struct gdbarch
*gdbarch
,
1091 gdb::function_view
<void (ULONGEST count
)>
1093 gdb::function_view
<void (int num
,
1097 const char *filename
)>
1102 void _initialize_gdbarch_utils ();
1104 _initialize_gdbarch_utils ()
1106 add_setshow_enum_cmd ("endian", class_support
,
1107 endian_enum
, &set_endian_string
,
1108 _("Set endianness of target."),
1109 _("Show endianness of target."),
1110 NULL
, set_endian
, show_endian
,
1111 &setlist
, &showlist
);