Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
... / ...
CommitLineData
1/* Dynamic architecture support for GDB, the GNU debugger.
2
3 Copyright (C) 1998-2019 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/* Local non-gdb includes. */
23#include "arch-utils.h"
24#include "common/version.h"
25#include "dis-asm.h"
26#include "floatformat.h"
27#include "gdbcmd.h"
28#include "gdbcore.h"
29#include "inferior.h"
30#include "infrun.h"
31#include "language.h"
32#include "objfiles.h"
33#include "osabi.h"
34#include "regcache.h"
35#include "sim-regno.h"
36#include "symtab.h"
37#include "target-descriptions.h"
38
39int
40default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
41 struct displaced_step_closure *closure)
42{
43 return !gdbarch_software_single_step_p (gdbarch);
44}
45
46CORE_ADDR
47displaced_step_at_entry_point (struct gdbarch *gdbarch)
48{
49 CORE_ADDR addr;
50 int bp_len;
51
52 addr = entry_point_address ();
53
54 /* Inferior calls also use the entry point as a breakpoint location.
55 We don't want displaced stepping to interfere with those
56 breakpoints, so leave space. */
57 gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
58 addr += bp_len * 2;
59
60 return addr;
61}
62
63int
64legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
65{
66 /* Only makes sense to supply raw registers. */
67 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
68 /* NOTE: cagney/2002-05-13: The old code did it this way and it is
69 suspected that some GDB/SIM combinations may rely on this
70 behavour. The default should be one2one_register_sim_regno
71 (below). */
72 if (gdbarch_register_name (gdbarch, regnum) != NULL
73 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
74 return regnum;
75 else
76 return LEGACY_SIM_REGNO_IGNORE;
77}
78
79CORE_ADDR
80generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
81{
82 return 0;
83}
84
85CORE_ADDR
86generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
87{
88 return 0;
89}
90
91int
92generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
93 CORE_ADDR pc, const char *name)
94{
95 return 0;
96}
97
98int
99generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
100{
101 return 0;
102}
103
104int
105default_code_of_frame_writable (struct gdbarch *gdbarch,
106 struct frame_info *frame)
107{
108 return 1;
109}
110
111/* Helper functions for gdbarch_inner_than */
112
113int
114core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
115{
116 return (lhs < rhs);
117}
118
119int
120core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
121{
122 return (lhs > rhs);
123}
124
125/* Misc helper functions for targets. */
126
127CORE_ADDR
128core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
129{
130 return addr;
131}
132
133CORE_ADDR
134convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
135 struct target_ops *targ)
136{
137 return addr;
138}
139
140int
141no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
142{
143 return reg;
144}
145
146void
147default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
148{
149 return;
150}
151
152/* See arch-utils.h. */
153
154void
155default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
156{
157 return;
158}
159
160/* See arch-utils.h. */
161
162CORE_ADDR
163default_adjust_dwarf2_addr (CORE_ADDR pc)
164{
165 return pc;
166}
167
168/* See arch-utils.h. */
169
170CORE_ADDR
171default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
172{
173 return addr;
174}
175
176/* See arch-utils.h. */
177
178bool
179default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
180 struct dwarf2_frame_state *fs)
181{
182 return false;
183}
184
185int
186cannot_register_not (struct gdbarch *gdbarch, int regnum)
187{
188 return 0;
189}
190
191/* Legacy version of target_virtual_frame_pointer(). Assumes that
192 there is an gdbarch_deprecated_fp_regnum and that it is the same,
193 cooked or raw. */
194
195void
196legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
197 CORE_ADDR pc,
198 int *frame_regnum,
199 LONGEST *frame_offset)
200{
201 /* FIXME: cagney/2002-09-13: This code is used when identifying the
202 frame pointer of the current PC. It is assuming that a single
203 register and an offset can determine this. I think it should
204 instead generate a byte code expression as that would work better
205 with things like Dwarf2's CFI. */
206 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
207 && gdbarch_deprecated_fp_regnum (gdbarch)
208 < gdbarch_num_regs (gdbarch))
209 *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
210 else if (gdbarch_sp_regnum (gdbarch) >= 0
211 && gdbarch_sp_regnum (gdbarch)
212 < gdbarch_num_regs (gdbarch))
213 *frame_regnum = gdbarch_sp_regnum (gdbarch);
214 else
215 /* Should this be an internal error? I guess so, it is reflecting
216 an architectural limitation in the current design. */
217 internal_error (__FILE__, __LINE__,
218 _("No virtual frame pointer available"));
219 *frame_offset = 0;
220}
221
222/* Return a floating-point format for a floating-point variable of
223 length LEN in bits. If non-NULL, NAME is the name of its type.
224 If no suitable type is found, return NULL. */
225
226const struct floatformat **
227default_floatformat_for_type (struct gdbarch *gdbarch,
228 const char *name, int len)
229{
230 const struct floatformat **format = NULL;
231
232 if (len == gdbarch_half_bit (gdbarch))
233 format = gdbarch_half_format (gdbarch);
234 else if (len == gdbarch_float_bit (gdbarch))
235 format = gdbarch_float_format (gdbarch);
236 else if (len == gdbarch_double_bit (gdbarch))
237 format = gdbarch_double_format (gdbarch);
238 else if (len == gdbarch_long_double_bit (gdbarch))
239 format = gdbarch_long_double_format (gdbarch);
240 /* On i386 the 'long double' type takes 96 bits,
241 while the real number of used bits is only 80,
242 both in processor and in memory.
243 The code below accepts the real bit size. */
244 else if (gdbarch_long_double_format (gdbarch) != NULL
245 && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
246 format = gdbarch_long_double_format (gdbarch);
247
248 return format;
249}
250\f
251int
252generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
253 struct type *type)
254{
255 return 0;
256}
257
258int
259default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
260{
261 return 0;
262}
263
264int
265generic_instruction_nullified (struct gdbarch *gdbarch,
266 struct regcache *regcache)
267{
268 return 0;
269}
270
271int
272default_remote_register_number (struct gdbarch *gdbarch,
273 int regno)
274{
275 return regno;
276}
277
278/* See arch-utils.h. */
279
280int
281default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
282{
283 return 0;
284}
285
286\f
287/* Functions to manipulate the endianness of the target. */
288
289static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
290
291static const char endian_big[] = "big";
292static const char endian_little[] = "little";
293static const char endian_auto[] = "auto";
294static const char *const endian_enum[] =
295{
296 endian_big,
297 endian_little,
298 endian_auto,
299 NULL,
300};
301static const char *set_endian_string;
302
303enum bfd_endian
304selected_byte_order (void)
305{
306 return target_byte_order_user;
307}
308
309/* Called by ``show endian''. */
310
311static void
312show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
313 const char *value)
314{
315 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
316 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
317 fprintf_unfiltered (file, _("The target endianness is set automatically "
318 "(currently big endian)\n"));
319 else
320 fprintf_unfiltered (file, _("The target endianness is set automatically "
321 "(currently little endian)\n"));
322 else
323 if (target_byte_order_user == BFD_ENDIAN_BIG)
324 fprintf_unfiltered (file,
325 _("The target is assumed to be big endian\n"));
326 else
327 fprintf_unfiltered (file,
328 _("The target is assumed to be little endian\n"));
329}
330
331static void
332set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
333{
334 struct gdbarch_info info;
335
336 gdbarch_info_init (&info);
337
338 if (set_endian_string == endian_auto)
339 {
340 target_byte_order_user = BFD_ENDIAN_UNKNOWN;
341 if (! gdbarch_update_p (info))
342 internal_error (__FILE__, __LINE__,
343 _("set_endian: architecture update failed"));
344 }
345 else if (set_endian_string == endian_little)
346 {
347 info.byte_order = BFD_ENDIAN_LITTLE;
348 if (! gdbarch_update_p (info))
349 printf_unfiltered (_("Little endian target not supported by GDB\n"));
350 else
351 target_byte_order_user = BFD_ENDIAN_LITTLE;
352 }
353 else if (set_endian_string == endian_big)
354 {
355 info.byte_order = BFD_ENDIAN_BIG;
356 if (! gdbarch_update_p (info))
357 printf_unfiltered (_("Big endian target not supported by GDB\n"));
358 else
359 target_byte_order_user = BFD_ENDIAN_BIG;
360 }
361 else
362 internal_error (__FILE__, __LINE__,
363 _("set_endian: bad value"));
364
365 show_endian (gdb_stdout, from_tty, NULL, NULL);
366}
367
368/* Given SELECTED, a currently selected BFD architecture, and
369 TARGET_DESC, the current target description, return what
370 architecture to use.
371
372 SELECTED may be NULL, in which case we return the architecture
373 associated with TARGET_DESC. If SELECTED specifies a variant
374 of the architecture associtated with TARGET_DESC, return the
375 more specific of the two.
376
377 If SELECTED is a different architecture, but it is accepted as
378 compatible by the target, we can use the target architecture.
379
380 If SELECTED is obviously incompatible, warn the user. */
381
382static const struct bfd_arch_info *
383choose_architecture_for_target (const struct target_desc *target_desc,
384 const struct bfd_arch_info *selected)
385{
386 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
387 const struct bfd_arch_info *compat1, *compat2;
388
389 if (selected == NULL)
390 return from_target;
391
392 if (from_target == NULL)
393 return selected;
394
395 /* struct bfd_arch_info objects are singletons: that is, there's
396 supposed to be exactly one instance for a given machine. So you
397 can tell whether two are equivalent by comparing pointers. */
398 if (from_target == selected)
399 return selected;
400
401 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
402 incompatible. But if they are compatible, it returns the 'more
403 featureful' of the two arches. That is, if A can run code
404 written for B, but B can't run code written for A, then it'll
405 return A.
406
407 Some targets (e.g. MIPS as of 2006-12-04) don't fully
408 implement this, instead always returning NULL or the first
409 argument. We detect that case by checking both directions. */
410
411 compat1 = selected->compatible (selected, from_target);
412 compat2 = from_target->compatible (from_target, selected);
413
414 if (compat1 == NULL && compat2 == NULL)
415 {
416 /* BFD considers the architectures incompatible. Check our
417 target description whether it accepts SELECTED as compatible
418 anyway. */
419 if (tdesc_compatible_p (target_desc, selected))
420 return from_target;
421
422 warning (_("Selected architecture %s is not compatible "
423 "with reported target architecture %s"),
424 selected->printable_name, from_target->printable_name);
425 return selected;
426 }
427
428 if (compat1 == NULL)
429 return compat2;
430 if (compat2 == NULL)
431 return compat1;
432 if (compat1 == compat2)
433 return compat1;
434
435 /* If the two didn't match, but one of them was a default
436 architecture, assume the more specific one is correct. This
437 handles the case where an executable or target description just
438 says "mips", but the other knows which MIPS variant. */
439 if (compat1->the_default)
440 return compat2;
441 if (compat2->the_default)
442 return compat1;
443
444 /* We have no idea which one is better. This is a bug, but not
445 a critical problem; warn the user. */
446 warning (_("Selected architecture %s is ambiguous with "
447 "reported target architecture %s"),
448 selected->printable_name, from_target->printable_name);
449 return selected;
450}
451
452/* Functions to manipulate the architecture of the target. */
453
454enum set_arch { set_arch_auto, set_arch_manual };
455
456static const struct bfd_arch_info *target_architecture_user;
457
458static const char *set_architecture_string;
459
460const char *
461selected_architecture_name (void)
462{
463 if (target_architecture_user == NULL)
464 return NULL;
465 else
466 return set_architecture_string;
467}
468
469/* Called if the user enters ``show architecture'' without an
470 argument. */
471
472static void
473show_architecture (struct ui_file *file, int from_tty,
474 struct cmd_list_element *c, const char *value)
475{
476 if (target_architecture_user == NULL)
477 fprintf_filtered (file, _("The target architecture is set "
478 "automatically (currently %s)\n"),
479 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
480 else
481 fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
482 set_architecture_string);
483}
484
485
486/* Called if the user enters ``set architecture'' with or without an
487 argument. */
488
489static void
490set_architecture (const char *ignore_args,
491 int from_tty, struct cmd_list_element *c)
492{
493 struct gdbarch_info info;
494
495 gdbarch_info_init (&info);
496
497 if (strcmp (set_architecture_string, "auto") == 0)
498 {
499 target_architecture_user = NULL;
500 if (!gdbarch_update_p (info))
501 internal_error (__FILE__, __LINE__,
502 _("could not select an architecture automatically"));
503 }
504 else
505 {
506 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
507 if (info.bfd_arch_info == NULL)
508 internal_error (__FILE__, __LINE__,
509 _("set_architecture: bfd_scan_arch failed"));
510 if (gdbarch_update_p (info))
511 target_architecture_user = info.bfd_arch_info;
512 else
513 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
514 set_architecture_string);
515 }
516 show_architecture (gdb_stdout, from_tty, NULL, NULL);
517}
518
519/* Try to select a global architecture that matches "info". Return
520 non-zero if the attempt succeeds. */
521int
522gdbarch_update_p (struct gdbarch_info info)
523{
524 struct gdbarch *new_gdbarch;
525
526 /* Check for the current file. */
527 if (info.abfd == NULL)
528 info.abfd = exec_bfd;
529 if (info.abfd == NULL)
530 info.abfd = core_bfd;
531
532 /* Check for the current target description. */
533 if (info.target_desc == NULL)
534 info.target_desc = target_current_description ();
535
536 new_gdbarch = gdbarch_find_by_info (info);
537
538 /* If there no architecture by that name, reject the request. */
539 if (new_gdbarch == NULL)
540 {
541 if (gdbarch_debug)
542 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
543 "Architecture not found\n");
544 return 0;
545 }
546
547 /* If it is the same old architecture, accept the request (but don't
548 swap anything). */
549 if (new_gdbarch == target_gdbarch ())
550 {
551 if (gdbarch_debug)
552 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
553 "Architecture %s (%s) unchanged\n",
554 host_address_to_string (new_gdbarch),
555 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
556 return 1;
557 }
558
559 /* It's a new architecture, swap it in. */
560 if (gdbarch_debug)
561 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
562 "New architecture %s (%s) selected\n",
563 host_address_to_string (new_gdbarch),
564 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
565 set_target_gdbarch (new_gdbarch);
566
567 return 1;
568}
569
570/* Return the architecture for ABFD. If no suitable architecture
571 could be find, return NULL. */
572
573struct gdbarch *
574gdbarch_from_bfd (bfd *abfd)
575{
576 struct gdbarch_info info;
577 gdbarch_info_init (&info);
578
579 info.abfd = abfd;
580 return gdbarch_find_by_info (info);
581}
582
583/* Set the dynamic target-system-dependent parameters (architecture,
584 byte-order) using information found in the BFD */
585
586void
587set_gdbarch_from_file (bfd *abfd)
588{
589 struct gdbarch_info info;
590 struct gdbarch *gdbarch;
591
592 gdbarch_info_init (&info);
593 info.abfd = abfd;
594 info.target_desc = target_current_description ();
595 gdbarch = gdbarch_find_by_info (info);
596
597 if (gdbarch == NULL)
598 error (_("Architecture of file not recognized."));
599 set_target_gdbarch (gdbarch);
600}
601
602/* Initialize the current architecture. Update the ``set
603 architecture'' command so that it specifies a list of valid
604 architectures. */
605
606#ifdef DEFAULT_BFD_ARCH
607extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
608static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
609#else
610static const bfd_arch_info_type *default_bfd_arch;
611#endif
612
613#ifdef DEFAULT_BFD_VEC
614extern const bfd_target DEFAULT_BFD_VEC;
615static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
616#else
617static const bfd_target *default_bfd_vec;
618#endif
619
620static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
621
622void
623initialize_current_architecture (void)
624{
625 const char **arches = gdbarch_printable_names ();
626 struct gdbarch_info info;
627
628 /* determine a default architecture and byte order. */
629 gdbarch_info_init (&info);
630
631 /* Find a default architecture. */
632 if (default_bfd_arch == NULL)
633 {
634 /* Choose the architecture by taking the first one
635 alphabetically. */
636 const char *chosen = arches[0];
637 const char **arch;
638 for (arch = arches; *arch != NULL; arch++)
639 {
640 if (strcmp (*arch, chosen) < 0)
641 chosen = *arch;
642 }
643 if (chosen == NULL)
644 internal_error (__FILE__, __LINE__,
645 _("initialize_current_architecture: No arch"));
646 default_bfd_arch = bfd_scan_arch (chosen);
647 if (default_bfd_arch == NULL)
648 internal_error (__FILE__, __LINE__,
649 _("initialize_current_architecture: Arch not found"));
650 }
651
652 info.bfd_arch_info = default_bfd_arch;
653
654 /* Take several guesses at a byte order. */
655 if (default_byte_order == BFD_ENDIAN_UNKNOWN
656 && default_bfd_vec != NULL)
657 {
658 /* Extract BFD's default vector's byte order. */
659 switch (default_bfd_vec->byteorder)
660 {
661 case BFD_ENDIAN_BIG:
662 default_byte_order = BFD_ENDIAN_BIG;
663 break;
664 case BFD_ENDIAN_LITTLE:
665 default_byte_order = BFD_ENDIAN_LITTLE;
666 break;
667 default:
668 break;
669 }
670 }
671 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
672 {
673 /* look for ``*el-*'' in the target name. */
674 const char *chp;
675 chp = strchr (target_name, '-');
676 if (chp != NULL
677 && chp - 2 >= target_name
678 && startswith (chp - 2, "el"))
679 default_byte_order = BFD_ENDIAN_LITTLE;
680 }
681 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
682 {
683 /* Wire it to big-endian!!! */
684 default_byte_order = BFD_ENDIAN_BIG;
685 }
686
687 info.byte_order = default_byte_order;
688 info.byte_order_for_code = info.byte_order;
689
690 if (! gdbarch_update_p (info))
691 internal_error (__FILE__, __LINE__,
692 _("initialize_current_architecture: Selection of "
693 "initial architecture failed"));
694
695 /* Create the ``set architecture'' command appending ``auto'' to the
696 list of architectures. */
697 {
698 /* Append ``auto''. */
699 int nr;
700 for (nr = 0; arches[nr] != NULL; nr++);
701 arches = XRESIZEVEC (const char *, arches, nr + 2);
702 arches[nr + 0] = "auto";
703 arches[nr + 1] = NULL;
704 add_setshow_enum_cmd ("architecture", class_support,
705 arches, &set_architecture_string,
706 _("Set architecture of target."),
707 _("Show architecture of target."), NULL,
708 set_architecture, show_architecture,
709 &setlist, &showlist);
710 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
711 }
712}
713
714
715/* Initialize a gdbarch info to values that will be automatically
716 overridden. Note: Originally, this ``struct info'' was initialized
717 using memset(0). Unfortunately, that ran into problems, namely
718 BFD_ENDIAN_BIG is zero. An explicit initialization function that
719 can explicitly set each field to a well defined value is used. */
720
721void
722gdbarch_info_init (struct gdbarch_info *info)
723{
724 memset (info, 0, sizeof (struct gdbarch_info));
725 info->byte_order = BFD_ENDIAN_UNKNOWN;
726 info->byte_order_for_code = info->byte_order;
727}
728
729/* Similar to init, but this time fill in the blanks. Information is
730 obtained from the global "set ..." options and explicitly
731 initialized INFO fields. */
732
733void
734gdbarch_info_fill (struct gdbarch_info *info)
735{
736 /* "(gdb) set architecture ...". */
737 if (info->bfd_arch_info == NULL
738 && target_architecture_user)
739 info->bfd_arch_info = target_architecture_user;
740 /* From the file. */
741 if (info->bfd_arch_info == NULL
742 && info->abfd != NULL
743 && bfd_get_arch (info->abfd) != bfd_arch_unknown
744 && bfd_get_arch (info->abfd) != bfd_arch_obscure)
745 info->bfd_arch_info = bfd_get_arch_info (info->abfd);
746 /* From the target. */
747 if (info->target_desc != NULL)
748 info->bfd_arch_info = choose_architecture_for_target
749 (info->target_desc, info->bfd_arch_info);
750 /* From the default. */
751 if (info->bfd_arch_info == NULL)
752 info->bfd_arch_info = default_bfd_arch;
753
754 /* "(gdb) set byte-order ...". */
755 if (info->byte_order == BFD_ENDIAN_UNKNOWN
756 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
757 info->byte_order = target_byte_order_user;
758 /* From the INFO struct. */
759 if (info->byte_order == BFD_ENDIAN_UNKNOWN
760 && info->abfd != NULL)
761 info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
762 : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
763 : BFD_ENDIAN_UNKNOWN);
764 /* From the default. */
765 if (info->byte_order == BFD_ENDIAN_UNKNOWN)
766 info->byte_order = default_byte_order;
767 info->byte_order_for_code = info->byte_order;
768 /* Wire the default to the last selected byte order. */
769 default_byte_order = info->byte_order;
770
771 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
772 /* From the manual override, or from file. */
773 if (info->osabi == GDB_OSABI_UNKNOWN)
774 info->osabi = gdbarch_lookup_osabi (info->abfd);
775 /* From the target. */
776
777 if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
778 info->osabi = tdesc_osabi (info->target_desc);
779 /* From the configured default. */
780#ifdef GDB_OSABI_DEFAULT
781 if (info->osabi == GDB_OSABI_UNKNOWN)
782 info->osabi = GDB_OSABI_DEFAULT;
783#endif
784 /* If we still don't know which osabi to pick, pick none. */
785 if (info->osabi == GDB_OSABI_UNKNOWN)
786 info->osabi = GDB_OSABI_NONE;
787
788 /* Must have at least filled in the architecture. */
789 gdb_assert (info->bfd_arch_info != NULL);
790}
791
792/* Return "current" architecture. If the target is running, this is
793 the architecture of the selected frame. Otherwise, the "current"
794 architecture defaults to the target architecture.
795
796 This function should normally be called solely by the command
797 interpreter routines to determine the architecture to execute a
798 command in. */
799struct gdbarch *
800get_current_arch (void)
801{
802 if (has_stack_frames ())
803 return get_frame_arch (get_selected_frame (NULL));
804 else
805 return target_gdbarch ();
806}
807
808int
809default_has_shared_address_space (struct gdbarch *gdbarch)
810{
811 /* Simply say no. In most unix-like targets each inferior/process
812 has its own address space. */
813 return 0;
814}
815
816int
817default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
818 std::string *msg)
819{
820 /* We don't know if maybe the target has some way to do fast
821 tracepoints that doesn't need gdbarch, so always say yes. */
822 if (msg)
823 msg->clear ();
824 return 1;
825}
826
827const gdb_byte *
828default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
829 int *lenptr)
830{
831 int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
832
833 return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
834}
835int
836default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
837 struct regcache *regcache,
838 CORE_ADDR *pcptr)
839{
840 return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
841}
842
843
844void
845default_gen_return_address (struct gdbarch *gdbarch,
846 struct agent_expr *ax, struct axs_value *value,
847 CORE_ADDR scope)
848{
849 error (_("This architecture has no method to collect a return address."));
850}
851
852int
853default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
854 struct type *type)
855{
856 /* Usually, the return value's address is stored the in the "first hidden"
857 parameter if the return value should be passed by reference, as
858 specified in ABI. */
859 return language_pass_by_reference (type);
860}
861
862int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
863{
864 return 0;
865}
866
867int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
868{
869 return 0;
870}
871
872int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
873{
874 return 0;
875}
876
877void
878default_skip_permanent_breakpoint (struct regcache *regcache)
879{
880 struct gdbarch *gdbarch = regcache->arch ();
881 CORE_ADDR current_pc = regcache_read_pc (regcache);
882 int bp_len;
883
884 gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
885 current_pc += bp_len;
886 regcache_write_pc (regcache, current_pc);
887}
888
889CORE_ADDR
890default_infcall_mmap (CORE_ADDR size, unsigned prot)
891{
892 error (_("This target does not support inferior memory allocation by mmap."));
893}
894
895void
896default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
897{
898 /* Memory reserved by inferior mmap is kept leaked. */
899}
900
901/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
902 created in inferior memory by GDB (normally it is set by ld.so). */
903
904char *
905default_gcc_target_options (struct gdbarch *gdbarch)
906{
907 return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
908 gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
909}
910
911/* gdbarch gnu_triplet_regexp method. */
912
913const char *
914default_gnu_triplet_regexp (struct gdbarch *gdbarch)
915{
916 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
917}
918
919/* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has
920 a size of 1 octet. */
921
922int
923default_addressable_memory_unit_size (struct gdbarch *gdbarch)
924{
925 return 1;
926}
927
928void
929default_guess_tracepoint_registers (struct gdbarch *gdbarch,
930 struct regcache *regcache,
931 CORE_ADDR addr)
932{
933 int pc_regno = gdbarch_pc_regnum (gdbarch);
934 gdb_byte *regs;
935
936 /* This guessing code below only works if the PC register isn't
937 a pseudo-register. The value of a pseudo-register isn't stored
938 in the (non-readonly) regcache -- instead it's recomputed
939 (probably from some other cached raw register) whenever the
940 register is read. In this case, a custom method implementation
941 should be used by the architecture. */
942 if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
943 return;
944
945 regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
946 store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
947 gdbarch_byte_order (gdbarch), addr);
948 regcache->raw_supply (pc_regno, regs);
949}
950
951int
952default_print_insn (bfd_vma memaddr, disassemble_info *info)
953{
954 disassembler_ftype disassemble_fn;
955
956 disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
957 info->mach, exec_bfd);
958
959 gdb_assert (disassemble_fn != NULL);
960 return (*disassemble_fn) (memaddr, info);
961}
962
963/* See arch-utils.h. */
964
965CORE_ADDR
966gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
967{
968 CORE_ADDR new_pc = pc;
969
970 TRY
971 {
972 new_pc = gdbarch_skip_prologue (gdbarch, pc);
973 }
974 CATCH (ex, RETURN_MASK_ALL)
975 {}
976 END_CATCH
977
978 return new_pc;
979}
980
981/* See arch-utils.h. */
982
983bool
984default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
985{
986 return false;
987}
988
989/* See arch-utils.h. */
990
991ULONGEST
992default_type_align (struct gdbarch *gdbarch, struct type *type)
993{
994 return 0;
995}
996
997void
998_initialize_gdbarch_utils (void)
999{
1000 add_setshow_enum_cmd ("endian", class_support,
1001 endian_enum, &set_endian_string,
1002 _("Set endianness of target."),
1003 _("Show endianness of target."),
1004 NULL, set_endian, show_endian,
1005 &setlist, &showlist);
1006}
This page took 0.026246 seconds and 4 git commands to generate.