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