x86: Move x86-specific linker options to elf_linker_x86_params
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
f4f9705a 2
42a4f53d 3 Copyright (C) 1998-2019 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
d55e5aa6 22/* Local non-gdb includes. */
fb6ecb0f 23#include "arch-utils.h"
d55e5aa6
TT
24#include "common/version.h"
25#include "dis-asm.h"
26#include "floatformat.h"
c0e8c252 27#include "gdbcmd.h"
d55e5aa6
TT
28#include "gdbcore.h"
29#include "inferior.h"
45741a9c 30#include "infrun.h"
d55e5aa6
TT
31#include "language.h"
32#include "objfiles.h"
33#include "osabi.h"
fbec36e2 34#include "regcache.h"
4182591f 35#include "sim-regno.h"
3e29f34a 36#include "symtab.h"
d55e5aa6 37#include "target-descriptions.h"
1fd35568 38
99e40580
UW
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}
237fc4c9
PA
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
237fc4c9
PA
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);
5931a2fa 58 addr += bp_len * 2;
237fc4c9
PA
59
60 return addr;
61}
62
4182591f 63int
e7faf938 64legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
4182591f
AC
65{
66 /* Only makes sense to supply raw registers. */
e7faf938 67 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
4182591f
AC
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). */
e7faf938
MD
72 if (gdbarch_register_name (gdbarch, regnum) != NULL
73 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
4182591f
AC
74 return regnum;
75 else
76 return LEGACY_SIM_REGNO_IGNORE;
77}
78
bdcd319a 79CORE_ADDR
52f729a7 80generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
bdcd319a
CV
81{
82 return 0;
83}
84
dea0c52f 85CORE_ADDR
4c8c40e6 86generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
dea0c52f
MK
87{
88 return 0;
89}
90
d50355b6 91int
e17a4113 92generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 93 CORE_ADDR pc, const char *name)
d50355b6
MS
94{
95 return 0;
96}
97
c12260ac 98int
c9cf6e20 99generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
c12260ac
CV
100{
101 return 0;
102}
103
7eb89530
YQ
104int
105default_code_of_frame_writable (struct gdbarch *gdbarch,
106 struct frame_info *frame)
107{
108 return 1;
109}
110
4d1e7dd1 111/* Helper functions for gdbarch_inner_than */
3339cf8b
AC
112
113int
fba45db2 114core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
115{
116 return (lhs < rhs);
117}
118
119int
fba45db2 120core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
121{
122 return (lhs > rhs);
123}
124
0e2de366 125/* Misc helper functions for targets. */
193e3b1a 126
f517ea4e 127CORE_ADDR
24568a2c 128core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
f517ea4e
PS
129{
130 return addr;
131}
132
e2d0e7eb
AC
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
88c72b7d 140int
d3f73121 141no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
88c72b7d
AC
142{
143 return reg;
144}
145
a2cf933a 146void
3e29f34a 147default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
a2cf933a
EZ
148{
149 return;
150}
151
3e29f34a
MR
152/* See arch-utils.h. */
153
a2cf933a 154void
3e29f34a 155default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
a2cf933a
EZ
156{
157 return;
158}
159
3e29f34a
MR
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
b41c5a85
JW
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
01fb7433 185int
64a3914f 186cannot_register_not (struct gdbarch *gdbarch, int regnum)
01fb7433
AC
187{
188 return 0;
189}
39d4ef09
AC
190
191/* Legacy version of target_virtual_frame_pointer(). Assumes that
0e2de366
MS
192 there is an gdbarch_deprecated_fp_regnum and that it is the same,
193 cooked or raw. */
39d4ef09
AC
194
195void
a54fba4c
MD
196legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
197 CORE_ADDR pc,
39d4ef09
AC
198 int *frame_regnum,
199 LONGEST *frame_offset)
200{
20bcf01c
AC
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. */
a54fba4c
MD
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);
20bcf01c
AC
214 else
215 /* Should this be an internal error? I guess so, it is reflecting
216 an architectural limitation in the current design. */
0e2de366
MS
217 internal_error (__FILE__, __LINE__,
218 _("No virtual frame pointer available"));
39d4ef09
AC
219 *frame_offset = 0;
220}
46cd78fb 221
9b790ce7
UW
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}
d7bd68ca 250\f
13d01224 251int
76a8ddb9
UW
252generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
253 struct type *type)
13d01224 254{
9730f241 255 return 0;
13d01224
AC
256}
257
192cb3d4
MK
258int
259default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
260{
192cb3d4
MK
261 return 0;
262}
263
3ca64954
RC
264int
265generic_instruction_nullified (struct gdbarch *gdbarch,
266 struct regcache *regcache)
267{
268 return 0;
269}
270
123dc839
DJ
271int
272default_remote_register_number (struct gdbarch *gdbarch,
273 int regno)
274{
275 return regno;
276}
277
3437254d
PA
278/* See arch-utils.h. */
279
280int
281default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
282{
283 return 0;
284}
285
01fb7433 286\f
b4a20239
AC
287/* Functions to manipulate the endianness of the target. */
288
f486487f 289static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
b4a20239 290
53904c9e
AC
291static const char endian_big[] = "big";
292static const char endian_little[] = "little";
293static const char endian_auto[] = "auto";
40478521 294static const char *const endian_enum[] =
b4a20239
AC
295{
296 endian_big,
297 endian_little,
298 endian_auto,
299 NULL,
300};
53904c9e 301static const char *set_endian_string;
b4a20239 302
b6d373df
DJ
303enum bfd_endian
304selected_byte_order (void)
305{
e17c207e 306 return target_byte_order_user;
b6d373df
DJ
307}
308
b4a20239
AC
309/* Called by ``show endian''. */
310
311static void
7ab04401
AC
312show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
313 const char *value)
b4a20239 314{
7b6b9e83 315 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
e17c207e 316 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
7ab04401
AC
317 fprintf_unfiltered (file, _("The target endianness is set automatically "
318 "(currently big endian)\n"));
edefbb7c 319 else
7ab04401 320 fprintf_unfiltered (file, _("The target endianness is set automatically "
3e43a32a 321 "(currently little endian)\n"));
b4a20239 322 else
e17c207e 323 if (target_byte_order_user == BFD_ENDIAN_BIG)
7ab04401
AC
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"));
b4a20239
AC
329}
330
331static void
eb4c3f4a 332set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
b4a20239 333{
7a107747
DJ
334 struct gdbarch_info info;
335
336 gdbarch_info_init (&info);
337
3fd3d7d2 338 if (set_endian_string == endian_auto)
b4a20239 339 {
7a107747
DJ
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"));
b4a20239
AC
344 }
345 else if (set_endian_string == endian_little)
346 {
d90cf509
AC
347 info.byte_order = BFD_ENDIAN_LITTLE;
348 if (! gdbarch_update_p (info))
edefbb7c 349 printf_unfiltered (_("Little endian target not supported by GDB\n"));
7a107747
DJ
350 else
351 target_byte_order_user = BFD_ENDIAN_LITTLE;
b4a20239
AC
352 }
353 else if (set_endian_string == endian_big)
354 {
d90cf509
AC
355 info.byte_order = BFD_ENDIAN_BIG;
356 if (! gdbarch_update_p (info))
edefbb7c 357 printf_unfiltered (_("Big endian target not supported by GDB\n"));
7a107747
DJ
358 else
359 target_byte_order_user = BFD_ENDIAN_BIG;
b4a20239
AC
360 }
361 else
8e65ff28 362 internal_error (__FILE__, __LINE__,
edefbb7c 363 _("set_endian: bad value"));
7a107747 364
7ab04401 365 show_endian (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
366}
367
23181151 368/* Given SELECTED, a currently selected BFD architecture, and
e35359c5
UW
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. */
23181151
DJ
381
382static const struct bfd_arch_info *
e35359c5
UW
383choose_architecture_for_target (const struct target_desc *target_desc,
384 const struct bfd_arch_info *selected)
23181151 385{
e35359c5 386 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
23181151
DJ
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 {
0e2de366
MS
416 /* BFD considers the architectures incompatible. Check our
417 target description whether it accepts SELECTED as compatible
418 anyway. */
e35359c5
UW
419 if (tdesc_compatible_p (target_desc, selected))
420 return from_target;
421
23181151
DJ
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
0e2de366
MS
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. */
23181151
DJ
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
0e2de366 452/* Functions to manipulate the architecture of the target. */
b4a20239
AC
453
454enum set_arch { set_arch_auto, set_arch_manual };
455
7a107747 456static const struct bfd_arch_info *target_architecture_user;
b4a20239 457
a8cf2722
AC
458static const char *set_architecture_string;
459
460const char *
461selected_architecture_name (void)
462{
7a107747 463 if (target_architecture_user == NULL)
a8cf2722
AC
464 return NULL;
465 else
466 return set_architecture_string;
467}
b4a20239 468
b4a20239 469/* Called if the user enters ``show architecture'' without an
0e2de366 470 argument. */
b4a20239
AC
471
472static void
7ab04401
AC
473show_architecture (struct ui_file *file, int from_tty,
474 struct cmd_list_element *c, const char *value)
b4a20239 475{
7a107747 476 if (target_architecture_user == NULL)
3e43a32a
MS
477 fprintf_filtered (file, _("The target architecture is set "
478 "automatically (currently %s)\n"),
479 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
b4a20239 480 else
3e43a32a
MS
481 fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
482 set_architecture_string);
b4a20239
AC
483}
484
485
486/* Called if the user enters ``set architecture'' with or without an
0e2de366 487 argument. */
b4a20239
AC
488
489static void
eb4c3f4a
TT
490set_architecture (const char *ignore_args,
491 int from_tty, struct cmd_list_element *c)
b4a20239 492{
7a107747
DJ
493 struct gdbarch_info info;
494
495 gdbarch_info_init (&info);
496
b4a20239
AC
497 if (strcmp (set_architecture_string, "auto") == 0)
498 {
7a107747
DJ
499 target_architecture_user = NULL;
500 if (!gdbarch_update_p (info))
501 internal_error (__FILE__, __LINE__,
502 _("could not select an architecture automatically"));
b4a20239 503 }
d90cf509 504 else
b4a20239 505 {
b4a20239
AC
506 info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
507 if (info.bfd_arch_info == NULL)
8e65ff28 508 internal_error (__FILE__, __LINE__,
edefbb7c 509 _("set_architecture: bfd_scan_arch failed"));
16f33e29 510 if (gdbarch_update_p (info))
7a107747 511 target_architecture_user = info.bfd_arch_info;
b4a20239 512 else
edefbb7c 513 printf_unfiltered (_("Architecture `%s' not recognized.\n"),
b4a20239
AC
514 set_architecture_string);
515 }
7ab04401 516 show_architecture (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
517}
518
ebdba546 519/* Try to select a global architecture that matches "info". Return
0f9741f2 520 non-zero if the attempt succeeds. */
ebdba546
AC
521int
522gdbarch_update_p (struct gdbarch_info info)
523{
a7f1256d
UW
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);
ebdba546
AC
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). */
f5656ead 549 if (new_gdbarch == target_gdbarch ())
ebdba546
AC
550 {
551 if (gdbarch_debug)
552 fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
e3cb3832
JB
553 "Architecture %s (%s) unchanged\n",
554 host_address_to_string (new_gdbarch),
ebdba546
AC
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: "
e3cb3832
JB
562 "New architecture %s (%s) selected\n",
563 host_address_to_string (new_gdbarch),
ebdba546 564 gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
aff68abb 565 set_target_gdbarch (new_gdbarch);
ebdba546
AC
566
567 return 1;
568}
569
2b026650
MK
570/* Return the architecture for ABFD. If no suitable architecture
571 could be find, return NULL. */
572
573struct gdbarch *
574gdbarch_from_bfd (bfd *abfd)
b4a20239 575{
d90cf509
AC
576 struct gdbarch_info info;
577 gdbarch_info_init (&info);
05c547f6 578
d90cf509 579 info.abfd = abfd;
b60eb90d 580 return gdbarch_find_by_info (info);
2b026650
MK
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{
a7f1256d 589 struct gdbarch_info info;
2b026650
MK
590 struct gdbarch *gdbarch;
591
a7f1256d
UW
592 gdbarch_info_init (&info);
593 info.abfd = abfd;
594 info.target_desc = target_current_description ();
595 gdbarch = gdbarch_find_by_info (info);
596
2b026650 597 if (gdbarch == NULL)
8a3fe4f8 598 error (_("Architecture of file not recognized."));
aff68abb 599 set_target_gdbarch (gdbarch);
b4a20239
AC
600}
601
602/* Initialize the current architecture. Update the ``set
603 architecture'' command so that it specifies a list of valid
604 architectures. */
605
1ba607ad
AC
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
4b9b3959 610static const bfd_arch_info_type *default_bfd_arch;
1ba607ad
AC
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
f486487f 620static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
7a107747 621
b4a20239
AC
622void
623initialize_current_architecture (void)
624{
625 const char **arches = gdbarch_printable_names ();
05c547f6 626 struct gdbarch_info info;
b4a20239 627
0e2de366 628 /* determine a default architecture and byte order. */
fb6ecb0f 629 gdbarch_info_init (&info);
1ba607ad 630
0e2de366 631 /* Find a default architecture. */
7a107747 632 if (default_bfd_arch == NULL)
b4a20239 633 {
1ba607ad 634 /* Choose the architecture by taking the first one
0e2de366 635 alphabetically. */
1ba607ad 636 const char *chosen = arches[0];
b4a20239 637 const char **arch;
b4a20239
AC
638 for (arch = arches; *arch != NULL; arch++)
639 {
b4a20239
AC
640 if (strcmp (*arch, chosen) < 0)
641 chosen = *arch;
642 }
643 if (chosen == NULL)
8e65ff28 644 internal_error (__FILE__, __LINE__,
edefbb7c 645 _("initialize_current_architecture: No arch"));
7a107747
DJ
646 default_bfd_arch = bfd_scan_arch (chosen);
647 if (default_bfd_arch == NULL)
8e65ff28 648 internal_error (__FILE__, __LINE__,
edefbb7c 649 _("initialize_current_architecture: Arch not found"));
1ba607ad
AC
650 }
651
7a107747
DJ
652 info.bfd_arch_info = default_bfd_arch;
653
afe64c1a 654 /* Take several guesses at a byte order. */
7a107747 655 if (default_byte_order == BFD_ENDIAN_UNKNOWN
1ba607ad
AC
656 && default_bfd_vec != NULL)
657 {
0e2de366 658 /* Extract BFD's default vector's byte order. */
1ba607ad
AC
659 switch (default_bfd_vec->byteorder)
660 {
661 case BFD_ENDIAN_BIG:
7a107747 662 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
663 break;
664 case BFD_ENDIAN_LITTLE:
7a107747 665 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad
AC
666 break;
667 default:
668 break;
669 }
670 }
7a107747 671 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad 672 {
0e2de366 673 /* look for ``*el-*'' in the target name. */
1ba607ad
AC
674 const char *chp;
675 chp = strchr (target_name, '-');
676 if (chp != NULL
677 && chp - 2 >= target_name
61012eef 678 && startswith (chp - 2, "el"))
7a107747 679 default_byte_order = BFD_ENDIAN_LITTLE;
1ba607ad 680 }
7a107747 681 if (default_byte_order == BFD_ENDIAN_UNKNOWN)
1ba607ad
AC
682 {
683 /* Wire it to big-endian!!! */
7a107747 684 default_byte_order = BFD_ENDIAN_BIG;
1ba607ad
AC
685 }
686
7a107747 687 info.byte_order = default_byte_order;
9d4fde75 688 info.byte_order_for_code = info.byte_order;
7a107747 689
d90cf509
AC
690 if (! gdbarch_update_p (info))
691 internal_error (__FILE__, __LINE__,
edefbb7c
AC
692 _("initialize_current_architecture: Selection of "
693 "initial architecture failed"));
b4a20239 694
1ba607ad 695 /* Create the ``set architecture'' command appending ``auto'' to the
0e2de366 696 list of architectures. */
b4a20239 697 {
0e2de366 698 /* Append ``auto''. */
b4a20239
AC
699 int nr;
700 for (nr = 0; arches[nr] != NULL; nr++);
224c3ddb 701 arches = XRESIZEVEC (const char *, arches, nr + 2);
b4a20239
AC
702 arches[nr + 0] = "auto";
703 arches[nr + 1] = NULL;
7ab04401 704 add_setshow_enum_cmd ("architecture", class_support,
3e43a32a
MS
705 arches, &set_architecture_string,
706 _("Set architecture of target."),
707 _("Show architecture of target."), NULL,
7ab04401
AC
708 set_architecture, show_architecture,
709 &setlist, &showlist);
b4a20239 710 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
b4a20239
AC
711 }
712}
713
714
fb6ecb0f
AC
715/* Initialize a gdbarch info to values that will be automatically
716 overridden. Note: Originally, this ``struct info'' was initialized
ce2826aa 717 using memset(0). Unfortunately, that ran into problems, namely
fb6ecb0f
AC
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));
428721aa 725 info->byte_order = BFD_ENDIAN_UNKNOWN;
9d4fde75 726 info->byte_order_for_code = info->byte_order;
fb6ecb0f
AC
727}
728
100bcc3f 729/* Similar to init, but this time fill in the blanks. Information is
7a107747
DJ
730 obtained from the global "set ..." options and explicitly
731 initialized INFO fields. */
bf922ad9
AC
732
733void
7a107747 734gdbarch_info_fill (struct gdbarch_info *info)
bf922ad9
AC
735{
736 /* "(gdb) set architecture ...". */
737 if (info->bfd_arch_info == NULL
7a107747
DJ
738 && target_architecture_user)
739 info->bfd_arch_info = target_architecture_user;
424163ea 740 /* From the file. */
bf922ad9
AC
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);
23181151
DJ
746 /* From the target. */
747 if (info->target_desc != NULL)
748 info->bfd_arch_info = choose_architecture_for_target
e35359c5 749 (info->target_desc, info->bfd_arch_info);
7a107747
DJ
750 /* From the default. */
751 if (info->bfd_arch_info == NULL)
752 info->bfd_arch_info = default_bfd_arch;
bf922ad9
AC
753
754 /* "(gdb) set byte-order ...". */
755 if (info->byte_order == BFD_ENDIAN_UNKNOWN
7a107747
DJ
756 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
757 info->byte_order = target_byte_order_user;
bf922ad9
AC
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
7a107747
DJ
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;
9d4fde75 767 info->byte_order_for_code = info->byte_order;
4b2dfa9d
MR
768 /* Wire the default to the last selected byte order. */
769 default_byte_order = info->byte_order;
bf922ad9
AC
770
771 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
08d16641 772 /* From the manual override, or from file. */
26540402 773 if (info->osabi == GDB_OSABI_UNKNOWN)
bf922ad9 774 info->osabi = gdbarch_lookup_osabi (info->abfd);
08d16641 775 /* From the target. */
26540402 776
08d16641
PA
777 if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
778 info->osabi = tdesc_osabi (info->target_desc);
779 /* From the configured default. */
f4290e2a 780#ifdef GDB_OSABI_DEFAULT
08d16641
PA
781 if (info->osabi == GDB_OSABI_UNKNOWN)
782 info->osabi = GDB_OSABI_DEFAULT;
f4290e2a 783#endif
26540402
SM
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;
bf922ad9
AC
787
788 /* Must have at least filled in the architecture. */
789 gdb_assert (info->bfd_arch_info != NULL);
790}
791
0e2de366
MS
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.
e17c207e 795
0e2de366
MS
796 This function should normally be called solely by the command
797 interpreter routines to determine the architecture to execute a
798 command in. */
e17c207e
UW
799struct gdbarch *
800get_current_arch (void)
801{
802 if (has_stack_frames ())
803 return get_frame_arch (get_selected_frame (NULL));
804 else
f5656ead 805 return target_gdbarch ();
e17c207e
UW
806}
807
6c95b8df
PA
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
7a697b8d 816int
6b940e6a 817default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
281d762b 818 std::string *msg)
7a697b8d
SS
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)
281d762b 823 msg->clear ();
7a697b8d
SS
824 return 1;
825}
826
22f13eb8
YQ
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}
833b7ab5
YQ
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
22f13eb8 843
6710bf39
SS
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
18648a37
YQ
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
c2170eef
MM
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
ae9bb220
PA
877void
878default_skip_permanent_breakpoint (struct regcache *regcache)
879{
ac7936df 880 struct gdbarch *gdbarch = regcache->arch ();
ae9bb220 881 CORE_ADDR current_pc = regcache_read_pc (regcache);
ae9bb220
PA
882 int bp_len;
883
ac298888 884 gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
ae9bb220
PA
885 current_pc += bp_len;
886 regcache_write_pc (regcache, current_pc);
887}
c0e8c252 888
f208eee0
JK
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
7f361056
JK
895void
896default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
897{
898 /* Memory reserved by inferior mmap is kept leaked. */
899}
900
f208eee0
JK
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
ac04f72b
TT
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
3374165f
SM
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
5f034a78
MK
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);
73e1c03f 948 regcache->raw_supply (pc_regno, regs);
5f034a78
MK
949}
950
39503f82
YQ
951int
952default_print_insn (bfd_vma memaddr, disassemble_info *info)
953{
954 disassembler_ftype disassemble_fn;
955
39503f82
YQ
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
46a62268
YQ
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
1d509aa6
MM
981/* See arch-utils.h. */
982
983bool
984default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
985{
986 return false;
987}
988
2b4424c3
TT
989/* See arch-utils.h. */
990
991ULONGEST
992default_type_align (struct gdbarch *gdbarch, struct type *type)
993{
5561fc30 994 return 0;
2b4424c3
TT
995}
996
c0e8c252 997void
b4a20239 998_initialize_gdbarch_utils (void)
c0e8c252 999{
7ab04401 1000 add_setshow_enum_cmd ("endian", class_support,
3e43a32a
MS
1001 endian_enum, &set_endian_string,
1002 _("Set endianness of target."),
1003 _("Show endianness of target."),
1004 NULL, set_endian, show_endian,
7ab04401 1005 &setlist, &showlist);
c0e8c252 1006}
This page took 1.138067 seconds and 4 git commands to generate.