Remove path name from test case
[binutils-gdb.git] / gdb / arch-utils.c
1 /* Dynamic architecture support for GDB, the GNU debugger.
2
3 Copyright (C) 1998-2023 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"
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 #include "dummy-frame.h"
35 #include "frame-unwind.h"
36 #include "reggroups.h"
37 #include "auxv.h"
38 #include "observable.h"
39 #include "solib-target.h"
40
41 #include "gdbsupport/version.h"
42
43 #include "floatformat.h"
44
45 #include "dis-asm.h"
46
47 bool
48 default_displaced_step_hw_singlestep (struct gdbarch *gdbarch)
49 {
50 return !gdbarch_software_single_step_p (gdbarch);
51 }
52
53 CORE_ADDR
54 displaced_step_at_entry_point (struct gdbarch *gdbarch)
55 {
56 CORE_ADDR addr;
57 int bp_len;
58
59 addr = entry_point_address ();
60
61 /* Inferior calls also use the entry point as a breakpoint location.
62 We don't want displaced stepping to interfere with those
63 breakpoints, so leave space. */
64 gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
65 addr += bp_len * 2;
66
67 return addr;
68 }
69
70 int
71 legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
72 {
73 /* Only makes sense to supply raw registers. */
74 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
75 /* NOTE: cagney/2002-05-13: The old code did it this way and it is
76 suspected that some GDB/SIM combinations may rely on this
77 behaviour. The default should be one2one_register_sim_regno
78 (below). */
79 if (gdbarch_register_name (gdbarch, regnum)[0] != '\0')
80 return regnum;
81 else
82 return LEGACY_SIM_REGNO_IGNORE;
83 }
84
85 /* See arch-utils.h */
86
87 CORE_ADDR
88 default_remove_non_address_bits (struct gdbarch *gdbarch, CORE_ADDR pointer)
89 {
90 /* By default, just return the pointer value. */
91 return pointer;
92 }
93
94 /* See arch-utils.h */
95
96 std::string
97 default_memtag_to_string (struct gdbarch *gdbarch, struct value *tag)
98 {
99 error (_("This architecture has no method to convert a memory tag to"
100 " a string."));
101 }
102
103 /* See arch-utils.h */
104
105 bool
106 default_tagged_address_p (struct gdbarch *gdbarch, struct value *address)
107 {
108 /* By default, assume the address is untagged. */
109 return false;
110 }
111
112 /* See arch-utils.h */
113
114 bool
115 default_memtag_matches_p (struct gdbarch *gdbarch, struct value *address)
116 {
117 /* By default, assume the tags match. */
118 return true;
119 }
120
121 /* See arch-utils.h */
122
123 bool
124 default_set_memtags (struct gdbarch *gdbarch, struct value *address,
125 size_t length, const gdb::byte_vector &tags,
126 memtag_type tag_type)
127 {
128 /* By default, return true (successful); */
129 return true;
130 }
131
132 /* See arch-utils.h */
133
134 struct value *
135 default_get_memtag (struct gdbarch *gdbarch, struct value *address,
136 memtag_type tag_type)
137 {
138 /* By default, return no tag. */
139 return nullptr;
140 }
141
142 CORE_ADDR
143 generic_skip_trampoline_code (frame_info_ptr frame, CORE_ADDR pc)
144 {
145 return 0;
146 }
147
148 CORE_ADDR
149 generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
150 {
151 return 0;
152 }
153
154 int
155 generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
156 CORE_ADDR pc, const char *name)
157 {
158 return 0;
159 }
160
161 int
162 generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
163 {
164 return 0;
165 }
166
167 int
168 default_code_of_frame_writable (struct gdbarch *gdbarch,
169 frame_info_ptr frame)
170 {
171 return 1;
172 }
173
174 /* Helper functions for gdbarch_inner_than */
175
176 int
177 core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
178 {
179 return (lhs < rhs);
180 }
181
182 int
183 core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
184 {
185 return (lhs > rhs);
186 }
187
188 /* Misc helper functions for targets. */
189
190 CORE_ADDR
191 core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
192 {
193 return addr;
194 }
195
196 CORE_ADDR
197 convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
198 struct target_ops *targ)
199 {
200 return addr;
201 }
202
203 int
204 no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
205 {
206 return reg;
207 }
208
209 void
210 default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
211 {
212 return;
213 }
214
215 /* See arch-utils.h. */
216
217 void
218 default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
219 {
220 return;
221 }
222
223 /* See arch-utils.h. */
224
225 CORE_ADDR
226 default_adjust_dwarf2_addr (CORE_ADDR pc)
227 {
228 return pc;
229 }
230
231 /* See arch-utils.h. */
232
233 CORE_ADDR
234 default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
235 {
236 return addr;
237 }
238
239 /* See arch-utils.h. */
240
241 bool
242 default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
243 struct dwarf2_frame_state *fs)
244 {
245 return false;
246 }
247
248 int
249 cannot_register_not (struct gdbarch *gdbarch, int regnum)
250 {
251 return 0;
252 }
253
254 /* Legacy version of target_virtual_frame_pointer(). Assumes that
255 there is an gdbarch_deprecated_fp_regnum and that it is the same,
256 cooked or raw. */
257
258 void
259 legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
260 CORE_ADDR pc,
261 int *frame_regnum,
262 LONGEST *frame_offset)
263 {
264 /* FIXME: cagney/2002-09-13: This code is used when identifying the
265 frame pointer of the current PC. It is assuming that a single
266 register and an offset can determine this. I think it should
267 instead generate a byte code expression as that would work better
268 with things like Dwarf2's CFI. */
269 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
270 && gdbarch_deprecated_fp_regnum (gdbarch)
271 < gdbarch_num_regs (gdbarch))
272 *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
273 else if (gdbarch_sp_regnum (gdbarch) >= 0
274 && gdbarch_sp_regnum (gdbarch)
275 < gdbarch_num_regs (gdbarch))
276 *frame_regnum = gdbarch_sp_regnum (gdbarch);
277 else
278 /* Should this be an internal error? I guess so, it is reflecting
279 an architectural limitation in the current design. */
280 internal_error (_("No virtual frame pointer available"));
281 *frame_offset = 0;
282 }
283
284 /* Return a floating-point format for a floating-point variable of
285 length LEN in bits. If non-NULL, NAME is the name of its type.
286 If no suitable type is found, return NULL. */
287
288 const struct floatformat **
289 default_floatformat_for_type (struct gdbarch *gdbarch,
290 const char *name, int len)
291 {
292 const struct floatformat **format = NULL;
293
294 /* Check if this is a bfloat16 type. It has the same size as the
295 IEEE half float type, so we use the base type name to tell them
296 apart. */
297 if (name != nullptr && strcmp (name, "__bf16") == 0
298 && len == gdbarch_bfloat16_bit (gdbarch))
299 format = gdbarch_bfloat16_format (gdbarch);
300 else if (len == gdbarch_half_bit (gdbarch))
301 format = gdbarch_half_format (gdbarch);
302 else if (len == gdbarch_float_bit (gdbarch))
303 format = gdbarch_float_format (gdbarch);
304 else if (len == gdbarch_double_bit (gdbarch))
305 format = gdbarch_double_format (gdbarch);
306 else if (len == gdbarch_long_double_bit (gdbarch))
307 format = gdbarch_long_double_format (gdbarch);
308 /* On i386 the 'long double' type takes 96 bits,
309 while the real number of used bits is only 80,
310 both in processor and in memory.
311 The code below accepts the real bit size. */
312 else if (gdbarch_long_double_format (gdbarch) != NULL
313 && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
314 format = gdbarch_long_double_format (gdbarch);
315
316 return format;
317 }
318 \f
319 int
320 generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
321 struct type *type)
322 {
323 return 0;
324 }
325
326 int
327 default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
328 {
329 return 0;
330 }
331
332 int
333 generic_instruction_nullified (struct gdbarch *gdbarch,
334 struct regcache *regcache)
335 {
336 return 0;
337 }
338
339 int
340 default_remote_register_number (struct gdbarch *gdbarch,
341 int regno)
342 {
343 return regno;
344 }
345
346 /* See arch-utils.h. */
347
348 int
349 default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
350 {
351 return 0;
352 }
353
354 \f
355 /* Functions to manipulate the endianness of the target. */
356
357 static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
358
359 static const char endian_big[] = "big";
360 static const char endian_little[] = "little";
361 static const char endian_auto[] = "auto";
362 static const char *const endian_enum[] =
363 {
364 endian_big,
365 endian_little,
366 endian_auto,
367 NULL,
368 };
369 static const char *set_endian_string = endian_auto;
370
371 enum bfd_endian
372 selected_byte_order (void)
373 {
374 return target_byte_order_user;
375 }
376
377 /* Called by ``show endian''. */
378
379 static void
380 show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
381 const char *value)
382 {
383 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
384 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
385 gdb_printf (file, _("The target endianness is set automatically "
386 "(currently big endian).\n"));
387 else
388 gdb_printf (file, _("The target endianness is set automatically "
389 "(currently little endian).\n"));
390 else
391 if (target_byte_order_user == BFD_ENDIAN_BIG)
392 gdb_printf (file,
393 _("The target is set to big endian.\n"));
394 else
395 gdb_printf (file,
396 _("The target is set to little endian.\n"));
397 }
398
399 static void
400 set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
401 {
402 struct gdbarch_info info;
403
404 if (set_endian_string == endian_auto)
405 {
406 target_byte_order_user = BFD_ENDIAN_UNKNOWN;
407 if (! gdbarch_update_p (info))
408 internal_error (_("set_endian: architecture update failed"));
409 }
410 else if (set_endian_string == endian_little)
411 {
412 info.byte_order = BFD_ENDIAN_LITTLE;
413 if (! gdbarch_update_p (info))
414 gdb_printf (gdb_stderr,
415 _("Little endian target not supported by GDB\n"));
416 else
417 target_byte_order_user = BFD_ENDIAN_LITTLE;
418 }
419 else if (set_endian_string == endian_big)
420 {
421 info.byte_order = BFD_ENDIAN_BIG;
422 if (! gdbarch_update_p (info))
423 gdb_printf (gdb_stderr,
424 _("Big endian target not supported by GDB\n"));
425 else
426 target_byte_order_user = BFD_ENDIAN_BIG;
427 }
428 else
429 internal_error (_("set_endian: bad value"));
430
431 show_endian (gdb_stdout, from_tty, NULL, NULL);
432 }
433
434 /* Given SELECTED, a currently selected BFD architecture, and
435 TARGET_DESC, the current target description, return what
436 architecture to use.
437
438 SELECTED may be NULL, in which case we return the architecture
439 associated with TARGET_DESC. If SELECTED specifies a variant
440 of the architecture associated with TARGET_DESC, return the
441 more specific of the two.
442
443 If SELECTED is a different architecture, but it is accepted as
444 compatible by the target, we can use the target architecture.
445
446 If SELECTED is obviously incompatible, warn the user. */
447
448 static const struct bfd_arch_info *
449 choose_architecture_for_target (const struct target_desc *target_desc,
450 const struct bfd_arch_info *selected)
451 {
452 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
453 const struct bfd_arch_info *compat1, *compat2;
454
455 if (selected == NULL)
456 return from_target;
457
458 if (from_target == NULL)
459 return selected;
460
461 /* struct bfd_arch_info objects are singletons: that is, there's
462 supposed to be exactly one instance for a given machine. So you
463 can tell whether two are equivalent by comparing pointers. */
464 if (from_target == selected)
465 return selected;
466
467 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
468 incompatible. But if they are compatible, it returns the 'more
469 featureful' of the two arches. That is, if A can run code
470 written for B, but B can't run code written for A, then it'll
471 return A.
472
473 Some targets (e.g. MIPS as of 2006-12-04) don't fully
474 implement this, instead always returning NULL or the first
475 argument. We detect that case by checking both directions. */
476
477 compat1 = selected->compatible (selected, from_target);
478 compat2 = from_target->compatible (from_target, selected);
479
480 if (compat1 == NULL && compat2 == NULL)
481 {
482 /* BFD considers the architectures incompatible. Check our
483 target description whether it accepts SELECTED as compatible
484 anyway. */
485 if (tdesc_compatible_p (target_desc, selected))
486 return from_target;
487
488 warning (_("Selected architecture %s is not compatible "
489 "with reported target architecture %s"),
490 selected->printable_name, from_target->printable_name);
491 return selected;
492 }
493
494 if (compat1 == NULL)
495 return compat2;
496 if (compat2 == NULL)
497 return compat1;
498 if (compat1 == compat2)
499 return compat1;
500
501 /* If the two didn't match, but one of them was a default
502 architecture, assume the more specific one is correct. This
503 handles the case where an executable or target description just
504 says "mips", but the other knows which MIPS variant. */
505 if (compat1->the_default)
506 return compat2;
507 if (compat2->the_default)
508 return compat1;
509
510 /* We have no idea which one is better. This is a bug, but not
511 a critical problem; warn the user. */
512 warning (_("Selected architecture %s is ambiguous with "
513 "reported target architecture %s"),
514 selected->printable_name, from_target->printable_name);
515 return selected;
516 }
517
518 /* Functions to manipulate the architecture of the target. */
519
520 enum set_arch { set_arch_auto, set_arch_manual };
521
522 static const struct bfd_arch_info *target_architecture_user;
523
524 static const char *set_architecture_string;
525
526 const char *
527 selected_architecture_name (void)
528 {
529 if (target_architecture_user == NULL)
530 return NULL;
531 else
532 return set_architecture_string;
533 }
534
535 /* Called if the user enters ``show architecture'' without an
536 argument. */
537
538 static void
539 show_architecture (struct ui_file *file, int from_tty,
540 struct cmd_list_element *c, const char *value)
541 {
542 if (target_architecture_user == NULL)
543 gdb_printf (file, _("The target architecture is set to "
544 "\"auto\" (currently \"%s\").\n"),
545 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
546 else
547 gdb_printf (file, _("The target architecture is set to \"%s\".\n"),
548 set_architecture_string);
549 }
550
551
552 /* Called if the user enters ``set architecture'' with or without an
553 argument. */
554
555 static void
556 set_architecture (const char *ignore_args,
557 int from_tty, struct cmd_list_element *c)
558 {
559 struct gdbarch_info info;
560
561 if (strcmp (set_architecture_string, "auto") == 0)
562 {
563 target_architecture_user = NULL;
564 if (!gdbarch_update_p (info))
565 internal_error (_("could not select an architecture automatically"));
566 }
567 else
568 {
569 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
570 if (info.bfd_arch_info == NULL)
571 internal_error (_("set_architecture: bfd_scan_arch failed"));
572 if (gdbarch_update_p (info))
573 target_architecture_user = info.bfd_arch_info;
574 else
575 gdb_printf (gdb_stderr,
576 _("Architecture `%s' not recognized.\n"),
577 set_architecture_string);
578 }
579 show_architecture (gdb_stdout, from_tty, NULL, NULL);
580 }
581
582 /* Try to select a global architecture that matches "info". Return
583 non-zero if the attempt succeeds. */
584 int
585 gdbarch_update_p (struct gdbarch_info info)
586 {
587 struct gdbarch *new_gdbarch;
588
589 /* Check for the current file. */
590 if (info.abfd == NULL)
591 info.abfd = current_program_space->exec_bfd ();
592 if (info.abfd == NULL)
593 info.abfd = core_bfd;
594
595 /* Check for the current target description. */
596 if (info.target_desc == NULL)
597 info.target_desc = target_current_description ();
598
599 new_gdbarch = gdbarch_find_by_info (info);
600
601 /* If there no architecture by that name, reject the request. */
602 if (new_gdbarch == NULL)
603 {
604 if (gdbarch_debug)
605 gdb_printf (gdb_stdlog, "gdbarch_update_p: "
606 "Architecture not found\n");
607 return 0;
608 }
609
610 /* If it is the same old architecture, accept the request (but don't
611 swap anything). */
612 if (new_gdbarch == current_inferior ()->arch ())
613 {
614 if (gdbarch_debug)
615 gdb_printf (gdb_stdlog, "gdbarch_update_p: "
616 "Architecture %s (%s) unchanged\n",
617 host_address_to_string (new_gdbarch),
618 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
619 return 1;
620 }
621
622 /* It's a new architecture, swap it in. */
623 if (gdbarch_debug)
624 gdb_printf (gdb_stdlog, "gdbarch_update_p: "
625 "New architecture %s (%s) selected\n",
626 host_address_to_string (new_gdbarch),
627 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
628
629 current_inferior ()->set_arch (new_gdbarch);
630
631 return 1;
632 }
633
634 /* Return the architecture for ABFD. If no suitable architecture
635 could be find, return NULL. */
636
637 struct gdbarch *
638 gdbarch_from_bfd (bfd *abfd)
639 {
640 struct gdbarch_info info;
641
642 info.abfd = abfd;
643 return gdbarch_find_by_info (info);
644 }
645
646 /* Set the dynamic target-system-dependent parameters (architecture,
647 byte-order) using information found in the BFD */
648
649 void
650 set_gdbarch_from_file (bfd *abfd)
651 {
652 struct gdbarch_info info;
653 struct gdbarch *gdbarch;
654
655 info.abfd = abfd;
656 info.target_desc = target_current_description ();
657 gdbarch = gdbarch_find_by_info (info);
658
659 if (gdbarch == NULL)
660 error (_("Architecture of file not recognized."));
661
662 current_inferior ()->set_arch (gdbarch);
663 }
664
665 /* Initialize the current architecture. Update the ``set
666 architecture'' command so that it specifies a list of valid
667 architectures. */
668
669 #ifdef DEFAULT_BFD_ARCH
670 extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
671 static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
672 #else
673 static const bfd_arch_info_type *default_bfd_arch;
674 #endif
675
676 #ifdef DEFAULT_BFD_VEC
677 extern const bfd_target DEFAULT_BFD_VEC;
678 static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
679 #else
680 static const bfd_target *default_bfd_vec;
681 #endif
682
683 static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
684
685 /* Printable names of architectures. Used as the enum list of the
686 "set arch" command. */
687 static std::vector<const char *> arches;
688
689 void
690 initialize_current_architecture (void)
691 {
692 arches = gdbarch_printable_names ();
693
694 /* Find a default architecture. */
695 if (default_bfd_arch == NULL)
696 {
697 /* Choose the architecture by taking the first one
698 alphabetically. */
699 const char *chosen = arches[0];
700
701 for (const char *arch : arches)
702 {
703 if (strcmp (arch, chosen) < 0)
704 chosen = arch;
705 }
706
707 if (chosen == NULL)
708 internal_error (_("initialize_current_architecture: No arch"));
709
710 default_bfd_arch = bfd_scan_arch (chosen);
711 if (default_bfd_arch == NULL)
712 internal_error (_("initialize_current_architecture: Arch not found"));
713 }
714
715 gdbarch_info info;
716 info.bfd_arch_info = default_bfd_arch;
717
718 /* Take several guesses at a byte order. */
719 if (default_byte_order == BFD_ENDIAN_UNKNOWN
720 && default_bfd_vec != NULL)
721 {
722 /* Extract BFD's default vector's byte order. */
723 switch (default_bfd_vec->byteorder)
724 {
725 case BFD_ENDIAN_BIG:
726 default_byte_order = BFD_ENDIAN_BIG;
727 break;
728 case BFD_ENDIAN_LITTLE:
729 default_byte_order = BFD_ENDIAN_LITTLE;
730 break;
731 default:
732 break;
733 }
734 }
735 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
736 {
737 /* look for ``*el-*'' in the target name. */
738 const char *chp;
739 chp = strchr (target_name, '-');
740 if (chp != NULL
741 && chp - 2 >= target_name
742 && startswith (chp - 2, "el"))
743 default_byte_order = BFD_ENDIAN_LITTLE;
744 }
745 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
746 {
747 /* Wire it to big-endian!!! */
748 default_byte_order = BFD_ENDIAN_BIG;
749 }
750
751 info.byte_order = default_byte_order;
752 info.byte_order_for_code = info.byte_order;
753
754 if (! gdbarch_update_p (info))
755 internal_error (_("initialize_current_architecture: Selection of "
756 "initial architecture failed"));
757
758 /* Create the ``set architecture'' command appending ``auto'' to the
759 list of architectures. */
760 {
761 /* Append ``auto''. */
762 set_architecture_string = "auto";
763 arches.push_back (set_architecture_string);
764 arches.push_back (nullptr);
765 set_show_commands architecture_cmds
766 = add_setshow_enum_cmd ("architecture", class_support,
767 arches.data (), &set_architecture_string,
768 _("Set architecture of target."),
769 _("Show architecture of target."), NULL,
770 set_architecture, show_architecture,
771 &setlist, &showlist);
772 add_alias_cmd ("processor", architecture_cmds.set, class_support, 1,
773 &setlist);
774 }
775 }
776
777 /* Similar to init, but this time fill in the blanks. Information is
778 obtained from the global "set ..." options and explicitly
779 initialized INFO fields. */
780
781 void
782 gdbarch_info_fill (struct gdbarch_info *info)
783 {
784 /* "(gdb) set architecture ...". */
785 if (info->bfd_arch_info == NULL
786 && target_architecture_user)
787 info->bfd_arch_info = target_architecture_user;
788 /* From the file. */
789 if (info->bfd_arch_info == NULL
790 && info->abfd != NULL
791 && bfd_get_arch (info->abfd) != bfd_arch_unknown
792 && bfd_get_arch (info->abfd) != bfd_arch_obscure)
793 info->bfd_arch_info = bfd_get_arch_info (info->abfd);
794 /* From the target. */
795 if (info->target_desc != NULL)
796 info->bfd_arch_info = choose_architecture_for_target
797 (info->target_desc, info->bfd_arch_info);
798 /* From the default. */
799 if (info->bfd_arch_info == NULL)
800 info->bfd_arch_info = default_bfd_arch;
801
802 /* "(gdb) set byte-order ...". */
803 if (info->byte_order == BFD_ENDIAN_UNKNOWN
804 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
805 info->byte_order = target_byte_order_user;
806 /* From the INFO struct. */
807 if (info->byte_order == BFD_ENDIAN_UNKNOWN
808 && info->abfd != NULL)
809 info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
810 : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
811 : BFD_ENDIAN_UNKNOWN);
812 /* From the default. */
813 if (info->byte_order == BFD_ENDIAN_UNKNOWN)
814 info->byte_order = default_byte_order;
815 info->byte_order_for_code = info->byte_order;
816 /* Wire the default to the last selected byte order. */
817 default_byte_order = info->byte_order;
818
819 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
820 /* From the manual override, or from file. */
821 if (info->osabi == GDB_OSABI_UNKNOWN)
822 info->osabi = gdbarch_lookup_osabi (info->abfd);
823 /* From the target. */
824
825 if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
826 info->osabi = tdesc_osabi (info->target_desc);
827 /* From the configured default. */
828 #ifdef GDB_OSABI_DEFAULT
829 if (info->osabi == GDB_OSABI_UNKNOWN)
830 info->osabi = GDB_OSABI_DEFAULT;
831 #endif
832 /* If we still don't know which osabi to pick, pick none. */
833 if (info->osabi == GDB_OSABI_UNKNOWN)
834 info->osabi = GDB_OSABI_NONE;
835
836 /* Must have at least filled in the architecture. */
837 gdb_assert (info->bfd_arch_info != NULL);
838 }
839
840 /* Return "current" architecture. If the target is running, this is
841 the architecture of the selected frame. Otherwise, the "current"
842 architecture defaults to the target architecture.
843
844 This function should normally be called solely by the command
845 interpreter routines to determine the architecture to execute a
846 command in. */
847 struct gdbarch *
848 get_current_arch (void)
849 {
850 if (has_stack_frames ())
851 return get_frame_arch (get_selected_frame (NULL));
852 else
853 return current_inferior ()->arch ();
854 }
855
856 int
857 default_has_shared_address_space (struct gdbarch *gdbarch)
858 {
859 /* Simply say no. In most unix-like targets each inferior/process
860 has its own address space. */
861 return 0;
862 }
863
864 int
865 default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
866 std::string *msg)
867 {
868 /* We don't know if maybe the target has some way to do fast
869 tracepoints that doesn't need gdbarch, so always say yes. */
870 if (msg)
871 msg->clear ();
872 return 1;
873 }
874
875 const gdb_byte *
876 default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
877 int *lenptr)
878 {
879 int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
880
881 return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
882 }
883 int
884 default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
885 struct regcache *regcache,
886 CORE_ADDR *pcptr)
887 {
888 return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
889 }
890
891
892 void
893 default_gen_return_address (struct gdbarch *gdbarch,
894 struct agent_expr *ax, struct axs_value *value,
895 CORE_ADDR scope)
896 {
897 error (_("This architecture has no method to collect a return address."));
898 }
899
900 int
901 default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
902 struct type *type)
903 {
904 /* Usually, the return value's address is stored the in the "first hidden"
905 parameter if the return value should be passed by reference, as
906 specified in ABI. */
907 return !(language_pass_by_reference (type).trivially_copyable);
908 }
909
910 int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
911 {
912 return 0;
913 }
914
915 int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
916 {
917 return 0;
918 }
919
920 int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
921 {
922 return 0;
923 }
924
925 /* See arch-utils.h. */
926
927 bool
928 default_program_breakpoint_here_p (struct gdbarch *gdbarch,
929 CORE_ADDR address)
930 {
931 int len;
932 const gdb_byte *bpoint = gdbarch_breakpoint_from_pc (gdbarch, &address, &len);
933
934 /* Software breakpoints unsupported? */
935 if (bpoint == nullptr)
936 return false;
937
938 gdb_byte *target_mem = (gdb_byte *) alloca (len);
939
940 /* Enable the automatic memory restoration from breakpoints while
941 we read the memory. Otherwise we may find temporary breakpoints, ones
942 inserted by GDB, and flag them as permanent breakpoints. */
943 scoped_restore restore_memory
944 = make_scoped_restore_show_memory_breakpoints (0);
945
946 if (target_read_memory (address, target_mem, len) == 0)
947 {
948 /* Check if this is a breakpoint instruction for this architecture,
949 including ones used by GDB. */
950 if (memcmp (target_mem, bpoint, len) == 0)
951 return true;
952 }
953
954 return false;
955 }
956
957 void
958 default_skip_permanent_breakpoint (struct regcache *regcache)
959 {
960 struct gdbarch *gdbarch = regcache->arch ();
961 CORE_ADDR current_pc = regcache_read_pc (regcache);
962 int bp_len;
963
964 gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
965 current_pc += bp_len;
966 regcache_write_pc (regcache, current_pc);
967 }
968
969 CORE_ADDR
970 default_infcall_mmap (CORE_ADDR size, unsigned prot)
971 {
972 error (_("This target does not support inferior memory allocation by mmap."));
973 }
974
975 void
976 default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
977 {
978 /* Memory reserved by inferior mmap is kept leaked. */
979 }
980
981 /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
982 created in inferior memory by GDB (normally it is set by ld.so). */
983
984 std::string
985 default_gcc_target_options (struct gdbarch *gdbarch)
986 {
987 return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
988 (gdbarch_ptr_bit (gdbarch) == 64
989 ? " -mcmodel=large" : ""));
990 }
991
992 /* gdbarch gnu_triplet_regexp method. */
993
994 const char *
995 default_gnu_triplet_regexp (struct gdbarch *gdbarch)
996 {
997 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
998 }
999
1000 /* Default method for gdbarch_addressable_memory_unit_size. The default is
1001 based on the bits_per_byte defined in the bfd library for the current
1002 architecture, this is usually 8-bits, and so this function will usually
1003 return 1 indicating 1 byte is 1 octet. */
1004
1005 int
1006 default_addressable_memory_unit_size (struct gdbarch *gdbarch)
1007 {
1008 return gdbarch_bfd_arch_info (gdbarch)->bits_per_byte / 8;
1009 }
1010
1011 void
1012 default_guess_tracepoint_registers (struct gdbarch *gdbarch,
1013 struct regcache *regcache,
1014 CORE_ADDR addr)
1015 {
1016 int pc_regno = gdbarch_pc_regnum (gdbarch);
1017 gdb_byte *regs;
1018
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))
1026 return;
1027
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);
1032 }
1033
1034 int
1035 default_print_insn (bfd_vma memaddr, disassemble_info *info)
1036 {
1037 disassembler_ftype disassemble_fn;
1038
1039 disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
1040 info->mach, current_program_space->exec_bfd ());
1041
1042 gdb_assert (disassemble_fn != NULL);
1043 return (*disassemble_fn) (memaddr, info);
1044 }
1045
1046 /* See arch-utils.h. */
1047
1048 CORE_ADDR
1049 gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
1050 {
1051 CORE_ADDR new_pc = pc;
1052
1053 try
1054 {
1055 new_pc = gdbarch_skip_prologue (gdbarch, pc);
1056 }
1057 catch (const gdb_exception &ex)
1058 {}
1059
1060 return new_pc;
1061 }
1062
1063 /* See arch-utils.h. */
1064
1065 bool
1066 default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
1067 {
1068 return false;
1069 }
1070
1071 /* See arch-utils.h. */
1072
1073 ULONGEST
1074 default_type_align (struct gdbarch *gdbarch, struct type *type)
1075 {
1076 return 0;
1077 }
1078
1079 /* See arch-utils.h. */
1080
1081 std::string
1082 default_get_pc_address_flags (frame_info_ptr frame, CORE_ADDR pc)
1083 {
1084 return "";
1085 }
1086
1087 /* See arch-utils.h. */
1088 void
1089 default_read_core_file_mappings
1090 (struct gdbarch *gdbarch,
1091 struct bfd *cbfd,
1092 read_core_file_mappings_pre_loop_ftype pre_loop_cb,
1093 read_core_file_mappings_loop_ftype loop_cb)
1094 {
1095 }
1096
1097 /* See arch-utils.h. */
1098 bool
1099 default_use_target_description_from_corefile_notes (struct gdbarch *gdbarch,
1100 struct bfd *corefile_bfd)
1101 {
1102 /* Always trust the corefile target description contained in the target
1103 description note. */
1104 return true;
1105 }
1106
1107 CORE_ADDR
1108 default_get_return_buf_addr (struct type *val_type, frame_info_ptr cur_frame)
1109 {
1110 return 0;
1111 }
1112
1113 bool
1114 default_dwarf2_omit_typedef_p (struct type *target_type, const char *producer,
1115 const char *name)
1116 {
1117 return false;
1118 }
1119
1120 static CORE_ADDR
1121 default_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
1122 {
1123 return pc;
1124 }
1125
1126 /* Non-zero if we want to trace architecture code. */
1127
1128 #ifndef GDBARCH_DEBUG
1129 #define GDBARCH_DEBUG 0
1130 #endif
1131 unsigned int gdbarch_debug = GDBARCH_DEBUG;
1132 static void
1133 show_gdbarch_debug (struct ui_file *file, int from_tty,
1134 struct cmd_list_element *c, const char *value)
1135 {
1136 gdb_printf (file, _("Architecture debugging is %s.\n"), value);
1137 }
1138
1139 static const char *
1140 pformat (struct gdbarch *gdbarch, const struct floatformat **format)
1141 {
1142 if (format == NULL)
1143 return "(null)";
1144
1145 int format_index = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE ? 1 : 0;
1146 return format[format_index]->name;
1147 }
1148
1149 static const char *
1150 pstring (const char *string)
1151 {
1152 if (string == NULL)
1153 return "(null)";
1154 return string;
1155 }
1156
1157 static const char *
1158 pstring_ptr (char **string)
1159 {
1160 if (string == NULL || *string == NULL)
1161 return "(null)";
1162 return *string;
1163 }
1164
1165 /* Helper function to print a list of strings, represented as "const
1166 char *const *". The list is printed comma-separated. */
1167
1168 static const char *
1169 pstring_list (const char *const *list)
1170 {
1171 static char ret[100];
1172 const char *const *p;
1173 size_t offset = 0;
1174
1175 if (list == NULL)
1176 return "(null)";
1177
1178 ret[0] = '\0';
1179 for (p = list; *p != NULL && offset < sizeof (ret); ++p)
1180 {
1181 size_t s = xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
1182 offset += 2 + s;
1183 }
1184
1185 if (offset > 0)
1186 {
1187 gdb_assert (offset - 2 < sizeof (ret));
1188 ret[offset - 2] = '\0';
1189 }
1190
1191 return ret;
1192 }
1193
1194 #include "gdbarch.c"
1195
1196 enum return_value_convention
1197 default_gdbarch_return_value
1198 (struct gdbarch *gdbarch, struct value *function, struct type *valtype,
1199 struct regcache *regcache, struct value **read_value,
1200 const gdb_byte *writebuf)
1201 {
1202 gdb_byte *readbuf = nullptr;
1203
1204 if (read_value != nullptr)
1205 {
1206 *read_value = value::allocate (valtype);
1207 readbuf = (*read_value)->contents_raw ().data ();
1208 }
1209
1210 return gdbarch->return_value (gdbarch, function, valtype, regcache,
1211 readbuf, writebuf);
1212 }
1213
1214 obstack *gdbarch_obstack (gdbarch *arch)
1215 {
1216 return &arch->obstack;
1217 }
1218
1219 /* See gdbarch.h. */
1220
1221 char *
1222 gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
1223 {
1224 return obstack_strdup (&arch->obstack, string);
1225 }
1226
1227 /* Free a gdbarch struct. This should never happen in normal
1228 operation --- once you've created a gdbarch, you keep it around.
1229 However, if an architecture's init function encounters an error
1230 building the structure, it may need to clean up a partially
1231 constructed gdbarch. */
1232
1233 void
1234 gdbarch_free (struct gdbarch *arch)
1235 {
1236 gdb_assert (arch != NULL);
1237 gdb_assert (!arch->initialized_p);
1238 delete arch;
1239 }
1240
1241 /* See gdbarch.h. */
1242
1243 struct gdbarch_tdep_base *
1244 gdbarch_tdep_1 (struct gdbarch *gdbarch)
1245 {
1246 if (gdbarch_debug >= 2)
1247 gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
1248 return gdbarch->tdep.get ();
1249 }
1250
1251 registry<gdbarch> *
1252 registry_accessor<gdbarch>::get (gdbarch *arch)
1253 {
1254 return &arch->registry_fields;
1255 }
1256
1257 /* Keep a registry of the architectures known by GDB. */
1258
1259 struct gdbarch_registration
1260 {
1261 enum bfd_architecture bfd_architecture;
1262 gdbarch_init_ftype *init;
1263 gdbarch_dump_tdep_ftype *dump_tdep;
1264 gdbarch_supports_arch_info_ftype *supports_arch_info;
1265 struct gdbarch_list *arches;
1266 struct gdbarch_registration *next;
1267 };
1268
1269 static struct gdbarch_registration *gdbarch_registry = NULL;
1270
1271 std::vector<const char *>
1272 gdbarch_printable_names ()
1273 {
1274 /* Accumulate a list of names based on the registered list of
1275 architectures. */
1276 std::vector<const char *> arches;
1277
1278 for (gdbarch_registration *rego = gdbarch_registry;
1279 rego != nullptr;
1280 rego = rego->next)
1281 {
1282 const struct bfd_arch_info *ap
1283 = bfd_lookup_arch (rego->bfd_architecture, 0);
1284 if (ap == nullptr)
1285 internal_error (_("gdbarch_architecture_names: multi-arch unknown"));
1286 do
1287 {
1288 if (rego->supports_arch_info == nullptr
1289 || rego->supports_arch_info (ap))
1290 arches.push_back (ap->printable_name);
1291 ap = ap->next;
1292 }
1293 while (ap != NULL);
1294 }
1295
1296 return arches;
1297 }
1298
1299
1300 void
1301 gdbarch_register (enum bfd_architecture bfd_architecture,
1302 gdbarch_init_ftype *init,
1303 gdbarch_dump_tdep_ftype *dump_tdep,
1304 gdbarch_supports_arch_info_ftype *supports_arch_info)
1305 {
1306 struct gdbarch_registration **curr;
1307 const struct bfd_arch_info *bfd_arch_info;
1308
1309 /* Check that BFD recognizes this architecture */
1310 bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
1311 if (bfd_arch_info == NULL)
1312 {
1313 internal_error (_("gdbarch: Attempt to register "
1314 "unknown architecture (%d)"),
1315 bfd_architecture);
1316 }
1317 /* Check that we haven't seen this architecture before. */
1318 for (curr = &gdbarch_registry;
1319 (*curr) != NULL;
1320 curr = &(*curr)->next)
1321 {
1322 if (bfd_architecture == (*curr)->bfd_architecture)
1323 internal_error (_("gdbarch: Duplicate registration "
1324 "of architecture (%s)"),
1325 bfd_arch_info->printable_name);
1326 }
1327 /* log it */
1328 if (gdbarch_debug)
1329 gdb_printf (gdb_stdlog, "gdbarch_register (%s, %s)\n",
1330 bfd_arch_info->printable_name,
1331 host_address_to_string (init));
1332 /* Append it */
1333 (*curr) = XNEW (struct gdbarch_registration);
1334 (*curr)->bfd_architecture = bfd_architecture;
1335 (*curr)->init = init;
1336 (*curr)->dump_tdep = dump_tdep;
1337 (*curr)->supports_arch_info = supports_arch_info;
1338 (*curr)->arches = NULL;
1339 (*curr)->next = NULL;
1340 }
1341
1342 /* Look for an architecture using gdbarch_info. */
1343
1344 struct gdbarch_list *
1345 gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
1346 const struct gdbarch_info *info)
1347 {
1348 for (; arches != NULL; arches = arches->next)
1349 {
1350 if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
1351 continue;
1352 if (info->byte_order != arches->gdbarch->byte_order)
1353 continue;
1354 if (info->osabi != arches->gdbarch->osabi)
1355 continue;
1356 if (info->target_desc != arches->gdbarch->target_desc)
1357 continue;
1358 return arches;
1359 }
1360 return NULL;
1361 }
1362
1363
1364 /* Find an architecture that matches the specified INFO. Create a new
1365 architecture if needed. Return that new architecture. */
1366
1367 struct gdbarch *
1368 gdbarch_find_by_info (struct gdbarch_info info)
1369 {
1370 struct gdbarch *new_gdbarch;
1371 struct gdbarch_registration *rego;
1372
1373 /* Fill in missing parts of the INFO struct using a number of
1374 sources: "set ..."; INFOabfd supplied; and the global
1375 defaults. */
1376 gdbarch_info_fill (&info);
1377
1378 /* Must have found some sort of architecture. */
1379 gdb_assert (info.bfd_arch_info != nullptr);
1380
1381 if (gdbarch_debug)
1382 {
1383 gdb_printf (gdb_stdlog,
1384 "gdbarch_find_by_info: info.bfd_arch_info %s\n",
1385 (info.bfd_arch_info != nullptr
1386 ? info.bfd_arch_info->printable_name
1387 : "(null)"));
1388 gdb_printf (gdb_stdlog,
1389 "gdbarch_find_by_info: info.byte_order %d (%s)\n",
1390 info.byte_order,
1391 (info.byte_order == BFD_ENDIAN_BIG ? "big"
1392 : info.byte_order == BFD_ENDIAN_LITTLE ? "little"
1393 : "default"));
1394 gdb_printf (gdb_stdlog,
1395 "gdbarch_find_by_info: info.osabi %d (%s)\n",
1396 info.osabi, gdbarch_osabi_name (info.osabi));
1397 gdb_printf (gdb_stdlog,
1398 "gdbarch_find_by_info: info.abfd %s\n",
1399 host_address_to_string (info.abfd));
1400 }
1401
1402 /* Find the tdep code that knows about this architecture. */
1403 for (rego = gdbarch_registry;
1404 rego != nullptr;
1405 rego = rego->next)
1406 if (rego->bfd_architecture == info.bfd_arch_info->arch)
1407 break;
1408 if (rego == nullptr)
1409 {
1410 if (gdbarch_debug)
1411 gdb_printf (gdb_stdlog, "gdbarch_find_by_info: "
1412 "No matching architecture\n");
1413 return nullptr;
1414 }
1415
1416 /* Ask the tdep code for an architecture that matches "info". */
1417 new_gdbarch = rego->init (info, rego->arches);
1418
1419 /* Did the tdep code like it? No. Reject the change and revert to
1420 the old architecture. */
1421 if (new_gdbarch == nullptr)
1422 {
1423 if (gdbarch_debug)
1424 gdb_printf (gdb_stdlog, "gdbarch_find_by_info: "
1425 "Target rejected architecture\n");
1426 return nullptr;
1427 }
1428
1429 /* Is this a pre-existing architecture (as determined by already
1430 being initialized)? Move it to the front of the architecture
1431 list (keeping the list sorted Most Recently Used). */
1432 if (new_gdbarch->initialized_p)
1433 {
1434 struct gdbarch_list **list;
1435 struct gdbarch_list *self;
1436 if (gdbarch_debug)
1437 gdb_printf (gdb_stdlog, "gdbarch_find_by_info: "
1438 "Previous architecture %s (%s) selected\n",
1439 host_address_to_string (new_gdbarch),
1440 new_gdbarch->bfd_arch_info->printable_name);
1441 /* Find the existing arch in the list. */
1442 for (list = &rego->arches;
1443 (*list) != nullptr && (*list)->gdbarch != new_gdbarch;
1444 list = &(*list)->next);
1445 /* It had better be in the list of architectures. */
1446 gdb_assert ((*list) != nullptr && (*list)->gdbarch == new_gdbarch);
1447 /* Unlink SELF. */
1448 self = (*list);
1449 (*list) = self->next;
1450 /* Insert SELF at the front. */
1451 self->next = rego->arches;
1452 rego->arches = self;
1453 /* Return it. */
1454 return new_gdbarch;
1455 }
1456
1457 /* It's a new architecture. */
1458 if (gdbarch_debug)
1459 gdb_printf (gdb_stdlog, "gdbarch_find_by_info: "
1460 "New architecture %s (%s) selected\n",
1461 host_address_to_string (new_gdbarch),
1462 new_gdbarch->bfd_arch_info->printable_name);
1463
1464 /* Insert the new architecture into the front of the architecture
1465 list (keep the list sorted Most Recently Used). */
1466 {
1467 struct gdbarch_list *self = XNEW (struct gdbarch_list);
1468 self->next = rego->arches;
1469 self->gdbarch = new_gdbarch;
1470 rego->arches = self;
1471 }
1472
1473 /* Check that the newly installed architecture is valid. Plug in
1474 any post init values. */
1475 new_gdbarch->dump_tdep = rego->dump_tdep;
1476 verify_gdbarch (new_gdbarch);
1477 new_gdbarch->initialized_p = true;
1478
1479 if (gdbarch_debug)
1480 gdbarch_dump (new_gdbarch, gdb_stdlog);
1481
1482 gdb::observers::new_architecture.notify (new_gdbarch);
1483
1484 return new_gdbarch;
1485 }
1486
1487 /* See gdbarch.h. */
1488
1489 bool
1490 gdbarch_initialized_p (gdbarch *arch)
1491 {
1492 return arch->initialized_p;
1493 }
1494
1495 void _initialize_gdbarch_utils ();
1496 void
1497 _initialize_gdbarch_utils ()
1498 {
1499 add_setshow_enum_cmd ("endian", class_support,
1500 endian_enum, &set_endian_string,
1501 _("Set endianness of target."),
1502 _("Show endianness of target."),
1503 NULL, set_endian, show_endian,
1504 &setlist, &showlist);
1505 add_setshow_zuinteger_cmd ("arch", class_maintenance, &gdbarch_debug, _("\
1506 Set architecture debugging."), _("\
1507 Show architecture debugging."), _("\
1508 When non-zero, architecture debugging is enabled."),
1509 NULL,
1510 show_gdbarch_debug,
1511 &setdebuglist, &showdebuglist);
1512 }