Target FP: Use target format throughout expression parsing
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
CommitLineData
c0e8c252 1/* Dynamic architecture support for GDB, the GNU debugger.
f4f9705a 2
61baf725 3 Copyright (C) 1998-2017 Free Software Foundation, Inc.
c0e8c252
AC
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c0e8c252
AC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c0e8c252
AC
19
20#include "defs.h"
21
fb6ecb0f 22#include "arch-utils.h"
192cb3d4 23#include "buildsym.h"
c0e8c252 24#include "gdbcmd.h"
0e2de366 25#include "inferior.h" /* enum CALL_DUMMY_LOCATION et al. */
45741a9c 26#include "infrun.h"
fbec36e2 27#include "regcache.h"
4182591f 28#include "sim-regno.h"
750eb019 29#include "gdbcore.h"
bf922ad9 30#include "osabi.h"
424163ea 31#include "target-descriptions.h"
237fc4c9 32#include "objfiles.h"
18648a37 33#include "language.h"
3e29f34a 34#include "symtab.h"
bf922ad9 35
1ba607ad
AC
36#include "version.h"
37
f0d4cc9e
AC
38#include "floatformat.h"
39
39503f82 40#include "dis-asm.h"
1fd35568 41
99e40580
UW
42int
43default_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
44 struct displaced_step_closure *closure)
45{
46 return !gdbarch_software_single_step_p (gdbarch);
47}
237fc4c9
PA
48
49CORE_ADDR
50displaced_step_at_entry_point (struct gdbarch *gdbarch)
51{
52 CORE_ADDR addr;
53 int bp_len;
54
55 addr = entry_point_address ();
56
237fc4c9
PA
57 /* Inferior calls also use the entry point as a breakpoint location.
58 We don't want displaced stepping to interfere with those
59 breakpoints, so leave space. */
60 gdbarch_breakpoint_from_pc (gdbarch, &addr, &bp_len);
5931a2fa 61 addr += bp_len * 2;
237fc4c9
PA
62
63 return addr;
64}
65
4182591f 66int
e7faf938 67legacy_register_sim_regno (struct gdbarch *gdbarch, int regnum)
4182591f
AC
68{
69 /* Only makes sense to supply raw registers. */
e7faf938 70 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
4182591f
AC
71 /* NOTE: cagney/2002-05-13: The old code did it this way and it is
72 suspected that some GDB/SIM combinations may rely on this
73 behavour. The default should be one2one_register_sim_regno
74 (below). */
e7faf938
MD
75 if (gdbarch_register_name (gdbarch, regnum) != NULL
76 && gdbarch_register_name (gdbarch, regnum)[0] != '\0')
4182591f
AC
77 return regnum;
78 else
79 return LEGACY_SIM_REGNO_IGNORE;
80}
81
bdcd319a 82CORE_ADDR
52f729a7 83generic_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
bdcd319a
CV
84{
85 return 0;
86}
87
dea0c52f 88CORE_ADDR
4c8c40e6 89generic_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
dea0c52f
MK
90{
91 return 0;
92}
93
d50355b6 94int
e17a4113 95generic_in_solib_return_trampoline (struct gdbarch *gdbarch,
2c02bd72 96 CORE_ADDR pc, const char *name)
d50355b6
MS
97{
98 return 0;
99}
100
c12260ac 101int
c9cf6e20 102generic_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
c12260ac
CV
103{
104 return 0;
105}
106
7eb89530
YQ
107int
108default_code_of_frame_writable (struct gdbarch *gdbarch,
109 struct frame_info *frame)
110{
111 return 1;
112}
113
4d1e7dd1 114/* Helper functions for gdbarch_inner_than */
3339cf8b
AC
115
116int
fba45db2 117core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
118{
119 return (lhs < rhs);
120}
121
122int
fba45db2 123core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
3339cf8b
AC
124{
125 return (lhs > rhs);
126}
127
0e2de366 128/* Misc helper functions for targets. */
193e3b1a 129
f517ea4e 130CORE_ADDR
24568a2c 131core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
f517ea4e
PS
132{
133 return addr;
134}
135
e2d0e7eb
AC
136CORE_ADDR
137convert_from_func_ptr_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr,
138 struct target_ops *targ)
139{
140 return addr;
141}
142
88c72b7d 143int
d3f73121 144no_op_reg_to_regnum (struct gdbarch *gdbarch, int reg)
88c72b7d
AC
145{
146 return reg;
147}
148
a2cf933a 149void
3e29f34a 150default_coff_make_msymbol_special (int val, struct minimal_symbol *msym)
a2cf933a
EZ
151{
152 return;
153}
154
3e29f34a
MR
155/* See arch-utils.h. */
156
a2cf933a 157void
3e29f34a 158default_make_symbol_special (struct symbol *sym, struct objfile *objfile)
a2cf933a
EZ
159{
160 return;
161}
162
3e29f34a
MR
163/* See arch-utils.h. */
164
165CORE_ADDR
166default_adjust_dwarf2_addr (CORE_ADDR pc)
167{
168 return pc;
169}
170
171/* See arch-utils.h. */
172
173CORE_ADDR
174default_adjust_dwarf2_line (CORE_ADDR addr, int rel)
175{
176 return addr;
177}
178
b41c5a85
JW
179/* See arch-utils.h. */
180
181bool
182default_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
183 struct dwarf2_frame_state *fs)
184{
185 return false;
186}
187
01fb7433 188int
64a3914f 189cannot_register_not (struct gdbarch *gdbarch, int regnum)
01fb7433
AC
190{
191 return 0;
192}
39d4ef09
AC
193
194/* Legacy version of target_virtual_frame_pointer(). Assumes that
0e2de366
MS
195 there is an gdbarch_deprecated_fp_regnum and that it is the same,
196 cooked or raw. */
39d4ef09
AC
197
198void
a54fba4c
MD
199legacy_virtual_frame_pointer (struct gdbarch *gdbarch,
200 CORE_ADDR pc,
39d4ef09
AC
201 int *frame_regnum,
202 LONGEST *frame_offset)
203{
20bcf01c
AC
204 /* FIXME: cagney/2002-09-13: This code is used when identifying the
205 frame pointer of the current PC. It is assuming that a single
206 register and an offset can determine this. I think it should
207 instead generate a byte code expression as that would work better
208 with things like Dwarf2's CFI. */
a54fba4c
MD
209 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0
210 && gdbarch_deprecated_fp_regnum (gdbarch)
211 < gdbarch_num_regs (gdbarch))
212 *frame_regnum = gdbarch_deprecated_fp_regnum (gdbarch);
213 else if (gdbarch_sp_regnum (gdbarch) >= 0
214 && gdbarch_sp_regnum (gdbarch)
215 < gdbarch_num_regs (gdbarch))
216 *frame_regnum = gdbarch_sp_regnum (gdbarch);
20bcf01c
AC
217 else
218 /* Should this be an internal error? I guess so, it is reflecting
219 an architectural limitation in the current design. */
0e2de366
MS
220 internal_error (__FILE__, __LINE__,
221 _("No virtual frame pointer available"));
39d4ef09
AC
222 *frame_offset = 0;
223}
46cd78fb 224
9b790ce7
UW
225/* Return a floating-point format for a floating-point variable of
226 length LEN in bits. If non-NULL, NAME is the name of its type.
227 If no suitable type is found, return NULL. */
228
229const struct floatformat **
230default_floatformat_for_type (struct gdbarch *gdbarch,
231 const char *name, int len)
232{
233 const struct floatformat **format = NULL;
234
235 if (len == gdbarch_half_bit (gdbarch))
236 format = gdbarch_half_format (gdbarch);
237 else if (len == gdbarch_float_bit (gdbarch))
238 format = gdbarch_float_format (gdbarch);
239 else if (len == gdbarch_double_bit (gdbarch))
240 format = gdbarch_double_format (gdbarch);
241 else if (len == gdbarch_long_double_bit (gdbarch))
242 format = gdbarch_long_double_format (gdbarch);
243 /* On i386 the 'long double' type takes 96 bits,
244 while the real number of used bits is only 80,
245 both in processor and in memory.
246 The code below accepts the real bit size. */
247 else if (gdbarch_long_double_format (gdbarch) != NULL
248 && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
249 format = gdbarch_long_double_format (gdbarch);
250
251 return format;
252}
d7bd68ca 253\f
13d01224 254int
76a8ddb9
UW
255generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
256 struct type *type)
13d01224 257{
9730f241 258 return 0;
13d01224
AC
259}
260
192cb3d4
MK
261int
262default_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
263{
192cb3d4
MK
264 return 0;
265}
266
3ca64954
RC
267int
268generic_instruction_nullified (struct gdbarch *gdbarch,
269 struct regcache *regcache)
270{
271 return 0;
272}
273
123dc839
DJ
274int
275default_remote_register_number (struct gdbarch *gdbarch,
276 int regno)
277{
278 return regno;
279}
280
3437254d
PA
281/* See arch-utils.h. */
282
283int
284default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range)
285{
286 return 0;
287}
288
01fb7433 289\f
b4a20239
AC
290/* Functions to manipulate the endianness of the target. */
291
f486487f 292static enum bfd_endian target_byte_order_user = BFD_ENDIAN_UNKNOWN;
b4a20239 293
53904c9e
AC
294static const char endian_big[] = "big";
295static const char endian_little[] = "little";
296static const char endian_auto[] = "auto";
40478521 297static const char *const endian_enum[] =
b4a20239
AC
298{
299 endian_big,
300 endian_little,
301 endian_auto,
302 NULL,
303};
53904c9e 304static const char *set_endian_string;
b4a20239 305
b6d373df
DJ
306enum bfd_endian
307selected_byte_order (void)
308{
e17c207e 309 return target_byte_order_user;
b6d373df
DJ
310}
311
b4a20239
AC
312/* Called by ``show endian''. */
313
314static void
7ab04401
AC
315show_endian (struct ui_file *file, int from_tty, struct cmd_list_element *c,
316 const char *value)
b4a20239 317{
7b6b9e83 318 if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
e17c207e 319 if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
7ab04401
AC
320 fprintf_unfiltered (file, _("The target endianness is set automatically "
321 "(currently big endian)\n"));
edefbb7c 322 else
7ab04401 323 fprintf_unfiltered (file, _("The target endianness is set automatically "
3e43a32a 324 "(currently little endian)\n"));
b4a20239 325 else
e17c207e 326 if (target_byte_order_user == BFD_ENDIAN_BIG)
7ab04401
AC
327 fprintf_unfiltered (file,
328 _("The target is assumed to be big endian\n"));
329 else
330 fprintf_unfiltered (file,
331 _("The target is assumed to be little endian\n"));
b4a20239
AC
332}
333
334static void
335set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
336{
7a107747
DJ
337 struct gdbarch_info info;
338
339 gdbarch_info_init (&info);
340
3fd3d7d2 341 if (set_endian_string == endian_auto)
b4a20239 342 {
7a107747
DJ
343 target_byte_order_user = BFD_ENDIAN_UNKNOWN;
344 if (! gdbarch_update_p (info))
345 internal_error (__FILE__, __LINE__,
346 _("set_endian: architecture update failed"));
b4a20239
AC
347 }
348 else if (set_endian_string == endian_little)
349 {
d90cf509
AC
350 info.byte_order = BFD_ENDIAN_LITTLE;
351 if (! gdbarch_update_p (info))
edefbb7c 352 printf_unfiltered (_("Little endian target not supported by GDB\n"));
7a107747
DJ
353 else
354 target_byte_order_user = BFD_ENDIAN_LITTLE;
b4a20239
AC
355 }
356 else if (set_endian_string == endian_big)
357 {
d90cf509
AC
358 info.byte_order = BFD_ENDIAN_BIG;
359 if (! gdbarch_update_p (info))
edefbb7c 360 printf_unfiltered (_("Big endian target not supported by GDB\n"));
7a107747
DJ
361 else
362 target_byte_order_user = BFD_ENDIAN_BIG;
b4a20239
AC
363 }
364 else
8e65ff28 365 internal_error (__FILE__, __LINE__,
edefbb7c 366 _("set_endian: bad value"));
7a107747 367
7ab04401 368 show_endian (gdb_stdout, from_tty, NULL, NULL);
b4a20239
AC
369}
370
23181151 371/* Given SELECTED, a currently selected BFD architecture, and
e35359c5
UW
372 TARGET_DESC, the current target description, return what
373 architecture to use.
374
375 SELECTED may be NULL, in which case we return the architecture
376 associated with TARGET_DESC. If SELECTED specifies a variant
377 of the architecture associtated with TARGET_DESC, return the
378 more specific of the two.
379
380 If SELECTED is a different architecture, but it is accepted as
381 compatible by the target, we can use the target architecture.
382
383 If SELECTED is obviously incompatible, warn the user. */
23181151
DJ
384
385static const struct bfd_arch_info *
e35359c5
UW
386choose_architecture_for_target (const struct target_desc *target_desc,
387 const struct bfd_arch_info *selected)
23181151 388{
e35359c5 389 const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
23181151
DJ
390 const struct bfd_arch_info *compat1, *compat2;
391
392 if (selected == NULL)
393 return from_target;
394
395 if (from_target == NULL)
396 return selected;
397
398 /* struct bfd_arch_info objects are singletons: that is, there's
399 supposed to be exactly one instance for a given machine. So you
400 can tell whether two are equivalent by comparing pointers. */
401 if (from_target == selected)
402 return selected;
403
404 /* BFD's 'A->compatible (A, B)' functions return zero if A and B are
405 incompatible. But if they are compatible, it returns the 'more
406 featureful' of the two arches. That is, if A can run code
407 written for B, but B can't run code written for A, then it'll
408 return A.
409
410 Some targets (e.g. MIPS as of 2006-12-04) don't fully
411 implement this, instead always returning NULL or the first
412 argument. We detect that case by checking both directions. */
413
414 compat1 = selected->compatible (selected, from_target);
415 compat2 = from_target->compatible (from_target, selected);
416
417 if (compat1 == NULL && compat2 == NULL)
418 {
0e2de366
MS
419 /* BFD considers the architectures incompatible. Check our
420 target description whether it accepts SELECTED as compatible
421 anyway. */
e35359c5
UW
422 if (tdesc_compatible_p (target_desc, selected))
423 return from_target;
424
23181151
DJ
425 warning (_("Selected architecture %s is not compatible "
426 "with reported target architecture %s"),
427 selected->printable_name, from_target->printable_name);
428 return selected;
429 }
430
431 if (compat1 == NULL)
432 return compat2;
433 if (compat2 == NULL)
434 return compat1;
435 if (compat1 == compat2)
436 return compat1;
437
0e2de366
MS
438 /* If the two didn't match, but one of them was a default
439 architecture, assume the more specific one is correct. This
440 handles the case where an executable or target description just
441 says "mips", but the other knows which MIPS variant. */
23181151
DJ
442 if (compat1->the_default)
443 return compat2;
444 if (compat2->the_default)
445 return compat1;
446
447 /* We have no idea which one is better. This is a bug, but not
448 a critical problem; warn the user. */
449 warning (_("Selected architecture %s is ambiguous with "
450 "reported target architecture %s"),
451 selected->printable_name, from_target->printable_name);
452 return selected;
453}
454
0e2de366 455/* Functions to manipulate the architecture of the target. */
b4a20239
AC
456
457enum set_arch { set_arch_auto, set_arch_manual };
458
7a107747 459static const struct bfd_arch_info *target_architecture_user;
b4a20239 460
a8cf2722
AC
461static const char *set_architecture_string;
462
463const char *
464selected_architecture_name (void)
465{
7a107747 466 if (target_architecture_user == NULL)
a8cf2722
AC
467 return NULL;
468 else
469 return set_architecture_string;
470}
b4a20239 471
b4a20239 472/* Called if the user enters ``show architecture'' without an
0e2de366 473 argument. */
b4a20239
AC
474
475static void
7ab04401
AC
476show_architecture (struct ui_file *file, int from_tty,
477 struct cmd_list_element *c, const char *value)
b4a20239 478{
7a107747 479 if (target_architecture_user == NULL)
3e43a32a
MS
480 fprintf_filtered (file, _("The target architecture is set "
481 "automatically (currently %s)\n"),
482 gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
b4a20239 483 else
3e43a32a
MS
484 fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
485 set_architecture_string);
b4a20239
AC
486}
487
488
489/* Called if the user enters ``set architecture'' with or without an
0e2de366 490 argument. */
b4a20239
AC
491
492static void
493set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
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;
4be87837 729 info->osabi = GDB_OSABI_UNINITIALIZED;
fb6ecb0f
AC
730}
731
100bcc3f 732/* Similar to init, but this time fill in the blanks. Information is
7a107747
DJ
733 obtained from the global "set ..." options and explicitly
734 initialized INFO fields. */
bf922ad9
AC
735
736void
7a107747 737gdbarch_info_fill (struct gdbarch_info *info)
bf922ad9
AC
738{
739 /* "(gdb) set architecture ...". */
740 if (info->bfd_arch_info == NULL
7a107747
DJ
741 && target_architecture_user)
742 info->bfd_arch_info = target_architecture_user;
424163ea 743 /* From the file. */
bf922ad9
AC
744 if (info->bfd_arch_info == NULL
745 && info->abfd != NULL
746 && bfd_get_arch (info->abfd) != bfd_arch_unknown
747 && bfd_get_arch (info->abfd) != bfd_arch_obscure)
748 info->bfd_arch_info = bfd_get_arch_info (info->abfd);
23181151
DJ
749 /* From the target. */
750 if (info->target_desc != NULL)
751 info->bfd_arch_info = choose_architecture_for_target
e35359c5 752 (info->target_desc, info->bfd_arch_info);
7a107747
DJ
753 /* From the default. */
754 if (info->bfd_arch_info == NULL)
755 info->bfd_arch_info = default_bfd_arch;
bf922ad9
AC
756
757 /* "(gdb) set byte-order ...". */
758 if (info->byte_order == BFD_ENDIAN_UNKNOWN
7a107747
DJ
759 && target_byte_order_user != BFD_ENDIAN_UNKNOWN)
760 info->byte_order = target_byte_order_user;
bf922ad9
AC
761 /* From the INFO struct. */
762 if (info->byte_order == BFD_ENDIAN_UNKNOWN
763 && info->abfd != NULL)
764 info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
7a107747
DJ
765 : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
766 : BFD_ENDIAN_UNKNOWN);
767 /* From the default. */
768 if (info->byte_order == BFD_ENDIAN_UNKNOWN)
769 info->byte_order = default_byte_order;
9d4fde75 770 info->byte_order_for_code = info->byte_order;
bf922ad9
AC
771
772 /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */
08d16641 773 /* From the manual override, or from file. */
bf922ad9
AC
774 if (info->osabi == GDB_OSABI_UNINITIALIZED)
775 info->osabi = gdbarch_lookup_osabi (info->abfd);
08d16641
PA
776 /* From the target. */
777 if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL)
778 info->osabi = tdesc_osabi (info->target_desc);
779 /* From the configured default. */
f4290e2a 780#ifdef GDB_OSABI_DEFAULT
08d16641
PA
781 if (info->osabi == GDB_OSABI_UNKNOWN)
782 info->osabi = GDB_OSABI_DEFAULT;
f4290e2a 783#endif
bf922ad9
AC
784
785 /* Must have at least filled in the architecture. */
786 gdb_assert (info->bfd_arch_info != NULL);
787}
788
0e2de366
MS
789/* Return "current" architecture. If the target is running, this is
790 the architecture of the selected frame. Otherwise, the "current"
791 architecture defaults to the target architecture.
e17c207e 792
0e2de366
MS
793 This function should normally be called solely by the command
794 interpreter routines to determine the architecture to execute a
795 command in. */
e17c207e
UW
796struct gdbarch *
797get_current_arch (void)
798{
799 if (has_stack_frames ())
800 return get_frame_arch (get_selected_frame (NULL));
801 else
f5656ead 802 return target_gdbarch ();
e17c207e
UW
803}
804
6c95b8df
PA
805int
806default_has_shared_address_space (struct gdbarch *gdbarch)
807{
808 /* Simply say no. In most unix-like targets each inferior/process
809 has its own address space. */
810 return 0;
811}
812
7a697b8d 813int
6b940e6a
PL
814default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
815 char **msg)
7a697b8d
SS
816{
817 /* We don't know if maybe the target has some way to do fast
818 tracepoints that doesn't need gdbarch, so always say yes. */
819 if (msg)
820 *msg = NULL;
821 return 1;
822}
823
22f13eb8
YQ
824const gdb_byte *
825default_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
826 int *lenptr)
827{
828 int kind = gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
829
830 return gdbarch_sw_breakpoint_from_kind (gdbarch, kind, lenptr);
831}
833b7ab5
YQ
832int
833default_breakpoint_kind_from_current_state (struct gdbarch *gdbarch,
834 struct regcache *regcache,
835 CORE_ADDR *pcptr)
836{
837 return gdbarch_breakpoint_kind_from_pc (gdbarch, pcptr);
838}
839
22f13eb8 840
6710bf39
SS
841void
842default_gen_return_address (struct gdbarch *gdbarch,
843 struct agent_expr *ax, struct axs_value *value,
844 CORE_ADDR scope)
845{
846 error (_("This architecture has no method to collect a return address."));
847}
848
18648a37
YQ
849int
850default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
851 struct type *type)
852{
853 /* Usually, the return value's address is stored the in the "first hidden"
854 parameter if the return value should be passed by reference, as
855 specified in ABI. */
856 return language_pass_by_reference (type);
857}
858
c2170eef
MM
859int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
860{
861 return 0;
862}
863
864int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
865{
866 return 0;
867}
868
869int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
870{
871 return 0;
872}
873
ae9bb220
PA
874void
875default_skip_permanent_breakpoint (struct regcache *regcache)
876{
877 struct gdbarch *gdbarch = get_regcache_arch (regcache);
878 CORE_ADDR current_pc = regcache_read_pc (regcache);
ae9bb220
PA
879 int bp_len;
880
ac298888 881 gdbarch_breakpoint_from_pc (gdbarch, &current_pc, &bp_len);
ae9bb220
PA
882 current_pc += bp_len;
883 regcache_write_pc (regcache, current_pc);
884}
c0e8c252 885
f208eee0
JK
886CORE_ADDR
887default_infcall_mmap (CORE_ADDR size, unsigned prot)
888{
889 error (_("This target does not support inferior memory allocation by mmap."));
890}
891
7f361056
JK
892void
893default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
894{
895 /* Memory reserved by inferior mmap is kept leaked. */
896}
897
f208eee0
JK
898/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
899 created in inferior memory by GDB (normally it is set by ld.so). */
900
901char *
902default_gcc_target_options (struct gdbarch *gdbarch)
903{
904 return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
905 gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
906}
907
ac04f72b
TT
908/* gdbarch gnu_triplet_regexp method. */
909
910const char *
911default_gnu_triplet_regexp (struct gdbarch *gdbarch)
912{
913 return gdbarch_bfd_arch_info (gdbarch)->arch_name;
914}
915
3374165f
SM
916/* Default method for gdbarch_addressable_memory_unit_size. By default, a memory byte has
917 a size of 1 octet. */
918
919int
920default_addressable_memory_unit_size (struct gdbarch *gdbarch)
921{
922 return 1;
923}
924
5f034a78
MK
925void
926default_guess_tracepoint_registers (struct gdbarch *gdbarch,
927 struct regcache *regcache,
928 CORE_ADDR addr)
929{
930 int pc_regno = gdbarch_pc_regnum (gdbarch);
931 gdb_byte *regs;
932
933 /* This guessing code below only works if the PC register isn't
934 a pseudo-register. The value of a pseudo-register isn't stored
935 in the (non-readonly) regcache -- instead it's recomputed
936 (probably from some other cached raw register) whenever the
937 register is read. In this case, a custom method implementation
938 should be used by the architecture. */
939 if (pc_regno < 0 || pc_regno >= gdbarch_num_regs (gdbarch))
940 return;
941
942 regs = (gdb_byte *) alloca (register_size (gdbarch, pc_regno));
943 store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
944 gdbarch_byte_order (gdbarch), addr);
945 regcache_raw_supply (regcache, pc_regno, regs);
946}
947
39503f82
YQ
948int
949default_print_insn (bfd_vma memaddr, disassemble_info *info)
950{
951 disassembler_ftype disassemble_fn;
952
39503f82
YQ
953 disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG,
954 info->mach, exec_bfd);
955
956 gdb_assert (disassemble_fn != NULL);
957 return (*disassemble_fn) (memaddr, info);
958}
959
46a62268
YQ
960/* See arch-utils.h. */
961
962CORE_ADDR
963gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
964{
965 CORE_ADDR new_pc = pc;
966
967 TRY
968 {
969 new_pc = gdbarch_skip_prologue (gdbarch, pc);
970 }
971 CATCH (ex, RETURN_MASK_ALL)
972 {}
973 END_CATCH
974
975 return new_pc;
976}
977
c0e8c252 978void
b4a20239 979_initialize_gdbarch_utils (void)
c0e8c252 980{
7ab04401 981 add_setshow_enum_cmd ("endian", class_support,
3e43a32a
MS
982 endian_enum, &set_endian_string,
983 _("Set endianness of target."),
984 _("Show endianness of target."),
985 NULL, set_endian, show_endian,
7ab04401 986 &setlist, &showlist);
c0e8c252 987}
This page took 1.531927 seconds and 4 git commands to generate.