xtensa: fix gas segfault with --text-section-literals
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
f4f9705a 2
32d0add0 3 Copyright (C) 1998-2015 Free Software Foundation, Inc.
c0e8c252
AC
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c0e8c252
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c0e8c252
AC
19
20#include "defs.h"
21
fb6ecb0f 22#include "arch-utils.h"
192cb3d4 23#include "buildsym.h"
c0e8c252 24#include "gdbcmd.h"
0e2de366 25#include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */
45741a9c 26#include "infrun.h"
fbec36e2 27#include "regcache.h"
4182591f 28#include "sim-regno.h"
750eb019 29#include "gdbcore.h"
bf922ad9 30#include "osabi.h"
424163ea 31#include "target-descriptions.h"
237fc4c9 32#include "objfiles.h"
18648a37 33#include "language.h"
3e29f34a 34#include "symtab.h"
bf922ad9 35
1ba607ad
AC
36#include "version.h"
37
f0d4cc9e
AC
38#include "floatformat.h"
39
1fd35568 40
237fc4c9
PA
41struct displaced_step_closure *
42simple_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 {
5af949e3
UW
54 fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
55 paddress (gdbarch, from), paddress (gdbarch, to));
237fc4c9
PA
56 displaced_step_dump_bytes (gdb_stdlog, buf, len);
57 }
58
59 return (struct displaced_step_closure *) buf;
60}
61
62
63void
64simple_displaced_step_free_closure (struct gdbarch *gdbarch,
65 struct displaced_step_closure *closure)
66{
67 xfree (closure);
68}
69
99e40580
UW
70int
71default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
72 struct displaced_step_closure *closure)
73{
74 return !gdbarch_software_single_step_p (gdbarch);
75}
237fc4c9
PA
76
77CORE_ADDR
78displaced_step_at_entry_point (struct gdbarch *gdbarch)
79{
80 CORE_ADDR addr;
81 int bp_len;
82
83 addr = entry_point_address ();
84
237fc4c9
PA
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);
5931a2fa 89 addr += bp_len * 2;
237fc4c9
PA
90
91 return addr;
92}
93
4182591f 94int
e7faf938 95legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
4182591f
AC
96{
97 /* Only makes sense to supply raw registers. */
e7faf938 98 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
4182591f
AC
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). */
e7faf938
MD
103 if (gdbarch_register_name (gdbarch, regnum) != NULL
104 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
4182591f
AC
105 return regnum;
106 else
107 return LEGACY_SIM_REGNO_IGNORE;
108}
109
bdcd319a 110CORE_ADDR
52f729a7 111generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
bdcd319a
CV
112{
113 return 0;
114}
115
dea0c52f 116CORE_ADDR
4c8c40e6 117generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
dea0c52f
MK
118{
119 return 0;
120}
121
d50355b6 122int
e17a4113 123generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 124 CORE_ADDR pc, const char *name)
d50355b6
MS
125{
126 return 0;
127}
128
c12260ac
CV
129int
130generic_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
131{
132 return 0;
133}
134
4d1e7dd1 135/* Helper functions for gdbarch_inner_than */
3339cf8b
AC
136
137int
fba45db2 138core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
139{
140 return (lhs < rhs);
141}
142
143int
fba45db2 144core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
145{
146 return (lhs > rhs);
147}
148
0e2de366 149/* Misc helper functions for targets. */
193e3b1a 150
f517ea4e 151CORE_ADDR
24568a2c 152core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
f517ea4e
PS
153{
154 return addr;
155}
156
e2d0e7eb
AC
157CORE_ADDR
158convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
159 struct target_ops *targ)
160{
161 return addr;
162}
163
88c72b7d 164int
d3f73121 165no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
88c72b7d
AC
166{
167 return reg;
168}
169
a2cf933a 170void
3e29f34a 171default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
a2cf933a
EZ
172{
173 return;
174}
175
3e29f34a
MR
176/* See arch-utils.h. */
177
a2cf933a 178void
3e29f34a 179default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
a2cf933a
EZ
180{
181 return;
182}
183
3e29f34a
MR
184/* See arch-utils.h. */
185
186CORE_ADDR
187default_adjust_dwarf2_addr (CORE_ADDR pc)
188{
189 return pc;
190}
191
192/* See arch-utils.h. */
193
194CORE_ADDR
195default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
196{
197 return addr;
198}
199
01fb7433 200int
64a3914f 201cannot_register_not (struct gdbarch *gdbarch, int regnum)
01fb7433
AC
202{
203 return 0;
204}
39d4ef09
AC
205
206/* Legacy version of target_virtual_frame_pointer(). Assumes that
0e2de366
MS
207 there is an gdbarch_deprecated_fp_regnum and that it is the same,
208 cooked or raw. */
39d4ef09
AC
209
210void
a54fba4c
MD
211legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
212 CORE_ADDR pc,
39d4ef09
AC
213 int *frame_regnum,
214 LONGEST *frame_offset)
215{
20bcf01c
AC
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. */
a54fba4c
MD
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);
20bcf01c
AC
229 else
230 /* Should this be an internal error? I guess so, it is reflecting
231 an architectural limitation in the current design. */
0e2de366
MS
232 internal_error (__FILE__, __LINE__,
233 _("No virtual frame pointer available"));
39d4ef09
AC
234 *frame_offset = 0;
235}
46cd78fb 236
d7bd68ca 237\f
13d01224 238int
76a8ddb9
UW
239generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
240 struct type *type)
13d01224 241{
9730f241 242 return 0;
13d01224
AC
243}
244
192cb3d4
MK
245int
246default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
247{
192cb3d4
MK
248 return 0;
249}
250
3ca64954
RC
251int
252generic_instruction_nullified (struct gdbarch *gdbarch,
253 struct regcache *regcache)
254{
255 return 0;
256}
257
123dc839
DJ
258int
259default_remote_register_number (struct gdbarch *gdbarch,
260 int regno)
261{
262 return regno;
263}
264
3437254d
PA
265/* See arch-utils.h. */
266
267int
268default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
269{
270 return 0;
271}
272
01fb7433 273\f
b4a20239
AC
274/* Functions to manipulate the endianness of the target. */
275
7a107747 276static int target_byte_order_user = BFD_ENDIAN_UNKNOWN;
b4a20239 277
53904c9e
AC
278static const char endian_big[] = "big";
279static const char endian_little[] = "little";
280static const char endian_auto[] = "auto";
40478521 281static const char *const endian_enum[] =
b4a20239
AC
282{
283 endian_big,
284 endian_little,
285 endian_auto,
286 NULL,
287};
53904c9e 288static const char *set_endian_string;
b4a20239 289
b6d373df
DJ
290enum bfd_endian
291selected_byte_order (void)
292{
e17c207e 293 return target_byte_order_user;
b6d373df
DJ
294}
295
b4a20239
AC
296/* Called by ``show endian''. */
297
298static void
7ab04401
AC
299show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
300 const char *value)
b4a20239 301{
7b6b9e83 302 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
e17c207e 303 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
7ab04401
AC
304 fprintf_unfiltered (file, _("The target endianness is set automatically "
305 "(currently big endian)\n"));
edefbb7c 306 else
7ab04401 307 fprintf_unfiltered (file, _("The target endianness is set automatically "
3e43a32a 308 "(currently little endian)\n"));
b4a20239 309 else
e17c207e 310 if (target_byte_order_user == BFD_ENDIAN_BIG)
7ab04401
AC
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"));
b4a20239
AC
316}
317
318static void
319set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
320{
7a107747
DJ
321 struct gdbarch_info info;
322
323 gdbarch_info_init (&info);
324
3fd3d7d2 325 if (set_endian_string == endian_auto)
b4a20239 326 {
7a107747
DJ
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"));
b4a20239
AC
331 }
332 else if (set_endian_string == endian_little)
333 {
d90cf509
AC
334 info.byte_order = BFD_ENDIAN_LITTLE;
335 if (! gdbarch_update_p (info))
edefbb7c 336 printf_unfiltered (_("Little endian target not supported by GDB\n"));
7a107747
DJ
337 else
338 target_byte_order_user = BFD_ENDIAN_LITTLE;
b4a20239
AC
339 }
340 else if (set_endian_string == endian_big)
341 {
d90cf509
AC
342 info.byte_order = BFD_ENDIAN_BIG;
343 if (! gdbarch_update_p (info))
edefbb7c 344 printf_unfiltered (_("Big endian target not supported by GDB\n"));
7a107747
DJ
345 else
346 target_byte_order_user = BFD_ENDIAN_BIG;
b4a20239
AC
347 }
348 else
8e65ff28 349 internal_error (__FILE__, __LINE__,
edefbb7c 350 _("set_endian: bad value"));
7a107747 351
7ab04401 352 show_endian (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
353}
354
23181151 355/* Given SELECTED, a currently selected BFD architecture, and
e35359c5
UW
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. */
23181151
DJ
368
369static const struct bfd_arch_info *
e35359c5
UW
370choose_architecture_for_target (const struct target_desc *target_desc,
371 const struct bfd_arch_info *selected)
23181151 372{
e35359c5 373 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
23181151
DJ
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 {
0e2de366
MS
403 /* BFD considers the architectures incompatible. Check our
404 target description whether it accepts SELECTED as compatible
405 anyway. */
e35359c5
UW
406 if (tdesc_compatible_p (target_desc, selected))
407 return from_target;
408
23181151
DJ
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
0e2de366
MS
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. */
23181151
DJ
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
0e2de366 439/* Functions to manipulate the architecture of the target. */
b4a20239
AC
440
441enum set_arch { set_arch_auto, set_arch_manual };
442
7a107747 443static const struct bfd_arch_info *target_architecture_user;
b4a20239 444
a8cf2722
AC
445static const char *set_architecture_string;
446
447const char *
448selected_architecture_name (void)
449{
7a107747 450 if (target_architecture_user == NULL)
a8cf2722
AC
451 return NULL;
452 else
453 return set_architecture_string;
454}
b4a20239 455
b4a20239 456/* Called if the user enters ``show architecture'' without an
0e2de366 457 argument. */
b4a20239
AC
458
459static void
7ab04401
AC
460show_architecture (struct ui_file *file, int from_tty,
461 struct cmd_list_element *c, const char *value)
b4a20239 462{
7a107747 463 if (target_architecture_user == NULL)
3e43a32a
MS
464 fprintf_filtered (file, _("The target architecture is set "
465 "automatically (currently %s)\n"),
466 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
b4a20239 467 else
3e43a32a
MS
468 fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
469 set_architecture_string);
b4a20239
AC
470}
471
472
473/* Called if the user enters ``set architecture'' with or without an
0e2de366 474 argument. */
b4a20239
AC
475
476static void
477set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
478{
7a107747
DJ
479 struct gdbarch_info info;
480
481 gdbarch_info_init (&info);
482
b4a20239
AC
483 if (strcmp (set_architecture_string, "auto") == 0)
484 {
7a107747
DJ
485 target_architecture_user = NULL;
486 if (!gdbarch_update_p (info))
487 internal_error (__FILE__, __LINE__,
488 _("could not select an architecture automatically"));
b4a20239 489 }
d90cf509 490 else
b4a20239 491 {
b4a20239
AC
492 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
493 if (info.bfd_arch_info == NULL)
8e65ff28 494 internal_error (__FILE__, __LINE__,
edefbb7c 495 _("set_architecture: bfd_scan_arch failed"));
16f33e29 496 if (gdbarch_update_p (info))
7a107747 497 target_architecture_user = info.bfd_arch_info;
b4a20239 498 else
edefbb7c 499 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
b4a20239
AC
500 set_architecture_string);
501 }
7ab04401 502 show_architecture (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
503}
504
ebdba546 505/* Try to select a global architecture that matches "info". Return
0f9741f2 506 non-zero if the attempt succeeds. */
ebdba546
AC
507int
508gdbarch_update_p (struct gdbarch_info info)
509{
a7f1256d
UW
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);
ebdba546
AC
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). */
f5656ead 535 if (new_gdbarch == target_gdbarch ())
ebdba546
AC
536 {
537 if (gdbarch_debug)
538 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
e3cb3832
JB
539 "Architecture %s (%s) unchanged\n",
540 host_address_to_string (new_gdbarch),
ebdba546
AC
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: "
e3cb3832
JB
548 "New architecture %s (%s) selected\n",
549 host_address_to_string (new_gdbarch),
ebdba546 550 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
aff68abb 551 set_target_gdbarch (new_gdbarch);
ebdba546
AC
552
553 return 1;
554}
555
2b026650
MK
556/* Return the architecture for ABFD. If no suitable architecture
557 could be find, return NULL. */
558
559struct gdbarch *
560gdbarch_from_bfd (bfd *abfd)
b4a20239 561{
d90cf509
AC
562 struct gdbarch_info info;
563 gdbarch_info_init (&info);
05c547f6 564
d90cf509 565 info.abfd = abfd;
b60eb90d 566 return gdbarch_find_by_info (info);
2b026650
MK
567}
568
569/* Set the dynamic target-system-dependent parameters (architecture,
570 byte-order) using information found in the BFD */
571
572void
573set_gdbarch_from_file (bfd *abfd)
574{
a7f1256d 575 struct gdbarch_info info;
2b026650
MK
576 struct gdbarch *gdbarch;
577
a7f1256d
UW
578 gdbarch_info_init (&info);
579 info.abfd = abfd;
580 info.target_desc = target_current_description ();
581 gdbarch = gdbarch_find_by_info (info);
582
2b026650 583 if (gdbarch == NULL)
8a3fe4f8 584 error (_("Architecture of file not recognized."));
aff68abb 585 set_target_gdbarch (gdbarch);
b4a20239
AC
586}
587
588/* Initialize the current architecture. Update the ``set
589 architecture'' command so that it specifies a list of valid
590 architectures. */
591
1ba607ad
AC
592#ifdef DEFAULT_BFD_ARCH
593extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
594static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
595#else
4b9b3959 596static const bfd_arch_info_type *default_bfd_arch;
1ba607ad
AC
597#endif
598
599#ifdef DEFAULT_BFD_VEC
600extern const bfd_target DEFAULT_BFD_VEC;
601static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
602#else
603static const bfd_target *default_bfd_vec;
604#endif
605
7a107747
DJ
606static int default_byte_order = BFD_ENDIAN_UNKNOWN;
607
b4a20239
AC
608void
609initialize_current_architecture (void)
610{
611 const char **arches = gdbarch_printable_names ();
05c547f6 612 struct gdbarch_info info;
b4a20239 613
0e2de366 614 /* determine a default architecture and byte order. */
fb6ecb0f 615 gdbarch_info_init (&info);
1ba607ad 616
0e2de366 617 /* Find a default architecture. */
7a107747 618 if (default_bfd_arch == NULL)
b4a20239 619 {
1ba607ad 620 /* Choose the architecture by taking the first one
0e2de366 621 alphabetically. */
1ba607ad 622 const char *chosen = arches[0];
b4a20239 623 const char **arch;
b4a20239
AC
624 for (arch = arches; *arch != NULL; arch++)
625 {
b4a20239
AC
626 if (strcmp (*arch, chosen) < 0)
627 chosen = *arch;
628 }
629 if (chosen == NULL)
8e65ff28 630 internal_error (__FILE__, __LINE__,
edefbb7c 631 _("initialize_current_architecture: No arch"));
7a107747
DJ
632 default_bfd_arch = bfd_scan_arch (chosen);
633 if (default_bfd_arch == NULL)
8e65ff28 634 internal_error (__FILE__, __LINE__,
edefbb7c 635 _("initialize_current_architecture: Arch not found"));
1ba607ad
AC
636 }
637
7a107747
DJ
638 info.bfd_arch_info = default_bfd_arch;
639
afe64c1a 640 /* Take several guesses at a byte order. */
7a107747 641 if (default_byte_order == BFD_ENDIAN_UNKNOWN
1ba607ad
AC
642 && default_bfd_vec != NULL)
643 {
0e2de366 644 /* Extract BFD's default vector's byte order. */
1ba607ad
AC
645 switch (default_bfd_vec->byteorder)
646 {
647 case BFD_ENDIAN_BIG:
7a107747 648 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
649 break;
650 case BFD_ENDIAN_LITTLE:
7a107747 651 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad
AC
652 break;
653 default:
654 break;
655 }
656 }
7a107747 657 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad 658 {
0e2de366 659 /* look for ``*el-*'' in the target name. */
1ba607ad
AC
660 const char *chp;
661 chp = strchr (target_name, '-');
662 if (chp != NULL
663 && chp - 2 >= target_name
61012eef 664 && startswith (chp - 2, "el"))
7a107747 665 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad 666 }
7a107747 667 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad
AC
668 {
669 /* Wire it to big-endian!!! */
7a107747 670 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
671 }
672
7a107747 673 info.byte_order = default_byte_order;
9d4fde75 674 info.byte_order_for_code = info.byte_order;
7a107747 675
d90cf509
AC
676 if (! gdbarch_update_p (info))
677 internal_error (__FILE__, __LINE__,
edefbb7c
AC
678 _("initialize_current_architecture: Selection of "
679 "initial architecture failed"));
b4a20239 680
1ba607ad 681 /* Create the ``set architecture'' command appending ``auto'' to the
0e2de366 682 list of architectures. */
b4a20239 683 {
0e2de366 684 /* Append ``auto''. */
b4a20239
AC
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;
7ab04401 690 add_setshow_enum_cmd ("architecture", class_support,
3e43a32a
MS
691 arches, &set_architecture_string,
692 _("Set architecture of target."),
693 _("Show architecture of target."), NULL,
7ab04401
AC
694 set_architecture, show_architecture,
695 &setlist, &showlist);
b4a20239 696 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
b4a20239
AC
697 }
698}
699
700
fb6ecb0f
AC
701/* Initialize a gdbarch info to values that will be automatically
702 overridden. Note: Originally, this ``struct info'' was initialized
ce2826aa 703 using memset(0). Unfortunately, that ran into problems, namely
fb6ecb0f
AC
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
707void
708gdbarch_info_init (struct gdbarch_info *info)
709{
710 memset (info, 0, sizeof (struct gdbarch_info));
428721aa 711 info->byte_order = BFD_ENDIAN_UNKNOWN;
9d4fde75 712 info->byte_order_for_code = info->byte_order;
4be87837 713 info->osabi = GDB_OSABI_UNINITIALIZED;
fb6ecb0f
AC
714}
715
100bcc3f 716/* Similar to init, but this time fill in the blanks. Information is
7a107747
DJ
717 obtained from the global "set ..." options and explicitly
718 initialized INFO fields. */
bf922ad9
AC
719
720void
7a107747 721gdbarch_info_fill (struct gdbarch_info *info)
bf922ad9
AC
722{
723 /* "(gdb) set architecture ...". */
724 if (info->bfd_arch_info == NULL
7a107747
DJ
725 && target_architecture_user)
726 info->bfd_arch_info = target_architecture_user;
424163ea 727 /* From the file. */
bf922ad9
AC
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);
23181151
DJ
733 /* From the target. */
734 if (info->target_desc != NULL)
735 info->bfd_arch_info = choose_architecture_for_target
e35359c5 736 (info->target_desc, info->bfd_arch_info);
7a107747
DJ
737 /* From the default. */
738 if (info->bfd_arch_info == NULL)
739 info->bfd_arch_info = default_bfd_arch;
bf922ad9
AC
740
741 /* "(gdb) set byte-order ...". */
742 if (info->byte_order == BFD_ENDIAN_UNKNOWN
7a107747
DJ
743 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
744 info->byte_order = target_byte_order_user;
bf922ad9
AC
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
7a107747
DJ
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;
9d4fde75 754 info->byte_order_for_code = info->byte_order;
bf922ad9
AC
755
756 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
08d16641 757 /* From the manual override, or from file. */
bf922ad9
AC
758 if (info->osabi == GDB_OSABI_UNINITIALIZED)
759 info->osabi = gdbarch_lookup_osabi (info->abfd);
08d16641
PA
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. */
f4290e2a 764#ifdef GDB_OSABI_DEFAULT
08d16641
PA
765 if (info->osabi == GDB_OSABI_UNKNOWN)
766 info->osabi = GDB_OSABI_DEFAULT;
f4290e2a 767#endif
bf922ad9
AC
768
769 /* Must have at least filled in the architecture. */
770 gdb_assert (info->bfd_arch_info != NULL);
771}
772
0e2de366
MS
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.
e17c207e 776
0e2de366
MS
777 This function should normally be called solely by the command
778 interpreter routines to determine the architecture to execute a
779 command in. */
e17c207e
UW
780struct gdbarch *
781get_current_arch (void)
782{
783 if (has_stack_frames ())
784 return get_frame_arch (get_selected_frame (NULL));
785 else
f5656ead 786 return target_gdbarch ();
e17c207e
UW
787}
788
6c95b8df
PA
789int
790default_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
7a697b8d
SS
797int
798default_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
a1dcb23a
DJ
808void
809default_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
810 int *kindptr)
811{
812 gdbarch_breakpoint_from_pc (gdbarch, pcptr, kindptr);
813}
814
6710bf39
SS
815void
816default_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
18648a37
YQ
823int
824default_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
c2170eef
MM
833int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
834{
835 return 0;
836}
837
838int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
839{
840 return 0;
841}
842
843int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
844{
845 return 0;
846}
847
ae9bb220
PA
848void
849default_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}
c0e8c252 860
f208eee0
JK
861CORE_ADDR
862default_infcall_mmap (CORE_ADDR size, unsigned prot)
863{
864 error (_("This target does not support inferior memory allocation by mmap."));
865}
866
867/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
868 created in inferior memory by GDB (normally it is set by ld.so). */
869
870char *
871default_gcc_target_options (struct gdbarch *gdbarch)
872{
873 return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
874 gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
875}
876
ac04f72b
TT
877/* gdbarch gnu_triplet_regexp method. */
878
879const char *
880default_gnu_triplet_regexp (struct gdbarch *gdbarch)
881{
882 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
883}
884
3e43a32a
MS
885/* -Wmissing-prototypes */
886extern initialize_file_ftype _initialize_gdbarch_utils;
c0e8c252
AC
887
888void
b4a20239 889_initialize_gdbarch_utils (void)
c0e8c252 890{
7ab04401 891 add_setshow_enum_cmd ("endian", class_support,
3e43a32a
MS
892 endian_enum, &set_endian_string,
893 _("Set endianness of target."),
894 _("Show endianness of target."),
895 NULL, set_endian, show_endian,
7ab04401 896 &setlist, &showlist);
c0e8c252 897}
This page took 0.910892 seconds and 4 git commands to generate.