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