]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/arch-utils.c
gdb: remove `other` parameter in read_core_file_mappings parameter
[thirdparty/binutils-gdb.git] / gdb / arch-utils.c
1 /* Dynamic architecture support for GDB, the GNU debugger.
2
3 Copyright (C) 1998-2020 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 "gdbcmd.h"
24 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */
25 #include "infrun.h"
26 #include "regcache.h"
27 #include "sim-regno.h"
28 #include "gdbcore.h"
29 #include "osabi.h"
30 #include "target-descriptions.h"
31 #include "objfiles.h"
32 #include "language.h"
33 #include "symtab.h"
34
35 #include "gdbsupport/version.h"
36
37 #include "floatformat.h"
38
39 #include "dis-asm.h"
40
41 bool
42 default_displaced_step_hw_singlestep (struct gdbarch *gdbarch)
43 {
44 return !gdbarch_software_single_step_p (gdbarch);
45 }
46
47 CORE_ADDR
48 displaced_step_at_entry_point (struct gdbarch *gdbarch)
49 {
50 CORE_ADDR addr;
51 int bp_len;
52
53 addr = entry_point_address ();
54
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);
59 addr += bp_len * 2;
60
61 return addr;
62 }
63
64 int
65 legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
66 {
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
72 (below). */
73 if (gdbarch_register_name (gdbarch, regnum) != NULL
74 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
75 return regnum;
76 else
77 return LEGACY_SIM_REGNO_IGNORE;
78 }
79
80 CORE_ADDR
81 generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
82 {
83 return 0;
84 }
85
86 CORE_ADDR
87 generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
88 {
89 return 0;
90 }
91
92 int
93 generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
94 CORE_ADDR pc, const char *name)
95 {
96 return 0;
97 }
98
99 int
100 generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
101 {
102 return 0;
103 }
104
105 int
106 default_code_of_frame_writable (struct gdbarch *gdbarch,
107 struct frame_info *frame)
108 {
109 return 1;
110 }
111
112 /* Helper functions for gdbarch_inner_than */
113
114 int
115 core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
116 {
117 return (lhs < rhs);
118 }
119
120 int
121 core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
122 {
123 return (lhs > rhs);
124 }
125
126 /* Misc helper functions for targets. */
127
128 CORE_ADDR
129 core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
130 {
131 return addr;
132 }
133
134 CORE_ADDR
135 convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
136 struct target_ops *targ)
137 {
138 return addr;
139 }
140
141 int
142 no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
143 {
144 return reg;
145 }
146
147 void
148 default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
149 {
150 return;
151 }
152
153 /* See arch-utils.h. */
154
155 void
156 default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
157 {
158 return;
159 }
160
161 /* See arch-utils.h. */
162
163 CORE_ADDR
164 default_adjust_dwarf2_addr (CORE_ADDR pc)
165 {
166 return pc;
167 }
168
169 /* See arch-utils.h. */
170
171 CORE_ADDR
172 default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
173 {
174 return addr;
175 }
176
177 /* See arch-utils.h. */
178
179 bool
180 default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
181 struct dwarf2_frame_state *fs)
182 {
183 return false;
184 }
185
186 int
187 cannot_register_not (struct gdbarch *gdbarch, int regnum)
188 {
189 return 0;
190 }
191
192 /* Legacy version of target_virtual_frame_pointer(). Assumes that
193 there is an gdbarch_deprecated_fp_regnum and that it is the same,
194 cooked or raw. */
195
196 void
197 legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
198 CORE_ADDR pc,
199 int *frame_regnum,
200 LONGEST *frame_offset)
201 {
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);
215 else
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"));
220 *frame_offset = 0;
221 }
222
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. */
226
227 const struct floatformat **
228 default_floatformat_for_type (struct gdbarch *gdbarch,
229 const char *name, int len)
230 {
231 const struct floatformat **format = NULL;
232
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);
248
249 return format;
250 }
251 \f
252 int
253 generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
254 struct type *type)
255 {
256 return 0;
257 }
258
259 int
260 default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
261 {
262 return 0;
263 }
264
265 int
266 generic_instruction_nullified (struct gdbarch *gdbarch,
267 struct regcache *regcache)
268 {
269 return 0;
270 }
271
272 int
273 default_remote_register_number (struct gdbarch *gdbarch,
274 int regno)
275 {
276 return regno;
277 }
278
279 /* See arch-utils.h. */
280
281 int
282 default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
283 {
284 return 0;
285 }
286
287 \f
288 /* Functions to manipulate the endianness of the target. */
289
290 static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
291
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[] =
296 {
297 endian_big,
298 endian_little,
299 endian_auto,
300 NULL,
301 };
302 static const char *set_endian_string;
303
304 enum bfd_endian
305 selected_byte_order (void)
306 {
307 return target_byte_order_user;
308 }
309
310 /* Called by ``show endian''. */
311
312 static void
313 show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
314 const char *value)
315 {
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"));
320 else
321 fprintf_unfiltered (file, _("The target endianness is set automatically "
322 "(currently little endian).\n"));
323 else
324 if (target_byte_order_user == BFD_ENDIAN_BIG)
325 fprintf_unfiltered (file,
326 _("The target is set to big endian.\n"));
327 else
328 fprintf_unfiltered (file,
329 _("The target is set to little endian.\n"));
330 }
331
332 static void
333 set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
334 {
335 struct gdbarch_info info;
336
337 gdbarch_info_init (&info);
338
339 if (set_endian_string == endian_auto)
340 {
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"));
345 }
346 else if (set_endian_string == endian_little)
347 {
348 info.byte_order = BFD_ENDIAN_LITTLE;
349 if (! gdbarch_update_p (info))
350 printf_unfiltered (_("Little endian target not supported by GDB\n"));
351 else
352 target_byte_order_user = BFD_ENDIAN_LITTLE;
353 }
354 else if (set_endian_string == endian_big)
355 {
356 info.byte_order = BFD_ENDIAN_BIG;
357 if (! gdbarch_update_p (info))
358 printf_unfiltered (_("Big endian target not supported by GDB\n"));
359 else
360 target_byte_order_user = BFD_ENDIAN_BIG;
361 }
362 else
363 internal_error (__FILE__, __LINE__,
364 _("set_endian: bad value"));
365
366 show_endian (gdb_stdout, from_tty, NULL, NULL);
367 }
368
369 /* Given SELECTED, a currently selected BFD architecture, and
370 TARGET_DESC, the current target description, return what
371 architecture to use.
372
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.
377
378 If SELECTED is a different architecture, but it is accepted as
379 compatible by the target, we can use the target architecture.
380
381 If SELECTED is obviously incompatible, warn the user. */
382
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)
386 {
387 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
388 const struct bfd_arch_info *compat1, *compat2;
389
390 if (selected == NULL)
391 return from_target;
392
393 if (from_target == NULL)
394 return selected;
395
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)
400 return selected;
401
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
406 return A.
407
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. */
411
412 compat1 = selected->compatible (selected, from_target);
413 compat2 = from_target->compatible (from_target, selected);
414
415 if (compat1 == NULL && compat2 == NULL)
416 {
417 /* BFD considers the architectures incompatible. Check our
418 target description whether it accepts SELECTED as compatible
419 anyway. */
420 if (tdesc_compatible_p (target_desc, selected))
421 return from_target;
422
423 warning (_("Selected architecture %s is not compatible "
424 "with reported target architecture %s"),
425 selected->printable_name, from_target->printable_name);
426 return selected;
427 }
428
429 if (compat1 == NULL)
430 return compat2;
431 if (compat2 == NULL)
432 return compat1;
433 if (compat1 == compat2)
434 return compat1;
435
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)
441 return compat2;
442 if (compat2->the_default)
443 return compat1;
444
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);
450 return selected;
451 }
452
453 /* Functions to manipulate the architecture of the target. */
454
455 enum set_arch { set_arch_auto, set_arch_manual };
456
457 static const struct bfd_arch_info *target_architecture_user;
458
459 static const char *set_architecture_string;
460
461 const char *
462 selected_architecture_name (void)
463 {
464 if (target_architecture_user == NULL)
465 return NULL;
466 else
467 return set_architecture_string;
468 }
469
470 /* Called if the user enters ``show architecture'' without an
471 argument. */
472
473 static void
474 show_architecture (struct ui_file *file, int from_tty,
475 struct cmd_list_element *c, const char *value)
476 {
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);
481 else
482 fprintf_filtered (file, _("The target architecture is set to \"%s\".\n"),
483 set_architecture_string);
484 }
485
486
487 /* Called if the user enters ``set architecture'' with or without an
488 argument. */
489
490 static void
491 set_architecture (const char *ignore_args,
492 int from_tty, struct cmd_list_element *c)
493 {
494 struct gdbarch_info info;
495
496 gdbarch_info_init (&info);
497
498 if (strcmp (set_architecture_string, "auto") == 0)
499 {
500 target_architecture_user = NULL;
501 if (!gdbarch_update_p (info))
502 internal_error (__FILE__, __LINE__,
503 _("could not select an architecture automatically"));
504 }
505 else
506 {
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;
513 else
514 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
515 set_architecture_string);
516 }
517 show_architecture (gdb_stdout, from_tty, NULL, NULL);
518 }
519
520 /* Try to select a global architecture that matches "info". Return
521 non-zero if the attempt succeeds. */
522 int
523 gdbarch_update_p (struct gdbarch_info info)
524 {
525 struct gdbarch *new_gdbarch;
526
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;
532
533 /* Check for the current target description. */
534 if (info.target_desc == NULL)
535 info.target_desc = target_current_description ();
536
537 new_gdbarch = gdbarch_find_by_info (info);
538
539 /* If there no architecture by that name, reject the request. */
540 if (new_gdbarch == NULL)
541 {
542 if (gdbarch_debug)
543 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
544 "Architecture not found\n");
545 return 0;
546 }
547
548 /* If it is the same old architecture, accept the request (but don't
549 swap anything). */
550 if (new_gdbarch == target_gdbarch ())
551 {
552 if (gdbarch_debug)
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);
557 return 1;
558 }
559
560 /* It's a new architecture, swap it in. */
561 if (gdbarch_debug)
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);
567
568 return 1;
569 }
570
571 /* Return the architecture for ABFD. If no suitable architecture
572 could be find, return NULL. */
573
574 struct gdbarch *
575 gdbarch_from_bfd (bfd *abfd)
576 {
577 struct gdbarch_info info;
578 gdbarch_info_init (&info);
579
580 info.abfd = abfd;
581 return gdbarch_find_by_info (info);
582 }
583
584 /* Set the dynamic target-system-dependent parameters (architecture,
585 byte-order) using information found in the BFD */
586
587 void
588 set_gdbarch_from_file (bfd *abfd)
589 {
590 struct gdbarch_info info;
591 struct gdbarch *gdbarch;
592
593 gdbarch_info_init (&info);
594 info.abfd = abfd;
595 info.target_desc = target_current_description ();
596 gdbarch = gdbarch_find_by_info (info);
597
598 if (gdbarch == NULL)
599 error (_("Architecture of file not recognized."));
600 set_target_gdbarch (gdbarch);
601 }
602
603 /* Initialize the current architecture. Update the ``set
604 architecture'' command so that it specifies a list of valid
605 architectures. */
606
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;
610 #else
611 static const bfd_arch_info_type *default_bfd_arch;
612 #endif
613
614 #ifdef DEFAULT_BFD_VEC
615 extern const bfd_target DEFAULT_BFD_VEC;
616 static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
617 #else
618 static const bfd_target *default_bfd_vec;
619 #endif
620
621 static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
622
623 void
624 initialize_current_architecture (void)
625 {
626 const char **arches = gdbarch_printable_names ();
627 struct gdbarch_info info;
628
629 /* determine a default architecture and byte order. */
630 gdbarch_info_init (&info);
631
632 /* Find a default architecture. */
633 if (default_bfd_arch == NULL)
634 {
635 /* Choose the architecture by taking the first one
636 alphabetically. */
637 const char *chosen = arches[0];
638 const char **arch;
639 for (arch = arches; *arch != NULL; arch++)
640 {
641 if (strcmp (*arch, chosen) < 0)
642 chosen = *arch;
643 }
644 if (chosen == NULL)
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"));
651 }
652
653 info.bfd_arch_info = default_bfd_arch;
654
655 /* Take several guesses at a byte order. */
656 if (default_byte_order == BFD_ENDIAN_UNKNOWN
657 && default_bfd_vec != NULL)
658 {
659 /* Extract BFD's default vector's byte order. */
660 switch (default_bfd_vec->byteorder)
661 {
662 case BFD_ENDIAN_BIG:
663 default_byte_order = BFD_ENDIAN_BIG;
664 break;
665 case BFD_ENDIAN_LITTLE:
666 default_byte_order = BFD_ENDIAN_LITTLE;
667 break;
668 default:
669 break;
670 }
671 }
672 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
673 {
674 /* look for ``*el-*'' in the target name. */
675 const char *chp;
676 chp = strchr (target_name, '-');
677 if (chp != NULL
678 && chp - 2 >= target_name
679 && startswith (chp - 2, "el"))
680 default_byte_order = BFD_ENDIAN_LITTLE;
681 }
682 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
683 {
684 /* Wire it to big-endian!!! */
685 default_byte_order = BFD_ENDIAN_BIG;
686 }
687
688 info.byte_order = default_byte_order;
689 info.byte_order_for_code = info.byte_order;
690
691 if (! gdbarch_update_p (info))
692 internal_error (__FILE__, __LINE__,
693 _("initialize_current_architecture: Selection of "
694 "initial architecture failed"));
695
696 /* Create the ``set architecture'' command appending ``auto'' to the
697 list of architectures. */
698 {
699 /* Append ``auto''. */
700 int nr;
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);
712 }
713 }
714
715
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. */
721
722 void
723 gdbarch_info_init (struct gdbarch_info *info)
724 {
725 memset (info, 0, sizeof (struct gdbarch_info));
726 info->byte_order = BFD_ENDIAN_UNKNOWN;
727 info->byte_order_for_code = info->byte_order;
728 }
729
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. */
733
734 void
735 gdbarch_info_fill (struct gdbarch_info *info)
736 {
737 /* "(gdb) set architecture ...". */
738 if (info->bfd_arch_info == NULL
739 && target_architecture_user)
740 info->bfd_arch_info = target_architecture_user;
741 /* From the file. */
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;
754
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;
771
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. */
777
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 /* 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;
788
789 /* Must have at least filled in the architecture. */
790 gdb_assert (info->bfd_arch_info != NULL);
791 }
792
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.
796
797 This function should normally be called solely by the command
798 interpreter routines to determine the architecture to execute a
799 command in. */
800 struct gdbarch *
801 get_current_arch (void)
802 {
803 if (has_stack_frames ())
804 return get_frame_arch (get_selected_frame (NULL));
805 else
806 return target_gdbarch ();
807 }
808
809 int
810 default_has_shared_address_space (struct gdbarch *gdbarch)
811 {
812 /* Simply say no. In most unix-like targets each inferior/process
813 has its own address space. */
814 return 0;
815 }
816
817 int
818 default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
819 std::string *msg)
820 {
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. */
823 if (msg)
824 msg->clear ();
825 return 1;
826 }
827
828 const gdb_byte *
829 default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
830 int *lenptr)
831 {
832 int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
833
834 return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
835 }
836 int
837 default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
838 struct regcache *regcache,
839 CORE_ADDR *pcptr)
840 {
841 return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
842 }
843
844
845 void
846 default_gen_return_address (struct gdbarch *gdbarch,
847 struct agent_expr *ax, struct axs_value *value,
848 CORE_ADDR scope)
849 {
850 error (_("This architecture has no method to collect a return address."));
851 }
852
853 int
854 default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
855 struct type *type)
856 {
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
859 specified in ABI. */
860 return !(language_pass_by_reference (type).trivially_copyable);
861 }
862
863 int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
864 {
865 return 0;
866 }
867
868 int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
869 {
870 return 0;
871 }
872
873 int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
874 {
875 return 0;
876 }
877
878 /* See arch-utils.h. */
879
880 bool
881 default_program_breakpoint_here_p (struct gdbarch *gdbarch,
882 CORE_ADDR address)
883 {
884 int len;
885 const gdb_byte *bpoint = gdbarch_breakpoint_from_pc (gdbarch, &address, &len);
886
887 /* Software breakpoints unsupported? */
888 if (bpoint == nullptr)
889 return false;
890
891 gdb_byte *target_mem = (gdb_byte *) alloca (len);
892
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);
898
899 if (target_read_memory (address, target_mem, len) == 0)
900 {
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)
904 return true;
905 }
906
907 return false;
908 }
909
910 void
911 default_skip_permanent_breakpoint (struct regcache *regcache)
912 {
913 struct gdbarch *gdbarch = regcache->arch ();
914 CORE_ADDR current_pc = regcache_read_pc (regcache);
915 int bp_len;
916
917 gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
918 current_pc += bp_len;
919 regcache_write_pc (regcache, current_pc);
920 }
921
922 CORE_ADDR
923 default_infcall_mmap (CORE_ADDR size, unsigned prot)
924 {
925 error (_("This target does not support inferior memory allocation by mmap."));
926 }
927
928 void
929 default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
930 {
931 /* Memory reserved by inferior mmap is kept leaked. */
932 }
933
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). */
936
937 std::string
938 default_gcc_target_options (struct gdbarch *gdbarch)
939 {
940 return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
941 (gdbarch_ptr_bit (gdbarch) == 64
942 ? " -mcmodel=large" : ""));
943 }
944
945 /* gdbarch gnu_triplet_regexp method. */
946
947 const char *
948 default_gnu_triplet_regexp (struct gdbarch *gdbarch)
949 {
950 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
951 }
952
953 /* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has
954 a size of 1 octet. */
955
956 int
957 default_addressable_memory_unit_size (struct gdbarch *gdbarch)
958 {
959 return 1;
960 }
961
962 void
963 default_guess_tracepoint_registers (struct gdbarch *gdbarch,
964 struct regcache *regcache,
965 CORE_ADDR addr)
966 {
967 int pc_regno = gdbarch_pc_regnum (gdbarch);
968 gdb_byte *regs;
969
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))
977 return;
978
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);
983 }
984
985 int
986 default_print_insn (bfd_vma memaddr, disassemble_info *info)
987 {
988 disassembler_ftype disassemble_fn;
989
990 disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
991 info->mach, current_program_space->exec_bfd ());
992
993 gdb_assert (disassemble_fn != NULL);
994 return (*disassemble_fn) (memaddr, info);
995 }
996
997 /* See arch-utils.h. */
998
999 CORE_ADDR
1000 gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
1001 {
1002 CORE_ADDR new_pc = pc;
1003
1004 try
1005 {
1006 new_pc = gdbarch_skip_prologue (gdbarch, pc);
1007 }
1008 catch (const gdb_exception &ex)
1009 {}
1010
1011 return new_pc;
1012 }
1013
1014 /* See arch-utils.h. */
1015
1016 bool
1017 default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
1018 {
1019 return false;
1020 }
1021
1022 /* See arch-utils.h. */
1023
1024 ULONGEST
1025 default_type_align (struct gdbarch *gdbarch, struct type *type)
1026 {
1027 return 0;
1028 }
1029
1030 /* See arch-utils.h. */
1031
1032 std::string
1033 default_get_pc_address_flags (frame_info *frame, CORE_ADDR pc)
1034 {
1035 return "";
1036 }
1037
1038 /* See arch-utils.h. */
1039 void
1040 default_read_core_file_mappings (struct gdbarch *gdbarch,
1041 struct bfd *cbfd,
1042 gdb::function_view<void (ULONGEST count)>
1043 pre_loop_cb,
1044 gdb::function_view<void (int num,
1045 ULONGEST start,
1046 ULONGEST end,
1047 ULONGEST file_ofs,
1048 const char *filename)>
1049 loop_cb)
1050 {
1051 }
1052
1053 void _initialize_gdbarch_utils ();
1054 void
1055 _initialize_gdbarch_utils ()
1056 {
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);
1063 }