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