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