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