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