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